vulkan/wsi: hangs on FreeBSD because DMA_BUF_IOCTL_{EXPORT,IMPORT}_SYNC_FILE fails with EBADF (not ENOTTY)
Regressed by 30b57f10. ENOTTY
vs. EBADF
maybe related to broken DMA_BUF_IOCTL_SYNC. CC @jekstrand @manu @unrelentingtech
$ cc --version
FreeBSD clang version 14.0.3 (https://github.com/llvm/llvm-project.git llvmorg-14.0.3-0-g1f9140064dfb)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin
$ pkg info -x drm
drm-510-kmod-5.10.113
libdrm-2.4.110,1
$ vkcube-wayland
Selected GPU 0: Intel(R) HD Graphics 530 (SKL GT2), type: IntegratedGpu
Assertion failed: (!err), function demo_draw, file Vulkan-Tools-1.3.216/cube/cube.c, line 1062.
$ vkmark --winsys wayland
=======================================================
vkmark 2017.08-29-gd872846
=======================================================
Vendor ID: 0x8086
Device ID: 0x1912
Device Name: Intel(R) HD Graphics 530 (SKL GT2)
Driver Version: 92278883
Device UUID: b6e7ec54100b39904ca468cdeaa87050
=======================================================
[vertex] device-local=true: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[vertex] device-local=false: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[texture] anisotropy=0: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[texture] anisotropy=16: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[shading] shading=gouraud:
^C
(lldb) bt
* thread #1, name = 'vkmark', stop reason = signal SIGSTOP
* frame #0: 0x0000000825d42aea libc.so.7`__sys_ppoll at _ppoll.S:4
frame #1: 0x0000000823d978cc libthr.so.3`__thr_ppoll(pfd=0x00000008203bdc20, nfds=1, timeout=0x00000008203bdc38, newsigmask=0x0000000000000000) at thr_syscalls.c:358:8
frame #2: 0x00000008304c992c libvulkan_intel.so`wsi_wl_swapchain_acquire_next_image(wsi_chain=0x0000000843304000, info=0x00000008203bdd60, image_index=0x00000008203bddbc) at wsi_common_wayland.c:1004:13
frame #3: 0x00000008304beb5f libvulkan_intel.so`wsi_common_acquire_next_image2(wsi=0x000000082857aae0, _device=0x00000008433de000, pAcquireInfo=0x00000008203bdd60, pImageIndex=0x00000008203bddbc) at wsi_common.c:927:22
frame #4: 0x00000008300906b1 libvulkan_intel.so`anv_AcquireNextImage2KHR(_device=0x00000008433de000, pAcquireInfo=0x00000008203bdd60, pImageIndex=0x00000008203bddbc) at anv_wsi.c:82:7
frame #5: 0x00000008304beadd libvulkan_intel.so`wsi_AcquireNextImageKHR(_device=0x00000008433de000, swapchain=0x0000000843304000, timeout=18446744073709551615, semaphore=0x00000008286b6fc0, fence=0x0000000000000000, pImageIndex=0x00000008203bddbc) at wsi_common.c:850:11
frame #6: 0x000000082be1e9ea wayland.so`SwapchainWindowSystem::next_vulkan_image() + 74
frame #7: 0x000000000025a1ef vkmark`MainLoop::run() + 431
[...]
$ vkmark --winsys xcb
=======================================================
vkmark 2017.08-29-gd872846
=======================================================
Vendor ID: 0x8086
Device ID: 0x1912
Device Name: Intel(R) HD Graphics 530 (SKL GT2)
Driver Version: 92278883
Device UUID: b6e7ec54100b39904ca468cdeaa87050
=======================================================
[vertex] device-local=true: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[vertex] device-local=false: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[texture] anisotropy=0: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[texture] anisotropy=16: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[shading] shading=gouraud: Failed with exception: vk::Device::acquireNextImageKHR: ErrorOutOfHostMemory
[shading] shading=blinn-phong-inf:
^C
(lldb) bt
* thread #1, name = 'vkmark', stop reason = signal SIGSTOP
* frame #0: 0x0000000826884aca libc.so.7`__sys_poll at _poll.S:4
frame #1: 0x0000000827420226 libthr.so.3`__thr_poll(fds=0x0000000820f6b978, nfds=1, timeout=-1) at thr_syscalls.c:338:8
frame #2: 0x000000082e9831e2 libxcb.so.1`_xcb_conn_wait + 226
frame #3: 0x000000082e985db9 libxcb.so.1`xcb_wait_for_special_event + 169
frame #4: 0x0000000831ec6719 libvulkan_intel-devel.so`x11_acquire_next_image_poll_x11(chain=0x0000000846381600, image_index=0x0000000820f6bc8c, timeout=18446744073709551615) at wsi_common_x11.c:1130:18
frame #5: 0x0000000831ec4f02 libvulkan_intel-devel.so`x11_acquire_next_image(anv_chain=0x0000000846381600, info=0x0000000820f6bc30, image_index=0x0000000820f6bc8c) at wsi_common_x11.c:1352:14
frame #6: 0x0000000831ebeb5f libvulkan_intel-devel.so`wsi_common_acquire_next_image2(wsi=0x000000082b383ae0, _device=0x000000084641d000, pAcquireInfo=0x0000000820f6bc30, pImageIndex=0x0000000820f6bc8c) at wsi_common.c:927:22
frame #7: 0x0000000831a906b1 libvulkan_intel-devel.so`anv_AcquireNextImage2KHR(_device=0x000000084641d000, pAcquireInfo=0x0000000820f6bc30, pImageIndex=0x0000000820f6bc8c) at anv_wsi.c:82:7
frame #8: 0x0000000831ebeadd libvulkan_intel-devel.so`wsi_AcquireNextImageKHR(_device=0x000000084641d000, swapchain=0x0000000846381600, timeout=18446744073709551615, semaphore=0x000000082b4d8fc0, fence=0x0000000000000000, pImageIndex=0x0000000820f6bc8c) at wsi_common.c:850:11
frame #9: 0x000000082d4c627a xcb.so`SwapchainWindowSystem::next_vulkan_image() + 74
frame #10: 0x000000000025a1ef vkmark`MainLoop::run() + 431
[...]
$ GSK_RENDERER=vulkan gtk4-demo
^T
load: 15.86 cmd: gtk4-demo 79845 [sched] 4.09r 0.35u 0.04s 1% 121368k
mi_switch+0xbf sleepq_catch_signals+0x324 sleepq_timedwait_sig+0x12 linux_add_to_sleepqueue+0x96 linux_schedule_timeout+0x87 drm_syncobj_array_wait_timeout+0x5aa drm_syncobj_timeline_wait_ioctl+0xfe drm_ioctl_kernel+0xcb drm_ioctl+0x2de linux_file_ioctl+0x388 kern_ioctl+0x23b sys_ioctl+0x101 amd64_syscall+0x103 fast_syscall_common+0xf8
^C
(lldb) bt
* thread #1, name = 'gtk4-demo', stop reason = signal SIGSTOP
* frame #0: 0x000000082ad1ed48 libc.so.7`__sys_ioctl at ioctl.S:4
frame #1: 0x000000087134eee8 libdrm.so.2`drmSyncobjTimelineWait + 72
frame #2: 0x000000088890bc81 libvulkan_intel.so`vk_drm_syncobj_wait_many(device=0x000000088545a000, wait_count=1, waits=0x0000000820f7c480, wait_flags=VK_SYNC_WAIT_PENDING, abs_timeout_ns=9223372036854775807) at vk_drm_syncobj.c:263:13
frame #3: 0x0000000888907b3c libvulkan_intel.so`__vk_sync_wait(device=0x000000088545a000, sync=0x000000087cb80790, wait_value=0, wait_flags=VK_SYNC_WAIT_PENDING, abs_timeout_ns=18446744073709551615) at vk_sync.c:234:14
frame #4: 0x0000000888907c8c libvulkan_intel.so`__vk_sync_wait_many(device=0x000000088545a000, wait_count=1, waits=0x0000000820f7c5c0, wait_flags=VK_SYNC_WAIT_PENDING, abs_timeout_ns=18446744073709551615) at vk_sync.c:292:14
frame #5: 0x0000000888907c1f libvulkan_intel.so`vk_sync_wait_many(device=0x000000088545a000, wait_count=1, waits=0x0000000820f7c5c0, wait_flags=VK_SYNC_WAIT_PENDING, abs_timeout_ns=18446744073709551615) at vk_sync.c:343:14
frame #6: 0x00000008888fb6b9 libvulkan_intel.so`vk_queue_wait_before_present(queue=0x0000000848140700, pPresentInfo=0x0000000820f7c6f0) at vk_queue.c:1050:22
frame #7: 0x00000008884907f4 libvulkan_intel.so`anv_QueuePresentKHR(_queue=0x0000000848140700, pPresentInfo=0x0000000820f7c6f0) at anv_wsi.c:106:13
frame #8: 0x00000008235f2557 libgtk-4.so.1`gdk_vulkan_context_end_frame + 311
frame #9: 0x000000082361911b libgtk-4.so.1`gdk_vulkan_context_wayland_end_frame + 59
[...]
Workaround:
--- src/vulkan/wsi/wsi_common_drm.c.orig 22.1-branchpoint-2850-gcbcdcc412c9 + !16987
+++ src/vulkan/wsi/wsi_common_drm.c
@@ -54,7 +54,7 @@ wsi_dma_buf_export_sync_file(int dma_buf_fd, int *sync
};
int ret = drmIoctl(dma_buf_fd, DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &export);
if (ret) {
- if (errno == ENOTTY) {
+ if (errno == ENOTTY || errno == EBADF) {
no_dma_buf_sync_file = true;
return VK_ERROR_FEATURE_NOT_PRESENT;
} else {
@@ -81,7 +81,7 @@ wsi_dma_buf_import_sync_file(int dma_buf_fd, int sync_
};
int ret = drmIoctl(dma_buf_fd, DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &import);
if (ret) {
- if (errno == ENOTTY) {
+ if (errno == ENOTTY || errno == EBADF) {
no_dma_buf_sync_file = true;
return VK_ERROR_FEATURE_NOT_PRESENT;
} else {
Edited by Jan Beich