All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Daniel Kurtz <djkurtz@chromium.org>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>,
	dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v3 12/20] drm: omapdrm: Prevent processing the same event multiple times
Date: Mon, 12 Dec 2016 12:21:19 +0200	[thread overview]
Message-ID: <2027355.0QBI6rq3fm@avalon> (raw)
In-Reply-To: <CAGS+omCsKpzXYwbz=7GqwiG8N9Xska0iS2byrU2TWFXrq7TdWw@mail.gmail.com>

Hi Daniel,

On Tuesday 27 Sep 2016 23:05:20 Daniel Kurtz wrote:
> On Mon, Sep 19, 2016 at 8:27 PM, Laurent Pinchart wrote:
> > The vblank interrupt is disabled after one occurrence, preventing the
> > atomic update event from being processed twice. However, this also
> > prevents the software frame counter from being updated correctly that
> > would require vblank interrupts to be kept enabled while the CRTC is
> > active.
> > 
> > In preparation for vblank interrupt fixes, make sure that the atomic
> > update event will be processed once only when the vblank interrupt will
> > be kept enabled.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > 
> >  drivers/gpu/drm/omapdrm/omap_crtc.c | 22 +++++++++++++++++++---
> >  1 file changed, 19 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c
> > b/drivers/gpu/drm/omapdrm/omap_crtc.c index a0c26592fc69..8fef6558197b
> > 100644
> > --- a/drivers/gpu/drm/omapdrm/omap_crtc.c
> > +++ b/drivers/gpu/drm/omapdrm/omap_crtc.c
> > @@ -43,6 +43,7 @@ struct omap_crtc {
> >         bool enabled;
> >         bool pending;
> >         wait_queue_head_t pending_wait;
> > +       struct drm_pending_vblank_event *event;
> >  };
> >  
> >  /* ---------------------------------------------------------------------
> > @@ -260,11 +261,15 @@ static const struct dss_mgr_ops mgr_ops = {
> > 
> >  static void omap_crtc_complete_page_flip(struct drm_crtc *crtc)
> >  {
> > +       struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
> >         struct drm_pending_vblank_event *event;
> >         struct drm_device *dev = crtc->dev;
> >         unsigned long flags;
> > 
> > -       event = crtc->state->event;
> > +       spin_lock_irqsave(&dev->event_lock, flags);
> > +       event = omap_crtc->event;
> > +       omap_crtc->event = NULL;
> > +       spin_unlock_irqrestore(&dev->event_lock, flags);
> 
> Perhaps just hold the lock until after drm_crtc_send_vblank_event(crtc,
> event)?

Good point, I'll do that.

> >         if (!event)
> >                 return;
> > 
> > @@ -384,12 +389,23 @@ static int omap_crtc_atomic_check(struct drm_crtc
> > *crtc,
> >  }
> >  
> >  static void omap_crtc_atomic_begin(struct drm_crtc *crtc,
> > -                                  struct drm_crtc_state *old_crtc_state)
> > +                                  struct drm_crtc_state *old_crtc_state)
> >  {
> > +       struct drm_pending_vblank_event *event = crtc->state->event;
> > +       struct omap_crtc *omap_crtc = to_omap_crtc(crtc);
> > +       unsigned long flags;
> > +
> > +       if (event) {
> > +               WARN_ON(drm_crtc_vblank_get(crtc) != 0);
> > +
> > +               spin_lock_irqsave(&crtc->dev->event_lock, flags);
> > +               omap_crtc->event = event;
> > +               spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
> > +       }
> 
> AFAICT, the only reason to use the spin_lock_irqsave here is if there
> is a possibility that the vblank irq can run in parallel to
> atomic_begin().
> 
> If this is the case, then setting omap_crtc->event here in
> atomic_begin() may not work exactly as you wish.
> It sets up a race: the vblank irq may call
> omap_crtc_complete_page_flip and send the event between here and when
> the "GO" bit is set in atomic_flush(), and thus, it may send the event
> too early, on the wrong vblank.
> 
> By the way, it looks like there is the same race, but just much
> shorter, with the "omap_crtc->pending" flag.  Since it is set in
> atomic_flush() before hitting the go bit - there is a tiny window
> where an irq could arrive and see pending = true for the wrong vblank.

This should be fixed in patch 14/20 ("drm: omapdrm: Keep vblank interrupt 
enabled while CRTC is active") in this series.

> I'm not familiar enough with this driver, however, to tell if it is
> really possible to get an irq here or not.

It shouldn't be as the driver only enables interrupts after setting the GO 
bit. However, that logic is changed in the aforementioned patch, which will 
introduce the race condition you described. I'll move the code to the atomic 
flush handler in this patch to fix it.

> >  }
> >  
> >  static void omap_crtc_atomic_flush(struct drm_crtc *crtc,
> > -                                  struct drm_crtc_state *old_crtc_state)
> > +                                  struct drm_crtc_state *old_crtc_state)
> >  {
> >         struct omap_crtc *omap_crtc = to_omap_crtc(crtc);

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2016-12-12 10:20 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-19 12:27 [PATCH v3 00/20] OMAP DRM fixes and improvements Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 01/20] drm: omapdrm: fb: Limit number of planes per framebuffer to two Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 02/20] drm: omapdrm: fb: Use format information provided by the DRM core Laurent Pinchart
2016-09-20 12:47   ` Tomi Valkeinen
2016-12-12 21:41     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 03/20] drm: omapdrm: fb: Simplify objects lookup when creating framebuffer Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 04/20] drm: omapdrm: fb: Simplify mode command checks " Laurent Pinchart
2016-09-20 12:55   ` Tomi Valkeinen
2016-09-19 12:27 ` [PATCH v3 05/20] drm: omapdrm: fb: Turn framebuffer creation error messages into debug Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 06/20] drm: omapdrm: Handle FIFO underflow IRQs internally Laurent Pinchart
2016-09-20 13:17   ` Tomi Valkeinen
2016-09-20 13:27   ` Tomi Valkeinen
2016-12-12 21:59     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 07/20] drm: omapdrm: Handle CRTC error IRQs directly Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 08/20] drm: omapdrm: Handle OCP error IRQ directly Laurent Pinchart
2016-09-20 13:34   ` Tomi Valkeinen
2016-12-12 22:09     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 09/20] drm: omapdrm: Replace DSS manager state check with omapdrm CRTC state Laurent Pinchart
2016-09-20 13:44   ` Tomi Valkeinen
2016-12-12 22:16     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 10/20] drm: omapdrm: Only commit planes on active CRTCs Laurent Pinchart
2016-09-20 13:51   ` Tomi Valkeinen
2016-12-12 22:53     ` Laurent Pinchart
2016-12-13  7:58       ` Tomi Valkeinen
2016-12-13 13:12         ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 11/20] drm: omapdrm: Check DSS manager state in the enable/disable helpers Laurent Pinchart
2016-09-20 13:57   ` Tomi Valkeinen
2016-12-12 23:07     ` Laurent Pinchart
2016-12-13  8:15       ` Tomi Valkeinen
2016-12-13 23:56         ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 12/20] drm: omapdrm: Prevent processing the same event multiple times Laurent Pinchart
2016-09-27 12:24   ` Tomi Valkeinen
2016-12-12 10:29     ` Laurent Pinchart
2016-09-27 15:05   ` Daniel Kurtz
2016-12-12 10:21     ` Laurent Pinchart [this message]
2016-09-19 12:27 ` [PATCH v3 13/20] drm: omapdrm: Use a spinlock to protect the CRTC pending flag Laurent Pinchart
2016-09-27 12:27   ` Tomi Valkeinen
2016-09-19 12:27 ` [PATCH v3 14/20] drm: omapdrm: Keep vblank interrupt enabled while CRTC is active Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 15/20] drm: omapdrm: Don't expose the omap_irq_(un)register() functions Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 16/20] drm: omapdrm: Remove unused parameter from omap_drm_irq handler Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 17/20] drm: omapdrm: Don't call DISPC power handling in IRQ wait functions Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 18/20] drm: omapdrm: Make pipe2vbl function static Laurent Pinchart
2016-12-12 10:41   ` Tomi Valkeinen
2016-12-12 23:17     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 19/20] drm: omapdrm: Simplify IRQ wait implementation Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 20/20] drm: omapdrm: Remove global variables Laurent Pinchart

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=2027355.0QBI6rq3fm@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=djkurtz@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tomi.valkeinen@ti.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.