From a6f2db03cde6d7fa20aa484c5e020b2bc1750fce Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 10 Dec 2025 09:44:42 +0100 Subject: [PATCH] radv: fix race condition when getting the blit queue Cc: mesa-stable Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14439 Signed-off-by: Samuel Pitoiset (cherry picked from commit a89118c5b0f7c59603b3d0552f13b4edbfed588e) Part-of: --- .pick_status.json | 2 +- src/amd/vulkan/radv_device.c | 2 ++ src/amd/vulkan/radv_device.h | 2 ++ src/amd/vulkan/radv_wsi.c | 9 ++++++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index c156f15ff76..9164cc69355 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1394,7 +1394,7 @@ "description": "radv: fix race condition when getting the blit queue", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index a97bcb490d8..98a921085ef 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -1137,6 +1137,7 @@ radv_destroy_device(struct radv_device *device, const VkAllocationCallbacks *pAl simple_mtx_destroy(&device->trace_mtx); simple_mtx_destroy(&device->rt_handles_mtx); simple_mtx_destroy(&device->pso_cache_stats_mtx); + simple_mtx_destroy(&device->blit_queue_mtx); radv_destroy_shader_arenas(device); if (device->capture_replay_arena_vas) @@ -1192,6 +1193,7 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr simple_mtx_init(&device->pstate_mtx, mtx_plain); simple_mtx_init(&device->rt_handles_mtx, mtx_plain); simple_mtx_init(&device->pso_cache_stats_mtx, mtx_plain); + simple_mtx_init(&device->blit_queue_mtx, mtx_plain); device->rt_handles = _mesa_hash_table_create(NULL, _mesa_hash_u32, _mesa_key_u32_equal); diff --git a/src/amd/vulkan/radv_device.h b/src/amd/vulkan/radv_device.h index a57a98093a4..3ecf6a6a5ad 100644 --- a/src/amd/vulkan/radv_device.h +++ b/src/amd/vulkan/radv_device.h @@ -317,6 +317,8 @@ struct radv_device { simple_mtx_t pso_cache_stats_mtx; struct radv_pso_cache_stats pso_cache_stats[RADV_PIPELINE_TYPE_COUNT]; + simple_mtx_t blit_queue_mtx; + struct radv_address_binding_tracker *addr_binding_tracker; }; diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c index 49f21b388b7..835b17e50aa 100644 --- a/src/amd/vulkan/radv_wsi.c +++ b/src/amd/vulkan/radv_wsi.c @@ -41,8 +41,12 @@ radv_wsi_get_prime_blit_queue(VkDevice _device) struct radv_physical_device *pdev = radv_device_physical(device); const struct radv_instance *instance = radv_physical_device_instance(pdev); - if (device->private_sdma_queue != VK_NULL_HANDLE) + simple_mtx_lock(&device->blit_queue_mtx); + + if (device->private_sdma_queue != VK_NULL_HANDLE) { + simple_mtx_unlock(&device->blit_queue_mtx); return &device->private_sdma_queue->vk; + } if (pdev->info.gfx_level >= GFX9 && !(instance->debug_flags & RADV_DEBUG_NO_DMA_BLIT)) { @@ -58,12 +62,15 @@ radv_wsi_get_prime_blit_queue(VkDevice _device) VkResult result = radv_queue_init(device, device->private_sdma_queue, 0, &queue_create, NULL); if (result == VK_SUCCESS) { + simple_mtx_unlock(&device->blit_queue_mtx); return &device->private_sdma_queue->vk; } else { vk_free(&device->vk.alloc, device->private_sdma_queue); device->private_sdma_queue = VK_NULL_HANDLE; } } + + simple_mtx_unlock(&device->blit_queue_mtx); return NULL; }