From bafc27583cf7c2d136fa05764e5e2145fedbc9cc Mon Sep 17 00:00:00 2001 From: Andrew Gazizov Date: Thu, 9 Nov 2023 09:33:43 +0100 Subject: [PATCH] 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 Reviewed-by: Yiwei Zhang Part-of: --- 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;