* [RFC 1/4] PM: hibernate: export hibernation_in_progress()
2025-10-18 14:21 [RFC 0/4] PM: Hibernate: Add hibernation cancellation support Muhammad Usama Anjum
@ 2025-10-18 14:21 ` Muhammad Usama Anjum
2025-10-21 21:07 ` Mario Limonciello (AMD) (kernel.org)
2025-10-18 14:21 ` [RFC 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation Muhammad Usama Anjum
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: Muhammad Usama Anjum @ 2025-10-18 14:21 UTC (permalink / raw)
To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
Danilo Krummrich, Dmitry Torokhov, Thomas Gleixner,
Peter Zijlstra, linux-acpi, linux-kernel, linux-pm, linux-input
Cc: Muhammad Usama Anjum, kernel, superm1
Export hibernation_in_progress() to be used by other modules. Add its
signature when hibernation config isn't enabled as well.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
include/linux/suspend.h | 2 ++
kernel/power/hibernate.c | 1 +
2 files changed, 3 insertions(+)
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index b02876f1ae38a..348831cdb60e4 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -393,6 +393,7 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
extern int hibernate(void);
extern bool system_entering_hibernation(void);
extern bool hibernation_available(void);
+extern bool hibernation_in_progress(void);
asmlinkage int swsusp_save(void);
extern struct pbe *restore_pblist;
int pfn_is_nosave(unsigned long pfn);
@@ -412,6 +413,7 @@ static inline void hibernation_set_ops(const struct platform_hibernation_ops *op
static inline int hibernate(void) { return -ENOSYS; }
static inline bool system_entering_hibernation(void) { return false; }
static inline bool hibernation_available(void) { return false; }
+static inline bool hibernation_in_progress(void) { return false; }
static inline int hibernate_quiet_exec(int (*func)(void *data), void *data) {
return -ENOTSUPP;
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 14e85ff235512..aadf82f57e868 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -105,6 +105,7 @@ bool hibernation_in_progress(void)
{
return !atomic_read(&hibernate_atomic);
}
+EXPORT_SYMBOL_GPL(hibernation_in_progress);
bool hibernation_available(void)
{
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [RFC 1/4] PM: hibernate: export hibernation_in_progress()
2025-10-18 14:21 ` [RFC 1/4] PM: hibernate: export hibernation_in_progress() Muhammad Usama Anjum
@ 2025-10-21 21:07 ` Mario Limonciello (AMD) (kernel.org)
2025-10-22 9:53 ` Rafael J. Wysocki
0 siblings, 1 reply; 12+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2025-10-21 21:07 UTC (permalink / raw)
To: Muhammad Usama Anjum, Rafael J. Wysocki, Len Brown, Pavel Machek,
Greg Kroah-Hartman, Danilo Krummrich, Dmitry Torokhov,
Thomas Gleixner, Peter Zijlstra, linux-acpi, linux-kernel,
linux-pm, linux-input
Cc: kernel
On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
> Export hibernation_in_progress() to be used by other modules. Add its
> signature when hibernation config isn't enabled as well.
I wonder if you actually want to have pm_sleep_transition_in_progress()
exported instead. "Logically" I would expect cancelling a hibernate and
cancelling a suspend should work similarly.
>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> include/linux/suspend.h | 2 ++
> kernel/power/hibernate.c | 1 +
> 2 files changed, 3 insertions(+)
>
> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
> index b02876f1ae38a..348831cdb60e4 100644
> --- a/include/linux/suspend.h
> +++ b/include/linux/suspend.h
> @@ -393,6 +393,7 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
> extern int hibernate(void);
> extern bool system_entering_hibernation(void);
> extern bool hibernation_available(void);
> +extern bool hibernation_in_progress(void);
> asmlinkage int swsusp_save(void);
> extern struct pbe *restore_pblist;
> int pfn_is_nosave(unsigned long pfn);
> @@ -412,6 +413,7 @@ static inline void hibernation_set_ops(const struct platform_hibernation_ops *op
> static inline int hibernate(void) { return -ENOSYS; }
> static inline bool system_entering_hibernation(void) { return false; }
> static inline bool hibernation_available(void) { return false; }
> +static inline bool hibernation_in_progress(void) { return false; }
>
> static inline int hibernate_quiet_exec(int (*func)(void *data), void *data) {
> return -ENOTSUPP;
> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> index 14e85ff235512..aadf82f57e868 100644
> --- a/kernel/power/hibernate.c
> +++ b/kernel/power/hibernate.c
> @@ -105,6 +105,7 @@ bool hibernation_in_progress(void)
> {
> return !atomic_read(&hibernate_atomic);
> }
> +EXPORT_SYMBOL_GPL(hibernation_in_progress);
>
> bool hibernation_available(void)
> {
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [RFC 1/4] PM: hibernate: export hibernation_in_progress()
2025-10-21 21:07 ` Mario Limonciello (AMD) (kernel.org)
@ 2025-10-22 9:53 ` Rafael J. Wysocki
2025-10-22 16:27 ` Muhammad Usama Anjum
0 siblings, 1 reply; 12+ messages in thread
From: Rafael J. Wysocki @ 2025-10-22 9:53 UTC (permalink / raw)
To: Mario Limonciello (AMD) (kernel.org)
Cc: Muhammad Usama Anjum, Rafael J. Wysocki, Len Brown, Pavel Machek,
Greg Kroah-Hartman, Danilo Krummrich, Dmitry Torokhov,
Thomas Gleixner, Peter Zijlstra, linux-acpi, linux-kernel,
linux-pm, linux-input, kernel
On Tue, Oct 21, 2025 at 11:07 PM Mario Limonciello (AMD) (kernel.org)
<superm1@kernel.org> wrote:
>
>
>
> On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
> > Export hibernation_in_progress() to be used by other modules. Add its
> > signature when hibernation config isn't enabled as well.
>
> I wonder if you actually want to have pm_sleep_transition_in_progress()
> exported instead. "Logically" I would expect cancelling a hibernate and
> cancelling a suspend should work similarly.
Well, it does AFAICS, except that only the "freeze" and "poweroff"
transitions can be aborted during hibernation. This is analogous to
aborting a suspend transition.
The missing part is a mechanism to cancel hibernation between image
creation and the "poweroff" transition.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC 1/4] PM: hibernate: export hibernation_in_progress()
2025-10-22 9:53 ` Rafael J. Wysocki
@ 2025-10-22 16:27 ` Muhammad Usama Anjum
0 siblings, 0 replies; 12+ messages in thread
From: Muhammad Usama Anjum @ 2025-10-22 16:27 UTC (permalink / raw)
To: Rafael J. Wysocki, Mario Limonciello (AMD) (kernel.org)
Cc: usama.anjum, Len Brown, Pavel Machek, Greg Kroah-Hartman,
Danilo Krummrich, Dmitry Torokhov, Thomas Gleixner,
Peter Zijlstra, linux-acpi, linux-kernel, linux-pm, linux-input,
kernel
On 10/22/25 2:53 PM, Rafael J. Wysocki wrote:
> On Tue, Oct 21, 2025 at 11:07 PM Mario Limonciello (AMD) (kernel.org)
> <superm1@kernel.org> wrote:
>>
>>
>>
>> On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
>>> Export hibernation_in_progress() to be used by other modules. Add its
>>> signature when hibernation config isn't enabled as well.
>>
>> I wonder if you actually want to have pm_sleep_transition_in_progress()
>> exported instead. "Logically" I would expect cancelling a hibernate and
>> cancelling a suspend should work similarly.
>
> Well, it does AFAICS, except that only the "freeze" and "poweroff"
> transitions can be aborted during hibernation. This is analogous to
> aborting a suspend transition.
I'll switch up with pm_sleep_transition_in_progress().
>
> The missing part is a mechanism to cancel hibernation between image
> creation and the "poweroff" transition.
I'll add wakeup checking there and see if it works.
--
---
Thanks,
Usama
^ permalink raw reply [flat|nested] 12+ messages in thread
* [RFC 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation
2025-10-18 14:21 [RFC 0/4] PM: Hibernate: Add hibernation cancellation support Muhammad Usama Anjum
2025-10-18 14:21 ` [RFC 1/4] PM: hibernate: export hibernation_in_progress() Muhammad Usama Anjum
@ 2025-10-18 14:21 ` Muhammad Usama Anjum
2025-10-21 21:12 ` Mario Limonciello (AMD) (kernel.org)
2025-10-18 14:21 ` [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress Muhammad Usama Anjum
2025-10-18 14:21 ` [RFC 4/4] PM: sleep: clear pm_abort_suspend at suspend Muhammad Usama Anjum
3 siblings, 1 reply; 12+ messages in thread
From: Muhammad Usama Anjum @ 2025-10-18 14:21 UTC (permalink / raw)
To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
Danilo Krummrich, Dmitry Torokhov, Thomas Gleixner,
Peter Zijlstra, linux-acpi, linux-kernel, linux-pm, linux-input
Cc: Muhammad Usama Anjum, kernel, superm1
acpi_pm_wakeup_event() is called from acpi_button_notify() which is
called when power button is pressed. But system doesn't wake up as
pm_wakeup_dev_event() isn't called with hard parameter set in case of
hibernation. It gets set only for s2idle cases.
Call acpi_pm_wakeup_event() if power button is pressed and hibernation
is in progress. Set the hard parameter such that pm_system_wakeup()
gets called which increments pm_abort_suspend counter. Hence hibernation
would be cancelled as in hibernation path, this counter is checked if it
should be aborted.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
drivers/acpi/button.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 0a70260401882..4a2575c0c44e3 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -20,6 +20,7 @@
#include <linux/acpi.h>
#include <linux/dmi.h>
#include <acpi/button.h>
+#include <linux/suspend.h>
#define ACPI_BUTTON_CLASS "button"
#define ACPI_BUTTON_FILE_STATE "state"
@@ -458,11 +459,16 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
acpi_pm_wakeup_event(&device->dev);
button = acpi_driver_data(device);
- if (button->suspended || event == ACPI_BUTTON_NOTIFY_WAKE)
- return;
-
input = button->input;
keycode = test_bit(KEY_SLEEP, input->keybit) ? KEY_SLEEP : KEY_POWER;
+ if (event == ACPI_BUTTON_NOTIFY_STATUS && keycode == KEY_POWER &&
+ hibernation_in_progress()) {
+ pm_wakeup_dev_event(&device->dev, 0, true);
+ return;
+ }
+
+ if (button->suspended || event == ACPI_BUTTON_NOTIFY_WAKE)
+ return;
input_report_key(input, keycode, 1);
input_sync(input);
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [RFC 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation
2025-10-18 14:21 ` [RFC 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation Muhammad Usama Anjum
@ 2025-10-21 21:12 ` Mario Limonciello (AMD) (kernel.org)
0 siblings, 0 replies; 12+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2025-10-21 21:12 UTC (permalink / raw)
To: Muhammad Usama Anjum, Rafael J. Wysocki, Len Brown, Pavel Machek,
Greg Kroah-Hartman, Danilo Krummrich, Dmitry Torokhov,
Thomas Gleixner, Peter Zijlstra, linux-acpi, linux-kernel,
linux-pm, linux-input
Cc: kernel
On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
> acpi_pm_wakeup_event() is called from acpi_button_notify() which is
> called when power button is pressed. But system doesn't wake up as
> pm_wakeup_dev_event() isn't called with hard parameter set in case of
> hibernation. It gets set only for s2idle cases.
>
> Call acpi_pm_wakeup_event() if power button is pressed and hibernation
> is in progress. Set the hard parameter such that pm_system_wakeup()
> gets called which increments pm_abort_suspend counter. Hence hibernation
> would be cancelled as in hibernation path, this counter is checked if it
> should be aborted.
>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> drivers/acpi/button.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
> index 0a70260401882..4a2575c0c44e3 100644
> --- a/drivers/acpi/button.c
> +++ b/drivers/acpi/button.c
> @@ -20,6 +20,7 @@
> #include <linux/acpi.h>
> #include <linux/dmi.h>
> #include <acpi/button.h>
> +#include <linux/suspend.h>
>
> #define ACPI_BUTTON_CLASS "button"
> #define ACPI_BUTTON_FILE_STATE "state"
> @@ -458,11 +459,16 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
> acpi_pm_wakeup_event(&device->dev);
>
> button = acpi_driver_data(device);
> - if (button->suspended || event == ACPI_BUTTON_NOTIFY_WAKE)
> - return;
> -
> input = button->input;
> keycode = test_bit(KEY_SLEEP, input->keybit) ? KEY_SLEEP : KEY_POWER;
> + if (event == ACPI_BUTTON_NOTIFY_STATUS && keycode == KEY_POWER &&
> + hibernation_in_progress()) {
> + pm_wakeup_dev_event(&device->dev, 0, true);
The comments for pm_wakeup_dev_event() say that hard is used
specifically for suspend to idle, but now you're overloading it.
So I think the comment in pm_wakeup_dev_event() needs to be updated if
this is the way forward.
> + return;
> + }
> +
> + if (button->suspended || event == ACPI_BUTTON_NOTIFY_WAKE)
> + return;
>
> input_report_key(input, keycode, 1);
> input_sync(input);
^ permalink raw reply [flat|nested] 12+ messages in thread
* [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
2025-10-18 14:21 [RFC 0/4] PM: Hibernate: Add hibernation cancellation support Muhammad Usama Anjum
2025-10-18 14:21 ` [RFC 1/4] PM: hibernate: export hibernation_in_progress() Muhammad Usama Anjum
2025-10-18 14:21 ` [RFC 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation Muhammad Usama Anjum
@ 2025-10-18 14:21 ` Muhammad Usama Anjum
2025-10-21 21:14 ` Mario Limonciello (AMD) (kernel.org)
2025-10-18 14:21 ` [RFC 4/4] PM: sleep: clear pm_abort_suspend at suspend Muhammad Usama Anjum
3 siblings, 1 reply; 12+ messages in thread
From: Muhammad Usama Anjum @ 2025-10-18 14:21 UTC (permalink / raw)
To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
Danilo Krummrich, Dmitry Torokhov, Thomas Gleixner,
Peter Zijlstra, linux-acpi, linux-kernel, linux-pm, linux-input
Cc: Muhammad Usama Anjum, kernel, superm1
Serio drivers call input_handle_event(). Although the serio drivers have
duplicate events, they have separate code path and call
input_handle_event(). Ignore the KEY_POWER such that this event isn't
sent to the userspace if hibernation is in progress.
Abort the hibernation by calling pm awake API as well.
Without this, the event is sent to the userspace and it suspends the
device after hibernation cancellation.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
drivers/input/input.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/input/input.c b/drivers/input/input.c
index a500e1e276c21..0979f18aae6a2 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -26,6 +26,7 @@
#include <linux/kstrtox.h>
#include <linux/mutex.h>
#include <linux/rcupdate.h>
+#include <linux/suspend.h>
#include "input-compat.h"
#include "input-core-private.h"
#include "input-poller.h"
@@ -362,6 +363,11 @@ void input_handle_event(struct input_dev *dev,
lockdep_assert_held(&dev->event_lock);
+ if (code == KEY_POWER && hibernation_in_progress()) {
+ pm_wakeup_dev_event(&dev->dev, 0, true);
+ return;
+ }
+
disposition = input_get_disposition(dev, type, code, &value);
if (disposition != INPUT_IGNORE_EVENT) {
if (type != EV_SYN)
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread* Re: [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
2025-10-18 14:21 ` [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress Muhammad Usama Anjum
@ 2025-10-21 21:14 ` Mario Limonciello (AMD) (kernel.org)
2025-10-22 16:33 ` Muhammad Usama Anjum
0 siblings, 1 reply; 12+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2025-10-21 21:14 UTC (permalink / raw)
To: Muhammad Usama Anjum, Rafael J. Wysocki, Len Brown, Pavel Machek,
Greg Kroah-Hartman, Danilo Krummrich, Dmitry Torokhov,
Thomas Gleixner, Peter Zijlstra, linux-acpi, linux-kernel,
linux-pm, linux-input
Cc: kernel
On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
> Serio drivers call input_handle_event(). Although the serio drivers have
> duplicate events, they have separate code path and call
> input_handle_event(). Ignore the KEY_POWER such that this event isn't
> sent to the userspace if hibernation is in progress.
>
> Abort the hibernation by calling pm awake API as well.
So do you observe events both from ACPI and from input? Or was this
patch based upon an earlier version of the ACPI patch?
Because it feels like to me perhaps another way to solve this would be
for patch 2 to to send the input event and just keep
pm_wakeup_dev_event() here instead of both places.
>
> Without this, the event is sent to the userspace and it suspends the
> device after hibernation cancellation.
>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> drivers/input/input.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index a500e1e276c21..0979f18aae6a2 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -26,6 +26,7 @@
> #include <linux/kstrtox.h>
> #include <linux/mutex.h>
> #include <linux/rcupdate.h>
> +#include <linux/suspend.h>
> #include "input-compat.h"
> #include "input-core-private.h"
> #include "input-poller.h"
> @@ -362,6 +363,11 @@ void input_handle_event(struct input_dev *dev,
>
> lockdep_assert_held(&dev->event_lock);
>
> + if (code == KEY_POWER && hibernation_in_progress()) {
> + pm_wakeup_dev_event(&dev->dev, 0, true);
> + return;
> + }
> +
> disposition = input_get_disposition(dev, type, code, &value);
> if (disposition != INPUT_IGNORE_EVENT) {
> if (type != EV_SYN)
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
2025-10-21 21:14 ` Mario Limonciello (AMD) (kernel.org)
@ 2025-10-22 16:33 ` Muhammad Usama Anjum
2025-10-22 16:40 ` Mario Limonciello
0 siblings, 1 reply; 12+ messages in thread
From: Muhammad Usama Anjum @ 2025-10-22 16:33 UTC (permalink / raw)
To: Mario Limonciello (AMD) (kernel.org), Rafael J. Wysocki,
Len Brown, Pavel Machek, Greg Kroah-Hartman, Danilo Krummrich,
Dmitry Torokhov, Thomas Gleixner, Peter Zijlstra, linux-acpi,
linux-kernel, linux-pm, linux-input
Cc: usama.anjum, kernel
On 10/22/25 2:14 AM, Mario Limonciello (AMD) (kernel.org) wrote:
>
>
> On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
>> Serio drivers call input_handle_event(). Although the serio drivers have
>> duplicate events, they have separate code path and call
>> input_handle_event(). Ignore the KEY_POWER such that this event isn't
>> sent to the userspace if hibernation is in progress.
>>
>> Abort the hibernation by calling pm awake API as well.
>
> So do you observe events both from ACPI and from input? Or was this patch based upon an earlier version of the ACPI patch?
Yes, I observe events from both ACPI and input driver when power button is pressed.
AFAIU this happens because of historic reasons of button wired through keyboard
controller.
The call to pm_wakeup_dev_event() can be removed. But I've added it for non-ACPI
devices. Maybe those devices handle only input events through this path. Do you
think this can be the case?
>
> Because it feels like to me perhaps another way to solve this would be for patch 2 to to send the input event and just keep pm_wakeup_dev_event() here instead of both places.
I was sending input event in patch 2 earlier. I was having difficulty in managing
so many dependencies in acpi_button_notify(). It suspends the button events. I'll
reiterate and see if I can achieve this in next series because this would be most
clean solution.
>
>>
>> Without this, the event is sent to the userspace and it suspends the
>> device after hibernation cancellation.
>>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>> ---
>> drivers/input/input.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/input/input.c b/drivers/input/input.c
>> index a500e1e276c21..0979f18aae6a2 100644
>> --- a/drivers/input/input.c
>> +++ b/drivers/input/input.c
>> @@ -26,6 +26,7 @@
>> #include <linux/kstrtox.h>
>> #include <linux/mutex.h>
>> #include <linux/rcupdate.h>
>> +#include <linux/suspend.h>
>> #include "input-compat.h"
>> #include "input-core-private.h"
>> #include "input-poller.h"
>> @@ -362,6 +363,11 @@ void input_handle_event(struct input_dev *dev,
>> lockdep_assert_held(&dev->event_lock);
>> + if (code == KEY_POWER && hibernation_in_progress()) {
>> + pm_wakeup_dev_event(&dev->dev, 0, true);
>> + return;
>> + }
>> +
>> disposition = input_get_disposition(dev, type, code, &value);
>> if (disposition != INPUT_IGNORE_EVENT) {
>> if (type != EV_SYN)
>
--
---
Thanks,
Usama
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
2025-10-22 16:33 ` Muhammad Usama Anjum
@ 2025-10-22 16:40 ` Mario Limonciello
0 siblings, 0 replies; 12+ messages in thread
From: Mario Limonciello @ 2025-10-22 16:40 UTC (permalink / raw)
To: Muhammad Usama Anjum, Rafael J. Wysocki, Len Brown, Pavel Machek,
Greg Kroah-Hartman, Danilo Krummrich, Dmitry Torokhov,
Thomas Gleixner, Peter Zijlstra, linux-acpi, linux-kernel,
linux-pm, linux-input
Cc: kernel
On 10/22/25 11:33 AM, Muhammad Usama Anjum wrote:
> On 10/22/25 2:14 AM, Mario Limonciello (AMD) (kernel.org) wrote:
>>
>>
>> On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
>>> Serio drivers call input_handle_event(). Although the serio drivers have
>>> duplicate events, they have separate code path and call
>>> input_handle_event(). Ignore the KEY_POWER such that this event isn't
>>> sent to the userspace if hibernation is in progress.
>>>
>>> Abort the hibernation by calling pm awake API as well.
>>
>> So do you observe events both from ACPI and from input? Or was this patch based upon an earlier version of the ACPI patch?
> Yes, I observe events from both ACPI and input driver when power button is pressed.
> AFAIU this happens because of historic reasons of button wired through keyboard
> controller.
>
> The call to pm_wakeup_dev_event() can be removed. But I've added it for non-ACPI
> devices. Maybe those devices handle only input events through this path. Do you
> think this can be the case?
Well my point was if both are coming through - it's probably better to
just have pm_wakeup_dev_event() in input and pass the input event from ACPI.
> >
>> Because it feels like to me perhaps another way to solve this would be for patch 2 to to send the input event and just keep pm_wakeup_dev_event() here instead of both places.
> I was sending input event in patch 2 earlier. I was having difficulty in managing
> so many dependencies in acpi_button_notify(). It suspends the button events. I'll
> reiterate and see if I can achieve this in next series because this would be most
> clean solution.
OK!
>
>>
>>>
>>> Without this, the event is sent to the userspace and it suspends the
>>> device after hibernation cancellation.
>>>
>>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>>> ---
>>> drivers/input/input.c | 6 ++++++
>>> 1 file changed, 6 insertions(+)
>>>
>>> diff --git a/drivers/input/input.c b/drivers/input/input.c
>>> index a500e1e276c21..0979f18aae6a2 100644
>>> --- a/drivers/input/input.c
>>> +++ b/drivers/input/input.c
>>> @@ -26,6 +26,7 @@
>>> #include <linux/kstrtox.h>
>>> #include <linux/mutex.h>
>>> #include <linux/rcupdate.h>
>>> +#include <linux/suspend.h>
>>> #include "input-compat.h"
>>> #include "input-core-private.h"
>>> #include "input-poller.h"
>>> @@ -362,6 +363,11 @@ void input_handle_event(struct input_dev *dev,
>>> lockdep_assert_held(&dev->event_lock);
>>> + if (code == KEY_POWER && hibernation_in_progress()) {
>>> + pm_wakeup_dev_event(&dev->dev, 0, true);
>>> + return;
>>> + }
>>> +
>>> disposition = input_get_disposition(dev, type, code, &value);
>>> if (disposition != INPUT_IGNORE_EVENT) {
>>> if (type != EV_SYN)
>>
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [RFC 4/4] PM: sleep: clear pm_abort_suspend at suspend
2025-10-18 14:21 [RFC 0/4] PM: Hibernate: Add hibernation cancellation support Muhammad Usama Anjum
` (2 preceding siblings ...)
2025-10-18 14:21 ` [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress Muhammad Usama Anjum
@ 2025-10-18 14:21 ` Muhammad Usama Anjum
3 siblings, 0 replies; 12+ messages in thread
From: Muhammad Usama Anjum @ 2025-10-18 14:21 UTC (permalink / raw)
To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
Danilo Krummrich, Dmitry Torokhov, Thomas Gleixner,
Peter Zijlstra, linux-acpi, linux-kernel, linux-pm, linux-input
Cc: Muhammad Usama Anjum, kernel, superm1
Clear pm_abort_suspend counter in case a wakeup is detected during
hibernation process. If this counter isn't reset, it'll affect the
next hibernation cycle and next time hibernation will not happen as
pm_abort_suspend is still positive.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
drivers/base/power/main.c | 2 ++
kernel/cpu.c | 1 +
kernel/power/hibernate.c | 5 ++++-
kernel/power/process.c | 1 +
4 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index bcfb170baca63..481744e7d9688 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1627,6 +1627,7 @@ static void device_suspend_late(struct device *dev, pm_message_t state, bool asy
goto Complete;
if (pm_wakeup_pending()) {
+ pm_wakeup_clear(0);
WRITE_ONCE(async_error, -EBUSY);
goto Complete;
}
@@ -1872,6 +1873,7 @@ static void device_suspend(struct device *dev, pm_message_t state, bool async)
if (pm_wakeup_pending()) {
dev->power.direct_complete = false;
+ pm_wakeup_clear(0);
WRITE_ONCE(async_error, -EBUSY);
goto Complete;
}
diff --git a/kernel/cpu.c b/kernel/cpu.c
index db9f6c539b28c..74c9f6b4947dd 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1921,6 +1921,7 @@ int freeze_secondary_cpus(int primary)
if (pm_wakeup_pending()) {
pr_info("Wakeup pending. Abort CPU freeze\n");
+ pm_wakeup_clear(0);
error = -EBUSY;
break;
}
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index aadf82f57e868..1a4a5c3c64970 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -350,8 +350,10 @@ static int create_image(int platform_mode)
goto Enable_irqs;
}
- if (hibernation_test(TEST_CORE) || pm_wakeup_pending())
+ if (hibernation_test(TEST_CORE) || pm_wakeup_pending()) {
+ pm_wakeup_clear(0);
goto Power_up;
+ }
in_suspend = 1;
save_processor_state();
@@ -661,6 +663,7 @@ int hibernation_platform_enter(void)
goto Enable_irqs;
if (pm_wakeup_pending()) {
+ pm_wakeup_clear(0);
error = -EAGAIN;
goto Power_up;
}
diff --git a/kernel/power/process.c b/kernel/power/process.c
index 8ff68ebaa1e08..7a278e049940c 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -67,6 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
break;
if (pm_wakeup_pending()) {
+ pm_wakeup_clear(0);
wakeup = true;
break;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 12+ messages in thread