On 1/10/23 09:39, Alex Bennée wrote:
From: Emilio Cota<c...@braap.org>

Fixes this tsan crash, easy to reproduce with any large enough program:

$ tests/unit/test-qht
1..2
ThreadSanitizer: CHECK failed: sanitizer_deadlock_detector.h:67 "((n_all_locks_)) < 
(((sizeof(all_locks_with_contexts_)/sizeof((all_locks_with_contexts_)[0]))))" (0x40, 
0x40) (tid=1821568)
     #0 __tsan::CheckUnwind() 
../../../../src/libsanitizer/tsan/tsan_rtl.cpp:353 (libtsan.so.2+0x90034)
     #1 __sanitizer::CheckFailed(char const*, int, char const*, unsigned long 
long, unsigned long long) 
../../../../src/libsanitizer/sanitizer_common/sanitizer_termination.cpp:86 
(libtsan.so.2+0xca555)
     #2 __sanitizer::DeadlockDetectorTLS<__sanitizer::TwoLevelBitVector<1ul, 
__sanitizer::BasicBitVector<unsigned long> > >::addLock(unsigned long, unsigned long, 
unsigned int) ../../../../src/libsanitizer/sanitizer_common/sanitizer_deadlock_detector.h:67 
(libtsan.so.2+0xb3616)
     #3 __sanitizer::DeadlockDetectorTLS<__sanitizer::TwoLevelBitVector<1ul, 
__sanitizer::BasicBitVector<unsigned long> > >::addLock(unsigned long, unsigned long, 
unsigned int) ../../../../src/libsanitizer/sanitizer_common/sanitizer_deadlock_detector.h:59 
(libtsan.so.2+0xb3616)
     #4 __sanitizer::DeadlockDetector<__sanitizer::TwoLevelBitVector<1ul, 
__sanitizer::BasicBitVector<unsigned long> > 
>::onLockAfter(__sanitizer::DeadlockDetectorTLS<__sanitizer::TwoLevelBitVector<1ul, 
__sanitizer::BasicBitVector<unsigned long> > >*, unsigned long, unsigned int) 
../../../../src/libsanitizer/sanitizer_common/sanitizer_deadlock_detector.h:216 (libtsan.so.2+0xb3616)
     #5 __sanitizer::DD::MutexAfterLock(__sanitizer::DDCallback*, 
__sanitizer::DDMutex*, bool, bool) 
../../../../src/libsanitizer/sanitizer_common/sanitizer_deadlock_detector1.cpp:169
 (libtsan.so.2+0xb3616)
     #6 __tsan::MutexPostLock(__tsan::ThreadState*, unsigned long, unsigned 
long, unsigned int, int) 
../../../../src/libsanitizer/tsan/tsan_rtl_mutex.cpp:200 (libtsan.so.2+0xa3382)
     #7 __tsan_mutex_post_lock 
../../../../src/libsanitizer/tsan/tsan_interface_ann.cpp:384 
(libtsan.so.2+0x76bc3)
     #8 qemu_spin_lock /home/cota/src/qemu/include/qemu/thread.h:259 
(test-qht+0x44a97)
     #9 qht_map_lock_buckets ../util/qht.c:253 (test-qht+0x44a97)
     #10 do_qht_iter ../util/qht.c:809 (test-qht+0x45f33)
     #11 qht_iter ../util/qht.c:821 (test-qht+0x45f33)
     #12 iter_check ../tests/unit/test-qht.c:121 (test-qht+0xe473)
     #13 qht_do_test ../tests/unit/test-qht.c:202 (test-qht+0xe473)
     #14 qht_test ../tests/unit/test-qht.c:240 (test-qht+0xe7c1)
     #15 test_default ../tests/unit/test-qht.c:246 (test-qht+0xe828)
     #16 <null> <null> (libglib-2.0.so.0+0x7daed)
     #17 <null> <null> (libglib-2.0.so.0+0x7d80a)
     #18 <null> <null> (libglib-2.0.so.0+0x7d80a)
     #19 g_test_run_suite <null> (libglib-2.0.so.0+0x7dfe9)
     #20 g_test_run <null> (libglib-2.0.so.0+0x7e055)
     #21 main ../tests/unit/test-qht.c:259 (test-qht+0xd2c6)
     #22 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 
(libc.so.6+0x29d8f)
     #23 __libc_start_main_impl ../csu/libc-start.c:392 (libc.so.6+0x29e3f)
     #24 _start <null> (test-qht+0xdb44)

Signed-off-by: Emilio Cota<c...@braap.org>
Message-Id:<20230109224954.161672-5-c...@braap.org>
Signed-off-by: Alex Bennée<alex.ben...@linaro.org>
---
  util/qht.c | 101 +++++++++++++++++++++++++++++++++++++++++++++--------
  1 file changed, 87 insertions(+), 14 deletions(-)

Reviewed-by: Richard Henderson <richard.hender...@linaro.org>

r~

Reply via email to