radv: close the local fd immediately after the winsys is created
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

libdrm dups the fd internally, so local_fd and get_fd() are different
fd number but they point to the same file descriptor. Close it right
after the amdgpu device is initialized to avoid keeping two fds open
for the same thing.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41753>
This commit is contained in:
Samuel Pitoiset 2026-05-22 15:48:35 +02:00 committed by Marge Bot
parent 25ba73ef6e
commit e2631eca0f
5 changed files with 8 additions and 8 deletions

View file

@ -1065,7 +1065,7 @@ radv_check_gpu_hangs(struct radv_queue *queue, const struct radv_winsys_submit_i
break;
case RADV_DEVICE_FAULT_CHUNK_GPU_INFO:
radv_dump_device_name(device, f);
ac_print_gpu_info(f, &pdev->info, pdev->local_fd);
ac_print_gpu_info(f, &pdev->info, device->ws->get_fd(device->ws));
break;
case RADV_DEVICE_FAULT_CHUNK_DMESG:
radv_dump_dmesg(f);

View file

@ -2521,6 +2521,10 @@ radv_physical_device_try_create(struct radv_instance *instance, drmDevicePtr drm
if (drm_device) {
result = radv_amdgpu_winsys_create(fd, instance->debug_flags, instance->perftest_flags, is_virtio, &pdev->ws);
/* Close the fd immediately because libdrm dups it internally. */
close(fd);
fd = -1;
if (result != VK_SUCCESS) {
result = vk_errorf(instance, result, "failed to initialize winsys");
goto fail_base;
@ -2562,7 +2566,6 @@ radv_physical_device_try_create(struct radv_instance *instance, drmDevicePtr drm
}
pdev->master_fd = master_fd;
pdev->local_fd = fd;
pdev->use_llvm = instance->debug_flags & RADV_DEBUG_LLVM;
#if !AMD_LLVM_AVAILABLE
@ -2718,7 +2721,7 @@ radv_physical_device_try_create(struct radv_instance *instance, drmDevicePtr drm
radv_get_physical_device_properties(pdev);
if ((instance->debug_flags & RADV_DEBUG_INFO))
ac_print_gpu_info(stdout, &pdev->info, pdev->local_fd);
ac_print_gpu_info(stdout, &pdev->info, pdev->ws->get_fd(pdev->ws));
radv_init_physical_device_decoder(pdev);
radv_init_physical_device_encoder(pdev);
@ -2832,8 +2835,6 @@ radv_physical_device_destroy(struct vk_physical_device *vk_device)
pdev->ws->destroy(pdev->ws);
disk_cache_destroy(pdev->vk.disk_cache);
disk_cache_destroy(pdev->disk_cache_meta);
if (pdev->local_fd != -1)
close(pdev->local_fd);
if (pdev->master_fd != -1)
close(pdev->master_fd);
vk_physical_device_finish(&pdev->vk);

View file

@ -79,7 +79,6 @@ struct radv_physical_device {
struct ac_addrlib *addrlib;
int local_fd;
int master_fd;
struct wsi_device wsi_device;

View file

@ -109,7 +109,7 @@ radv_init_wsi(struct radv_physical_device *pdev)
pdev->wsi_device.supports_protected[i] = radv_tmz_enabled(pdev);
}
wsi_device_setup_syncobj_fd(&pdev->wsi_device, pdev->local_fd);
wsi_device_setup_syncobj_fd(&pdev->wsi_device, pdev->ws->get_fd(pdev->ws));
pdev->vk.wsi_device = &pdev->wsi_device;

View file

@ -300,7 +300,7 @@ radv_amdgpu_winsys_create(int fd, uint64_t debug_flags, uint64_t perftest_flags,
ws->info.is_virtio = is_virtio;
enum ac_query_gpu_info_result info_result =
ac_query_gpu_info(fd, ws->dev, &ws->info, true, !(debug_flags & RADV_DEBUG_NO_CACHE_COMPAT));
ac_query_gpu_info(ws->fd, ws->dev, &ws->info, true, !(debug_flags & RADV_DEBUG_NO_CACHE_COMPAT));
if (info_result != AC_QUERY_GPU_INFO_SUCCESS) {
result = info_result == AC_QUERY_GPU_INFO_FAIL ? VK_ERROR_INITIALIZATION_FAILED : VK_ERROR_INCOMPATIBLE_DRIVER;
goto winsys_fail;