Module: Mesa
Branch: main
Commit: bafc27583cf7c2d136fa05764e5e2145fedbc9cc
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=bafc27583cf7c2d136fa05764e5e2145fedbc9cc

Author: Andrew Gazizov <[email protected]>
Date:   Thu Nov  9 09:33:43 2023 +0100

venus: Make sure that guest allocated blobs from hostmem are mappable

For guest-based blob allocations from hostmem (Host visible memory),
to make sure that virtio-gpu driver will send to the host the address
(offset in the region) of the allocated blob using RESOURCE_MAP_BLOB
command a flag VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT must be set.

Otherwise, if the upper layers didn't set it, host can't import memory
and guest allocation from Host visible memory region makes no sense.

Signed-off-by: Andrew D. Gazizov <[email protected]>
Reviewed-by: Yiwei Zhang <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26130>

---

 src/virtio/vulkan/vn_device_memory.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/virtio/vulkan/vn_device_memory.c 
b/src/virtio/vulkan/vn_device_memory.c
index c3e4d5a8367..8d001254624 100644
--- a/src/virtio/vulkan/vn_device_memory.c
+++ b/src/virtio/vulkan/vn_device_memory.c
@@ -346,9 +346,18 @@ vn_device_memory_alloc_guest_vram(struct vn_device *dev,
    const struct vk_device_memory *mem_vk = &mem->base.base;
    const VkMemoryType *mem_type = &dev->physical_device->memory_properties
                                       .memoryTypes[mem_vk->memory_type_index];
+   VkMemoryPropertyFlags flags = mem_type->propertyFlags;
+
+   /* For external allocation handles, it's possible scenario when requested
+    * non-mappable memory. To make sure that virtio-gpu driver will send to
+    * the host the address of allocated blob using RESOURCE_MAP_BLOB command
+    * a flag VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT must be set.
+    */
+   if (mem_vk->export_handle_types)
+      flags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
 
    VkResult result = vn_renderer_bo_create_from_device_memory(
-      dev->renderer, mem_vk->size, mem->base.id, mem_type->propertyFlags,
+      dev->renderer, mem_vk->size, mem->base.id, flags,
       mem_vk->export_handle_types, &mem->base_bo);
    if (result != VK_SUCCESS) {
       return result;

Reply via email to