Skip to content

Commit

Permalink
drm/nouveau/pm/fan: drop the fan lock in fan_update() before reschedu…
Browse files Browse the repository at this point in the history
…ling

This should fix a deadlock that has been reported to us where fan_update()
would hold the fan lock and try to grab the alarm_program_lock to reschedule
an update. On an other CPU, the alarm_program_lock would have been taken
before calling fan_update(), leading to a deadlock.

We should Cc: <stable@vger.kernel.org> # 3.9+

Reported-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Tested-by: Timothée Ravier <tim@siosm.fr>
Tested-by: Boris Fersing (IRC nick fersingb, no public email address)
Signed-off-by: Martin Peres <martin.peres@free.fr>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
  • Loading branch information
Martin Peres authored and Ben Skeggs committed Mar 26, 2014
1 parent 6c3252b commit 61679fe
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ nouveau_fan_update(struct nouveau_fan *fan, bool immediate, int target)

/* check that we're not already at the target duty cycle */
duty = fan->get(therm);
if (duty == target)
goto done;
if (duty == target) {
spin_unlock_irqrestore(&fan->lock, flags);
return 0;
}

/* smooth out the fanspeed increase/decrease */
if (!immediate && duty >= 0) {
Expand All @@ -73,8 +75,15 @@ nouveau_fan_update(struct nouveau_fan *fan, bool immediate, int target)

nv_debug(therm, "FAN update: %d\n", duty);
ret = fan->set(therm, duty);
if (ret)
goto done;
if (ret) {
spin_unlock_irqrestore(&fan->lock, flags);
return ret;
}

/* fan speed updated, drop the fan lock before grabbing the
* alarm-scheduling lock and risking a deadlock
*/
spin_unlock_irqrestore(&fan->lock, flags);

/* schedule next fan update, if not at target speed already */
if (list_empty(&fan->alarm.head) && target != duty) {
Expand All @@ -92,8 +101,6 @@ nouveau_fan_update(struct nouveau_fan *fan, bool immediate, int target)
ptimer->alarm(ptimer, delay * 1000 * 1000, &fan->alarm);
}

done:
spin_unlock_irqrestore(&fan->lock, flags);
return ret;
}

Expand Down

0 comments on commit 61679fe

Please sign in to comment.