Skip to contentSkip to conversation

Revert "drm/amd: Stop evicting resources on APUs in suspend"

PATCH In review Alex Deucher 2 participants 4 messages May 1, 2025

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/3 Revert "drm/amd: Stop evicting resources on APUs in suspend"

This reverts commit 3a9626c816db901def438dc2513622e281186d39.

This breaks S4 because we end up setting the s3/s0ix flags even when we are entering s4 since prepare is used by both flows. The causes both the S3/s0ix and s4 flags to be set which breaks several checks in the driver which assume they are mutually exclusive.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c   | 18 ------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 11 ++---------
 3 files changed, 2 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -2
index ef6e78224fdfa..c3641331d4de7 100644
@@ -1614,11 +1614,9 @@ static inline void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_cap
 #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
 bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
 bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
-void amdgpu_choose_low_power_state(struct amdgpu_device *adev);
 #else
 static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev) { return false; }
 static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev) { return false; }
-static inline void amdgpu_choose_low_power_state(struct amdgpu_device *adev) { }
 #endif
 
 void amdgpu_register_gpu_instance(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c +0 -18
index b7f8f2ff143dd..707e131f89d23 100644
@@ -1533,22 +1533,4 @@ bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
 #endif /* CONFIG_AMD_PMC */
 }
 
-/**
- * amdgpu_choose_low_power_state
- *
- * @adev: amdgpu_device_pointer
- *
- * Choose the target low power state for the GPU
- */
-void amdgpu_choose_low_power_state(struct amdgpu_device *adev)
-{
-	if (adev->in_runpm)
-		return;
-
-	if (amdgpu_acpi_is_s0ix_active(adev))
-		adev->in_s0ix = true;
-	else if (amdgpu_acpi_is_s3_active(adev))
-		adev->in_s3 = true;
-}
-
 #endif /* CONFIG_SUSPEND */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -9
index 7f354cd532dc1..5ac7bd5942d01 100644
@@ -4949,15 +4949,13 @@ int amdgpu_device_prepare(struct drm_device *dev)
 	struct amdgpu_device *adev = drm_to_adev(dev);
 	int i, r;
 
-	amdgpu_choose_low_power_state(adev);
-
 	if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
 		return 0;
 
 	/* Evict the majority of BOs before starting suspend sequence */
 	r = amdgpu_device_evict_resources(adev);
 	if (r)
-		goto unprepare;
+		return r;
 
 	flush_delayed_work(&adev->gfx.gfx_off_delay_work);
 
@@ -4968,15 +4966,10 @@ int amdgpu_device_prepare(struct drm_device *dev)
 			continue;
 		r = adev->ip_blocks[i].version->funcs->prepare_suspend(&adev->ip_blocks[i]);
 		if (r)
-			goto unprepare;
+			return r;
 	}
 
 	return 0;
-
-unprepare:
-	adev->in_s0ix = adev->in_s3 = adev->in_s4 = false;
-
-	return r;
 }
 
 /**
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 2/3 drm/amdgpu: stop evicting resources on APUs on suspend

Set the s3/s0ix and s4 in the pm notifier so that we can skip the resource evictions in the pm notifier and pm prepare functions, then reset them in pm prepare so that they can be set properly in the suspend and freeze callbacks.

v2: always reset flags in pm prepare

Cc Mario Limonciello <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 +++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 14 +++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -1
index 5ac7bd5942d01..a3e9f289e37c9 100644
@@ -4919,8 +4919,20 @@ static int amdgpu_device_pm_notifier(struct notifier_block *nb, unsigned long mo
 	switch (mode) {
 	case PM_HIBERNATION_PREPARE:
 		adev->in_s4 = true;
-		fallthrough;
+		r = amdgpu_device_evict_resources(adev);
+		/*
+		 * This is considered non-fatal at this time because
+		 * amdgpu_device_prepare() will also fatally evict resources.
+		 * See https://gitlab.freedesktop.org/drm/amd/-/issues/3781
+		 */
+		if (r)
+			drm_warn(adev_to_drm(adev), "Failed to evict resources, freeze active processes if problems occur: %d\n", r);
+		break;
 	case PM_SUSPEND_PREPARE:
+		if (amdgpu_acpi_is_s0ix_active(adev))
+			adev->in_s0ix = true;
+		else if (amdgpu_acpi_is_s3_active(adev))
+			adev->in_s3 = true;
 		r = amdgpu_device_evict_resources(adev);
 		/*
 		 * This is considered non-fatal at this time because
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +11 -3
index 24ee4710f807f..60c032f124149 100644
@@ -2516,22 +2516,29 @@ 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
 	 */
 	if (amdgpu_device_supports_boco(drm_dev) &&
-	    pm_runtime_suspended(dev))
+	    pm_runtime_suspended(dev)) {
+		adev->in_s0ix = adev->in_s3 = adev->in_s4 = false;
 		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))
+	    !amdgpu_acpi_is_s3_active(adev)) {
+		adev->in_s0ix = adev->in_s3 = adev->in_s4 = false;
 		return 1;
+	}
 
-	return amdgpu_device_prepare(drm_dev);
+	r = amdgpu_device_prepare(drm_dev);
+	adev->in_s0ix = adev->in_s3 = adev->in_s4 = false;
+	return r;
 }
 
 static void amdgpu_pmops_complete(struct device *dev)
@@ -2603,6 +2610,7 @@ static int amdgpu_pmops_freeze(struct device *dev)
 	struct amdgpu_device *adev = drm_to_adev(drm_dev);
 	int r;
 
+	adev->in_s4 = true;
 	r = amdgpu_device_suspend(drm_dev, true);
 	if (r)
 		return r;
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH 2/3] drm/amdgpu: stop evicting resources on APUs on suspend

Quoted 5 lines · Alex Deucher

Set the s3/s0ix and s4 in the pm notifier so that we can skip the resource evictions in the pm notifier and pm prepare functions, then reset them in pm prepare so that they can be set properly in the suspend and freeze callbacks.

Actually, this won't work reliably. If the notifier chain fails, we'll end up with these flags being set. will respin.

Alex

Alex

Quoted 84 lines

v2: always reset flags in pm prepare

Cc Mario Limonciello <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 +++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 14 +++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -1
index 5ac7bd5942d01..a3e9f289e37c9 100644
@@ -4919,8 +4919,20 @@ static int amdgpu_device_pm_notifier(struct notifier_block *nb, unsigned long mo
        switch (mode) {
        case PM_HIBERNATION_PREPARE:
                adev->in_s4 = true;
-               fallthrough;
+               r = amdgpu_device_evict_resources(adev);
+               /*
+                * This is considered non-fatal at this time because
+                * amdgpu_device_prepare() will also fatally evict resources.
+                * See https://gitlab.freedesktop.org/drm/amd/-/issues/3781
+                */
+               if (r)
+                       drm_warn(adev_to_drm(adev), "Failed to evict resources, freeze active processes if problems occur: %d\n", r);
+               break;
        case PM_SUSPEND_PREPARE:
+               if (amdgpu_acpi_is_s0ix_active(adev))
+                       adev->in_s0ix = true;
+               else if (amdgpu_acpi_is_s3_active(adev))
+                       adev->in_s3 = true;
                r = amdgpu_device_evict_resources(adev);
                /*
                 * This is considered non-fatal at this time because
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +11 -4
index 24ee4710f807f..60c032f124149 100644
@@ -2516,22 +2516,29 @@ 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
         */
        if (amdgpu_device_supports_boco(drm_dev) &&
-           pm_runtime_suspended(dev))
+           pm_runtime_suspended(dev)) {
+               adev->in_s0ix = adev->in_s3 = adev->in_s4 = false;
                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))
+           !amdgpu_acpi_is_s3_active(adev)) {
+               adev->in_s0ix = adev->in_s3 = adev->in_s4 = false;
                return 1;
+       }
 
-       return amdgpu_device_prepare(drm_dev);
+       r = amdgpu_device_prepare(drm_dev);
+       adev->in_s0ix = adev->in_s3 = adev->in_s4 = false;
+       return r;
 }
 
 static void amdgpu_pmops_complete(struct device *dev)
@@ -2603,6 +2610,7 @@ static int amdgpu_pmops_freeze(struct device *dev)
        struct amdgpu_device *adev = drm_to_adev(drm_dev);
        int r;
 
+       adev->in_s4 = true;
        r = amdgpu_device_suspend(drm_dev, true);
        if (r)
                return r;
--

2.49.0

author maintainer
#3 lore raw

PATCH 3/3 drm/amdgpu: drop eviction in pm notifier callbacks

In reply to Alex Deucher

We can't evict VRAM while processes are running as they will continue to submit work which causes buffers to get pulled back into VRAM.

Unfortunately we need a way to still have swap while processes are fozen if memory is limited.

Fixes 2965e6355dcd ("drm/amd: Add Suspend/Hibernate notification callback support")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -19
index a3e9f289e37c9..dd2a557f97634 100644
@@ -4907,40 +4907,23 @@ static int amdgpu_device_evict_resources(struct amdgpu_device *adev)
  * @data: data
  *
  * This function is called when the system is about to suspend or hibernate.
- * It is used to evict resources from the device before the system goes to
- * sleep while there is still access to swap.
+ * It is used to set the appropriate flags so that eviction can be optimized
+ * in the pm prepare callback.
  */
 static int amdgpu_device_pm_notifier(struct notifier_block *nb, unsigned long mode,
 				     void *data)
 {
 	struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, pm_nb);
-	int r;
 
 	switch (mode) {
 	case PM_HIBERNATION_PREPARE:
 		adev->in_s4 = true;
-		r = amdgpu_device_evict_resources(adev);
-		/*
-		 * This is considered non-fatal at this time because
-		 * amdgpu_device_prepare() will also fatally evict resources.
-		 * See https://gitlab.freedesktop.org/drm/amd/-/issues/3781
-		 */
-		if (r)
-			drm_warn(adev_to_drm(adev), "Failed to evict resources, freeze active processes if problems occur: %d\n", r);
 		break;
 	case PM_SUSPEND_PREPARE:
 		if (amdgpu_acpi_is_s0ix_active(adev))
 			adev->in_s0ix = true;
 		else if (amdgpu_acpi_is_s3_active(adev))
 			adev->in_s3 = true;
-		r = amdgpu_device_evict_resources(adev);
-		/*
-		 * This is considered non-fatal at this time because
-		 * amdgpu_device_prepare() will also fatally evict resources.
-		 * See https://gitlab.freedesktop.org/drm/amd/-/issues/3781
-		 */
-		if (r)
-			drm_warn(adev_to_drm(adev), "Failed to evict resources, freeze active processes if problems occur: %d\n", r);
 		break;
 	}
 
Signature · 1 line
2.49.0