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@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10273>
This commit is contained in:
Yiwei Zhang 2021-04-15 23:41:49 +00:00 committed by Marge Bot
parent 23159f1a7a
commit 757a711f39

View file

@ -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;
const uint32_t gem_handle = virtgpu_ioctl_prime_fd_to_handle(gpu, fd);
if (!gem_handle)
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
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;
}
uint32_t gem_handle = 0;
bo->blob_flags = virtgpu_bo_blob_flags(flags, external_handles);
gem_handle = virtgpu_ioctl_prime_fd_to_handle(gpu, fd);
if (!gem_handle)
goto fail;
if (virtgpu_ioctl_resource_info(gpu, gem_handle, &info))
goto fail;
/* 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