Skip to contentSkip to conversation

Fixes for hybrid sleep

PATCH Superseded Mario Limonciello (AMD) 4 participants 8 messages Sep 24, 2025 – Sep 25, 2025

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Fixes for hybrid sleep

Ionut Nechita reported recently a hibernate failure, but in debugging the issue it's actually not a hibernate failure; but a hybrid sleep failure.

Multiple changes related to the change of when swap is disabled in the suspend sequence contribute to the failure. See the individual patches for details.

NOTE: I realize this is super late in the cycle, so sorry about that, but I debugged it as fast as I could as soon as I heard about it. If it needs to push out to the next cycle it is what it is.

As it touches two subsystems it either needs to go through linux-pm or drm. I would suggest linux-pm with an Ack from Alex on the 3rd patch.

Cc: Ionut Nechita <[email protected]> Mario Limonciello (3):
PM: hibernate: Fix hybrid-sleep
PM: hibernate: Add pm_hibernation_mode_is_suspend() drm/amd: Fix hybrid sleep

 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  2 +-
 include/linux/suspend.h                 |  2 ++
 kernel/power/hibernate.c                | 13 ++++++++++++-
 3 files changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/3 PM: hibernate: Fix hybrid-sleep

Hybrid sleep will hibernate the system followed by running through the suspend routine. Since both the hibernate and the suspend routine will call pm_restrict_gfp_mask(), pm_restore_gfp_mask() must be called before starting the suspend sequence.

Add an explicit call to pm_restore_gfp_mask() to power_down() before the suspend sequence starts. Don't call pm_restore_gfp_mask() when exiting suspend sequence it is already called:

```
power_down()
->suspend_devices_and_enter()
-->dpm_resume_end()
```
Fixes 12ffc3b1513eb ("PM: Restrict swap use to later in the suspend sequence")
---
 kernel/power/hibernate.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/power/hibernate.c +3 -1
index 2f66ab453823..1defe8081e64 100644
@@ -695,6 +695,7 @@ static void power_down(void)
 
 #ifdef CONFIG_SUSPEND
 	if (hibernation_mode == HIBERNATION_SUSPEND) {
+		pm_restore_gfp_mask();
 		error = suspend_devices_and_enter(mem_sleep_current);
 		if (error) {
 			hibernation_mode = hibernation_ops ?
@@ -862,7 +863,8 @@ int hibernate(void)
 				power_down();
 		}
 		in_suspend = 0;
-		pm_restore_gfp_mask();
+		if (hibernation_mode != HIBERNATION_SUSPEND)
+			pm_restore_gfp_mask();
 	} else {
 		pm_pr_dbg("Hibernation image restored successfully.\n");
 	}
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH 1/3] PM: hibernate: Fix hybrid-sleep

kernel test robot noticed the following build errors:

Hi Mario,

kernel test robot noticed the following build errors:

[auto build test ERROR on amd-pstate/linux-next]
[also build test ERROR on amd-pstate/bleeding-edge linus/master v6.17-rc7 next-20250924] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello-AMD/PM-hibernate-Fix-hybrid-sleep/20250925-045432
base:   https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git linux-next
patch link:    https://lore.kernel.org/r/20250924205211.1059571-2-superm1%40kernel.org
patch subject: [PATCH 1/3] PM: hibernate: Fix hybrid-sleep
config: i386-randconfig-014-20250925 (https://download.01.org/0day-ci/archive/20250925/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250925/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> kernel/power/hibernate.c:866:27: error: use of undeclared identifier 'HIBERNATION_SUSPEND'
     866 |                 if (hibernation_mode != HIBERNATION_SUSPEND)
         |                                         ^

1 error generated.

vim +/HIBERNATION_SUSPEND +866 kernel/power/hibernate.c

776
777 /**
778 * hibernate - Carry out system hibernation, including saving the image.
779 */
780 int hibernate(void)
781 {
782 bool snapshot_test = false;
783 unsigned int sleep_flags;
784 int error;
785
786 if (!hibernation_available()) {
787 pm_pr_dbg("Hibernation not available.\n");
788 return -EPERM;
789 }
790
791 /*
792 * Query for the compression algorithm support if compression is enabled.
793 */
794 if (!nocompress) {
795 strscpy(hib_comp_algo, hibernate_compressor);
796 if (!crypto_has_acomp(hib_comp_algo, 0, CRYPTO_ALG_ASYNC)) {
797 pr_err("%s compression is not available\n", hib_comp_algo);
798 return -EOPNOTSUPP;
799 }
800 }
801
802 sleep_flags = lock_system_sleep();
803 /* The snapshot device should not be opened while we're running */
804 if (!hibernate_acquire()) {
805 error = -EBUSY;
806 goto Unlock;
807 }
808
809 pr_info("hibernation entry\n");
810 pm_prepare_console();
811 error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
812 if (error)
813 goto Restore;
814
815 ksys_sync_helper();
816 if (filesystem_freeze_enabled)
817 filesystems_freeze();
818
819 error = freeze_processes();
820 if (error)
821 goto Exit;
822
823 lock_device_hotplug();
824 /* Allocate memory management structures */
825 error = create_basic_memory_bitmaps();
826 if (error)
827 goto Thaw;
828
829 error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
830 if (error || freezer_test_done)
831 goto Free_bitmaps;
832
833 if (in_suspend) {
834 unsigned int flags = 0;
835
836 if (hibernation_mode == HIBERNATION_PLATFORM)
837 flags |= SF_PLATFORM_MODE;
838 if (nocompress) {
839 flags |= SF_NOCOMPRESS_MODE;
840 } else {
841 flags |= SF_CRC32_MODE;
842
843 /*
844 * By default, LZO compression is enabled. Use SF_COMPRESSION_ALG_LZ4
845 * to override this behaviour and use LZ4.
846 *
847 * Refer kernel/power/power.h for more details
848 */
849
850 if (!strcmp(hib_comp_algo, COMPRESSION_ALGO_LZ4))
851 flags |= SF_COMPRESSION_ALG_LZ4;
852 else
853 flags |= SF_COMPRESSION_ALG_LZO;
854 }
855
856 pm_pr_dbg("Writing hibernation image.\n");
857 error = swsusp_write(flags);
858 swsusp_free();
859 if (!error) {
860 if (hibernation_mode == HIBERNATION_TEST_RESUME)
861 snapshot_test = true;
862 else
863 power_down();
864 }
865 in_suspend = 0;

 > 866			if (hibernation_mode != HIBERNATION_SUSPEND)

867 pm_restore_gfp_mask();
868 } else {
869 pm_pr_dbg("Hibernation image restored successfully.\n");
870 }
871
872 Free_bitmaps:
873 free_basic_memory_bitmaps();
874 Thaw:
875 unlock_device_hotplug();
876 if (snapshot_test) {
877 pm_pr_dbg("Checking hibernation image\n");
878 error = swsusp_check(false);
879 if (!error)
880 error = load_image_and_restore();
881 }
882 thaw_processes();
883
884 /* Don't bother checking whether freezer_test_done is true */
885 freezer_test_done = false;
886 Exit:
887 filesystems_thaw();
888 pm_notifier_call_chain(PM_POST_HIBERNATION);
889 Restore:
890 pm_restore_console();
891 hibernate_release();
892 Unlock:
893 unlock_system_sleep(sleep_flags);
894 pr_info("hibernation exit\n");
895
896 return error;
897 }
898

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

PATCH 2/3 PM: hibernate: Add pm_hibernation_mode_is_suspend()

In reply to Mario Limonciello (AMD)

Some drivers have different flows for hibernation and suspend. If the driver opportunistically will skip thaw() then it needs a hint to know what is happening after the hibernate.

Introduce a new symbol pm_hibernation_mode_is_suspend() that drivers can call to determine if suspending the system for this purpose.

---
 include/linux/suspend.h  | 2 ++
 kernel/power/hibernate.c | 9 +++++++++
 2 files changed, 11 insertions(+)
include/linux/suspend.h +2 -0
index 317ae31e89b3..4b11efd68729 100644
@@ -479,6 +479,7 @@ extern void unlock_system_sleep(unsigned int);
 
 extern bool pm_sleep_transition_in_progress(void);
 bool pm_hibernate_is_recovering(void);
+bool pm_hibernation_mode_is_suspend(void);
 
 #else /* !CONFIG_PM_SLEEP */
 
@@ -513,6 +514,7 @@ static inline void unlock_system_sleep(unsigned int flags) {}
 
 static inline bool pm_sleep_transition_in_progress(void) { return false; }
 static inline bool pm_hibernate_is_recovering(void) { return false; }
+static inline bool pm_hibernation_mode_is_suspend(void) { return false; }
 
 #endif /* !CONFIG_PM_SLEEP */
 
kernel/power/hibernate.c +9 -0
index 1defe8081e64..a991a1362d77 100644
@@ -80,6 +80,15 @@ static const struct platform_hibernation_ops *hibernation_ops;
 
 static atomic_t hibernate_atomic = ATOMIC_INIT(1);
 
+/**
+ * pm_hibernation_mode_is_suspend - Check if hibernation has been set to suspend
+ */
+bool pm_hibernation_mode_is_suspend(void)
+{
+	return hibernation_mode == HIBERNATION_SUSPEND;
+}
+EXPORT_SYMBOL_GPL(pm_hibernation_mode_is_suspend);
+
 bool hibernate_acquire(void)
 {
 	return atomic_add_unless(&hibernate_atomic, -1, 0);
Signature · 1 line
2.51.0
#4 lore raw

Re: [PATCH 2/3] PM: hibernate: Add pm_hibernation_mode_is_suspend()

kernel test robot noticed the following build warnings:

Hi Mario,

kernel test robot noticed the following build warnings:

[auto build test WARNING on amd-pstate/linux-next]
[also build test WARNING on amd-pstate/bleeding-edge linus/master v6.17-rc7 next-20250924] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello-AMD/PM-hibernate-Fix-hybrid-sleep/20250925-045432
base:   https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git linux-next
patch link:    https://lore.kernel.org/r/20250924205211.1059571-3-superm1%40kernel.org
patch subject: [PATCH 2/3] PM: hibernate: Add pm_hibernation_mode_is_suspend()
config: i386-randconfig-004-20250925 (https://download.01.org/0day-ci/archive/20250925/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250925/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

kernel/power/hibernate.c: In function 'pm_hibernation_mode_is_suspend':
kernel/power/hibernate.c:88:36: error: 'HIBERNATION_SUSPEND' undeclared (first use in this function); did you mean 'HIBERNATION_SHUTDOWN'?

      88 |         return hibernation_mode == HIBERNATION_SUSPEND;
         |                                    ^~~~~~~~~~~~~~~~~~~
         |                                    HIBERNATION_SHUTDOWN
   kernel/power/hibernate.c:88:36: note: each undeclared identifier is reported only once for each function it appears in
   kernel/power/hibernate.c: In function 'hibernate':
   kernel/power/hibernate.c:875:41: error: 'HIBERNATION_SUSPEND' undeclared (first use in this function); did you mean 'HIBERNATION_SHUTDOWN'?
     875 |                 if (hibernation_mode != HIBERNATION_SUSPEND)
         |                                         ^~~~~~~~~~~~~~~~~~~
         |                                         HIBERNATION_SHUTDOWN
   kernel/power/hibernate.c: In function 'pm_hibernation_mode_is_suspend':
>> kernel/power/hibernate.c:89:1: warning: control reaches end of non-void function [-Wreturn-type]
      89 | }
         | ^

vim +89 kernel/power/hibernate.c

    82	
    83	/**
    84	 * pm_hibernation_mode_is_suspend - Check if hibernation has been set to suspend
    85	 */
    86	bool pm_hibernation_mode_is_suspend(void)
    87	{
  > 88		return hibernation_mode == HIBERNATION_SUSPEND;
  > 89	}
    90	EXPORT_SYMBOL_GPL(pm_hibernation_mode_is_suspend);
    91	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

PATCH 3/3 drm/amd: Fix hybrid sleep

In reply to Mario Limonciello (AMD)

[Why]
commit 530694f54dd5e ("drm/amdgpu: do not resume device in thaw for normal hibernation") optimized the flow for systems that are going into S4 where the power would be turned off. Basically the thaw() callback wouldn't resume the device if the hibernation image was successfully created since the system would be powered off.

This however isn't the correct flow for a system entering into s0i3 after the hibernation image is created. Some of the amdgpu callbacks have different behavior depending upon the intended state of the suspend.

[How]
Use pm_hibernation_mode_is_suspend() as an input to decide whether to run resume during thaw() callback.

Fixes 530694f54dd5e ("drm/amdgpu: do not resume device in thaw for normal hibernation")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
index 395c6be901ce..dcea66aadfa3 100644
@@ -2665,7 +2665,7 @@ static int amdgpu_pmops_thaw(struct device *dev)
 	struct drm_device *drm_dev = dev_get_drvdata(dev);
 
 	/* do not resume device if it's normal hibernation */
-	if (!pm_hibernate_is_recovering())
+	if (!pm_hibernate_is_recovering() && !pm_hibernation_mode_is_suspend())
 		return 0;
 
 	return amdgpu_device_resume(drm_dev, true);
Signature · 1 line
2.51.0
maintainer Acked-by on v1 3/3
#6 lore raw

RE: [PATCH 3/3] drm/amd: Fix hybrid sleep

[Public]

Quoted 28 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mario Limonciello (AMD)
Sent: Wednesday, September 24, 2025 4:52 PM
To: Deucher, Alexander <[email protected]>; Rafael J . Wysocki <[email protected]>
Cc: Zhang, GuoQing (Sam) <[email protected]>; open list:RADEON and AMDGPU DRM DRIVERS <[email protected]>; open list:HIBERNATION (aka Software Suspend, aka swsusp) <linux- [email protected]>; Mario Limonciello <[email protected]>; Ionut Nechita <[email protected]>
Subject: [PATCH 3/3] drm/amd: Fix hybrid sleep

[Why]
commit 530694f54dd5e ("drm/amdgpu: do not resume device in thaw for normal hibernation") optimized the flow for systems that are going into S4 where the power would be turned off. Basically the thaw() callback wouldn't resume the device if the hibernation image was successfully created since the system would be powered off.

This however isn't the correct flow for a system entering into s0i3 after the hibernation image is created. Some of the amdgpu callbacks have different behavior depending upon the intended state of the suspend.

[How]
Use pm_hibernation_mode_is_suspend() as an input to decide whether to run resume during thaw() callback.

Quoted 6 lines
Fixes 530694f54dd5e ("drm/amdgpu: do not resume device in thaw for normal

hibernation")

Series is:

Feel free to take it through the Linux pm tree.

Alex

Quoted 21 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -2
index 395c6be901ce..dcea66aadfa3 100644
@@ -2665,7 +2665,7 @@ static int amdgpu_pmops_thaw(struct device *dev)
      struct drm_device *drm_dev = dev_get_drvdata(dev);
 
      /* do not resume device if it's normal hibernation */
-     if (!pm_hibernate_is_recovering())
+     if (!pm_hibernate_is_recovering() &&
+!pm_hibernation_mode_is_suspend())
              return 0;
 
      return amdgpu_device_resume(drm_dev, true);
--

2.51.0

Tested-by on the v1 series
#7 lore raw
In reply to Mario Limonciello (AMD)

(Thanks Mario for the hint re: replying via Lore!)

Quoted 9 lines · Mario Limonciello (AMD)

Ionut Nechita reported recently a hibernate failure, but in debugging the issue it's actually not a hibernate failure; but a hybrid sleep failure.

Multiple changes related to the change of when swap is disabled in the suspend sequence contribute to the failure. See the individual patches for details.

I just wanted to say that the non-AMD-display bits of this patch were tested by me and seem to have fixed a problem I'd had where if I had an NFS share mounted on suspend/hibernate, that ~50% of the time when resuming the machine would be up, but disk I/O would be deadlocked (so I really couldn't do anything except SysRq-S/U/B).

Still going to test a few more suspend/resume/hibernate cycles, but it does seem to have fixed that issue for me. There was a corresponding patch in linux-pm earlier along the same lines, but that one only had a limited success rate.

I have "hybrid sleep" enabled, where systemd will go into full hibernation after 4 hrs, BTW.

Quoted 5 lines
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  2 +-
  include/linux/suspend.h                 |  2 ++
  kernel/power/hibernate.c                | 13 ++++++++++++-
  3 files changed, 15 insertions(+), 2 deletions(-)

-Kenny

Signature · 1 line
Kenneth R. Crudup / Sr. SW Engineer, Scott County Consulting, Orange County CA