[RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress

Muhammad Usama Anjum posted 4 patches 3 months, 3 weeks ago
There is a newer version of this series
[RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
Posted by Muhammad Usama Anjum 3 months, 3 weeks ago
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
Re: [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
Posted by Mario Limonciello (AMD) (kernel.org) 3 months, 2 weeks ago

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)
Re: [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
Posted by Muhammad Usama Anjum 3 months, 2 weeks ago
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
Re: [RFC 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
Posted by Mario Limonciello 3 months, 2 weeks ago
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)
>>
> 
>