Mesa (master): venus: fix virtgpu_bo_init_dmabuf for classic resource
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Apr 16 05:06:19 UTC 2021
Module: Mesa
Branch: master
Commit: 757a711f396e42c6080563ef7fe589f173e38fb6
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=757a711f396e42c6080563ef7fe589f173e38fb6
Author: Yiwei Zhang <zzyiwei at chromium.org>
Date: Thu Apr 15 23:41:49 2021 +0000
venus: fix virtgpu_bo_init_dmabuf for classic resource
1. only do size check if the input size is not 0
2. blob_mem can be 0 because guest minigbm uses RESOURCE_CREATE_3D
3. set bo->blob_flags to 0 for classic resource to fail virtgpu_bo_map
Signed-off-by: Yiwei Zhang <zzyiwei at chromium.org>
Reviewed-by: Chia-I Wu <olvaffe at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10273>
---
src/virtio/vulkan/vn_renderer_virtgpu.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/virtio/vulkan/vn_renderer_virtgpu.c b/src/virtio/vulkan/vn_renderer_virtgpu.c
index 075d0bdfc04..8d9069c31f9 100644
--- a/src/virtio/vulkan/vn_renderer_virtgpu.c
+++ b/src/virtio/vulkan/vn_renderer_virtgpu.c
@@ -1108,24 +1108,36 @@ virtgpu_bo_init_dmabuf(struct vn_renderer_bo *_bo,
{
struct virtgpu_bo *bo = (struct virtgpu_bo *)_bo;
struct virtgpu *gpu = bo->gpu;
+ struct drm_virtgpu_resource_info info;
+ uint32_t gem_handle = 0;
- const uint32_t gem_handle = virtgpu_ioctl_prime_fd_to_handle(gpu, fd);
+ gem_handle = virtgpu_ioctl_prime_fd_to_handle(gpu, fd);
if (!gem_handle)
- return VK_ERROR_INVALID_EXTERNAL_HANDLE;
+ goto fail;
- struct drm_virtgpu_resource_info info;
- if (virtgpu_ioctl_resource_info(gpu, gem_handle, &info) ||
- info.blob_mem != VIRTGPU_BLOB_MEM_HOST3D || info.size < size) {
- virtgpu_ioctl_gem_close(gpu, gem_handle);
- return VK_ERROR_INVALID_EXTERNAL_HANDLE;
- }
+ if (virtgpu_ioctl_resource_info(gpu, gem_handle, &info))
+ goto fail;
- bo->blob_flags = virtgpu_bo_blob_flags(flags, external_handles);
+ /* must be VIRTGPU_BLOB_MEM_HOST3D or classic */
+ if (info.blob_mem && info.blob_mem != VIRTGPU_BLOB_MEM_HOST3D)
+ goto fail;
+
+ if (size && info.size < size)
+ goto fail;
+
+ /* set blob_flags to 0 for classic resources to fail virtgpu_bo_map */
+ bo->blob_flags =
+ info.blob_mem ? virtgpu_bo_blob_flags(flags, external_handles) : 0;
bo->size = size ? size : info.size;
bo->gem_handle = gem_handle;
bo->base.res_id = info.res_handle;
return VK_SUCCESS;
+
+fail:
+ if (gem_handle)
+ virtgpu_ioctl_gem_close(gpu, gem_handle);
+ return VK_ERROR_INVALID_EXTERNAL_HANDLE;
}
static VkResult
More information about the mesa-commit
mailing list