From 6c8f075fb3e45537b691c4ade33a2ac8c40dcbc2 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Sun, 13 Jul 2025 20:28:42 -0700 Subject: [PATCH] venus/virtgpu: drop mappable if blob size is smaller than requested Instead of failing the import, drop the mappable bit if blob size is smaller than the requested alloc size, which defers the error to the intended vkMapMemory api call if the client app requests Vulkan mapping from the imported external memory. Normally this won't occur if the app obeys the spec with a properly implemented blob mem allocator. However, legacy allocators like minigbm virtgpu_virgl backend could allocate via virgl w/o knowing the real blob size from the guest side. The unsatified cases are external gralloc images, which won't be mapped in any meaningful way after being imported. This is to prepare dropping the force_unmappable workaround, and to further prepare adopting common Android runtime. Part-of: --- src/virtio/vulkan/vn_renderer_virtgpu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/virtio/vulkan/vn_renderer_virtgpu.c b/src/virtio/vulkan/vn_renderer_virtgpu.c index 5b199aaadb2..fe11f9f507c 100644 --- a/src/virtio/vulkan/vn_renderer_virtgpu.c +++ b/src/virtio/vulkan/vn_renderer_virtgpu.c @@ -1187,10 +1187,14 @@ virtgpu_bo_create_from_dma_buf(struct vn_renderer *renderer, /* mmap_size is only used when mappable */ mmap_size = 0; if (blob_flags & VIRTGPU_BLOB_FLAG_USE_MAPPABLE) { + /* If queried blob size is smaller than requested allocation size, we + * drop the mappable flag to defer the mapping failure till the app's + * vkMapMemory api call. + */ if (info.size < size) - goto fail; - - mmap_size = size; + blob_flags &= ~VIRTGPU_BLOB_FLAG_USE_MAPPABLE; + else + mmap_size = size; } }