All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: run prepare-phase eviction for hibernation on APUs
@ 2026-12-04 21:07 Mario Limonciello
  2026-12-04 21:27 ` sashiko-bot
  2026-12-04 21:42 ` Alex Deucher
  0 siblings, 2 replies; 3+ messages in thread
From: Mario Limonciello @ 2026-12-04 21:07 UTC (permalink / raw)
  To: Alex Deucher; +Cc: amd-gfx, Mario Limonciello

amdgpu_pmops_prepare() returns early when neither s0ix nor s3 is
active.  On an APU both helpers test pm_suspend_target_state, which is
only set by suspend_devices_and_enter() and so is PM_SUSPEND_ON
throughout hibernation_snapshot().  As a result amdgpu_device_prepare()
is skipped for hibernation on APUs, and with it the VRAM eviction and
ttm_device_prepare_hibernation() that the PM notifier sets in_s4 up for.

The eviction instead happens from amdgpu_pmops_freeze(), after
hibernate_preallocate_memory() has already sized the image and after
pm_restrict_gfp_mask() has made it impossible to swap anything out.
Everything evicted into shmem/TTM pools at that point lands in the
image unaccounted for, and under memory pressure snapshot creation
fails:

  PM: hibernation: Not enough free memory for image creation
  PM: hibernation: Error -12 creating image

Discrete GPUs are unaffected as amdgpu_acpi_is_s3_active() is
unconditionally true for them.

Don't take the early return when adev->in_s4 is set, so the eviction
runs in the prepare phase, before the image is preallocated.

Fixes: 06f2dcc241e7 ("drm/amdgpu: fix pm notifier handling"),
Closes: https://gitlab.freedesktop.org/drm/amd/-/work_items/4711
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 9c14008720063..60d1c194d8cff 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2636,9 +2636,11 @@ static int amdgpu_pmops_prepare(struct device *dev)
 		return 1;
 
 	/* if we will not support s3 or s2i for the device
-	 *  then skip suspend
+	 *  then skip suspend, but not for hibernation: resources need to be
+	 *  evicted here, before the hibernation image is sized.
 	 */
-	if (!amdgpu_acpi_is_s0ix_active(adev) &&
+	if (!adev->in_s4 &&
+	    !amdgpu_acpi_is_s0ix_active(adev) &&
 	    !amdgpu_acpi_is_s3_active(adev))
 		return 1;
 

---
base-commit: a64568f32390f7480e31d3a303167f9b5cba9151
change-id: 20261204-amdgpu-apu-s4-prepare-9402402a15aa

Best regards,
--  
Mario Limonciello <mario.limonciello@amd.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: run prepare-phase eviction for hibernation on APUs
  2026-12-04 21:07 [PATCH] drm/amdgpu: run prepare-phase eviction for hibernation on APUs Mario Limonciello
@ 2026-12-04 21:27 ` sashiko-bot
  2026-12-04 21:42 ` Alex Deucher
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-04 21:27 UTC (permalink / raw)
  To: Mario Limonciello; +Cc: amd-gfx

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/amdgpu: unpaired prepare in amdgpu_pmops_prepare() during
  hybrid sleep
- [Low] drm/amdgpu: trailing comma in commit message Fixes trailer
--

commit f21df76d47cb0f407cd0216cb0a996e7fd62337d
Author: Mario Limonciello <mario.limonciello@amd.com>

> drm/amdgpu: run prepare-phase eviction for hibernation on APUs
>
> amdgpu_pmops_prepare() returns early when neither s0ix nor s3 is
> active.  On an APU both helpers test pm_suspend_target_state, which is
> only set by suspend_devices_and_enter() and so is PM_SUSPEND_ON
> throughout hibernation_snapshot().  As a result amdgpu_device_prepare()
> is skipped for hibernation on APUs, and with it the VRAM eviction and
> ttm_device_prepare_hibernation() that the PM notifier sets in_s4 up for.
>
> The eviction instead happens from amdgpu_pmops_freeze(), after
> hibernate_preallocate_memory() has already sized the image and after
> pm_restrict_gfp_mask() has made it impossible to swap anything out.
> Everything evicted into shmem/TTM pools at that point lands in the
> image unaccounted for, and under memory pressure snapshot creation
> fails:
>
>   PM: hibernation: Not enough free memory for image creation
>   PM: hibernation: Error -12 creating image
>
> Discrete GPUs are unaffected as amdgpu_acpi_is_s3_active() is
> unconditionally true for them.
>
> Don't take the early return when adev->in_s4 is set, so the eviction
> runs in the prepare phase, before the image is preallocated.
>
> Fixes: 06f2dcc241e7 ("drm/amdgpu: fix pm notifier handling"),
> Closes: https://gitlab.freedesktop.org/drm/amd/-/work_items/4711
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

[Severity: Low]
There is a stray trailing comma on the Fixes tag.  Should it be:

  Fixes: 06f2dcc241e7 ("drm/amdgpu: fix pm notifier handling")

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index d2db20c172c69..5d081bbe52260 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -2626,9 +2626,11 @@ static int amdgpu_pmops_prepare(struct device *dev)
>  		return 1;
>  
>  	/* if we will not support s3 or s2i for the device
> -	 *  then skip suspend
> +	 *  then skip suspend, but not for hibernation: resources need to be
> +	 *  evicted here, before the hibernation image is sized.
>  	 */
> -	if (!amdgpu_acpi_is_s0ix_active(adev) &&
> +	if (!adev->in_s4 &&
> +	    !amdgpu_acpi_is_s0ix_active(adev) &&
>  	    !amdgpu_acpi_is_s3_active(adev))
>  		return 1;

[Severity: Medium]
Can this run amdgpu_device_prepare() unpaired during hybrid sleep?

During HIBERNATION_SUSPEND, amdgpu_pmops_thaw() resumes the GPU and clears
adev->in_suspend while adev->in_s4 remains true until PM_POST_HIBERNATION.
power_down() then calls suspend_devices_and_enter(), which invokes
amdgpu_pmops_prepare().

On an APU where neither S0ix nor S3 is supported for the target sleep state,
!adev->in_s4 is false so amdgpu_pmops_prepare() falls through to
amdgpu_device_prepare(), while amdgpu_pmops_suspend() and
amdgpu_pmops_resume() skip suspend and resume.

This triggers a second VRAM eviction and ttm_device_prepare_hibernation()
while pm_restrict_gfp_mask() is still active.  On pre-Raven UVD APUs with
active UVD handles it also leaks adev->uvd.inst[j].saved_bo allocated in
amdgpu_uvd_prepare_suspend(), since no matching resume or complete frees it.

Gating the S4 check on !pm_suspend_in_progress() would keep
amdgpu_pmops_prepare() consistent with amdgpu_pmops_suspend() and
amdgpu_pmops_resume() during hybrid sleep.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-amdgpu-apu-s4-prepare-v1-1-1658fb81d9c9@amd.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: run prepare-phase eviction for hibernation on APUs
  2026-12-04 21:07 [PATCH] drm/amdgpu: run prepare-phase eviction for hibernation on APUs Mario Limonciello
  2026-12-04 21:27 ` sashiko-bot
@ 2026-12-04 21:42 ` Alex Deucher
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2026-12-04 21:42 UTC (permalink / raw)
  To: Mario Limonciello; +Cc: Alex Deucher, amd-gfx

On Fri, Dec 4, 2026 at 4:16 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> amdgpu_pmops_prepare() returns early when neither s0ix nor s3 is
> active.  On an APU both helpers test pm_suspend_target_state, which is
> only set by suspend_devices_and_enter() and so is PM_SUSPEND_ON
> throughout hibernation_snapshot().  As a result amdgpu_device_prepare()
> is skipped for hibernation on APUs, and with it the VRAM eviction and
> ttm_device_prepare_hibernation() that the PM notifier sets in_s4 up for.
>
> The eviction instead happens from amdgpu_pmops_freeze(), after
> hibernate_preallocate_memory() has already sized the image and after
> pm_restrict_gfp_mask() has made it impossible to swap anything out.
> Everything evicted into shmem/TTM pools at that point lands in the
> image unaccounted for, and under memory pressure snapshot creation
> fails:
>
>   PM: hibernation: Not enough free memory for image creation
>   PM: hibernation: Error -12 creating image
>
> Discrete GPUs are unaffected as amdgpu_acpi_is_s3_active() is
> unconditionally true for them.
>
> Don't take the early return when adev->in_s4 is set, so the eviction
> runs in the prepare phase, before the image is preallocated.
>
> Fixes: 06f2dcc241e7 ("drm/amdgpu: fix pm notifier handling"),
> Closes: https://gitlab.freedesktop.org/drm/amd/-/work_items/4711
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 9c14008720063..60d1c194d8cff 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -2636,9 +2636,11 @@ static int amdgpu_pmops_prepare(struct device *dev)
>                 return 1;
>
>         /* if we will not support s3 or s2i for the device
> -        *  then skip suspend
> +        *  then skip suspend, but not for hibernation: resources need to be
> +        *  evicted here, before the hibernation image is sized.
>          */
> -       if (!amdgpu_acpi_is_s0ix_active(adev) &&
> +       if (!adev->in_s4 &&
> +           !amdgpu_acpi_is_s0ix_active(adev) &&
>             !amdgpu_acpi_is_s3_active(adev))
>                 return 1;
>
>
> ---
> base-commit: a64568f32390f7480e31d3a303167f9b5cba9151
> change-id: 20261204-amdgpu-apu-s4-prepare-9402402a15aa
>
> Best regards,
> --
> Mario Limonciello <mario.limonciello@amd.com>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04 21:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 21:07 [PATCH] drm/amdgpu: run prepare-phase eviction for hibernation on APUs Mario Limonciello
2026-12-04 21:27 ` sashiko-bot
2026-12-04 21:42 ` Alex Deucher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.