Message ID | 1454411190-15721-9-git-send-email-tvrtko.ursulin@linux.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Feb 02, 2016 at 11:06:26AM +0000, Tvrtko Ursulin wrote: > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > RPS lock must be taken before the struct_mutex to avoid > locking inversion. So stop grabbing it for the whole > powersave initialization and instead only take it during > the sections which need it. > > Also, struct_mutex is not needed any more since dedicated > RPS lock was added in: > > commit 4fc688ce79772496503d22263d61b071a8fb596e > Author: Jesse Barnes <jbarnes@virtuousgeek.org> > Date: Fri Nov 2 11:14:01 2012 -0700 > > drm/i915: protect RPS/RC6 related accesses (including PCU) with a new mutex > > Based on prototype patch by Chris Wilson and a subsequent > mailing list discussion involving Ville, Imre, Chris and > Daniel. > > v2: More details in the commit. > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > Cc: Chris Wilson <chris@chris-wilson.co.uk> > Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> > Cc: Imre Deak <imre.deak@intel.com> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch> > --- > drivers/gpu/drm/i915/intel_display.c | 4 ---- > drivers/gpu/drm/i915/intel_pm.c | 9 +++++---- > 2 files changed, 5 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c > index 5018295cd92b..af0d33a3697a 100644 > --- a/drivers/gpu/drm/i915/intel_display.c > +++ b/drivers/gpu/drm/i915/intel_display.c > @@ -15995,9 +15995,7 @@ void intel_modeset_gem_init(struct drm_device *dev) > struct drm_i915_gem_object *obj; > int ret; > > - mutex_lock(&dev->struct_mutex); > intel_init_gt_powersave(dev); > - mutex_unlock(&dev->struct_mutex); > > intel_modeset_init_hw(dev); > > @@ -16077,9 +16075,7 @@ void intel_modeset_cleanup(struct drm_device *dev) > > intel_cleanup_overlay(dev); > > - mutex_lock(&dev->struct_mutex); > intel_cleanup_gt_powersave(dev); > - mutex_unlock(&dev->struct_mutex); The whitespace no longer conveys meaning, it used to be to clearly mark the mutex section. > @@ -5235,6 +5233,7 @@ static void valleyview_setup_pctx(struct drm_device *dev) > out: > DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); > dev_priv->vlv_pctx = pctx; > + mutex_unlock(&dev->struct_mutex); > } > > static void valleyview_cleanup_pctx(struct drm_device *dev) > @@ -5244,8 +5243,10 @@ static void valleyview_cleanup_pctx(struct drm_device *dev) > if (WARN_ON(!dev_priv->vlv_pctx)) > return; > > + mutex_lock(&dev->struct_mutex); > drm_gem_object_unreference(&dev_priv->vlv_pctx->base); > dev_priv->vlv_pctx = NULL; > + mutex_unlock(&dev->struct_mutex); This made me smile. Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> -Chris
On 02/02/16 13:16, Chris Wilson wrote: > On Tue, Feb 02, 2016 at 11:06:26AM +0000, Tvrtko Ursulin wrote: >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> >> RPS lock must be taken before the struct_mutex to avoid >> locking inversion. So stop grabbing it for the whole >> powersave initialization and instead only take it during >> the sections which need it. >> >> Also, struct_mutex is not needed any more since dedicated >> RPS lock was added in: >> >> commit 4fc688ce79772496503d22263d61b071a8fb596e >> Author: Jesse Barnes <jbarnes@virtuousgeek.org> >> Date: Fri Nov 2 11:14:01 2012 -0700 >> >> drm/i915: protect RPS/RC6 related accesses (including PCU) with a new mutex >> >> Based on prototype patch by Chris Wilson and a subsequent >> mailing list discussion involving Ville, Imre, Chris and >> Daniel. >> >> v2: More details in the commit. >> >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> Cc: Chris Wilson <chris@chris-wilson.co.uk> >> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> >> Cc: Imre Deak <imre.deak@intel.com> >> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> >> --- >> drivers/gpu/drm/i915/intel_display.c | 4 ---- >> drivers/gpu/drm/i915/intel_pm.c | 9 +++++---- >> 2 files changed, 5 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c >> index 5018295cd92b..af0d33a3697a 100644 >> --- a/drivers/gpu/drm/i915/intel_display.c >> +++ b/drivers/gpu/drm/i915/intel_display.c >> @@ -15995,9 +15995,7 @@ void intel_modeset_gem_init(struct drm_device *dev) >> struct drm_i915_gem_object *obj; >> int ret; >> >> - mutex_lock(&dev->struct_mutex); >> intel_init_gt_powersave(dev); >> - mutex_unlock(&dev->struct_mutex); >> >> intel_modeset_init_hw(dev); >> >> @@ -16077,9 +16075,7 @@ void intel_modeset_cleanup(struct drm_device *dev) >> >> intel_cleanup_overlay(dev); >> >> - mutex_lock(&dev->struct_mutex); >> intel_cleanup_gt_powersave(dev); >> - mutex_unlock(&dev->struct_mutex); > > The whitespace no longer conveys meaning, it used to be to clearly mark > the mutex section. Guess I can remove more lines of code and get credits for that. :D >> @@ -5235,6 +5233,7 @@ static void valleyview_setup_pctx(struct drm_device *dev) >> out: >> DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); >> dev_priv->vlv_pctx = pctx; >> + mutex_unlock(&dev->struct_mutex); >> } >> >> static void valleyview_cleanup_pctx(struct drm_device *dev) >> @@ -5244,8 +5243,10 @@ static void valleyview_cleanup_pctx(struct drm_device *dev) >> if (WARN_ON(!dev_priv->vlv_pctx)) >> return; >> >> + mutex_lock(&dev->struct_mutex); >> drm_gem_object_unreference(&dev_priv->vlv_pctx->base); >> dev_priv->vlv_pctx = NULL; >> + mutex_unlock(&dev->struct_mutex); > > This made me smile. Yeah mechanical- want unreference_unlocked instead? Regards, Tvrtko
On Tue, Feb 02, 2016 at 02:13:43PM +0000, Tvrtko Ursulin wrote: > > On 02/02/16 13:16, Chris Wilson wrote: > >On Tue, Feb 02, 2016 at 11:06:26AM +0000, Tvrtko Ursulin wrote: > >>@@ -5244,8 +5243,10 @@ static void valleyview_cleanup_pctx(struct drm_device *dev) > >> if (WARN_ON(!dev_priv->vlv_pctx)) > >> return; > >> > >>+ mutex_lock(&dev->struct_mutex); > >> drm_gem_object_unreference(&dev_priv->vlv_pctx->base); > >> dev_priv->vlv_pctx = NULL; > >>+ mutex_unlock(&dev->struct_mutex); > > > >This made me smile. > > Yeah mechanical- want unreference_unlocked instead? _unlocked() has the advantage of not suggesting that dev_priv->vlv_pctx needs to be part of the locked transaction (that's the bit that caused a double take). But it really doesn't matter. -Chris
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 5018295cd92b..af0d33a3697a 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -15995,9 +15995,7 @@ void intel_modeset_gem_init(struct drm_device *dev) struct drm_i915_gem_object *obj; int ret; - mutex_lock(&dev->struct_mutex); intel_init_gt_powersave(dev); - mutex_unlock(&dev->struct_mutex); intel_modeset_init_hw(dev); @@ -16077,9 +16075,7 @@ void intel_modeset_cleanup(struct drm_device *dev) intel_cleanup_overlay(dev); - mutex_lock(&dev->struct_mutex); intel_cleanup_gt_powersave(dev); - mutex_unlock(&dev->struct_mutex); intel_teardown_gmbus(dev); } diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c index 31bc4ea395ac..7f137a70b6ae 100644 --- a/drivers/gpu/drm/i915/intel_pm.c +++ b/drivers/gpu/drm/i915/intel_pm.c @@ -5175,8 +5175,6 @@ static void cherryview_setup_pctx(struct drm_device *dev) u32 pcbr; int pctx_size = 32*1024; - WARN_ON(!mutex_is_locked(&dev->struct_mutex)); - pcbr = I915_READ(VLV_PCBR); if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) { DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n"); @@ -5198,7 +5196,7 @@ static void valleyview_setup_pctx(struct drm_device *dev) u32 pcbr; int pctx_size = 24*1024; - WARN_ON(!mutex_is_locked(&dev->struct_mutex)); + mutex_lock(&dev->struct_mutex); pcbr = I915_READ(VLV_PCBR); if (pcbr) { @@ -5226,7 +5224,7 @@ static void valleyview_setup_pctx(struct drm_device *dev) pctx = i915_gem_object_create_stolen(dev, pctx_size); if (!pctx) { DRM_DEBUG("not enough stolen space for PCTX, disabling\n"); - return; + goto out; } pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start; @@ -5235,6 +5233,7 @@ static void valleyview_setup_pctx(struct drm_device *dev) out: DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR)); dev_priv->vlv_pctx = pctx; + mutex_unlock(&dev->struct_mutex); } static void valleyview_cleanup_pctx(struct drm_device *dev) @@ -5244,8 +5243,10 @@ static void valleyview_cleanup_pctx(struct drm_device *dev) if (WARN_ON(!dev_priv->vlv_pctx)) return; + mutex_lock(&dev->struct_mutex); drm_gem_object_unreference(&dev_priv->vlv_pctx->base); dev_priv->vlv_pctx = NULL; + mutex_unlock(&dev->struct_mutex); } static void valleyview_init_gt_powersave(struct drm_device *dev)