PM: hibernate: Avoid missing wakeup events during hibernation
authorChris Feng <chris.feng@mediatek.com>
Wed, 13 Dec 2023 08:32:51 +0000 (16:32 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 15 Dec 2023 11:33:39 +0000 (12:33 +0100)
Wakeup 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 wakeup event occurs, it ultimately performs a shutdown operation
because the system does not check the return value of
hibernation_platform_enter(). In short, if a wakeup event occurs before
putting the system into the final low-power state, it will be missed.

To solve this problem, check the return value of
hibernation_platform_enter(). When it returns -EAGAIN or -EBUSY (indicate
the occurrence of a wakeup event), execute the hibernation recovery
process, discard the previously saved image, and ultimately return to the
working state.

Signed-off-by: Chris Feng <chris.feng@mediatek.com>
[ rjw: Rephrase the message printed when going back to the working state ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/hibernate.c
kernel/power/power.h

index dee341ae4ace7849096bb80243168292c5e45a65..4b0b7cf2e01921015190d352ca5dbeaf6e104ab2 100644 (file)
@@ -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 == -EAGAIN || error == -EBUSY) {
+                       swsusp_unmark();
+                       events_check_enabled = false;
+                       pr_info("Wakeup event detected during hibernation, rolling back.\n");
+                       return;
+               }
                fallthrough;
        case HIBERNATION_SHUTDOWN:
                if (kernel_can_power_off())
index 17fd9aaaf084aa6f02ec4f262c6c8926c87bc336..8499a39c62f4b002f2126ac4f3602227577e1305 100644 (file)
@@ -175,6 +175,8 @@ extern int swsusp_write(unsigned int flags);
 void swsusp_close(void);
 #ifdef CONFIG_SUSPEND
 extern int swsusp_unmark(void);
+#else
+static inline int swsusp_unmark(void) { return 0; }
 #endif
 
 struct __kernel_old_timeval;