Commit 15266ae3 authored by Lyude Paul's avatar Lyude Paul Committed by Dave Airlie

drm/nouveau: Handle fbcon suspend/resume in seperate worker

Resuming from RPM can happen while already holding
dev->mode_config.mutex. This means we can't actually handle fbcon in
any RPM resume workers, since restoring fbcon requires grabbing
dev->mode_config.mutex again. So move the fbcon suspend/resume code into
it's own worker, and rely on that instead to avoid deadlocking.

This fixes more deadlocks for runtime suspending the GPU on the ThinkPad
W541. Reproduction recipe:

 - Get a machine with both optimus and a nvidia card with connectors
   attached to it
 - Wait for the nvidia GPU to suspend
 - Attempt to manually reprobe any of the connectors on the nvidia GPU
   using sysfs
 - *deadlock*

[airlied: use READ_ONCE to address Hans's comment]
Signed-off-by: default avatarLyude <lyude@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Kilian Singer <kilian.singer@quantumtechnology.info>
Cc: Lukas Wunner <lukas@wunner.de>
Cc: David Airlie <airlied@redhat.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent cae9ff03
...@@ -165,6 +165,8 @@ struct nouveau_drm { ...@@ -165,6 +165,8 @@ struct nouveau_drm {
struct backlight_device *backlight; struct backlight_device *backlight;
struct list_head bl_connectors; struct list_head bl_connectors;
struct work_struct hpd_work; struct work_struct hpd_work;
struct work_struct fbcon_work;
int fbcon_new_state;
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
struct notifier_block acpi_nb; struct notifier_block acpi_nb;
#endif #endif
......
...@@ -470,19 +470,43 @@ static const struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = { ...@@ -470,19 +470,43 @@ static const struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = {
.fb_probe = nouveau_fbcon_create, .fb_probe = nouveau_fbcon_create,
}; };
static void
nouveau_fbcon_set_suspend_work(struct work_struct *work)
{
struct nouveau_drm *drm = container_of(work, typeof(*drm), fbcon_work);
int state = READ_ONCE(drm->fbcon_new_state);
if (state == FBINFO_STATE_RUNNING)
pm_runtime_get_sync(drm->dev->dev);
console_lock();
if (state == FBINFO_STATE_RUNNING)
nouveau_fbcon_accel_restore(drm->dev);
drm_fb_helper_set_suspend(&drm->fbcon->helper, state);
if (state != FBINFO_STATE_RUNNING)
nouveau_fbcon_accel_save_disable(drm->dev);
console_unlock();
if (state == FBINFO_STATE_RUNNING) {
pm_runtime_mark_last_busy(drm->dev->dev);
pm_runtime_put_sync(drm->dev->dev);
}
}
void void
nouveau_fbcon_set_suspend(struct drm_device *dev, int state) nouveau_fbcon_set_suspend(struct drm_device *dev, int state)
{ {
struct nouveau_drm *drm = nouveau_drm(dev); struct nouveau_drm *drm = nouveau_drm(dev);
if (drm->fbcon) {
console_lock(); if (!drm->fbcon)
if (state == FBINFO_STATE_RUNNING) return;
nouveau_fbcon_accel_restore(dev);
drm_fb_helper_set_suspend(&drm->fbcon->helper, state); drm->fbcon_new_state = state;
if (state != FBINFO_STATE_RUNNING) /* Since runtime resume can happen as a result of a sysfs operation,
nouveau_fbcon_accel_save_disable(dev); * it's possible we already have the console locked. So handle fbcon
console_unlock(); * init/deinit from a seperate work thread
} */
schedule_work(&drm->fbcon_work);
} }
int int
...@@ -502,6 +526,7 @@ nouveau_fbcon_init(struct drm_device *dev) ...@@ -502,6 +526,7 @@ nouveau_fbcon_init(struct drm_device *dev)
return -ENOMEM; return -ENOMEM;
drm->fbcon = fbcon; drm->fbcon = fbcon;
INIT_WORK(&drm->fbcon_work, nouveau_fbcon_set_suspend_work);
drm_fb_helper_prepare(dev, &fbcon->helper, &nouveau_fbcon_helper_funcs); drm_fb_helper_prepare(dev, &fbcon->helper, &nouveau_fbcon_helper_funcs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment