Skip to contentSkip to conversation

Revert "drm/amd: flush any delayed gfxoff on suspend entry"

PATCH Superseded Mario Limonciello 2 participants 6 messages Feb 7, 2024

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 Revert "drm/amd: flush any delayed gfxoff on suspend entry"

commit ab4750332dbe ("drm/amdgpu/sdma5.2: add begin/end_use ring callbacks") caused GFXOFF control to be used more heavily and the codepath that was removed from commit 0dee72639533 ("drm/amd: flush any delayed gfxoff on suspend entry") now can be exercised at suspend again.

Users report that by using GNOME to suspend the lockscreen trigger will cause SDMA traffic and the system can deadlock.

This reverts commit 0dee726395333fea833eaaf838bc80962df886c8.

Fixes ab4750332dbe ("drm/amdgpu/sdma5.2: add begin/end_use ring callbacks")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 9 ++++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
index 670ecb789d59..2bc460cb993d 100644
@@ -4573,7 +4573,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)
 		drm_fb_helper_set_suspend_unlocked(adev_to_drm(adev)->fb_helper, true);
 
 	cancel_delayed_work_sync(&adev->delayed_init_work);
-	flush_delayed_work(&adev->gfx.gfx_off_delay_work);
 
 	amdgpu_ras_suspend(adev);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -1
index aa8e1d29d10a..9831dd854532 100644
@@ -727,8 +727,15 @@ void amdgpu_gfx_off_ctrl(struct amdgpu_device *adev, bool enable)
 
 		if (adev->gfx.gfx_off_req_count == 0 &&
 		    !adev->gfx.gfx_off_state) {
-			schedule_delayed_work(&adev->gfx.gfx_off_delay_work,
+			/* If going to s2idle, no need to wait */
+			if (adev->in_s0ix) {
+				if (!amdgpu_dpm_set_powergating_by_smu(adev,
+						AMD_IP_BLOCK_TYPE_GFX, true))
+					adev->gfx.gfx_off_state = true;
+			} else {
+				schedule_delayed_work(&adev->gfx.gfx_off_delay_work,
 					      delay);
+			}
 		}
 	} else {
 		if (adev->gfx.gfx_off_req_count == 0) {
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 drm/amd: Stop evicting resources on APUs in suspend

commit 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback") intentionally moved the eviction of resources to earlier in the suspend process, but this introduced a subtle change that it occurs before adev->in_s0ix or adev->in_s3 are set. This meant that APUs actually started to evict resources at suspend time as well.

Add a new in_prepare flag that is set for the life of the prepare() callback to return the old code flow. Drop the existing call to return 1 in this case because the suspend() callback looks for the flags too.

Also, introduce a new amdgpu_device_freeze() function to call at S4 and evict resources in this callback so that APUs will still get resources evicted.

Fixes 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback")

---
v1->v2:
* Add and use new in_prepare member

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 46 ++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 21 ++--------
 3 files changed, 48 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -1
index 5d5be3e20687..f9db09a9017a 100644
@@ -1075,7 +1075,8 @@ struct amdgpu_device {
 	u8				reset_magic[AMDGPU_RESET_MAGIC_NUM];
 
 	/* s3/s4 mask */
-	bool                            in_suspend;
+	bool				in_prepare;
+	bool				in_suspend;
 	bool				in_s3;
 	bool				in_s4;
 	bool				in_s0ix;
@@ -1462,6 +1463,7 @@ int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
 int amdgpu_device_prepare(struct drm_device *dev);
 int amdgpu_device_suspend(struct drm_device *dev, bool fbcon);
 int amdgpu_device_resume(struct drm_device *dev, bool fbcon);
+int amdgpu_device_freeze(struct drm_device *drm_dev);
 u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc);
 int amdgpu_enable_vblank_kms(struct drm_crtc *crtc);
 void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +42 -4

69 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -18
index b74f68a15802..fc9caa14c9d6 100644
@@ -2456,6 +2456,7 @@ static int amdgpu_pmops_prepare(struct device *dev)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = drm_to_adev(drm_dev);
+	int r;
 
 	/* Return a positive number here so
 	 * DPM_FLAG_SMART_SUSPEND works properly
@@ -2464,13 +2465,6 @@ static int amdgpu_pmops_prepare(struct device *dev)
 	    pm_runtime_suspended(dev))
 		return 1;
 
-	/* if we will not support s3 or s2i for the device
-	 *  then skip suspend
-	 */
-	if (!amdgpu_acpi_is_s0ix_active(adev) &&
-	    !amdgpu_acpi_is_s3_active(adev))
-		return 1;
-
 	return amdgpu_device_prepare(drm_dev);
 }
 
@@ -2488,6 +2482,7 @@ static int amdgpu_pmops_suspend(struct device *dev)
 		adev->in_s0ix = true;
 	else if (amdgpu_acpi_is_s3_active(adev))
 		adev->in_s3 = true;
+
 	if (!adev->in_s0ix && !adev->in_s3)
 		return 0;
 	return amdgpu_device_suspend(drm_dev, true);
@@ -2528,18 +2523,8 @@ static int amdgpu_pmops_resume(struct device *dev)
 static int amdgpu_pmops_freeze(struct device *dev)
 {
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
-	struct amdgpu_device *adev = drm_to_adev(drm_dev);
-	int r;
-
-	adev->in_s4 = true;
-	r = amdgpu_device_suspend(drm_dev, true);
-	adev->in_s4 = false;
-	if (r)
-		return r;
 
-	if (amdgpu_acpi_should_gpu_reset(adev))
-		return amdgpu_asic_reset(adev);
-	return 0;
+	return amdgpu_device_freeze(drm_dev);
 }
 
 static int amdgpu_pmops_thaw(struct device *dev)
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 2/2] drm/amd: Stop evicting resources on APUs in suspend

Quoted 54 lines · Mario Limonciello

commit 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback") intentionally moved the eviction of resources to earlier in the suspend process, but this introduced a subtle change that it occurs before adev->in_s0ix or adev->in_s3 are set. This meant that APUs actually started to evict resources at suspend time as well.

Add a new in_prepare flag that is set for the life of the prepare() callback to return the old code flow. Drop the existing call to return 1 in this case because the suspend() callback looks for the flags too.

Also, introduce a new amdgpu_device_freeze() function to call at S4 and evict resources in this callback so that APUs will still get resources evicted.

Fixes 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback")

---
v1->v2:
* Add and use new in_prepare member

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 46 ++++++++++++++++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 21 ++--------
 3 files changed, 48 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -1
index 5d5be3e20687..f9db09a9017a 100644
@@ -1075,7 +1075,8 @@ struct amdgpu_device {
        u8                              reset_magic[AMDGPU_RESET_MAGIC_NUM];
 
        /* s3/s4 mask */
-       bool                            in_suspend;
+       bool                            in_prepare;
+       bool                            in_suspend;
        bool                            in_s3;
        bool                            in_s4;
        bool                            in_s0ix;
@@ -1462,6 +1463,7 @@ int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
 int amdgpu_device_prepare(struct drm_device *dev);
 int amdgpu_device_suspend(struct drm_device *dev, bool fbcon);
 int amdgpu_device_resume(struct drm_device *dev, bool fbcon);
+int amdgpu_device_freeze(struct drm_device *drm_dev);
 u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc);
 int amdgpu_enable_vblank_kms(struct drm_crtc *crtc);
 void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 2bc460cb993d..0a337fcd89b4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_evict_resources(struct amdgpu_device *adev) · line 4495

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -4492,7 +4492,7 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)
        int ret;
 
        /* No need to evict vram on APUs for suspend to ram or s2idle */
-       if ((adev->in_s3 || adev->in_s0ix) && (adev->flags & AMD_IS_APU))
+       if ((adev->in_prepare) && (adev->flags & AMD_IS_APU))

Could probably simplify this to:
if ((!adev->in_s4) && (adev->flags & AMD_IS_APU))

Then you could drop the in_prepare variable.

Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +17 -3
                return 0;
 
        ret = amdgpu_ttm_evict_resources(adev, TTM_PL_VRAM);
@@ -4521,10 +4521,12 @@ int amdgpu_device_prepare(struct drm_device *dev)
        if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
                return 0;
 
+       adev->in_prepare = true;
+
        /* Evict the majority of BOs before starting suspend sequence */
        r = amdgpu_device_evict_resources(adev);
        if (r)
-               return r;
+               goto unprepare;
 
        for (i = 0; i < adev->num_ip_blocks; i++) {
                if (!adev->ip_blocks[i].status.valid)
@@ -4533,10 +4535,46 @@ int amdgpu_device_prepare(struct drm_device *dev)
                        continue;
                r = adev->ip_blocks[i].version->funcs->prepare_suspend((void *)adev);
                if (r)
-                       return r;
+                       goto unprepare;
        }
 
-       return 0;
+unprepare:
+       adev->in_prepare = FALSE;
+
+       return r;
+}
+
+/**
+ * amdgpu_device_freeze - run S4 sequence
+ *
+ * @dev: drm dev pointer
+ *
+ * Prepare to put the hw in the S4 state (all asics).
+ * Returns 0 for success or an error on failure.

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_prepare(struct drm_device *dev) · line 4563

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10 -0
+ * Called at driver freeze.
+ */
+int amdgpu_device_freeze(struct drm_device *drm_dev)
+{
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
+       int r;
+
+       adev->in_s4 = true;
+
+       r = amdgpu_device_evict_resources(adev);

Won't this be too late to allocate memory? Doesn't this need to happen in prepare() even for S4?

Alex

Quoted 74 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +14 -0
+       if (r)
+               goto cleanup;
+
+       r = amdgpu_device_suspend(drm_dev, true);
+       if (r)
+               goto cleanup;
+
+       if (amdgpu_acpi_should_gpu_reset(adev))
+               r = amdgpu_asic_reset(adev);
+
+cleanup:
+       adev->in_s4 = false;
+
+       return r;
 }
 
 /**
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -19
index b74f68a15802..fc9caa14c9d6 100644
@@ -2456,6 +2456,7 @@ static int amdgpu_pmops_prepare(struct device *dev)
 {
        struct drm_device *drm_dev = dev_get_drvdata(dev);
        struct amdgpu_device *adev = drm_to_adev(drm_dev);
+       int r;
 
        /* Return a positive number here so
         * DPM_FLAG_SMART_SUSPEND works properly
@@ -2464,13 +2465,6 @@ static int amdgpu_pmops_prepare(struct device *dev)
            pm_runtime_suspended(dev))
                return 1;
 
-       /* if we will not support s3 or s2i for the device
-        *  then skip suspend
-        */
-       if (!amdgpu_acpi_is_s0ix_active(adev) &&
-           !amdgpu_acpi_is_s3_active(adev))
-               return 1;
-
        return amdgpu_device_prepare(drm_dev);
 }
 
@@ -2488,6 +2482,7 @@ static int amdgpu_pmops_suspend(struct device *dev)
                adev->in_s0ix = true;
        else if (amdgpu_acpi_is_s3_active(adev))
                adev->in_s3 = true;
+
        if (!adev->in_s0ix && !adev->in_s3)
                return 0;
        return amdgpu_device_suspend(drm_dev, true);
@@ -2528,18 +2523,8 @@ static int amdgpu_pmops_resume(struct device *dev)
 static int amdgpu_pmops_freeze(struct device *dev)
 {
        struct drm_device *drm_dev = dev_get_drvdata(dev);
-       struct amdgpu_device *adev = drm_to_adev(drm_dev);
-       int r;
-
-       adev->in_s4 = true;
-       r = amdgpu_device_suspend(drm_dev, true);
-       adev->in_s4 = false;
-       if (r)
-               return r;
 
-       if (amdgpu_acpi_should_gpu_reset(adev))
-               return amdgpu_asic_reset(adev);
-       return 0;
+       return amdgpu_device_freeze(drm_dev);
 }
 
 static int amdgpu_pmops_thaw(struct device *dev)
--

2.34.1

#3 lore raw

Re: [PATCH v2 2/2] drm/amd: Stop evicting resources on APUs in suspend

Quoted 111 lines · Alex Deucher
Quoted 54 lines · Mario Limonciello

commit 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback") intentionally moved the eviction of resources to earlier in the suspend process, but this introduced a subtle change that it occurs before adev->in_s0ix or adev->in_s3 are set. This meant that APUs actually started to evict resources at suspend time as well.

Add a new in_prepare flag that is set for the life of the prepare() callback to return the old code flow. Drop the existing call to return 1 in this case because the suspend() callback looks for the flags too.

Also, introduce a new amdgpu_device_freeze() function to call at S4 and evict resources in this callback so that APUs will still get resources evicted.

Fixes 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback")

---
v1->v2:
* Add and use new in_prepare member

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  4 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 46 ++++++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 21 ++--------
  3 files changed, 48 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -1
index 5d5be3e20687..f9db09a9017a 100644
@@ -1075,7 +1075,8 @@ struct amdgpu_device {
         u8                              reset_magic[AMDGPU_RESET_MAGIC_NUM];
 
         /* s3/s4 mask */
-       bool                            in_suspend;
+       bool                            in_prepare;
+       bool                            in_suspend;
         bool                            in_s3;
         bool                            in_s4;
         bool                            in_s0ix;
@@ -1462,6 +1463,7 @@ int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
  int amdgpu_device_prepare(struct drm_device *dev);
  int amdgpu_device_suspend(struct drm_device *dev, bool fbcon);
  int amdgpu_device_resume(struct drm_device *dev, bool fbcon);
+int amdgpu_device_freeze(struct drm_device *drm_dev);
  u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc);
  int amdgpu_enable_vblank_kms(struct drm_crtc *crtc);
  void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 2bc460cb993d..0a337fcd89b4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_evict_resources(struct amdgpu_device *adev) · line 4495

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -4492,7 +4492,7 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)
         int ret;
 
         /* No need to evict vram on APUs for suspend to ram or s2idle */
-       if ((adev->in_s3 || adev->in_s0ix) && (adev->flags & AMD_IS_APU))
+       if ((adev->in_prepare) && (adev->flags & AMD_IS_APU))

Could probably simplify this to:
if ((!adev->in_s4) && (adev->flags & AMD_IS_APU))

Then you could drop the in_prepare variable.

Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +22 -3
                 return 0;
 
         ret = amdgpu_ttm_evict_resources(adev, TTM_PL_VRAM);
@@ -4521,10 +4521,12 @@ int amdgpu_device_prepare(struct drm_device *dev)
         if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
                 return 0;
 
+       adev->in_prepare = true;
+
         /* Evict the majority of BOs before starting suspend sequence */
         r = amdgpu_device_evict_resources(adev);
         if (r)
-               return r;
+               goto unprepare;
 
         for (i = 0; i < adev->num_ip_blocks; i++) {
                 if (!adev->ip_blocks[i].status.valid)
@@ -4533,10 +4535,46 @@ int amdgpu_device_prepare(struct drm_device *dev)
                         continue;
                 r = adev->ip_blocks[i].version->funcs->prepare_suspend((void *)adev);
                 if (r)
-                       return r;
+                       goto unprepare;
         }
 
-       return 0;
+unprepare:
+       adev->in_prepare = FALSE;
+
+       return r;
+}
+
+/**
+ * amdgpu_device_freeze - run S4 sequence
+ *
+ * @dev: drm dev pointer
+ *
+ * Prepare to put the hw in the S4 state (all asics).
+ * Returns 0 for success or an error on failure.
+ * Called at driver freeze.
+ */
+int amdgpu_device_freeze(struct drm_device *drm_dev)
+{
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_prepare(struct drm_device *dev) · line 4563

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
+       int r;
+
+       adev->in_s4 = true;
+
+       r = amdgpu_device_evict_resources(adev);

Won't this be too late to allocate memory? Doesn't this need to happen in prepare() even for S4?

Hmm; possibly. I'll swap it back with your other suggestion.

Thanks

Quoted 77 lines

Alex

Quoted 74 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +14 -0
+       if (r)
+               goto cleanup;
+
+       r = amdgpu_device_suspend(drm_dev, true);
+       if (r)
+               goto cleanup;
+
+       if (amdgpu_acpi_should_gpu_reset(adev))
+               r = amdgpu_asic_reset(adev);
+
+cleanup:
+       adev->in_s4 = false;
+
+       return r;
  }
 
  /**
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -19
index b74f68a15802..fc9caa14c9d6 100644
@@ -2456,6 +2456,7 @@ static int amdgpu_pmops_prepare(struct device *dev)
  {
         struct drm_device *drm_dev = dev_get_drvdata(dev);
         struct amdgpu_device *adev = drm_to_adev(drm_dev);
+       int r;
 
         /* Return a positive number here so
          * DPM_FLAG_SMART_SUSPEND works properly
@@ -2464,13 +2465,6 @@ static int amdgpu_pmops_prepare(struct device *dev)
             pm_runtime_suspended(dev))
                 return 1;
 
-       /* if we will not support s3 or s2i for the device
-        *  then skip suspend
-        */
-       if (!amdgpu_acpi_is_s0ix_active(adev) &&
-           !amdgpu_acpi_is_s3_active(adev))
-               return 1;
-
         return amdgpu_device_prepare(drm_dev);
  }
 
@@ -2488,6 +2482,7 @@ static int amdgpu_pmops_suspend(struct device *dev)
                 adev->in_s0ix = true;
         else if (amdgpu_acpi_is_s3_active(adev))
                 adev->in_s3 = true;
+
         if (!adev->in_s0ix && !adev->in_s3)
                 return 0;
         return amdgpu_device_suspend(drm_dev, true);
@@ -2528,18 +2523,8 @@ static int amdgpu_pmops_resume(struct device *dev)
  static int amdgpu_pmops_freeze(struct device *dev)
  {
         struct drm_device *drm_dev = dev_get_drvdata(dev);
-       struct amdgpu_device *adev = drm_to_adev(drm_dev);
-       int r;
-
-       adev->in_s4 = true;
-       r = amdgpu_device_suspend(drm_dev, true);
-       adev->in_s4 = false;
-       if (r)
-               return r;
 
-       if (amdgpu_acpi_should_gpu_reset(adev))
-               return amdgpu_asic_reset(adev);
-       return 0;
+       return amdgpu_device_freeze(drm_dev);
  }
 
  static int amdgpu_pmops_thaw(struct device *dev)
--

2.34.1

#4 lore raw

Re: [PATCH v2 2/2] drm/amd: Stop evicting resources on APUs in suspend

Quoted 122 lines · Mario Limonciello
Quoted 111 lines · Alex Deucher
Quoted 54 lines · Mario Limonciello

commit 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback") intentionally moved the eviction of resources to earlier in the suspend process, but this introduced a subtle change that it occurs before adev->in_s0ix or adev->in_s3 are set. This meant that APUs actually started to evict resources at suspend time as well.

Add a new in_prepare flag that is set for the life of the prepare() callback to return the old code flow. Drop the existing call to return 1 in this case because the suspend() callback looks for the flags too.

Also, introduce a new amdgpu_device_freeze() function to call at S4 and evict resources in this callback so that APUs will still get resources evicted.

Fixes 5095d5418193 ("drm/amd: Evict resources during PM ops prepare() callback")

---
v1->v2:
* Add and use new in_prepare member

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  4 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 46 ++++++++++++++++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 21 ++--------
  3 files changed, 48 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -1
index 5d5be3e20687..f9db09a9017a 100644
@@ -1075,7 +1075,8 @@ struct amdgpu_device {
         u8                              reset_magic[AMDGPU_RESET_MAGIC_NUM];
 
         /* s3/s4 mask */
-       bool                            in_suspend;
+       bool                            in_prepare;
+       bool                            in_suspend;
         bool                            in_s3;
         bool                            in_s4;
         bool                            in_s0ix;
@@ -1462,6 +1463,7 @@ int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
  int amdgpu_device_prepare(struct drm_device *dev);
  int amdgpu_device_suspend(struct drm_device *dev, bool fbcon);
  int amdgpu_device_resume(struct drm_device *dev, bool fbcon);
+int amdgpu_device_freeze(struct drm_device *drm_dev);
  u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc);
  int amdgpu_enable_vblank_kms(struct drm_crtc *crtc);
  void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 2bc460cb993d..0a337fcd89b4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_device_evict_resources(struct amdgpu_device *adev) · line 4495

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -4492,7 +4492,7 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)
         int ret;
 
         /* No need to evict vram on APUs for suspend to ram or s2idle */
-       if ((adev->in_s3 || adev->in_s0ix) && (adev->flags & AMD_IS_APU))
+       if ((adev->in_prepare) && (adev->flags & AMD_IS_APU))

Could probably simplify this to:
if ((!adev->in_s4) && (adev->flags & AMD_IS_APU))

Then you could drop the in_prepare variable.

Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +22 -3
                 return 0;
 
         ret = amdgpu_ttm_evict_resources(adev, TTM_PL_VRAM);
@@ -4521,10 +4521,12 @@ int amdgpu_device_prepare(struct drm_device *dev)
         if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
                 return 0;
 
+       adev->in_prepare = true;
+
         /* Evict the majority of BOs before starting suspend sequence */
         r = amdgpu_device_evict_resources(adev);
         if (r)
-               return r;
+               goto unprepare;
 
         for (i = 0; i < adev->num_ip_blocks; i++) {
                 if (!adev->ip_blocks[i].status.valid)
@@ -4533,10 +4535,46 @@ int amdgpu_device_prepare(struct drm_device *dev)
                         continue;
                 r = adev->ip_blocks[i].version->funcs->prepare_suspend((void *)adev);
                 if (r)
-                       return r;
+                       goto unprepare;
         }
 
-       return 0;
+unprepare:
+       adev->in_prepare = FALSE;
+
+       return r;
+}
+
+/**
+ * amdgpu_device_freeze - run S4 sequence
+ *
+ * @dev: drm dev pointer
+ *
+ * Prepare to put the hw in the S4 state (all asics).
+ * Returns 0 for success or an error on failure.
+ * Called at driver freeze.
+ */
+int amdgpu_device_freeze(struct drm_device *drm_dev)
+{
+       struct amdgpu_device *adev = drm_to_adev(drm_dev);
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_prepare(struct drm_device *dev) · line 4563

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
+       int r;
+
+       adev->in_s4 = true;
+
+       r = amdgpu_device_evict_resources(adev);

Won't this be too late to allocate memory? Doesn't this need to happen in prepare() even for S4?

Quoted 1 line

Hmm; possibly. I'll swap it back with your other suggestion.

I think we need to know at prepare time what state we are targeting. I think that would allow us to clean up a lot of the in_s3, in_s4, in_s0x checks. Something like adev->target_pm_state maybe?

Alex

Quoted 80 lines

Thanks

Quoted 77 lines

Alex

Quoted 74 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +14 -0
+       if (r)
+               goto cleanup;
+
+       r = amdgpu_device_suspend(drm_dev, true);
+       if (r)
+               goto cleanup;
+
+       if (amdgpu_acpi_should_gpu_reset(adev))
+               r = amdgpu_asic_reset(adev);
+
+cleanup:
+       adev->in_s4 = false;
+
+       return r;
  }
 
  /**
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -19
index b74f68a15802..fc9caa14c9d6 100644
@@ -2456,6 +2456,7 @@ static int amdgpu_pmops_prepare(struct device *dev)
  {
         struct drm_device *drm_dev = dev_get_drvdata(dev);
         struct amdgpu_device *adev = drm_to_adev(drm_dev);
+       int r;
 
         /* Return a positive number here so
          * DPM_FLAG_SMART_SUSPEND works properly
@@ -2464,13 +2465,6 @@ static int amdgpu_pmops_prepare(struct device *dev)
             pm_runtime_suspended(dev))
                 return 1;
 
-       /* if we will not support s3 or s2i for the device
-        *  then skip suspend
-        */
-       if (!amdgpu_acpi_is_s0ix_active(adev) &&
-           !amdgpu_acpi_is_s3_active(adev))
-               return 1;
-
         return amdgpu_device_prepare(drm_dev);
  }
 
@@ -2488,6 +2482,7 @@ static int amdgpu_pmops_suspend(struct device *dev)
                 adev->in_s0ix = true;
         else if (amdgpu_acpi_is_s3_active(adev))
                 adev->in_s3 = true;
+
         if (!adev->in_s0ix && !adev->in_s3)
                 return 0;
         return amdgpu_device_suspend(drm_dev, true);
@@ -2528,18 +2523,8 @@ static int amdgpu_pmops_resume(struct device *dev)
  static int amdgpu_pmops_freeze(struct device *dev)
  {
         struct drm_device *drm_dev = dev_get_drvdata(dev);
-       struct amdgpu_device *adev = drm_to_adev(drm_dev);
-       int r;
-
-       adev->in_s4 = true;
-       r = amdgpu_device_suspend(drm_dev, true);
-       adev->in_s4 = false;
-       if (r)
-               return r;
 
-       if (amdgpu_acpi_should_gpu_reset(adev))
-               return amdgpu_asic_reset(adev);
-       return 0;
+       return amdgpu_device_freeze(drm_dev);
  }
 
  static int amdgpu_pmops_thaw(struct device *dev)
--

2.34.1

Acked-by on v2 1/2
#5 lore raw
In reply to Mario Limonciello
Quoted 6 lines · Mario Limonciello

commit ab4750332dbe ("drm/amdgpu/sdma5.2: add begin/end_use ring callbacks") caused GFXOFF control to be used more heavily and the codepath that was removed from commit 0dee72639533 ("drm/amd: flush any delayed gfxoff on suspend entry") now can be exercised at suspend again.

Quoted 7 lines

Users report that by using GNOME to suspend the lockscreen trigger will cause SDMA traffic and the system can deadlock.

This reverts commit 0dee726395333fea833eaaf838bc80962df886c8.

Fixes ab4750332dbe ("drm/amdgpu/sdma5.2: add begin/end_use ring callbacks")
Quoted 41 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 9 ++++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -1
index 670ecb789d59..2bc460cb993d 100644
@@ -4573,7 +4573,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool fbcon)
                drm_fb_helper_set_suspend_unlocked(adev_to_drm(adev)->fb_helper, true);
 
        cancel_delayed_work_sync(&adev->delayed_init_work);
-       flush_delayed_work(&adev->gfx.gfx_off_delay_work);
 
        amdgpu_ras_suspend(adev);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -2
index aa8e1d29d10a..9831dd854532 100644
@@ -727,8 +727,15 @@ void amdgpu_gfx_off_ctrl(struct amdgpu_device *adev, bool enable)
 
                if (adev->gfx.gfx_off_req_count == 0 &&
                    !adev->gfx.gfx_off_state) {
-                       schedule_delayed_work(&adev->gfx.gfx_off_delay_work,
+                       /* If going to s2idle, no need to wait */
+                       if (adev->in_s0ix) {
+                               if (!amdgpu_dpm_set_powergating_by_smu(adev,
+                                               AMD_IP_BLOCK_TYPE_GFX, true))
+                                       adev->gfx.gfx_off_state = true;
+                       } else {
+                               schedule_delayed_work(&adev->gfx.gfx_off_delay_work,
                                              delay);
+                       }
                }
        } else {
                if (adev->gfx.gfx_off_req_count == 0) {
--

2.34.1