diff mbox

drm/i915: Fixing mutex deadlock window at eDP DRRS

Message ID 1425364906-31769-1-git-send-email-ramalingam.c@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ramalingam C March 3, 2015, 6:41 a.m. UTC
In invalidate and flush functions of eDP DRRS, if deferred downclock
work starts execution at a time window between acquiring the drrs
mutex and cancellation of the deferred work
(intel_edp_drrs_downclock_work), then deferred work will find
drrs mutex locked and wait for the same.

Meanwhile the function that acquired mutex drrs invalidate/flush will
wait for the completion of the deferred work before releasing the mutex.
Thats a deadlock.

To avoid such deadlock scenario, this change cancels the deferred work
before acquiring the mutex at invalidate and flush functions.

Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
---
 drivers/gpu/drm/i915/intel_dp.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Rodrigo Vivi March 4, 2015, 10:55 p.m. UTC | #1
Looks enough for me...

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

On Mon, Mar 2, 2015 at 10:41 PM, Ramalingam C <ramalingam.c@intel.com> wrote:
> In invalidate and flush functions of eDP DRRS, if deferred downclock
> work starts execution at a time window between acquiring the drrs
> mutex and cancellation of the deferred work
> (intel_edp_drrs_downclock_work), then deferred work will find
> drrs mutex locked and wait for the same.
>
> Meanwhile the function that acquired mutex drrs invalidate/flush will
> wait for the completion of the deferred work before releasing the mutex.
> Thats a deadlock.
>
> To avoid such deadlock scenario, this change cancels the deferred work
> before acquiring the mutex at invalidate and flush functions.
>
> Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
> ---
>  drivers/gpu/drm/i915/intel_dp.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index d1141d3..0a57763 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -4966,12 +4966,13 @@ void intel_edp_drrs_invalidate(struct drm_device *dev,
>         if (!dev_priv->drrs.dp)
>                 return;
>
> +       cancel_delayed_work_sync(&dev_priv->drrs.work);
> +
>         mutex_lock(&dev_priv->drrs.mutex);
>         crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
>         pipe = to_intel_crtc(crtc)->pipe;
>
>         if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) {
> -               cancel_delayed_work_sync(&dev_priv->drrs.work);
>                 intel_dp_set_drrs_state(dev_priv->dev,
>                                 dev_priv->drrs.dp->attached_connector->panel.
>                                 fixed_mode->vrefresh);
> @@ -5004,13 +5005,13 @@ void intel_edp_drrs_flush(struct drm_device *dev,
>         if (!dev_priv->drrs.dp)
>                 return;
>
> +       cancel_delayed_work_sync(&dev_priv->drrs.work);
> +
>         mutex_lock(&dev_priv->drrs.mutex);
>         crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
>         pipe = to_intel_crtc(crtc)->pipe;
>         dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
>
> -       cancel_delayed_work_sync(&dev_priv->drrs.work);
> -
>         if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR &&
>                         !dev_priv->drrs.busy_frontbuffer_bits)
>                 schedule_delayed_work(&dev_priv->drrs.work,
> --
> 1.7.9.5
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Daniel Vetter March 5, 2015, 11:49 a.m. UTC | #2
On Wed, Mar 04, 2015 at 02:55:23PM -0800, Rodrigo Vivi wrote:
> Looks enough for me...
> 
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> 
> On Mon, Mar 2, 2015 at 10:41 PM, Ramalingam C <ramalingam.c@intel.com> wrote:
> > In invalidate and flush functions of eDP DRRS, if deferred downclock
> > work starts execution at a time window between acquiring the drrs
> > mutex and cancellation of the deferred work
> > (intel_edp_drrs_downclock_work), then deferred work will find
> > drrs mutex locked and wait for the same.
> >
> > Meanwhile the function that acquired mutex drrs invalidate/flush will
> > wait for the completion of the deferred work before releasing the mutex.
> > Thats a deadlock.
> >
> > To avoid such deadlock scenario, this change cancels the deferred work
> > before acquiring the mutex at invalidate and flush functions.
> >
> > Signed-off-by: Ramalingam C <ramalingam.c@intel.com>

Queued for -next, thanks for the patch.
-Daniel

> > ---
> >  drivers/gpu/drm/i915/intel_dp.c |    7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> > index d1141d3..0a57763 100644
> > --- a/drivers/gpu/drm/i915/intel_dp.c
> > +++ b/drivers/gpu/drm/i915/intel_dp.c
> > @@ -4966,12 +4966,13 @@ void intel_edp_drrs_invalidate(struct drm_device *dev,
> >         if (!dev_priv->drrs.dp)
> >                 return;
> >
> > +       cancel_delayed_work_sync(&dev_priv->drrs.work);
> > +
> >         mutex_lock(&dev_priv->drrs.mutex);
> >         crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
> >         pipe = to_intel_crtc(crtc)->pipe;
> >
> >         if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) {
> > -               cancel_delayed_work_sync(&dev_priv->drrs.work);
> >                 intel_dp_set_drrs_state(dev_priv->dev,
> >                                 dev_priv->drrs.dp->attached_connector->panel.
> >                                 fixed_mode->vrefresh);
> > @@ -5004,13 +5005,13 @@ void intel_edp_drrs_flush(struct drm_device *dev,
> >         if (!dev_priv->drrs.dp)
> >                 return;
> >
> > +       cancel_delayed_work_sync(&dev_priv->drrs.work);
> > +
> >         mutex_lock(&dev_priv->drrs.mutex);
> >         crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
> >         pipe = to_intel_crtc(crtc)->pipe;
> >         dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
> >
> > -       cancel_delayed_work_sync(&dev_priv->drrs.work);
> > -
> >         if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR &&
> >                         !dev_priv->drrs.busy_frontbuffer_bits)
> >                 schedule_delayed_work(&dev_priv->drrs.work,
> > --
> > 1.7.9.5
> >
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
> 
> 
> -- 
> Rodrigo Vivi
> Blog: http://blog.vivi.eng.br
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index d1141d3..0a57763 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -4966,12 +4966,13 @@  void intel_edp_drrs_invalidate(struct drm_device *dev,
 	if (!dev_priv->drrs.dp)
 		return;
 
+	cancel_delayed_work_sync(&dev_priv->drrs.work);
+
 	mutex_lock(&dev_priv->drrs.mutex);
 	crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
 	pipe = to_intel_crtc(crtc)->pipe;
 
 	if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR) {
-		cancel_delayed_work_sync(&dev_priv->drrs.work);
 		intel_dp_set_drrs_state(dev_priv->dev,
 				dev_priv->drrs.dp->attached_connector->panel.
 				fixed_mode->vrefresh);
@@ -5004,13 +5005,13 @@  void intel_edp_drrs_flush(struct drm_device *dev,
 	if (!dev_priv->drrs.dp)
 		return;
 
+	cancel_delayed_work_sync(&dev_priv->drrs.work);
+
 	mutex_lock(&dev_priv->drrs.mutex);
 	crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
 	pipe = to_intel_crtc(crtc)->pipe;
 	dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
 
-	cancel_delayed_work_sync(&dev_priv->drrs.work);
-
 	if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR &&
 			!dev_priv->drrs.busy_frontbuffer_bits)
 		schedule_delayed_work(&dev_priv->drrs.work,