Commit 690a151a authored by Lukas Wunner's avatar Lukas Wunner Committed by Greg Kroah-Hartman

drm/amdgpu: Fix deadlock on runtime suspend

commit aa0aad57 upstream.

amdgpu's ->runtime_suspend hook calls drm_kms_helper_poll_disable(),
which waits for the output poll worker to finish if it's running.

The output poll worker meanwhile calls pm_runtime_get_sync() in
amdgpu's ->detect hooks, which waits for the ongoing suspend to finish,
causing a deadlock.

Fix by not acquiring a runtime PM ref if the ->detect hooks are called
in the output poll worker's context.  This is safe because the poll
worker is only enabled while runtime active and we know that
->runtime_suspend waits for it to finish.

Fixes: d38ceaf9 ("drm/amdgpu: add core driver (v4)")
Cc: stable@vger.kernel.org # v4.2+: 27d4ee03: workqueue: Allow retrieval of current task's work struct
Cc: stable@vger.kernel.org # v4.2+: 25c058cc: drm: Allow determining if current task is output poll worker
Cc: Alex Deucher <alexander.deucher@amd.com>
Tested-by: default avatarMike Lothian <mike@fireburn.co.uk>
Reviewed-by: default avatarLyude Paul <lyude@redhat.com>
Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
Link: https://patchwork.freedesktop.org/patch/msgid/4c9bf72aacae1eef062bd134cd112e0770a7f121.1518338789.git.lukas@wunner.deSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 40539a86
...@@ -739,9 +739,11 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force) ...@@ -739,9 +739,11 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force)
enum drm_connector_status ret = connector_status_disconnected; enum drm_connector_status ret = connector_status_disconnected;
int r; int r;
r = pm_runtime_get_sync(connector->dev->dev); if (!drm_kms_helper_is_poll_worker()) {
if (r < 0) r = pm_runtime_get_sync(connector->dev->dev);
return connector_status_disconnected; if (r < 0)
return connector_status_disconnected;
}
if (encoder) { if (encoder) {
struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
...@@ -760,8 +762,12 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force) ...@@ -760,8 +762,12 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force)
/* check acpi lid status ??? */ /* check acpi lid status ??? */
amdgpu_connector_update_scratch_regs(connector, ret); amdgpu_connector_update_scratch_regs(connector, ret);
pm_runtime_mark_last_busy(connector->dev->dev);
pm_runtime_put_autosuspend(connector->dev->dev); if (!drm_kms_helper_is_poll_worker()) {
pm_runtime_mark_last_busy(connector->dev->dev);
pm_runtime_put_autosuspend(connector->dev->dev);
}
return ret; return ret;
} }
...@@ -862,9 +868,11 @@ amdgpu_connector_vga_detect(struct drm_connector *connector, bool force) ...@@ -862,9 +868,11 @@ amdgpu_connector_vga_detect(struct drm_connector *connector, bool force)
enum drm_connector_status ret = connector_status_disconnected; enum drm_connector_status ret = connector_status_disconnected;
int r; int r;
r = pm_runtime_get_sync(connector->dev->dev); if (!drm_kms_helper_is_poll_worker()) {
if (r < 0) r = pm_runtime_get_sync(connector->dev->dev);
return connector_status_disconnected; if (r < 0)
return connector_status_disconnected;
}
encoder = amdgpu_connector_best_single_encoder(connector); encoder = amdgpu_connector_best_single_encoder(connector);
if (!encoder) if (!encoder)
...@@ -918,8 +926,10 @@ amdgpu_connector_vga_detect(struct drm_connector *connector, bool force) ...@@ -918,8 +926,10 @@ amdgpu_connector_vga_detect(struct drm_connector *connector, bool force)
amdgpu_connector_update_scratch_regs(connector, ret); amdgpu_connector_update_scratch_regs(connector, ret);
out: out:
pm_runtime_mark_last_busy(connector->dev->dev); if (!drm_kms_helper_is_poll_worker()) {
pm_runtime_put_autosuspend(connector->dev->dev); pm_runtime_mark_last_busy(connector->dev->dev);
pm_runtime_put_autosuspend(connector->dev->dev);
}
return ret; return ret;
} }
...@@ -981,9 +991,11 @@ amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force) ...@@ -981,9 +991,11 @@ amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force)
enum drm_connector_status ret = connector_status_disconnected; enum drm_connector_status ret = connector_status_disconnected;
bool dret = false, broken_edid = false; bool dret = false, broken_edid = false;
r = pm_runtime_get_sync(connector->dev->dev); if (!drm_kms_helper_is_poll_worker()) {
if (r < 0) r = pm_runtime_get_sync(connector->dev->dev);
return connector_status_disconnected; if (r < 0)
return connector_status_disconnected;
}
if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) { if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
ret = connector->status; ret = connector->status;
...@@ -1108,8 +1120,10 @@ amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force) ...@@ -1108,8 +1120,10 @@ amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force)
amdgpu_connector_update_scratch_regs(connector, ret); amdgpu_connector_update_scratch_regs(connector, ret);
exit: exit:
pm_runtime_mark_last_busy(connector->dev->dev); if (!drm_kms_helper_is_poll_worker()) {
pm_runtime_put_autosuspend(connector->dev->dev); pm_runtime_mark_last_busy(connector->dev->dev);
pm_runtime_put_autosuspend(connector->dev->dev);
}
return ret; return ret;
} }
...@@ -1351,9 +1365,11 @@ amdgpu_connector_dp_detect(struct drm_connector *connector, bool force) ...@@ -1351,9 +1365,11 @@ amdgpu_connector_dp_detect(struct drm_connector *connector, bool force)
struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector); struct drm_encoder *encoder = amdgpu_connector_best_single_encoder(connector);
int r; int r;
r = pm_runtime_get_sync(connector->dev->dev); if (!drm_kms_helper_is_poll_worker()) {
if (r < 0) r = pm_runtime_get_sync(connector->dev->dev);
return connector_status_disconnected; if (r < 0)
return connector_status_disconnected;
}
if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) { if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
ret = connector->status; ret = connector->status;
...@@ -1421,8 +1437,10 @@ amdgpu_connector_dp_detect(struct drm_connector *connector, bool force) ...@@ -1421,8 +1437,10 @@ amdgpu_connector_dp_detect(struct drm_connector *connector, bool force)
amdgpu_connector_update_scratch_regs(connector, ret); amdgpu_connector_update_scratch_regs(connector, ret);
out: out:
pm_runtime_mark_last_busy(connector->dev->dev); if (!drm_kms_helper_is_poll_worker()) {
pm_runtime_put_autosuspend(connector->dev->dev); pm_runtime_mark_last_busy(connector->dev->dev);
pm_runtime_put_autosuspend(connector->dev->dev);
}
return ret; return ret;
} }
......
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