[compiler-rt] 7f10ed6 - [tsan] Fix dead lock when starting StackDepot thread (#96456)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 08:17:13 PDT 2024
Author: Vitaly Buka
Date: 2024-06-25T08:17:10-07:00
New Revision: 7f10ed637e53c68ce62b756a3be8546a3dccf751
URL: https://github.com/llvm/llvm-project/commit/7f10ed637e53c68ce62b756a3be8546a3dccf751
DIFF: https://github.com/llvm/llvm-project/commit/7f10ed637e53c68ce62b756a3be8546a3dccf751.diff
LOG: [tsan] Fix dead lock when starting StackDepot thread (#96456)
Sometime tsan runtimes calls, like
`__tsan_mutex_create ()`, need to store a stack
in the StackDepot, and the Depot may need to start
and maintenance thread.
Example:
```
__sanitizer::FutexWait ()
__sanitizer::Semaphore::Wait ()
__sanitizer::Mutex::Lock ()
__tsan::SlotLock ()
__tsan::SlotLocker::SlotLocker ()
__tsan::Acquire ()
__tsan::CallUserSignalHandler ()
__tsan::ProcessPendingSignalsImpl ()
__tsan::ProcessPendingSignals ()
__tsan::ScopedInterceptor::~ScopedInterceptor ()
___interceptor_mmap ()
pthread_create ()
__sanitizer::internal_start_thread ()
__sanitizer::(anonymous namespace)::CompressThread::NewWorkNotify ()
__sanitizer::StackDepotNode::store ()
__sanitizer::StackDepotBase<__sanitizer::StackDepotNode, 1, 20>::Put ()
__tsan::CurrentStackId ()
__tsan::MutexCreate ()
__tsan_mutex_create ()
```
pthread_create() implementation may hit other
interceptors recursively, which may invoke
ProcessPendingSignals, which deadlocks.
Alternative solution could be block interceptors
closer to TSAN runtime API function, like
`__tsan_mutex_create`, or just before
`StackDepotPut``, but it's not needed for most
calls, only when new thread is created using
`real_pthread_create`.
I don't see a reasonable way to create a
regression test.
Added:
Modified:
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index 94adea777cafd..151693112158b 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -1088,7 +1088,18 @@ TSAN_INTERCEPTOR(int, pthread_join, void *th, void **ret) {
return res;
}
-DEFINE_REAL_PTHREAD_FUNCTIONS
+// DEFINE_REAL_PTHREAD_FUNCTIONS
+namespace __sanitizer {
+int real_pthread_create(void *th, void *attr, void *(*callback)(void *),
+ void *param) {
+ ScopedIgnoreInterceptors ignore;
+ return REAL(pthread_create)(th, attr, callback, param);
+}
+int real_pthread_join(void *th, void **ret) {
+ ScopedIgnoreInterceptors ignore;
+ return REAL(pthread_join(th, ret));
+}
+} // namespace __sanitizer
TSAN_INTERCEPTOR(int, pthread_detach, void *th) {
SCOPED_INTERCEPTOR_RAW(pthread_detach, th);
More information about the llvm-commits
mailing list