From: George Zhang <[email protected]>

If an HPD event occurs during gpu reset, dm_suspend will take dc_lock.
dm_suspend then calls irq_suspend, which will flush the IRQ workqueue.
This will cause any pending HPD work to try to take dc_lock, causing a
deadlock.

Don't take the lock in the HPD handler if gpu is in reset.

Also fix some KUnit tests that now requires a non-NULL
adev->reset_domain.

Cc: Alex Hung <[email protected]>
Signed-off-by: George Zhang <[email protected]>
Signed-off-by: Wayne Lin <[email protected]>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c  | 10 ++++++----
 .../amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c   |  6 ++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c
index 5b4ff079cd55..18060a9ee890 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c
@@ -1444,10 +1444,12 @@ STATIC_IFN_KUNIT void handle_hpd_irq_helper(struct 
amdgpu_dm_connector *aconnect
                if (delayed_work_pending(&aconnector->hdmi_hpd_debounce_work))
                        return;
 
-               scoped_guard(mutex, &adev->dm.dc_lock) {
-                       dc_exit_ips_for_hw_access(dc);
-                       ret = dc_link_detect(aconnector->dc_link, reason);
-               }
+               if (!amdgpu_in_reset(adev))
+                       mutex_lock(&adev->dm.dc_lock);
+               dc_exit_ips_for_hw_access(dc);
+               ret = dc_link_detect(aconnector->dc_link, reason);
+               if (!amdgpu_in_reset(adev))
+                       mutex_unlock(&adev->dm.dc_lock);
                if (ret) {
                        /* w/a delay for certain panels */
                        amdgpu_dm_apply_delay_after_dpcd_poweroff(adev, 
aconnector->dc_sink);
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c
index c0c913d95aec..105e3ba38290 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_irq_test.c
@@ -2746,6 +2746,9 @@ static struct amdgpu_dm_connector 
*dm_test_setup_hpd_irq_helper(struct kunit *te
 
        adev = dm_kunit_alloc_adev(test);
        mutex_init(&adev->dm.dc_lock);
+       adev->reset_domain = kunit_kzalloc(test, sizeof(*adev->reset_domain),
+                                          GFP_KERNEL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev->reset_domain);
 
        aconn = dm_kunit_alloc_connector(test, adev, NULL);
        mutex_init(&aconn->hpd_lock);
@@ -3462,6 +3465,9 @@ static void dm_test_dmub_hpd_callback_hpd_type(struct 
kunit *test)
 
        adev = dm_kunit_alloc_adev(test);
        mutex_init(&adev->dm.dc_lock);
+       adev->reset_domain = kunit_kzalloc(test, sizeof(*adev->reset_domain),
+                                          GFP_KERNEL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, adev->reset_domain);
 
        dc = kunit_kzalloc(test, sizeof(*dc), GFP_KERNEL);
        KUNIT_ASSERT_NOT_NULL(test, dc);
-- 
2.43.0

Reply via email to