Skip to content

Commit 45c5d2a

Browse files
gurchetansinghkraxel
authored andcommitted
drm/virtio: only destroy created contexts
This can happen if userspace doesn't issue any 3D ioctls before closing the DRM fd. Fixes: 72b48ae ("drm/virtio: enqueue virtio_gpu_create_context after the first 3D ioctl") Signed-off-by: Gurchetan Singh <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Gerd Hoffmann <[email protected]>
1 parent dbc05ae commit 45c5d2a

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

drivers/gpu/drm/virtio/virtgpu_kms.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ static void virtio_gpu_config_changed_work_func(struct work_struct *work)
5252
events_clear, &events_clear);
5353
}
5454

55-
static void virtio_gpu_context_destroy(struct virtio_gpu_device *vgdev,
56-
uint32_t ctx_id)
57-
{
58-
virtio_gpu_cmd_context_destroy(vgdev, ctx_id);
59-
virtio_gpu_notify(vgdev);
60-
ida_free(&vgdev->ctx_id_ida, ctx_id - 1);
61-
}
62-
6355
static void virtio_gpu_init_vq(struct virtio_gpu_queue *vgvq,
6456
void (*work_func)(struct work_struct *work))
6557
{
@@ -274,14 +266,17 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
274266
void virtio_gpu_driver_postclose(struct drm_device *dev, struct drm_file *file)
275267
{
276268
struct virtio_gpu_device *vgdev = dev->dev_private;
277-
struct virtio_gpu_fpriv *vfpriv;
269+
struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
278270

279271
if (!vgdev->has_virgl_3d)
280272
return;
281273

282-
vfpriv = file->driver_priv;
274+
if (vfpriv->context_created) {
275+
virtio_gpu_cmd_context_destroy(vgdev, vfpriv->ctx_id);
276+
virtio_gpu_notify(vgdev);
277+
}
283278

284-
virtio_gpu_context_destroy(vgdev, vfpriv->ctx_id);
279+
ida_free(&vgdev->ctx_id_ida, vfpriv->ctx_id - 1);
285280
mutex_destroy(&vfpriv->context_lock);
286281
kfree(vfpriv);
287282
file->driver_priv = NULL;

0 commit comments

Comments
 (0)