From 9efb3ee511bea492ccf3d995aa78e7c55371eef1 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Wed, 30 Jul 2025 22:00:16 +0300 Subject: [PATCH] anv: fix wsi image aliasing The private BO can get removed due to WSI aliasing and that breaks the submission code (expecting one). Delay the registration on the device to when the image actually gets bound and there is a private BO. Fixes: b21e62b71a ("anv: avoid leaking private binding for aliased wsi image") Reviewed-by: Yiwei Zhang Part-of: --- src/intel/vulkan/anv_image.c | 21 +++++++++++++-------- src/intel/vulkan/anv_private.h | 2 ++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 7b1ca50179d..db706ac54f4 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1486,11 +1486,6 @@ alloc_private_binding(struct anv_device *device, binding->memory_range.size, 0, 0, &binding->address.bo); ANV_DMR_BO_ALLOC(&image->vk.base, binding->address.bo, result); - if (result == VK_SUCCESS) { - pthread_mutex_lock(&device->mutex); - list_addtail(&image->link, &device->image_private_objects); - pthread_mutex_unlock(&device->mutex); - } return result; } @@ -2027,9 +2022,11 @@ anv_image_finish(struct anv_image *image) struct anv_bo *private_bo = image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo; if (private_bo) { - pthread_mutex_lock(&device->mutex); - list_del(&image->link); - pthread_mutex_unlock(&device->mutex); + if (image->device_registered) { + pthread_mutex_lock(&device->mutex); + list_del(&image->link); + pthread_mutex_unlock(&device->mutex); + } ANV_DMR_BO_FREE(&image->vk.base, private_bo); anv_device_release_bo(device, private_bo); } @@ -2931,6 +2928,14 @@ anv_bind_image_memory(struct anv_device *device, } } + if (image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo != NULL && + !image->device_registered) { + pthread_mutex_lock(&device->mutex); + list_addtail(&image->link, &device->image_private_objects); + image->device_registered = true; + pthread_mutex_unlock(&device->mutex); + } + if (bind_status) *bind_status->pResult = result; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 8205d8cb121..3d558252306 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -5657,6 +5657,8 @@ struct anv_image { /* Link in the anv_device.image_private_objects list */ struct list_head link; + /* Whether the image was added to anv_device.image_private_objects list */ + bool device_registered; struct anv_image_memory_range av1_cdf_table; };