From 40fbfd8b5b5058b795feffad26f237b091b91213 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 2 May 2021 20:38:36 -0700 Subject: [PATCH] venus: fix dmabuf import mmap_size check Do not set mmap_size to info.size. We do not track the size of the BO anymore. This fixes dEQP-VK.api.external.memory.dma_buf.suballocated.device_only.fd_properties where the test allocates a 1KB VkDeviceMemory, export and call vkGetMemoryFdPropertiesKHR. It can happen that bo->mmap_size is less than the aligned info.size. FWIW, the test fails because it violates a VU: VUID-vkGetMemoryFdPropertiesKHR-fd-00673 fd must be an external memory handle created outside of the Vulkan API Fixes: 88f481dd742 ("venus: make sure gem_handle and vn_renderer_bo are 1:1") Signed-off-by: Chia-I Wu Reviewed-by: Yiwei Zhang Part-of: --- src/virtio/vulkan/vn_renderer_virtgpu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/virtio/vulkan/vn_renderer_virtgpu.c b/src/virtio/vulkan/vn_renderer_virtgpu.c index eb459f029fe..d1a69824069 100644 --- a/src/virtio/vulkan/vn_renderer_virtgpu.c +++ b/src/virtio/vulkan/vn_renderer_virtgpu.c @@ -1164,29 +1164,29 @@ virtgpu_bo_create_from_dmabuf(struct vn_renderer *renderer, goto fail; uint32_t blob_flags; + size_t mmap_size; if (info.blob_mem) { /* must be VIRTGPU_BLOB_MEM_HOST3D */ if (info.blob_mem != VIRTGPU_BLOB_MEM_HOST3D) goto fail; - if (!size) - size = info.size; - else if (info.size < size) + if (info.size < size) goto fail; blob_flags = virtgpu_bo_blob_flags(flags, external_handles); + mmap_size = size; } else { /* must be classic resource here * set blob_flags to 0 to fail virtgpu_bo_map - * set size to 0 since mapping is not allowed + * set mmap_size to 0 since mapping is not allowed */ blob_flags = 0; - size = 0; + mmap_size = 0; } struct virtgpu_bo *bo = util_sparse_array_get(&gpu->bo_array, gem_handle); if (bo->gem_handle == gem_handle) { - if (bo->base.mmap_size < size) + if (bo->base.mmap_size < mmap_size) goto fail; if (blob_flags & ~bo->blob_flags) goto fail; @@ -1200,7 +1200,7 @@ virtgpu_bo_create_from_dmabuf(struct vn_renderer *renderer, .base = { .refcount = 1, .res_id = info.res_handle, - .mmap_size = size, + .mmap_size = mmap_size, }, .gem_handle = gem_handle, .blob_flags = blob_flags,