ThreadSanitizer: data races inside libvulkan_radeon.so
Description
While running my own test framework through the TSAN sanitizer (-fsanitize=thread
), I got a complaint about data races related to the vulkan driver.
I can reproduce similar outputs with other applications, such as the vkcube demo. But not all, for example a minimal vkCreateInstance
/vkDestroyInstance
doesn't trigger it, nor does vulkaninfo
. Given the string disk$1
in the trace, it might be related to shader compilation / shader caching.
I don't know if these are false positives or not, but I was recommended to open a bug report. Even if they are false positives, perhaps they can be worked around, allowing applications to use TSAN with mesa.
Log files (for system lockups / game freezes / crashes)
From my own test framework:
==================
WARNING: ThreadSanitizer: data race (pid=110368)
Write of size 1 at 0x7ffdae57e2e0 by main thread (mutexes: write M198):
#0 pthread_barrier_destroy <null> (libtsan.so.0+0x39dc8)
#1 util_barrier_destroy ../src/util/u_thread.h:262 (libvulkan_radeon.so+0x19776b)
#2 util_queue_finish ../src/util/u_queue.c:687 (libvulkan_radeon.so+0x19776b)
#3 main ../src/tests/vulkan.c:244 (test.vulkan.c+0x408095)
Previous read of size 1 at 0x7ffdae57e2e0 by thread T4:
#0 pthread_barrier_wait <null> (libtsan.so.0+0x4efca)
#1 util_queue_thread_func ../src/util/u_queue.c:308 (libvulkan_radeon.so+0x194624)
Location is stack of main thread.
Location is global '<null>' at 0x000000000000 ([stack]+0x00000001d2e0)
Mutex M198 (0x7f92b21150c0) created at:
#0 pthread_mutex_init <null> (libtsan.so.0+0x4d2d3)
#1 loader_platform_thread_create_mutex /usr/src/debug/vulkan-loader-1.2.165-1.1.x86_64/loader/vk_loader_platform.h:189 (libvulkan.so.1+0x164bb)
#2 loader_initialize /usr/src/debug/vulkan-loader-1.2.165-1.1.x86_64/loader/loader.c:2504 (libvulkan.so.1+0x164bb)
#3 loader_init_library /usr/src/debug/vulkan-loader-1.2.165-1.1.x86_64/loader/loader.c:7890 (libvulkan.so.1+0x164bb)
Thread T4 'test.vu:disk$3' (tid=110373, running) created by main thread at:
#0 pthread_create <null> (libtsan.so.0+0x5fdb5)
#1 thrd_create ../include/c11/threads_posix.h:289 (libvulkan_radeon.so+0xd575f)
#2 u_thread_create ../src/util/u_thread.h:91 (libvulkan_radeon.so+0xd575f)
#3 util_queue_create_thread ../src/util/u_queue.c:340 (libvulkan_radeon.so+0xd575f)
#4 util_queue_init ../src/util/u_queue.c:457 (libvulkan_radeon.so+0xd575f)
#5 disk_cache_create ../src/util/disk_cache.c:158 (libvulkan_radeon.so+0xd575f)
#6 radv_physical_device_try_create ../src/amd/vulkan/radv_device.c:407 (libvulkan_radeon.so+0xd575f)
#7 __libc_start_main ../csu/libc-start.c:332 (libc.so.6+0x27b24)
SUMMARY: ThreadSanitizer: data race (/usr/lib64/libtsan.so.0+0x39dc8) in __interceptor_pthread_barrier_destroy
==================
ThreadSanitizer: reported 1 warnings
1/1 vulkan.c FAIL 9.18s (exit status 66)
This data race gets printed during/after vkDestroyInstance
. (gdb doesn't like stepping into this call so I'm not sure where exactly)
With vkcube, I get a very similar output, so it appears to be the same issue:
==================
WARNING: ThreadSanitizer: data race (pid=34958)
Write of size 1 at 0x7ffe00ee34c0 by main thread (mutexes: write M9):
#0 pthread_barrier_destroy <null> (libtsan.so.0+0x39dc8)
#1 util_barrier_destroy ../src/util/u_thread.h:262 (libvulkan_radeon.so+0x19776b)
#2 util_queue_finish ../src/util/u_queue.c:687 (libvulkan_radeon.so+0x19776b)
#3 main <null> (vkcube+0x415a26)
Previous read of size 1 at 0x7ffe00ee34c0 by thread T3:
#0 pthread_barrier_wait <null> (libtsan.so.0+0x4efca)
#1 util_queue_thread_func ../src/util/u_queue.c:308 (libvulkan_radeon.so+0x194624)
Location is stack of main thread.
Location is global '<null>' at 0x000000000000 ([stack]+0x00000001e4c0)
Mutex M9 (0x7f9f742f2260) created at:
#0 pthread_mutex_init <null> (libtsan.so.0+0x4d2d3)
#1 loader_platform_thread_create_mutex /home/nand/dev/Vulkan-Tools/build/Vulkan-Loader/loader/vk_loader_platform.h:189 (libvulkan.so.1+0x16cea)
Thread T3 'vkcube:disk$2' (tid=34962, running) created by main thread at:
#0 pthread_create <null> (libtsan.so.0+0x5fdb5)
#1 thrd_create ../include/c11/threads_posix.h:289 (libvulkan_radeon.so+0xd575f)
#2 u_thread_create ../src/util/u_thread.h:91 (libvulkan_radeon.so+0xd575f)
#3 util_queue_create_thread ../src/util/u_queue.c:340 (libvulkan_radeon.so+0xd575f)
#4 util_queue_init ../src/util/u_queue.c:457 (libvulkan_radeon.so+0xd575f)
#5 disk_cache_create ../src/util/disk_cache.c:158 (libvulkan_radeon.so+0xd575f)
#6 radv_physical_device_try_create ../src/amd/vulkan/radv_device.c:407 (libvulkan_radeon.so+0xd575f)
#7 demo_init <null> (vkcube+0x41586c)
#8 main <null> (vkcube+0x4159db)
SUMMARY: ThreadSanitizer: data race (/usr/lib64/libtsan.so.0+0x39dc8) in __interceptor_pthread_barrier_destroy
==================
ThreadSanitizer: reported 1 warnings
Steps to reproduce
git clone https://github.com/KhronosGroup/Vulkan-Tools && cd Vulkan-Tools
mkdir build && cd build
../scripts/update_deps.py
cmake -C helper.cmake .. -DCMAKE_C_FLAGS="-fsanitize=thread"
make
./cube/vkcube
System information
System: Host: xor Kernel: 5.11.0-1-preempt x86_64 bits: 64 compiler: N/A Console: tty 10 wm: xmonad dm: SDDM
Distro: openSUSE Tumbleweed 20210220
CPU: Topology: 16-Core (2-Die) model: AMD Ryzen Threadripper 1950X bits: 64 type: MT MCP MCM arch: Zen rev: 1
L1 cache: 1536 KiB L2 cache: 8192 KiB L3 cache: 31.2 MiB
flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 217165
Speed: 3692 MHz min/max: 2200/3400 MHz Core speeds (MHz): 1: 3692 2: 2688 3: 2804 4: 2212 5: 3378 6: 3151 7: 2117
8: 2091 9: 3785 10: 1850 11: 1849 12: 1824 13: 2033 14: 2149 15: 2145 16: 1984 17: 1988 18: 3752 19: 1919 20: 1958
21: 2102 22: 3190 23: 3649 24: 1860 25: 2109 26: 1932 27: 2170 28: 2101 29: 2000 30: 1886 31: 3584 32: 1891
Graphics: Device-1: Advanced Micro Devices [AMD/ATI] Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT] vendor: Tul
driver: amdgpu v: kernel bus ID: 0a:00.0 chip ID: 1002:731f
Display: server: X.org 1.20.10 driver: amdgpu,ati unloaded: fbdev,modesetting,radeon,vesa
resolution: <xdpyinfo missing>
OpenGL: renderer: AMD Radeon RX 5700 XT (NAVI10 DRM 3.40.0 5.11.0-1-preempt LLVM 11.0.1) v: 4.6 Mesa 20.3.4
direct render: Yes