Fixes for hybrid sleep
Subsystems (4)
v2 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. Patch 3 has an Ack from Alex, this should merge through linux-pm.
---
v2:
* Fix LKP robot errors without CONFIG_SUSPEND
* Add tags
Mario Limonciello (AMD) (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 | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 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() ```
---
v2:
* Move under CONFIG_SUSPEND scope (LKP robot)
* Add tags
--- kernel/power/hibernate.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
kernel/power/hibernate.c +10 -1
@@ -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,15 @@ int hibernate(void)power_down (); } in_suspend =0 ; -pm_restore_gfp_mask (); +switch (hibernation_mode) { +#ifdef CONFIG_SUSPEND +case HIBERNATION_SUSPEND : +break ; +#endif +default : +pm_restore_gfp_mask (); +break ; + } }else {pm_pr_dbg ("Hibernation image restored successfully.\n" ); }
Signature · 1 line
2.43.0
Rafael J. Wysocki
maintainerRe: [PATCH v2 1/3] PM: hibernate: Fix hybrid-sleep
Quoted 47 lines · Mario Limonciello (AMD)
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()topower_down()before the suspend sequence starts. Don't callpm_restore_gfp_mask()when exiting suspend sequence it is already called:``` power_down() ->suspend_devices_and_enter() -->dpm_resume_end() ```Reported-by Ionut Nechita <[email protected]>Tested-by Ionut Nechita <[email protected]>Fixes 12ffc3b1513eb ("PM: Restrict swap use to later in the suspend sequence")Tested-by Kenneth Crudup <[email protected]>Acked-by Alex Deucher <[email protected]>Signed-off-by Mario Limonciello (AMD) <[email protected]>---
v2:
* Move underCONFIG_SUSPENDscope (LKP robot)
* Add tags--- kernel/power/hibernate.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)kernel/power/hibernate.c +1
-0@@ -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,15 @@ int hibernate(void)power_down (); } in_suspend =0 ;
kernel/power/hibernate.c int hibernate(void) · line 874
Quoted 10 lines
kernel/power/hibernate.c +9
-1-pm_restore_gfp_mask (); +switch (hibernation_mode) { +#ifdef CONFIG_SUSPEND +case HIBERNATION_SUSPEND : +break ; +#endif +default : +pm_restore_gfp_mask (); +break ; + }
You're breaking HIBERNATION_TEST_RESUME here AFAICS and power_down() doesn't return.
Quoted 4 lines
kernel/power/hibernate.c +0
-1}else {pm_pr_dbg ("Hibernation image restored successfully.\n" ); } --
Rafael J. Wysocki
maintainerRe: [PATCH v2 1/3] PM: hibernate: Fix hybrid-sleep
Quoted 54 lines · Rafael J. Wysocki
Quoted 51 lines · Mario Limonciello (AMD)
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()topower_down()before the suspend sequence starts. Don't callpm_restore_gfp_mask()when exiting suspend sequence it is already called:``` power_down() ->suspend_devices_and_enter() -->dpm_resume_end() ```Reported-by Ionut Nechita <[email protected]>Tested-by Ionut Nechita <[email protected]>Fixes 12ffc3b1513eb ("PM: Restrict swap use to later in the suspend sequence")Tested-by Kenneth Crudup <[email protected]>Acked-by Alex Deucher <[email protected]>Signed-off-by Mario Limonciello (AMD) <[email protected]>---
v2:
* Move underCONFIG_SUSPENDscope (LKP robot)
* Add tags--- kernel/power/hibernate.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)kernel/power/hibernate.c +4
-1@@ -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,15 @@ int hibernate(void)power_down (); } in_suspend =0 ; -pm_restore_gfp_mask (); +switch (hibernation_mode) { +#ifdef CONFIG_SUSPEND +case HIBERNATION_SUSPEND :
Quoted 8 lines
kernel/power/hibernate.c int hibernate(void) · line 874
Quoted 6 lines
kernel/power/hibernate.c +6
-0+break ; +#endif +default : +pm_restore_gfp_mask (); +break ; + }You're breaking
HIBERNATION_TEST_RESUMEhere AFAICS
Well, not really because of the hibernation_mode check.
Quoted 1 line
and
power_down()doesn't return.
But this still is true.
Quoted 5 lines
Quoted 5 lines
kernel/power/hibernate.c +0
-1}else {pm_pr_dbg ("Hibernation image restored successfully.\n" ); } --
Rafael J. Wysocki
maintainerRe: [PATCH v2 1/3] PM: hibernate: Fix hybrid-sleep
Quoted 65 lines · Rafael J. Wysocki
Quoted 54 lines · Rafael J. Wysocki
Quoted 51 lines · Mario Limonciello (AMD)
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()topower_down()before the suspend sequence starts. Don't callpm_restore_gfp_mask()when exiting suspend sequence it is already called:``` power_down() ->suspend_devices_and_enter() -->dpm_resume_end() ```Reported-by Ionut Nechita <[email protected]>Tested-by Ionut Nechita <[email protected]>Fixes 12ffc3b1513eb ("PM: Restrict swap use to later in the suspend sequence")Tested-by Kenneth Crudup <[email protected]>Acked-by Alex Deucher <[email protected]>Signed-off-by Mario Limonciello (AMD) <[email protected]>---
v2:
* Move underCONFIG_SUSPENDscope (LKP robot)
* Add tags--- kernel/power/hibernate.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)kernel/power/hibernate.c +4
-1@@ -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,15 @@ int hibernate(void)power_down (); } in_suspend =0 ; -pm_restore_gfp_mask (); +switch (hibernation_mode) { +#ifdef CONFIG_SUSPEND +case HIBERNATION_SUSPEND :Quoted 8 lines
kernel/power/hibernate.c int hibernate(void) · line 874
Quoted 6 lines
kernel/power/hibernate.c +6
-0+break ; +#endif +default : +pm_restore_gfp_mask (); +break ; + }You're breaking
HIBERNATION_TEST_RESUMEhere AFAICS
Quoted 5 lines
Well, not really because of the
hibernation_modecheck.Quoted 1 line
and
power_down()doesn't return.But this still is true.
Well, except when it does HIBERNATION_SUSPEND.
But can you just make power_down() call pm_restrict_gfp_mask() before returning and leave the code in hibernate() as is?
Re: [PATCH v2 1/3] PM: hibernate: Fix hybrid-sleep
Quoted 68 lines · Rafael J. Wysocki
Quoted 67 lines · Rafael J. Wysocki
Quoted 54 lines · Rafael J. Wysocki
Quoted 51 lines · Mario Limonciello (AMD)
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()topower_down()before the suspend sequence starts. Don't callpm_restore_gfp_mask()when exiting suspend sequence it is already called:``` power_down() ->suspend_devices_and_enter() -->dpm_resume_end() ```Reported-by Ionut Nechita <[email protected]>Tested-by Ionut Nechita <[email protected]>Fixes 12ffc3b1513eb ("PM: Restrict swap use to later in the suspend sequence")Tested-by Kenneth Crudup <[email protected]>Acked-by Alex Deucher <[email protected]>Signed-off-by Mario Limonciello (AMD) <[email protected]>---
v2:
* Move underCONFIG_SUSPENDscope (LKP robot)
* Add tags--- kernel/power/hibernate.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)kernel/power/hibernate.c +4
-1@@ -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,15 @@ int hibernate(void)power_down (); } in_suspend =0 ; -pm_restore_gfp_mask (); +switch (hibernation_mode) { +#ifdef CONFIG_SUSPEND +case HIBERNATION_SUSPEND :Quoted 8 lines
kernel/power/hibernate.c int hibernate(void) · line 874
Quoted 6 lines
kernel/power/hibernate.c +6
-0+break ; +#endif +default : +pm_restore_gfp_mask (); +break ; + }You're breaking
HIBERNATION_TEST_RESUMEhere AFAICSWell, not really because of the
hibernation_modecheck.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
and
power_down()doesn't return.But this still is true.
Well, except when it does
HIBERNATION_SUSPEND.But can you just make
power_down()callpm_restrict_gfp_mask()before returning and leave the code inhibernate()as is?
Ah good suggestion. I believe so. I'll test it and get out updated patches if that works.
PATCH v2 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.
---
v2:
* Move under CONFIG_SUSPEND scope (LKP robot)
* Add tags
--- include/linux/suspend.h | 2 ++ kernel/power/hibernate.c | 11 +++++++++++ 2 files changed, 13 insertions(+)
include/linux/suspend.h +2 -0
@@ -276,6 +276,7 @@ extern void arch_suspend_enable_irqs(void);extern int pm_suspend (suspend_state_t state);extern bool sync_on_suspend_enabled; +bool pm_hibernation_mode_is_suspend (void );#else /* !CONFIG_SUSPEND */ #define suspend_valid_only_mem NULL
@@ -288,6 +289,7 @@ static inline bool pm_suspend_via_firmware(void) { return false; }static inline bool pm_resume_via_firmware (void ) {return false; }static inline bool pm_suspend_no_platform (void ) {return false; }static inline bool pm_suspend_default_s2idle (void ) {return false; } +static inline bool pm_hibernation_mode_is_suspend (void ) {return false; }static inline void suspend_set_ops (const struct platform_suspend_ops *ops) {}static inline int pm_suspend (suspend_state_t state) {return -ENOSYS ; }
kernel/power/hibernate.c +11 -0
@@ -80,6 +80,17 @@ static const struct platform_hibernation_ops *hibernation_ops;static atomic_t hibernate_atomic =ATOMIC_INIT (1 ); +#ifdef CONFIG_SUSPEND +/** +* 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); +#endif +bool hibernate_acquire (void ) {return atomic_add_unless (&hibernate_atomic,-1 ,0 );
Signature · 1 line
2.43.0
PATCH v2 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.
---
v2:
* Add tags
--- 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
@@ -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.43.0
Rafael J. Wysocki
maintainerQuoted 5 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.
Quoted 7 lines
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,
No worries.
Quoted 2 lines
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.
Well, it can go into 6.18.
Fortunately, hybrid sleep isn't too popular with Linux users.
Quoted 3 lines
As it touches two subsystems it either needs to go through linux-pm or drm. Patch 3 has an Ack from Alex, this should merge through linux-pm.
Sure.
Thanks!