public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] PM: hibernate: Fix the bug where wake events cannot wake system during hibernation
@ 2023-11-20  8:15 Chris Feng
  2023-11-20 12:33 ` Rafael J. Wysocki
  2023-11-20 14:55 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Feng @ 2023-11-20  8:15 UTC (permalink / raw)
  To: rafael, pavel, len.brown
  Cc: linux-pm, linux-kernel, stable, hua.yang, ting.wang, liang.lu,
	chetan.kumar, Chris Feng

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 -EAGAIN or -EBUSY, 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>
---
[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 wake-up event.
---
 kernel/power/hibernate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 8d35b9f9aaa3..7e39a9baca9e 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -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_err("Hibernation Abort.\n");
+			return;
+		}
 		fallthrough;
 	case HIBERNATION_SHUTDOWN:
 		if (kernel_can_power_off())
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-20 15:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-20  8:15 [PATCH v2] PM: hibernate: Fix the bug where wake events cannot wake system during hibernation Chris Feng
2023-11-20 12:33 ` Rafael J. Wysocki
2023-11-20 14:55 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox