From: Ben Widawsky <ben@bwidawsk.net> To: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: intel-gfx@lists.freedesktop.org Subject: Re: [PATCH 2/3] drm/i915: close PM interrupt masking races in the rps work func Date: Sun, 4 Sep 2011 10:08:17 -0700 Message-ID: <20110904100817.16c6c4cc@bwidawsk.net> (raw) In-Reply-To: <1315150502-12537-3-git-send-email-daniel.vetter@ffwll.ch> On Sun, 4 Sep 2011 17:35:01 +0200 Daniel Vetter <daniel.vetter@ffwll.ch> wrote: > This patch closes the following race: > > We get a PM interrupt A, mask it, set dev_priv->iir = PM_A and kick > of the work item. Scheduler isn't grumpy, so the work queue takes > rps_lock, grabs pm_iir = dev_priv->pm_iir and pm_imr = READ(PMIMR). > Note that pm_imr == pm_iir because we've just masked the interrupt > we've got. > > Now hw sends out PM interrupt B (not masked), we process it and mask > it. Later on the irq handler also clears PMIIR. > > Then the work item proceeds and at the end clears PMIMR. Because > (local) pm_imr == pm_iir we have > pm_imr & ~pm_iir == 0 > so all interrupts are enabled. > > Hardware is still interrupt-happy, and sends out a new PM interrupt B. > PMIMR doesn't mask B (it does not mask anything), PMIIR is cleared, so > we get it and hit the WARN in the interrupt handler (because > dev_priv->pm_iir == PM_B). > > That's why I've moved the > WRITE(PMIMR, 0) > up under the protection of the rps_lock. And write an uncoditional 0 > to PMIMR, because that's what we'll do anyway. > > This races looks much more likely because we can arbitrarily extend > the window by grabing dev->struct mutex right after the irq handler > has processed the first PM_B interrupt. > > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> > --- > drivers/gpu/drm/i915/i915_irq.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/drivers/gpu/drm/i915/i915_irq.c > b/drivers/gpu/drm/i915/i915_irq.c index 2fdd9f9..21ebcbd 100644 > --- a/drivers/gpu/drm/i915/i915_irq.c > +++ b/drivers/gpu/drm/i915/i915_irq.c > @@ -383,6 +383,7 @@ static void gen6_pm_rps_work(struct work_struct > *work) pm_iir = dev_priv->pm_iir; > dev_priv->pm_iir = 0; > pm_imr = I915_READ(GEN6_PMIMR); > + I915_WRITE(GEN6_PMIMR, 0); > spin_unlock_irq(&dev_priv->rps_lock); > > if (!pm_iir) > @@ -420,7 +421,6 @@ static void gen6_pm_rps_work(struct work_struct > *work) > * an *extremely* unlikely race with gen6_rps_enable() that > is prevented > * by holding struct_mutex for the duration of the write. > */ > - I915_WRITE(GEN6_PMIMR, pm_imr & ~pm_iir); > mutex_unlock(&dev_priv->dev->struct_mutex); > } > How about this: diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 55518e3..3bc1479 100644 --- a/drivers/gpu/drm/i915/i915_irq.c +++ b/drivers/gpu/drm/i915/i915_irq.c @@ -415,12 +415,7 @@ static void gen6_pm_rps_work(struct work_struct *work) gen6_set_rps(dev_priv->dev, new_delay); dev_priv->cur_delay = new_delay; - /* - * rps_lock not held here because clearing is non-destructive. There is - * an *extremely* unlikely race with gen6_rps_enable() that is prevented - * by holding struct_mutex for the duration of the write. - */ - I915_WRITE(GEN6_PMIMR, pm_imr & ~pm_iir); + I915_WRITE(GEN6_PMIMR, pm_imr & dev_priv->pm_iir); mutex_unlock(&dev_priv->dev->struct_mutex); } Ben
next prev parent reply index Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-09-04 3:24 [PATCH] drm/i915: Fix rps irq warning Ben Widawsky 2011-09-04 9:03 ` Chris Wilson 2011-09-04 15:49 ` Ben Widawsky 2011-09-04 15:34 ` [PATCH 0/3] slaughter rps races some more Daniel Vetter 2011-09-04 15:35 ` [PATCH 1/3] drm/i915: close PM interrupt masking races in the irq handler Daniel Vetter 2011-09-04 17:09 ` Ben Widawsky 2011-09-04 15:35 ` [PATCH 2/3] drm/i915: close PM interrupt masking races in the rps work func Daniel Vetter 2011-09-04 17:08 ` Ben Widawsky [this message] 2011-09-04 19:26 ` Daniel Vetter 2011-09-04 19:56 ` Ben Widawsky 2011-09-04 20:10 ` Daniel Vetter 2011-09-04 21:38 ` Ben Widawsky 2011-09-05 6:38 ` Daniel Vetter 2011-09-05 6:51 ` Ben Widawsky 2011-09-05 12:15 ` Chris Wilson 2011-09-04 15:35 ` [PATCH 3/3] drm/i915: close rps work vs. rps disable races Daniel Vetter 2011-09-04 17:23 ` Ben Widawsky 2011-09-04 19:17 ` Daniel Vetter 2011-09-04 19:50 ` Ben Widawsky 2011-09-04 19:57 ` Daniel Vetter 2011-09-05 8:15 ` [PATCH] drm/i915: properly cancel rps_work on module unload Daniel Vetter 2011-09-05 17:27 ` Ben Widawsky 2011-09-08 12:00 [PATCH 1/3] drm/i915: close PM interrupt masking races in the irq handler Daniel Vetter 2011-09-08 12:00 ` [PATCH 2/3] drm/i915: close PM interrupt masking races in the rps work func Daniel Vetter 2011-09-08 15:19 ` Ben Widawsky
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=20110904100817.16c6c4cc@bwidawsk.net \ --to=ben@bwidawsk.net \ --cc=daniel.vetter@ffwll.ch \ --cc=intel-gfx@lists.freedesktop.org \ /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
Intel-GFX Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/intel-gfx/0 intel-gfx/git/0.git git clone --mirror https://lore.kernel.org/intel-gfx/1 intel-gfx/git/1.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 intel-gfx intel-gfx/ https://lore.kernel.org/intel-gfx \ intel-gfx@lists.freedesktop.org public-inbox-index intel-gfx Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.freedesktop.lists.intel-gfx AGPL code for this site: git clone https://public-inbox.org/public-inbox.git