Data races in TestBlockJob fields in test-block-iothread

Host environment

  • Operating system: Ubuntu Linux

Description of problem

A data race in the access of TestBlockJob fields in tests/unit/test-block-iothread.c was 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-block-iothread
MALLOC_PERTURB_=67 G_TEST_SRCDIR=$QEMU_BUILD_DIR/tests/unit G_TEST_BUILDDIR=$QEMU_BUILD_DIR/tests/unit $QEMU_BUILD_DIR/tests/unit/test-block-iothread --tap -k

Log

WARNING: ThreadSanitizer: data race (pid=1998572)
  Write of size 4 at 0x7b540000020c by thread T5:
    #0 test_job_run /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:516:13 (test-block-iothread+0x510e3b)
    #1 job_co_entry /home/mordan/qemu/build/../job.c:1106:11 (test-block-iothread+0x40fa99)
    #2 coroutine_trampoline /home/mordan/qemu/build/../util/coroutine-ucontext.c:175:9 (test-block-iothread+0xa67c58)
    #3 <null> stdlib/../sysdeps/unix/sysv/linux/x86_64/__start_context.S:90 (libc.so.6+0x5a12f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

  Previous read of size 4 at 0x7b540000020c by main thread:
    #0 test_attach_blockjob /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:573:18 (test-block-iothread+0x5114c6)
    #1 <null> <null> (libglib-2.0.so.0+0x7daed) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
    #2 __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 (libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

  Location is heap block of size 528 at 0x7b5400000000 allocated by main thread:
    #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-block-iothread+0x347377)
    #1 g_malloc0 <null> (libglib-2.0.so.0+0x5ec50) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
    #2 block_job_create /home/mordan/qemu/build/../blockjob.c:505:11 (test-block-iothread+0x40b954)
    #3 test_attach_blockjob /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:561:12 (test-block-iothread+0x511442)
    #4 <null> <null> (libglib-2.0.so.0+0x7daed) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
    #5 __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 (libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

  Thread T5 (tid=0, running) created by main thread at:
    #0 on_new_fiber /home/mordan/qemu/build/../util/coroutine-ucontext.c:91:25 (test-block-iothread+0xa67aed)
    #1 qemu_coroutine_new /home/mordan/qemu/build/../util/coroutine-ucontext.c:221:5 (test-block-iothread+0xa67aed)
    #2 qemu_coroutine_create /home/mordan/qemu/build/../util/qemu-coroutine.c:226:14 (test-block-iothread+0xa64d59)
    #3 bdrv_refresh_total_sectors /home/mordan/qemu/build/block/block-gen.c:1152:27 (test-block-iothread+0x4e22c6)
    #4 bdrv_open_driver /home/mordan/qemu/build/../block.c:1690:11 (test-block-iothread+0x3f8716)
    #5 bdrv_new_open_driver_opts /home/mordan/qemu/build/../block.c:1757:11 (test-block-iothread+0x3f8146)
    #6 bdrv_new_open_driver /home/mordan/qemu/build/../block.c:1775:12 (test-block-iothread+0x3f9228)
    #7 test_sync_op /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:477:10 (test-block-iothread+0x5112a0)
    #8 <null> <null> (libglib-2.0.so.0+0x7daed) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
    #9 __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 (libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

SUMMARY: ThreadSanitizer: data race /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:516:13 in test_job_run
==================
==================
WARNING: ThreadSanitizer: data race (pid=1998572)
  Read of size 4 at 0x7b540000020c by main thread:
    #0 test_attach_blockjob /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:587:18 (test-block-iothread+0x511556)
    #1 <null> <null> (libglib-2.0.so.0+0x7daed) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
    #2 __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 (libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

  Previous write of size 4 at 0x7b540000020c by thread T5:
    #0 test_job_run /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:516:13 (test-block-iothread+0x510e3b)
    #1 job_co_entry /home/mordan/qemu/build/../job.c:1106:11 (test-block-iothread+0x40fa99)
    #2 coroutine_trampoline /home/mordan/qemu/build/../util/coroutine-ucontext.c:175:9 (test-block-iothread+0xa67c58)
    #3 <null> stdlib/../sysdeps/unix/sysv/linux/x86_64/__start_context.S:90 (libc.so.6+0x5a12f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

  Location is heap block of size 528 at 0x7b5400000000 allocated by main thread:
    #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-block-iothread+0x347377)
    #1 g_malloc0 <null> (libglib-2.0.so.0+0x5ec50) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
    #2 block_job_create /home/mordan/qemu/build/../blockjob.c:505:11 (test-block-iothread+0x40b954)
    #3 test_attach_blockjob /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:561:12 (test-block-iothread+0x511442)
    #4 <null> <null> (libglib-2.0.so.0+0x7daed) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
    #5 __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 (libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

  Thread T5 (tid=0, running) created by main thread at:
    #0 on_new_fiber /home/mordan/qemu/build/../util/coroutine-ucontext.c:91:25 (test-block-iothread+0xa67aed)
    #1 qemu_coroutine_new /home/mordan/qemu/build/../util/coroutine-ucontext.c:221:5 (test-block-iothread+0xa67aed)
    #2 qemu_coroutine_create /home/mordan/qemu/build/../util/qemu-coroutine.c:226:14 (test-block-iothread+0xa64d59)
    #3 bdrv_refresh_total_sectors /home/mordan/qemu/build/block/block-gen.c:1152:27 (test-block-iothread+0x4e22c6)
    #4 bdrv_open_driver /home/mordan/qemu/build/../block.c:1690:11 (test-block-iothread+0x3f8716)
    #5 bdrv_new_open_driver_opts /home/mordan/qemu/build/../block.c:1757:11 (test-block-iothread+0x3f8146)
    #6 bdrv_new_open_driver /home/mordan/qemu/build/../block.c:1775:12 (test-block-iothread+0x3f9228)
    #7 test_sync_op /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:477:10 (test-block-iothread+0x5112a0)
    #8 <null> <null> (libglib-2.0.so.0+0x7daed) (BuildId: e845b8fd2f396872c036976626389ffc4f50c9c5)
    #9 __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 (libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)

SUMMARY: ThreadSanitizer: data race /home/mordan/qemu/build/../tests/unit/test-block-iothread.c:587:18 in test_attach_blockjob
Assignee Loading
Time tracking Loading