aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Debugify.cpp
diff options
context:
space:
mode:
authorJulian Brown <julian.brown@amd.com>2025-02-10 04:20:01 -0600
committerJoachim Jenke <jenke@itc.rwth-aachen.de>2025-02-14 10:55:59 +0100
commit2fdf191e244b62409fd73fa9bb717466d6e683b5 (patch)
treea450d4a8904143f3c148f9017125e153545ec299 /llvm/lib/Transforms/Utils/Debugify.cpp
parent2ad1089d632bd356cb61fba1690c5dcdbc78ba83 (diff)
downloadllvm-2fdf191e244b62409fd73fa9bb717466d6e683b5.zip
llvm-2fdf191e244b62409fd73fa9bb717466d6e683b5.tar.gz
llvm-2fdf191e244b62409fd73fa9bb717466d6e683b5.tar.bz2
[OpenMP] Fix crash with task stealing and task dependencies (#126049)
This patch series demonstrates and fixes a bug that causes crashes with OpenMP 'taskwait' directives in heavily multi-threaded scenarios. TLDR: The early return from __kmpc_omp_taskwait_deps_51 missed the synchronization mechanism in place for the late return. Additional debug assertions check for the implied invariants of the code. @jpeyton52 found the timing hole as this sequence of events: > > 1. THREAD 1: A regular task with dependences is created, call it T1 > 2. THREAD 1: Call into `__kmpc_omp_taskwait_deps_51()` and create a stack based depnode (`NULL` task), call it T2 (stack) > 3. THREAD 2: Steals task T1 and executes it getting to `__kmp_release_deps()` region. > 4. THREAD 1: During processing of dependences for T2 (stack) (within `__kmp_check_deps()` region), a link is created T1 -> T2. This increases T2's (stack) `nrefs` count. > 5. THREAD 2: Iterates through the successors list: decrement the T2's (stack) npredecessor count. BUT HASN'T YET `__kmp_node_deref()`-ed it. > 6. THREAD 1: Now when finished with `__kmp_check_deps()`, it returns false because npredecessor count is 0, but T2's (stack) `nrefs` count is 2 because THREAD 2 still references it! > 7. THREAD 1: Because `__kmp_check_deps()` returns false, early exit. > _Now the stack based depnode is invalid, but THREAD 2 still references it._ > > We've reached improper stack referencing behavior. Varied results/crashes/ asserts can occur if THREAD 1 comes back and recreates the exact same depnode in the exact same stack address during the same time THREAD 2 calls `__kmp_node_deref()`.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Debugify.cpp')
0 files changed, 0 insertions, 0 deletions