Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential race in VulkanContext (TSAN finding) #77390

Open
rcorre opened this issue May 23, 2023 · 0 comments
Open

Potential race in VulkanContext (TSAN finding) #77390

rcorre opened this issue May 23, 2023 · 0 comments

Comments

@rcorre
Copy link
Contributor

rcorre commented May 23, 2023

Godot version

4.0.2

System information

Linux

Issue description

@clayjohn suggested that #71929 (comment) may be caused by a synchronization issue, so I tried running my example project under TSAN.

I ran into an issue running TSAN with nvidia drivers (google/sanitizers#1647), so I ended up using lavapipe instead, as suggested by @Calinou.

I did get a TSAN finding in VulkanContext::_initialize_queues. I'm not quite following the report. It seems that initialize_queues somehow creates two threads, though I'm not sure how, possibly because I'm missing symbols for libvulkan_lvp.so?
Feel free to close this if it is noise, but I figured it could be relevant since some error messages in #71929 (comment) mention the graphics queue.

One example

WARNING: ThreadSanitizer: data race (pid=22868)
Write of size 1 at 0x7b1c000637a8 by thread T15 (mutexes: write M0):
#0 pthread_mutex_destroy (godot.linuxbsd.editor.x86_64.llvm.san+0x561e81) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#1 (libvulkan_lvp.so+0x331972) (BuildId: cf1adadfe59188457be25f35e22287583767a044)

Previous atomic read of size 1 at 0x7b1c000637a8 by thread T22:
#0 pthread_mutex_lock (godot.linuxbsd.editor.x86_64.llvm.san+0x57d641) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#1 (libvulkan_lvp.so+0x235f76) (BuildId: cf1adadfe59188457be25f35e22287583767a044)

Location is heap block of size 112 at 0x7b1c000637a0 allocated by thread T15:
#0 calloc (godot.linuxbsd.editor.x86_64.llvm.san+0x55debb) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#1 (libvulkan_lvp.so+0x234f3b) (BuildId: cf1adadfe59188457be25f35e22287583767a044)

Mutex M0 (0x7b6000002258) created at:
#0 pthread_mutex_init (godot.linuxbsd.editor.x86_64.llvm.san+0x5754b8) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#1 (libvulkan_lvp.so+0x5b510) (BuildId: cf1adadfe59188457be25f35e22287583767a044)
#2 VulkanContext::_window_create(int, DisplayServer::VSyncMode, VkSurfaceKHR_T*, int, int) /home/rcorre/src/godot/godot/drivers/vulkan/vulkan_context.cpp:1680:15 (godot.linuxbsd.editor.x86_64.llvm.san+0x26ed88b) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#3 VulkanContextX11::window_create(int, DisplayServer::VSyncMode, unsigned long, _XDisplay*, int, int) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/vulkan_context_x11.cpp:56:9 (godot.linuxbsd.editor.x86_64.llvm.san+0x651922) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#4 DisplayServerX11::_create_window(DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Rect2i const&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:5144:32 (godot.linuxbsd.editor.x86_64.llvm.san+0x5fe032) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#5 DisplayServerX11::DisplayServerX11(String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:5551:25 (godot.linuxbsd.editor.x86_64.llvm.san+0x6175bb) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#6 DisplayServerX11::create_func(String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:4845:22 (godot.linuxbsd.editor.x86_64.llvm.san+0x615921) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#7 DisplayServer::create(int, String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/servers/display_server.cpp:904:9 (godot.linuxbsd.editor.x86_64.llvm.san+0x5c384f4) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#8 Main::setup2(unsigned long) /home/rcorre/src/godot/godot/main/main.cpp:2001:20 (godot.linuxbsd.editor.x86_64.llvm.san+0x689068) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#9 Main::setup(char const*, int, char**, bool) /home/rcorre/src/godot/godot/main/main.cpp:1879:10 (godot.linuxbsd.editor.x86_64.llvm.san+0x681b60) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#10 main /home/rcorre/src/godot/godot/platform/linuxbsd/godot_linuxbsd.cpp:61:14 (godot.linuxbsd.editor.x86_64.llvm.san+0x5d2bef) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)

Thread T15 (tid=22927, running) created by main thread at:
#0 pthread_create (godot.linuxbsd.editor.x86_64.llvm.san+0x550566) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#1 (libvulkan_lvp.so+0xcaab5) (BuildId: cf1adadfe59188457be25f35e22287583767a044)
#2 VulkanContext::_initialize_queues(VkSurfaceKHR_T*) /home/rcorre/src/godot/godot/drivers/vulkan/vulkan_context.cpp:1528:2 (godot.linuxbsd.editor.x86_64.llvm.san+0x26ec928) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#3 VulkanContext::_window_create(int, DisplayServer::VSyncMode, VkSurfaceKHR_T*, int, int) /home/rcorre/src/godot/godot/drivers/vulkan/vulkan_context.cpp:1688:15 (godot.linuxbsd.editor.x86_64.llvm.san+0x26ed8b3) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#4 VulkanContextX11::window_create(int, DisplayServer::VSyncMode, unsigned long, _XDisplay*, int, int) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/vulkan_context_x11.cpp:56:9 (godot.linuxbsd.editor.x86_64.llvm.san+0x651922) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#5 DisplayServerX11::_create_window(DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Rect2i const&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:5144:32 (godot.linuxbsd.editor.x86_64.llvm.san+0x5fe032) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#6 DisplayServerX11::DisplayServerX11(String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:5551:25 (godot.linuxbsd.editor.x86_64.llvm.san+0x6175bb) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#7 DisplayServerX11::create_func(String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:4845:22 (godot.linuxbsd.editor.x86_64.llvm.san+0x615921) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#8 DisplayServer::create(int, String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/servers/display_server.cpp:904:9 (godot.linuxbsd.editor.x86_64.llvm.san+0x5c384f4) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#9 Main::setup2(unsigned long) /home/rcorre/src/godot/godot/main/main.cpp:2001:20 (godot.linuxbsd.editor.x86_64.llvm.san+0x689068) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#10 Main::setup(char const*, int, char**, bool) /home/rcorre/src/godot/godot/main/main.cpp:1879:10 (godot.linuxbsd.editor.x86_64.llvm.san+0x681b60) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#11 main /home/rcorre/src/godot/godot/platform/linuxbsd/godot_linuxbsd.cpp:61:14 (godot.linuxbsd.editor.x86_64.llvm.san+0x5d2bef) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)

Thread T22 'llvmpipe-6' (tid=22934, running) created by main thread at:
#0 pthread_create (godot.linuxbsd.editor.x86_64.llvm.san+0x550566) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#1 (libvulkan_lvp.so+0x7042b) (BuildId: cf1adadfe59188457be25f35e22287583767a044)
#2 VulkanContext::_initialize_queues(VkSurfaceKHR_T*) /home/rcorre/src/godot/godot/drivers/vulkan/vulkan_context.cpp:1528:2 (godot.linuxbsd.editor.x86_64.llvm.san+0x26ec928) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#3 VulkanContext::_window_create(int, DisplayServer::VSyncMode, VkSurfaceKHR_T*, int, int) /home/rcorre/src/godot/godot/drivers/vulkan/vulkan_context.cpp:1688:15 (godot.linuxbsd.editor.x86_64.llvm.san+0x26ed8b3) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#4 VulkanContextX11::window_create(int, DisplayServer::VSyncMode, unsigned long, _XDisplay*, int, int) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/vulkan_context_x11.cpp:56:9 (godot.linuxbsd.editor.x86_64.llvm.san+0x651922) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#5 DisplayServerX11::_create_window(DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Rect2i const&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:5144:32 (godot.linuxbsd.editor.x86_64.llvm.san+0x5fe032) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#6 DisplayServerX11::DisplayServerX11(String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:5551:25 (godot.linuxbsd.editor.x86_64.llvm.san+0x6175bb) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#7 DisplayServerX11::create_func(String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/platform/linuxbsd/x11/display_server_x11.cpp:4845:22 (godot.linuxbsd.editor.x86_64.llvm.san+0x615921) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#8 DisplayServer::create(int, String const&, DisplayServer::WindowMode, DisplayServer::VSyncMode, unsigned int, Vector2i const*, Vector2i const&, int, Error&) /home/rcorre/src/godot/godot/servers/display_server.cpp:904:9 (godot.linuxbsd.editor.x86_64.llvm.san+0x5c384f4) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#9 Main::setup2(unsigned long) /home/rcorre/src/godot/godot/main/main.cpp:2001:20 (godot.linuxbsd.editor.x86_64.llvm.san+0x689068) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#10 Main::setup(char const*, int, char**, bool) /home/rcorre/src/godot/godot/main/main.cpp:1879:10 (godot.linuxbsd.editor.x86_64.llvm.san+0x681b60) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)
#11 main /home/rcorre/src/godot/godot/platform/linuxbsd/godot_linuxbsd.cpp:61:14 (godot.linuxbsd.editor.x86_64.llvm.san+0x5d2bef) (BuildId: 4d838840588e872acec3016b35eaee94aed07d07)

full report

Steps to reproduce

  1. Build godot with TSAN (scons debug_symbols=yes use_llvm=yes use_static_cpp=no target=editor use_tsan=yes
  2. Navigate to the example project
  3. Run LIBGL_ALWAYS_SOFTWARE=1 __GLX_VENDOR_LIBRARY_NAME=mesa VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.x86_64.json:/usr/share/vulkan/icd.d/lvp_icd.x86_64.json godot.linuxbsd.editor.x86_64.llvm.san Halls.tscn 2>&1 | tee /tmp/tsan.txt

Minimal reproduction project

https://github.com/godotengine/godot/files/11348650/example.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants