PM: hibernate: Fix the bug where wake events cannot wake system during hibernation
Subsystems (2)
PATCH 1/1 PM: hibernate: Fix the bug where wake events cannot wake system during hibernation
From: Chris Feng <[email protected]>
Wake-up events that occur in the hibernation process's hibernation_platform_enter() cannot wake up the system. Although the current hibernation framework will execute part of the recovery process after a wake-up event occurs, it ultimately performs a shutdown operation because the system does not check the return value of hibernation_platform_enter(). Moreover, when restoring the device before system shutdown, the device's I/O and DMA capabilities will be turned on, which can lead to data loss.
To solve this problem, check the return value of hibernation_platform_enter(). When it returns a non-zero value, execute the hibernation recovery process, discard the previously saved image, and ultimately return to the working state.
--- kernel/power/hibernate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/power/hibernate.c +8 -2
@@ -642,9 +642,9 @@ int hibernation_platform_enter(void)*/ static void power_down (void ) { -#ifdef CONFIG_SUSPEND int error; +#ifdef CONFIG_SUSPEND if (hibernation_mode ==HIBERNATION_SUSPEND ) { error =suspend_devices_and_enter (mem_sleep_current);if (error) {
@@ -667,7 +667,13 @@ static void power_down(void)kernel_restart (NULL );break ;case HIBERNATION_PLATFORM : -hibernation_platform_enter (); + error =hibernation_platform_enter (); +if (error) { +swsusp_unmark (); + events_check_enabled = false; +pr_err ("Hibernation Abort.\n" ); +return ; + } fallthrough;case HIBERNATION_SHUTDOWN :if (kernel_can_power_off ())
Signature · 1 line
2.17.0
Rafael J. Wysocki
maintainerQuoted 12 lines · On Tue, Oct 24, 2023 at 11:15 AM <[email protected]> wrote:
From: Chris Feng <[email protected]>
Wake-up events that occur in the hibernation process's
hibernation_platform_enter()cannot wake up the system. Although the current hibernation framework will execute part of the recovery process after a wake-up event occurs, it ultimately performs a shutdown operation because the system does not check the return value ofhibernation_platform_enter(). Moreover, when restoring the device before system shutdown, the device's I/O and DMA capabilities will be turned on, which can lead to data loss.
Quoted 4 lines
To solve this problem, check the return value of
hibernation_platform_enter(). When it returns a non-zero value, execute the hibernation recovery process, discard the previously saved image, and ultimately return to the working state.
While I agree with the problem statement, I don't completely agree with the patch.
Quoted 21 lines
Signed-off-by Chris Feng <[email protected]>--- kernel/power/hibernate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/power/hibernate.c +1
-1@@ -642,9 +642,9 @@ int hibernation_platform_enter(void)*/ static void power_down (void ) { -#ifdef CONFIG_SUSPEND int error; +#ifdef CONFIG_SUSPEND if (hibernation_mode ==HIBERNATION_SUSPEND ) { error =suspend_devices_and_enter (mem_sleep_current);if (error) {
kernel/power/hibernate.c static void power_down(void) · line 671
Quoted 6 lines
kernel/power/hibernate.c +2
-1@@ -667,7 +667,13 @@ static void power_down(void)kernel_restart (NULL );break ;case HIBERNATION_PLATFORM : -hibernation_platform_enter (); + error =hibernation_platform_enter (); +if (error) {
This error need not be -EAGAIN which means pending wakeup. There are other errors that can be returned for which the fallback to shutdown is still desirable.
Quoted 11 lines
kernel/power/hibernate.c +5
-1+swsusp_unmark (); + events_check_enabled = false; +pr_err ("Hibernation Abort.\n" ); +return ; + } fallthrough;case HIBERNATION_SHUTDOWN :if (kernel_can_power_off ()) --2.17.0
Quoted 52 lines · Rafael J. Wysocki
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 5 lines · On Tue, Oct 24, 2023 at 11:15 AM <[email protected]> wrote:
From: Chris Feng <[email protected]>
Wake-up events that occur in the hibernation process's
hibernation_platform_enter()cannot wake up the system. Althoughthe
Quoted 1 line
current hibernation framework will execute part of the recovery
process
Quoted 1 line
after a wake-up event occurs, it ultimately performs a shutdown
operation
Quoted 2 lines
because the system does not check the return value of
hibernation_platform_enter(). Moreover, when restoring the devicebefore
Quoted 1 line
system shutdown, the device's I/O and DMA capabilities will be
turned on,
Quoted 4 lines
which can lead to data loss.
To solve this problem, check the return value of
hibernation_platform_enter(). When it returns a non-zero value,execute
Quoted 1 line
the hibernation recovery process, discard the previously saved
image, and
Quoted 1 line
ultimately return to the working state.
While I agree with the problem statement, I don't completely agree with the patch.
Quoted 10 lines
Signed-off-by Chris Feng <[email protected]>--- kernel/power/hibernate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/power/hibernate.c +0
-0kernel/power/hibernate.c int hibernation_platform_enter(void) · line 649
Quoted 9 lines
kernel/power/hibernate.c +1
-1@@ -642,9 +642,9 @@ int hibernation_platform_enter(void)*/ static void power_down (void ) { -#ifdef CONFIG_SUSPEND int error; +#ifdef CONFIG_SUSPEND if (hibernation_mode ==HIBERNATION_SUSPEND ) { error =
suspend_devices_and_enter(mem_sleep_current);
Quoted 13 lines
kernel/power/hibernate.c static void power_down(void) · line 671
Quoted 8 lines
kernel/power/hibernate.c +2
-1if (error) {@@ -667,7 +667,13 @@ static void power_down(void)kernel_restart (NULL );break ;case HIBERNATION_PLATFORM : -hibernation_platform_enter (); + error =hibernation_platform_enter (); +if (error) {This error need not be
-EAGAINwhich means pending wakeup. There are other errors that can be returned for which the fallback to shutdown is still desirable.
Thank you for your comments. I have some questions:
In function hibernation_platform_enter(), if function dpm_suspend_start/end returns error, it goes to resume devices flow. After the system restores the devices, the system shuts down. Is this expected design behivour? If it is, would you help to give the design reasons in short ? From my point of view, since the deivces are resumed, why dose the system go to shut down state ? And also, after the system shuts down , and when the system is waked up by power key, the devices will be resumed again when restoring the saved system's image.
Quoted 11 lines
Quoted 11 lines
kernel/power/hibernate.c +5
-1+swsusp_unmark (); + events_check_enabled = false; +pr_err ("Hibernation Abort.\n" ); +return ; + } fallthrough;case HIBERNATION_SHUTDOWN :if (kernel_can_power_off ()) --2.17.0
Hi Rafael J,
Quoted 39 lines · Chris Feng
Quoted 22 lines · Rafael J. Wysocki
Quoted 10 lines · On Tue, Oct 24, 2023 at 11:15 AM <[email protected]> wrote:
--- kernel/power/hibernate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/power/hibernate.c +0
-0kernel/power/hibernate.c int hibernation_platform_enter(void) · line 649
Quoted 9 lines
kernel/power/hibernate.c +1
-1@@ -642,9 +642,9 @@ int hibernation_platform_enter(void)*/ static void power_down (void ) { -#ifdef CONFIG_SUSPEND int error; +#ifdef CONFIG_SUSPEND if (hibernation_mode ==HIBERNATION_SUSPEND ) { error =
suspend_devices_and_enter(mem_sleep_current);Quoted 15 lines
kernel/power/hibernate.c static void power_down(void) · line 671
Quoted 8 lines
kernel/power/hibernate.c +2
-1if (error) {@@ -667,7 +667,13 @@ static void power_down(void)kernel_restart (NULL );break ;case HIBERNATION_PLATFORM : -hibernation_platform_enter (); + error =hibernation_platform_enter (); +if (error) {This error need not be
-EAGAINwhich means pending wakeup. There are
other errors that can be returned for which the fallback to shutdown
is still desirable.
Quoted 13 lines
Thank you for your comments. I have some questions:
In functionhibernation_platform_enter(), if function dpm_suspend_start/end returns error, it goes to resume devices flow. After the system restores the devices, the system shuts down. Is this
expected design behivour? If it is, would you help to give the design
reasons in short ? From my point of view, since the deivces are resumed, why dose the system go to shut down state ? And also, after the system shuts down , and when the system is waked up by power key, the devices will be resumed again when restoring the saved system's image.
We are looking forward to your reply.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
kernel/power/hibernate.c +5
-1+swsusp_unmark (); + events_check_enabled = false; +pr_err ("Hibernation Abort.\n" ); +return ; + } fallthrough;case HIBERNATION_SHUTDOWN :if (kernel_can_power_off ()) --2.17.0
Thanks!