From: "Mario Limonciello (AMD)" <[email protected]>

[Why]
On a normal hibernate sequence amdgpu will skip the thaw step due to
commit 530694f54dd5e ("drm/amdgpu: do not resume device in thaw for
normal hibernation").

If the hibernate sequence has been aborted however after this thawed
step runs the PM core will think the device is suspended and will skip
the restore() sequence for amdgpu.  This leads to accessing the device
while in a low power state and will freeze the system.

[How]
Set `dev->power.is_frozen` to indicate to the PM core that an error
code will be returned for thaw() callback because driver managed the
frozen state.  If the restore() callback is called by the PM core the
driver will resume the device.

Cc: Muhammad Usama Anjum <[email protected]>
Signed-off-by: Mario Limonciello (AMD) <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 ++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 3d032c4e2dce..693347eb6861 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -5247,6 +5247,11 @@ int amdgpu_device_suspend(struct drm_device *dev, bool 
notify_clients)
        if (r)
                return r;
 
+#ifdef CONFIG_HIBERNATE_CALLBACKS
+       if (adev->in_s4)
+               dev->dev->power.is_frozen = 1;
+#endif
+
        return 0;
 }
 
@@ -5385,6 +5390,11 @@ int amdgpu_device_resume(struct drm_device *dev, bool 
notify_clients)
        if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DEV_D0))
                dev_warn(adev->dev, "smart shift update failed\n");
 
+#ifdef CONFIG_HIBERNATE_CALLBACKS
+       if (adev->in_s4)
+               dev->dev->power.is_frozen = 0;
+#endif
+
        return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 61268aa82df4..d40af069f24d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2681,7 +2681,7 @@ static int amdgpu_pmops_thaw(struct device *dev)
 
        /* do not resume device if it's normal hibernation */
        if (!pm_hibernate_is_recovering() && !pm_hibernation_mode_is_suspend())
-               return 0;
+               return -EBUSY;
 
        return amdgpu_device_resume(drm_dev, true);
 }
-- 
2.51.0

Reply via email to