* [PATCH RESEND v3] PM: hibernate: Avoid missing wakeup events during hibernation
@ 2023-12-04 2:11 Chris Feng
2023-12-12 18:55 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Chris Feng @ 2023-12-04 2:11 UTC (permalink / raw)
To: rafael, pavel, len.brown
Cc: linux-pm, linux-kernel, stable, hua.yang, ting.wang, liang.lu,
chetan.kumar, Chris Feng
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
---
kernel/power/hibernate.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 8d35b9f9aaa3..fb3b63e178b0 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,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())
--
2.17.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RESEND v3] PM: hibernate: Avoid missing wakeup events during hibernation
2023-12-04 2:11 [PATCH RESEND v3] PM: hibernate: Avoid missing wakeup events during hibernation Chris Feng
@ 2023-12-12 18:55 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2023-12-12 18:55 UTC (permalink / raw)
To: Chris Feng
Cc: rafael, pavel, len.brown, linux-pm, linux-kernel, stable,
hua.yang, ting.wang, liang.lu, chetan.kumar
On Mon, Dec 4, 2023 at 3:12 AM Chris Feng <chris.feng@mediatek.com> wrote:
>
> 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
> ---
> kernel/power/hibernate.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> index 8d35b9f9aaa3..fb3b63e178b0 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,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
It would be somewhat cleaner to define an empty stub of
swsusp_unmark() for the CONFIG_SUSPEND undefined case in the header
file.
> + 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())
> --
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-12 18:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04 2:11 [PATCH RESEND v3] PM: hibernate: Avoid missing wakeup events during hibernation Chris Feng
2023-12-12 18:55 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).