Commit d2a983b2 authored by Gurchetan Singh's avatar Gurchetan Singh Committed by Gerd Hoffmann

drm/virtio: track whether or not a context has been initiated

Use an boolean variable to track whether a context has been
initiated.

v5: Fix possible race and sleep via mutex (olv)
Reviewed-by: default avatarChia-I Wu <olvaffe@gmail.com>
Reviewed-by: default avatarEmil Velikov <emil.velikov@collabora.com>
Signed-off-by: default avatarGurchetan Singh <gurchetansingh@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20200225000800.2966-3-gurchetansingh@chromium.orgSigned-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 40cadedd
...@@ -209,6 +209,8 @@ struct virtio_gpu_device { ...@@ -209,6 +209,8 @@ struct virtio_gpu_device {
struct virtio_gpu_fpriv { struct virtio_gpu_fpriv {
uint32_t ctx_id; uint32_t ctx_id;
bool context_created;
struct mutex context_lock;
}; };
/* virtio_ioctl.c */ /* virtio_ioctl.c */
......
...@@ -40,10 +40,18 @@ void virtio_gpu_create_context(struct drm_device *dev, ...@@ -40,10 +40,18 @@ void virtio_gpu_create_context(struct drm_device *dev,
struct virtio_gpu_fpriv *vfpriv = file->driver_priv; struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
char dbgname[TASK_COMM_LEN]; char dbgname[TASK_COMM_LEN];
mutex_lock(&vfpriv->context_lock);
if (vfpriv->context_created)
goto out_unlock;
get_task_comm(dbgname, current); get_task_comm(dbgname, current);
virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id,
strlen(dbgname), dbgname); strlen(dbgname), dbgname);
virtio_gpu_notify(vgdev); virtio_gpu_notify(vgdev);
vfpriv->context_created = true;
out_unlock:
mutex_unlock(&vfpriv->context_lock);
} }
static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data,
......
...@@ -258,6 +258,8 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) ...@@ -258,6 +258,8 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
if (!vfpriv) if (!vfpriv)
return -ENOMEM; return -ENOMEM;
mutex_init(&vfpriv->context_lock);
handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL); handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL);
if (handle < 0) { if (handle < 0) {
kfree(vfpriv); kfree(vfpriv);
...@@ -281,6 +283,7 @@ void virtio_gpu_driver_postclose(struct drm_device *dev, struct drm_file *file) ...@@ -281,6 +283,7 @@ void virtio_gpu_driver_postclose(struct drm_device *dev, struct drm_file *file)
vfpriv = file->driver_priv; vfpriv = file->driver_priv;
virtio_gpu_context_destroy(vgdev, vfpriv->ctx_id); virtio_gpu_context_destroy(vgdev, vfpriv->ctx_id);
mutex_destroy(&vfpriv->context_lock);
kfree(vfpriv); kfree(vfpriv);
file->driver_priv = NULL; file->driver_priv = NULL;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment