[RFC 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation

Muhammad Usama Anjum posted 4 patches 3 months, 3 weeks ago
There is a newer version of this series
[RFC 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation
Posted by Muhammad Usama Anjum 3 months, 3 weeks ago
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
Re: [RFC 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation
Posted by Mario Limonciello (AMD) (kernel.org) 3 months, 2 weeks ago

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);