Skip to contentSkip to conversation

PM: hibernate: Avoid missing wakeup events during hibernation

PATCH Superseded Chris Feng 1 participant 1 message Nov 22, 2023

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Chris Feng

author
#0 lore raw

PATCH v3 1/1 PM: hibernate: Avoid missing wakeup events during hibernation

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.

---
[PATCH v2]:
- Execute the hibernation recovery process and return to the working state when the return value of the function hibernation_platform_enter() is -EAGAIN or -EBUSY. Both of the two values may indicate the occurrence of a wakeup event.
[PATCH v3]:
- Use pr_info instead of pr_err, fix undeclared function 'swsusp_unmark' build error, refine commit and printing message.

---
 kernel/power/hibernate.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/power/hibernate.c +10 -2
index 8d35b9f9aaa3..fb3b63e178b0 100644
@@ -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,15 @@ static void power_down(void)
 		kernel_restart(NULL);
 		break;
 	case HIBERNATION_PLATFORM:
-		hibernation_platform_enter();
+		error = hibernation_platform_enter();
+		if (error == -EAGAIN || error == -EBUSY) {
+#ifdef CONFIG_SUSPEND
+			swsusp_unmark();
+#endif
+			events_check_enabled = false;
+			pr_info("Hibernation process aborted due to detected wakeup event.\n");
+			return;
+		}
 		fallthrough;
 	case HIBERNATION_SHUTDOWN:
 		if (kernel_can_power_off())
Signature · 1 line
2.17.0