Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/virtio: Don't attach GEM to a non-created context in gem_object_open()

The vfpriv->ctx_id is always initialized to a non-zero value. Check whether
context was created before attaching GEM to this context ID. This left
unnoticed previously because host silently skips attachment if context
doesn't exist, still we shouldn't do that for consistency.

Fixes: 086b9f27f0ab ("drm/virtio: Don't create a context with default param if context_init is supported")
Cc: <stable@vger.kernel.org> # v6.14+
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Link: https://lore.kernel.org/r/20250401123842.2232205-1-dmitry.osipenko@collabora.com

+6 -5
+6 -5
drivers/gpu/drm/virtio/virtgpu_gem.c
··· 115 115 if (!vgdev->has_context_init) 116 116 virtio_gpu_create_context(obj->dev, file); 117 117 118 - objs = virtio_gpu_array_alloc(1); 119 - if (!objs) 120 - return -ENOMEM; 121 - virtio_gpu_array_add_obj(objs, obj); 118 + if (vfpriv->context_created) { 119 + objs = virtio_gpu_array_alloc(1); 120 + if (!objs) 121 + return -ENOMEM; 122 + virtio_gpu_array_add_obj(objs, obj); 122 123 123 - if (vfpriv->ctx_id) 124 124 virtio_gpu_cmd_context_attach_resource(vgdev, vfpriv->ctx_id, objs); 125 + } 125 126 126 127 out_notify: 127 128 virtio_gpu_notify(vgdev);