Linux ACPI
 help / color / mirror / Atom feed
From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: usama.anjum@collabora.com, Len Brown <lenb@kernel.org>,
	Pavel Machek <pavel@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pm@vger.kernel.org, linux-input@vger.kernel.org,
	kernel@collabora.com, superm1@kernel.org
Subject: Re: [PATCH 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress
Date: Fri, 28 Nov 2025 22:00:54 +0500	[thread overview]
Message-ID: <a26e1b2f-50dc-4956-8bea-49d0e9ac2e4e@collabora.com> (raw)
In-Reply-To: <CAJZ5v0iDUPB9s2fPJxqVqPGj5wbw54tR4thmDD2V-r4+Q2prwg@mail.gmail.com>

On 11/25/25 5:25 PM, Rafael J. Wysocki wrote:
> On Tue, Nov 25, 2025 at 11:23 AM Muhammad Usama Anjum
> <usama.anjum@collabora.com> wrote:
>>
>> On 11/24/25 11:50 PM, Rafael J. Wysocki wrote:
>>> On Fri, Nov 7, 2025 at 7:45 PM Muhammad Usama Anjum
>>> <usama.anjum@collabora.com> wrote:
>>>>
>>>> Input (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.
>>>
>>> Your change affects suspend too.
>>>
>>> Also, what's the goal you want to achieve?
>> Two goals:
>> * Don't send event to userspace
>> * Set pm_wakeup for hibernation cancellation for non-acpi devices (This api
>>   call should be tested on non-acpi devices such as arm board to see if it
>>   helps. I don't have an arm board in hand)
>>
>>>
>>>> Abort the hibernation by calling pm_wakeup_dev_event(). In case of serio,
>>>> doesn't have wakeup source registered, this call doesn't do anything.
>>>> But there may be other input drivers which will require this.
>>>>
>>>> Without this, the event is sent to the userspace and it suspends the
>>>> device after hibernation cancellation.
>>>
>>> I think that's because user space handles it this way, isn't it?
>>
>> Yes, it depends on how userspace handles such events. There are different settings
>> configured for systemd-logind when power event is received. The purpose is to consume
>> this event to cancel the hibernation without letting userspace know about it.
>>
>> Thinking more about it, I wasn't sure if all of such events are compulsory to be
>> delivered to userspace. But then I found an example: In acpi_button_notify(), all
>> such events are not sent to userspace if button is suspended. So it seems okay to
>> not send this as well and just consume in the kernel.
> 
> You want the given key (and it doesn't matter whether or not this is
> KEY_POWER or something else) to play two roles.  One of them is to
> send a specific key code to user space and let it handle the keypress
> as it wants.  This is how it works most of the time.  The second one
> is to wake up the system from sleep (and I'm not sure why you want to
> limit this to hibernation) in which case the key code will not be sent
> to user space.
> 
> For this to work, you need to switch between the two modes quite
> precisely and checking things like pm_sleep_transition_in_progress()
> (which is only used for debug and its raciness is not relevant there)
> is not sufficient for this purpose.  That's what the "suspended" flag
> in the ACPI button driver is for.
I've been testing and trying out `suspended` flag. But this flag gets set very late.
If we depend on it, we'll not be able to wakeup in time after cancelling hibernation.

Initially we were using hibernation_in_progress() in RFC and we switched to
pm_sleep_transition_in_progress() in order to cancel the sleep as well (which wasn't 
the original intention).

The sleep detection isn't working through pm_suspend_target_state or pm_suspend_in_progress()
as it is set very late in suspend process. While hibernation_in_progress() gets set in
start of hibernation.

Then as you said, they are unreliable. I'm thinking what other options. But I've not
found any. Please share ideas what other way can work instead of suspended flag better? 

-- 
---
Thanks,
Usama

  parent reply	other threads:[~2025-11-28 17:01 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-07 18:44 [PATCH 0/4] PM: Hibernate: Add hibernation cancellation support Muhammad Usama Anjum
2025-11-07 18:44 ` [PATCH 1/4] PM: hibernate: export pm_sleep_transition_in_progress() Muhammad Usama Anjum
2025-11-24 17:01   ` Greg Kroah-Hartman
2025-11-25 16:44     ` Muhammad Usama Anjum
2025-11-07 18:44 ` [PATCH 2/4] ACPI: button: Cancel hibernation if button is pressed during hibernation Muhammad Usama Anjum
2025-11-24 17:03   ` Greg Kroah-Hartman
2025-11-25 11:12     ` Muhammad Usama Anjum
2025-11-25 11:47       ` Greg Kroah-Hartman
2025-11-25 16:41         ` Muhammad Usama Anjum
2025-11-26  7:38           ` Greg Kroah-Hartman
2025-11-26 12:55             ` Mario Limonciello
2025-11-26 13:26               ` Muhammad Usama Anjum
2025-11-26 13:41             ` Muhammad Usama Anjum
2025-11-24 18:42   ` Rafael J. Wysocki
2025-11-28 14:17     ` Muhammad Usama Anjum
2025-11-07 18:44 ` [PATCH 3/4] Input: Ignore the KEY_POWER events if hibernation is in progress Muhammad Usama Anjum
2025-11-24 18:50   ` Rafael J. Wysocki
2025-11-25 10:22     ` Muhammad Usama Anjum
2025-11-25 12:25       ` Rafael J. Wysocki
2025-11-25 16:05         ` Muhammad Usama Anjum
2025-11-28 17:00         ` Muhammad Usama Anjum [this message]
2025-11-07 18:44 ` [PATCH 4/4] PM: sleep: clear pm_abort_suspend at suspend Muhammad Usama Anjum
2025-11-24 18:54   ` Rafael J. Wysocki
2025-11-25  9:53     ` Muhammad Usama Anjum
2025-11-25 12:59       ` Rafael J. Wysocki
2025-11-24 13:03 ` [PATCH 0/4] PM: Hibernate: Add hibernation cancellation support Muhammad Usama Anjum
2026-01-02 22:40 ` Pavel Machek

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=a26e1b2f-50dc-4956-8bea-49d0e9ac2e4e@collabora.com \
    --to=usama.anjum@collabora.com \
    --cc=dakr@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@collabora.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=superm1@kernel.org \
    --cc=tglx@linutronix.de \
    /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