Data Race with slh_first Field in test-aio-multithread
Host environment
- Operating system: Ubuntu Linux
Description of problem
Potential data races in the QSLIST_INSERT_HEAD_ATOMIC macro were identified using TSAN.
Steps to reproduce
QEMU_BUILD_DIR=<path to the QEMU build directory>
QEMU_DIR=<path to the QEMU repository directory>
configure --enable-tsan --cc=clang --cxx=clang++ --enable-trace-backends=ust --enable-fdt=system --disable-slirp
make tests/unit/test-bdrv-drain
MALLOC_PERTURB_=102 G_TEST_SRCDIR=$QEMU_BUILD_DIR/tests/unit G_TEST_BUILDDIR=$QEMU_BUILD_DIR/tests/unit $QEMU_BUILD_DIR/tests/unit/test-aio-multithread --tap -k
Log
WARNING: ThreadSanitizer: data race (pid=1877528)
Read of size 8 at 0x7b4800020030 by main thread:
#0 aio_bh_enqueue /home/mordan/qemu/build/../util/async.c:93:9 (test-aio-multithread-smc+0xa5d627)
#1 aio_bh_schedule_oneshot_full /home/mordan/qemu/build/../util/async.c:139:5 (test-aio-multithread-smc+0xa5d627)
#2 ctx_run /home/mordan/qemu/build/../tests/unit/test-aio-multithread-smc.c:53:5 (test-aio-multithread-smc+0x50e72d)
#3 create_aio_contexts /home/mordan/qemu/build/../tests/unit/test-aio-multithread-smc.c:77:9 (test-aio-multithread-smc+0x50e72d)
#4 test_lifecycle /home/mordan/qemu/build/../tests/unit/test-aio-multithread-smc.c:103:5 (test-aio-multithread-smc+0x50e72d)
#5 main /home/mordan/qemu/build/../tests/unit/test-aio-multithread-smc.c:455:2 (test-aio-multithread-smc+0x50e529)
Previous atomic write of size 8 at 0x7b4800020030 by thread T4:
#0 aio_bh_poll /home/mordan/qemu/build/../util/async.c:186:5 (test-aio-multithread-smc+0xa5d99e)
#1 aio_poll /home/mordan/qemu/build/../util/aio-posix.c:722:17 (test-aio-multithread-smc+0xa430de)
#2 iothread_run /home/mordan/qemu/build/../tests/unit/iothread.c:71:9 (test-aio-multithread-smc+0x50ec79)
#3 qemu_thread_start /home/mordan/qemu/build/../util/qemu-thread-posix.c:541:9 (test-aio-multithread-smc+0xa48c80)
Location is heap block of size 352 at 0x7b480001ff80 allocated by thread T4:
#0 calloc out/lib/clangrt-x86_64-unknown-linux-gnu/./out/lib/clangrt-x86_64-unknown-linux-gnu/./toolchain/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:687:5 (test-aio-multithread-smc+0x346337)
#1 g_malloc0 <null> (libglib-2.0.so.0+0x5ec50) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
#2 iothread_run /home/mordan/qemu/build/../tests/unit/iothread.c:51:21 (test-aio-multithread-smc+0x50eb92)
#3 qemu_thread_start /home/mordan/qemu/build/../util/qemu-thread-posix.c:541:9 (test-aio-multithread-smc+0xa48c80)
Thread T4 (tid=1877533, running) created by main thread at:
#0 pthread_create out/lib/clangrt-x86_64-unknown-linux-gnu/./out/lib/clangrt-x86_64-unknown-linux-gnu/./toolchain/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1022:3 (test-aio-multithread-smc+0x34790d)
#1 qemu_thread_create /home/mordan/qemu/build/../util/qemu-thread-posix.c:581:11 (test-aio-multithread-smc+0xa48b10)
#2 iothread_new /home/mordan/qemu/build/../tests/unit/iothread.c:104:5 (test-aio-multithread-smc+0x50ea8f)
#3 create_aio_contexts /home/mordan/qemu/build/../tests/unit/test-aio-multithread-smc.c:71:22 (test-aio-multithread-smc+0x50e58a)
#4 test_lifecycle /home/mordan/qemu/build/../tests/unit/test-aio-multithread-smc.c:103:5 (test-aio-multithread-smc+0x50e58a)
#5 main /home/mordan/qemu/build/../tests/unit/test-aio-multithread-smc.c:455:2 (test-aio-multithread-smc+0x50e529)
SUMMARY: ThreadSanitizer: data race /home/mordan/qemu/build/../util/async.c:93:9 in aio_bh_enqueue