All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chia-I Wu <olvaffe@gmail.com>
To: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
	ML dri-devel <dri-devel@lists.freedesktop.org>,
	jbates@chromium.org
Subject: Re: [PATCH 3/5] drm/virtio: track whether or not a context has been initiated
Date: Fri, 14 Feb 2020 20:29:23 -0800	[thread overview]
Message-ID: <CAPaKu7SHrke+awMeOG_jsStcmKYX-GgoWK7iikoq4s5d0nNSZA@mail.gmail.com> (raw)
In-Reply-To: <CAAfnVB=MrO7KwYnUbVoG=TOqQMeFiZM3R2KgH=N7A5Ceq=Raaw@mail.gmail.com>

On Fri, Feb 14, 2020 at 6:29 PM Gurchetan Singh
<gurchetansingh@chromium.org> wrote:
>
> On Fri, Feb 14, 2020 at 11:27 AM Chia-I Wu <olvaffe@gmail.com> wrote:
> >
> > On Thu, Feb 13, 2020 at 3:18 PM Gurchetan Singh
> > <gurchetansingh@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@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.
virtio_gpu_cmd_context_create can sleep.  You will need a mutex (or
figure out another way to do the lazy initialization).

>
> >
> > >         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
> > >
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-02-15  4:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13 23:18 [PATCH v2 0/5] *** Delay context create cmd *** Gurchetan Singh
2020-02-13 23:18 ` [PATCH 1/5] drm/virtio: use consistent names for drm_files Gurchetan Singh
2020-02-13 23:18 ` [PATCH 2/5] drm/virtio: factor out context create hyercall Gurchetan Singh
2020-02-13 23:18 ` [PATCH 3/5] drm/virtio: track whether or not a context has been initiated Gurchetan Singh
2020-02-14 19:27   ` Chia-I Wu
2020-02-15  2:29     ` Gurchetan Singh
2020-02-15  4:29       ` Chia-I Wu [this message]
2020-02-13 23:18 ` [PATCH 4/5] drm/virtio: enqueue virtio_gpu_create_context after the first 3D ioctl Gurchetan Singh
2020-02-13 23:18 ` [PATCH 5/5] drm/virtio: add virtio_gpu_context_type Gurchetan Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPaKu7SHrke+awMeOG_jsStcmKYX-GgoWK7iikoq4s5d0nNSZA@mail.gmail.com \
    --to=olvaffe@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gurchetansingh@chromium.org \
    --cc=jbates@chromium.org \
    --cc=kraxel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.