From 97aa90dec2bdd5b8b1a0c274deb8c330aae7ae44 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 1 Sep 2021 21:30:36 +0000 Subject: [PATCH] venus: workaround a blob_mem mappable size check issue For blob_mem allocated from virtgpu_virgl backend, the guest mappable size queried can be smaller than the size returned from image memory requirement query from the host side. Here we temporarily workaround until we switch to use cross-domain backend in minigbm. Cc: 21.2.3 mesa-stable Signed-off-by: Yiwei Zhang Reviewed-by: Chia-I Wu Reviewed-by: Ryan Neph Part-of: --- src/virtio/vulkan/vn_android.c | 11 +++++++++-- src/virtio/vulkan/vn_device_memory.c | 15 +++++++++------ src/virtio/vulkan/vn_device_memory.h | 1 + 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/virtio/vulkan/vn_android.c b/src/virtio/vulkan/vn_android.c index 121f124..52901e7 100644 --- a/src/virtio/vulkan/vn_android.c +++ b/src/virtio/vulkan/vn_android.c @@ -918,6 +918,7 @@ vn_android_device_import_ahb(struct vn_device *dev, int dup_fd = -1; uint64_t alloc_size = 0; uint32_t mem_type_bits = 0; + bool force_unmappable = false; VkResult result = VK_SUCCESS; handle = AHardwareBuffer_getNativeHandle(ahb); @@ -960,6 +961,12 @@ vn_android_device_import_ahb(struct vn_device *dev, } alloc_size = mem_req.size; + + /* XXX Workaround before we use cross-domain backend in minigbm. The + * blob_mem allocated from virgl backend can have a queried guest mappable + * size smaller than the size returned from image memory requirement. + */ + force_unmappable = true; } if (dedicated_info && dedicated_info->buffer != VK_NULL_HANDLE) { @@ -999,8 +1006,8 @@ vn_android_device_import_ahb(struct vn_device *dev, .allocationSize = alloc_size, .memoryTypeIndex = alloc_info->memoryTypeIndex, }; - result = - vn_device_memory_import_dma_buf(dev, mem, &local_alloc_info, dup_fd); + result = vn_device_memory_import_dma_buf(dev, mem, &local_alloc_info, + force_unmappable, dup_fd); if (result != VK_SUCCESS) { close(dup_fd); return result; diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c index 89226dd..5a38cb4 100644 --- a/src/virtio/vulkan/vn_device_memory.c +++ b/src/virtio/vulkan/vn_device_memory.c @@ -224,20 +224,23 @@ VkResult vn_device_memory_import_dma_buf(struct vn_device *dev, struct vn_device_memory *mem, const VkMemoryAllocateInfo *alloc_info, + bool force_unmappable, int fd) { VkDevice device = vn_device_to_handle(dev); VkDeviceMemory memory = vn_device_memory_to_handle(mem); const VkPhysicalDeviceMemoryProperties *mem_props = &dev->physical_device->memory_properties.memoryProperties; - const VkMemoryType *mem_type = - &mem_props->memoryTypes[alloc_info->memoryTypeIndex]; + VkMemoryPropertyFlags mem_flags = + mem_props->memoryTypes[alloc_info->memoryTypeIndex].propertyFlags; struct vn_renderer_bo *bo; VkResult result = VK_SUCCESS; - result = vn_renderer_bo_create_from_dma_buf(dev->renderer, - alloc_info->allocationSize, fd, - mem_type->propertyFlags, &bo); + if (force_unmappable) + mem_flags &= ~VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; + + result = vn_renderer_bo_create_from_dma_buf( + dev->renderer, alloc_info->allocationSize, fd, mem_flags, &bo); if (result != VK_SUCCESS) return result; @@ -355,7 +358,7 @@ vn_AllocateMemory(VkDevice device, } else if (export_ahb) { result = vn_android_device_allocate_ahb(dev, mem, pAllocateInfo, alloc); } else if (import_fd_info) { - result = vn_device_memory_import_dma_buf(dev, mem, pAllocateInfo, + result = vn_device_memory_import_dma_buf(dev, mem, pAllocateInfo, false, import_fd_info->fd); } else if (export_info) { result = vn_device_memory_alloc(dev, mem, pAllocateInfo, true, diff --git a/src/virtio/vulkan/vn_device_memory.h b/src/virtio/vulkan/vn_device_memory.h index f480ad8..04f23d1 100644 --- a/src/virtio/vulkan/vn_device_memory.h +++ b/src/virtio/vulkan/vn_device_memory.h @@ -47,6 +47,7 @@ VkResult vn_device_memory_import_dma_buf(struct vn_device *dev, struct vn_device_memory *mem, const VkMemoryAllocateInfo *alloc_info, + bool force_unmappable, int fd); VkResult -- 2.7.4