[PATCH 3/5] drm/virtio: track whether or not a context has been initiated
Gurchetan Singh
gurchetansingh at chromium.org
Sat Feb 15 02:29:08 UTC 2020
On Fri, Feb 14, 2020 at 11:27 AM Chia-I Wu <olvaffe at gmail.com> wrote:
>
> On Thu, Feb 13, 2020 at 3:18 PM Gurchetan Singh
> <gurchetansingh at chromium.org> wrote:
> >
> > Use an atomic variable to track whether a context has been
> > initiated.
> >
> > v2: Fix possible race (@olv)
> >
> > Signed-off-by: Gurchetan Singh <gurchetansingh at chromium.org>
> > ---
> > drivers/gpu/drm/virtio/virtgpu_drv.h | 1 +
> > drivers/gpu/drm/virtio/virtgpu_ioctl.c | 3 +++
> > drivers/gpu/drm/virtio/virtgpu_kms.c | 1 +
> > 3 files changed, 5 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
> > index 72c1d9b59dfe..ca505984f8ab 100644
> > --- a/drivers/gpu/drm/virtio/virtgpu_drv.h
> > +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
> > @@ -209,6 +209,7 @@ struct virtio_gpu_device {
> >
> > struct virtio_gpu_fpriv {
> > uint32_t ctx_id;
> > + atomic_t context_initiated;
> > };
> >
> > /* virtio_ioctl.c */
> > diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> > index 896c3f419a6d..a98884462944 100644
> > --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> > +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
> > @@ -44,6 +44,9 @@ void virtio_gpu_create_context(struct drm_device *dev,
> > if (!vgdev->has_virgl_3d)
> > return;
> >
> > + if (!atomic_add_unless(&vfpriv->context_initiated, 1, 1))
> > + return;
> > +
> How does this work? When thread A and B enter this function at the
> same time, and thread B returns early, it is possible that thread B
> queues other commands before thread A has the chance to queue
> virtio_gpu_cmd_context_create.
Good catch, I'll add a spinlock in v3.
>
> > get_task_comm(dbgname, current);
> > virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id,
> > strlen(dbgname), dbgname);
> > diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
> > index 282558576527..25248bad3fc4 100644
> > --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> > +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> > @@ -263,6 +263,7 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
> > }
> >
> > vfpriv->ctx_id = handle + 1;
> > + atomic_set(&vfpriv->context_initiated, 0);
> > file->driver_priv = vfpriv;
> > virtio_gpu_create_context(dev, file);
> > return 0;
> > --
> > 2.25.0.265.gbab2e86ba0-goog
> >
More information about the dri-devel
mailing list