Commit aa0aad57 authored by Lukas Wunner's avatar Lukas Wunner

drm/amdgpu: Fix deadlock on runtime suspend

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.de
parent 15734fef
...@@ -737,9 +737,11 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force) ...@@ -737,9 +737,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);
...@@ -758,8 +760,12 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force) ...@@ -758,8 +760,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;
} }
...@@ -869,9 +875,11 @@ amdgpu_connector_vga_detect(struct drm_connector *connector, bool force) ...@@ -869,9 +875,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)
...@@ -925,8 +933,10 @@ amdgpu_connector_vga_detect(struct drm_connector *connector, bool force) ...@@ -925,8 +933,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;
} }
...@@ -989,9 +999,11 @@ amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force) ...@@ -989,9 +999,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;
...@@ -1116,8 +1128,10 @@ amdgpu_connector_dvi_detect(struct drm_connector *connector, bool force) ...@@ -1116,8 +1128,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;
} }
...@@ -1360,9 +1374,11 @@ amdgpu_connector_dp_detect(struct drm_connector *connector, bool force) ...@@ -1360,9 +1374,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;
...@@ -1430,8 +1446,10 @@ amdgpu_connector_dp_detect(struct drm_connector *connector, bool force) ...@@ -1430,8 +1446,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