From: Chris Feng <chris.feng@mediatek.com>
To: <rafael@kernel.org>, <pavel@ucw.cz>, <len.brown@intel.com>
Cc: <linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<stable@kernel.org>, <hua.yang@mediatek.com>,
<ting.wang@mediatek.com>, <liang.lu@mediatek.com>,
<chetan.kumar@mediatek.com>, Chris Feng <chris.feng@mediatek.com>
Subject: [PATCH v4] PM: hibernate: Avoid missing wakeup events during hibernation
Date: Wed, 13 Dec 2023 16:32:51 +0800 [thread overview]
Message-ID: <20231213083251.186935-1-chris.feng@mediatek.com> (raw)
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>
---
[PATCH v2]:
- Optimize the "if" condition logic.
- Link to v1: https://lore.kernel.org/all/20231024091447.108072-1-chris.feng@mediatek.com
[PATCH v3]:
- Use pr_info instead of pr_err.
- Fix undeclared function 'swsusp_unmark' build error.
- Refine commit and printing message.
- Change the subject.
- Link to v2: https://lore.kernel.org/all/20231120081516.55172-1-chris.feng@mediatek.com
[PATCH v4]:
- Define an empty swsusp_unmark() function for scenarios where
CONFIG_SUSPEND is not defined.
- Link to v3: https://lore.kernel.org/all/20231204021155.10434-1-chris.feng@mediatek.com
---
kernel/power/hibernate.c | 10 ++++++++--
kernel/power/power.h | 2 ++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index dee341ae4ace..621326b3e679 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_info("Hibernation process aborted due to detected wakeup event.\n");
+ return;
+ }
fallthrough;
case HIBERNATION_SHUTDOWN:
if (kernel_can_power_off())
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 17fd9aaaf084..8499a39c62f4 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -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;
--
2.17.0
next reply other threads:[~2023-12-13 8:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 8:32 Chris Feng [this message]
2023-12-13 13:45 ` Rafael J. Wysocki
2025-10-21 12:54 ` [REGRESSION][BISECTED] "Wakeup event detected during hibernation" on Dell Precision 7780 (was "[PATCH v4] PM: hibernate: Avoid missing wakeup events during hibernation") Askar Safin
2025-10-21 14:29 ` Mario Limonciello
2025-12-09 6:02 ` Askar Safin
2025-12-10 3:42 ` Mario Limonciello
2025-12-25 23:01 ` Askar Safin
2025-10-25 5:15 ` Askar Safin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231213083251.186935-1-chris.feng@mediatek.com \
--to=chris.feng@mediatek.com \
--cc=chetan.kumar@mediatek.com \
--cc=hua.yang@mediatek.com \
--cc=len.brown@intel.com \
--cc=liang.lu@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rafael@kernel.org \
--cc=stable@kernel.org \
--cc=ting.wang@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®