summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthoine Bourgeois <anthoine.bourgeois@gmail.com>2021-09-21 16:20:17 -0700
committerKaiyi Li <kaiyili@google.com>2023-04-27 06:42:54 -0700
commit87546febca2be695630acc5b9c844507e1fc9dfd (patch)
treeeaa19a1133582ea59e003e3518cf6b637a31b691
parentc6a28520439360ffc10ab1d5f39f94b168f9010d (diff)
downloadvirtual-device-android-gs-bluejay-5.10-u-beta3.tar.gz
This implements the context initialization ioctl. A list of params is passed in by userspace, and kernel driver validates them. The only currently supported param is VIRTGPU_CONTEXT_PARAM_CAPSET_ID. If the context has already been initialized, -EEXIST is returned. This happens after Linux userspace does dumb_create + followed by opening the Mesa virgl driver with the same virtgpu instance. However, for most applications, 3D contexts will be explicitly initialized when the feature is available. Signed-off-by: Anthoine Bourgeois <anthoine.bourgeois@gmail.com> Acked-by: Lingfeng Yang <lfy@google.com> Link: http://patchwork.freedesktop.org/patch/msgid/20210921232024.817-6-gurchetansingh@chromium.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Bug: 278150168 Change-Id: I3dd83a1765fd26f40e86e3b25b597e946a83da9f (cherry picked from commit 4fb530e5caf7cb666948db65f245b350ce520436) [kaiyili: Reslved merge conflicts in virtio_gpu/{virtgpu_drv.h,virtgpu_ioctl.c}] Signed-off-by: Kaiyi Li <kaiyili@google.com>
-rw-r--r--virtio_gpu/virtgpu_drv.h2
-rw-r--r--virtio_gpu/virtgpu_ioctl.c36
2 files changed, 25 insertions, 13 deletions
diff --git a/virtio_gpu/virtgpu_drv.h b/virtio_gpu/virtgpu_drv.h
index 0a6d8b9..ac6e7df 100644
--- a/virtio_gpu/virtgpu_drv.h
+++ b/virtio_gpu/virtgpu_drv.h
@@ -273,7 +273,7 @@ struct virtio_gpu_fpriv {
struct mutex context_lock;
};
-/* virtio_ioctl.c */
+/* virtgpu_ioctl.c */
#define DRM_VIRTIO_NUM_IOCTLS 12
extern struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS];
void virtio_gpu_create_context(struct drm_device *dev, struct drm_file *file);
diff --git a/virtio_gpu/virtgpu_ioctl.c b/virtio_gpu/virtgpu_ioctl.c
index 3514c90..2d8f9bc 100644
--- a/virtio_gpu/virtgpu_ioctl.c
+++ b/virtio_gpu/virtgpu_ioctl.c
@@ -713,7 +713,7 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,
int ret = 0;
uint32_t num_params, i, param, value;
size_t len;
- struct drm_virtgpu_context_set_param *ctx_set_params;
+ struct drm_virtgpu_context_set_param *ctx_set_params = NULL;
struct virtio_gpu_device *vgdev = dev->dev_private;
struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
struct drm_virtgpu_context_init *args = data;
@@ -746,31 +746,42 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,
switch (param) {
case VIRTGPU_CONTEXT_PARAM_CAPSET_ID:
- if (value > MAX_CAPSET_ID)
- return -EINVAL;
+ if (value > MAX_CAPSET_ID) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
- if ((vgdev->capset_id_mask & (1 << value)) == 0)
- return -EINVAL;
+ if ((vgdev->capset_id_mask & (1 << value)) == 0) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
/* Context capset ID already set */
if (vfpriv->context_init &
- VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK)
- return -EINVAL;
+ VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
vfpriv->context_init |= value;
break;
case VIRTGPU_CONTEXT_PARAM_NUM_FENCE_CONTEXTS:
- if (vfpriv->base_fence_ctx)
- return -EINVAL;
+ if (vfpriv->base_fence_ctx) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
- if (value > MAX_FENCE_CONTEXTS)
- return -EINVAL;
+ if (value > MAX_FENCE_CONTEXTS) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
vfpriv->base_fence_ctx = dma_fence_context_alloc(value);
vfpriv->num_fence_contexts = value;
break;
default:
- return -EINVAL;
+ ret = -EINVAL;
+ goto out_unlock;
}
}
@@ -779,6 +790,7 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,
out_unlock:
mutex_unlock(&vfpriv->context_lock);
+ kfree(ctx_set_params);
return ret;
}