public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] Input: atkbd - skip cleanup when used as a wakeup source
@ 2026-03-30 19:01 Henry Barnor via B4 Relay
  2026-03-30 21:56 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Henry Barnor via B4 Relay @ 2026-03-30 19:01 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel, Henry Barnor

From: Henry Barnor <hbarnor@chromium.org>

In systems using suspend-to-idle, the serio core calls atkbd_cleanup()
during the suspend transition. Currently, this function unconditionally
calls atkbd_disable(), setting atkbd->enabled to false.

This creates a race condition during wakeup: when a key is pressed to
wake the system, atkbd_receive_byte() is triggered. It correctly signals
a wakeup event to the PM core, but then checks atkbd->enabled. Because
the driver was disabled during suspend, the scancode is discarded.
The system wakes up, but the initial keystroke is lost.

This is particularly problematic for platforms like Android that rely on
the input event itself to complete the wakeup transition and turn on the
screen. On these systems, the device wakes up but remains in a dim state
because the initial interaction was lost.

This patch modifies atkbd_cleanup() to skip disabling and resetting
the keyboard if the device is configured as a wakeup source. This
preserves atkbd->enabled = true through the sleep duration, ensuring
the wake-up scancode is reported to the input subsystem.

Note that this also affects the shutdown path. However, if a device is
configured for wakeup, skipping the reset to "default" state is
consistent with the goal of allowing the hardware to trigger a
system-state transition. Modern BIOS/UEFI implementations perform their
own keyboard initialization, so skipping the legacy reset on reboot
for these devices poses minimal risk.

Signed-off-by: Henry Barnor <hbarnor@chromium.org>
---
 drivers/input/keyboard/atkbd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 4560d3964eee..1fba1932412e 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -958,6 +958,9 @@ static void atkbd_cleanup(struct serio *serio)
 {
 	struct atkbd *atkbd = atkbd_from_serio(serio);
 
+	if (device_may_wakeup(&serio->dev))
+		return;
+
 	atkbd_disable(atkbd);
 	ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);
 }

---
base-commit: 6d4b67a2a76a4ff2393fe88119ae4332821b82b4
change-id: 20260310-wakeup-ec57a88a0162

Best regards,
-- 
Henry Barnor <hbarnor@chromium.org>



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND] Input: atkbd - skip cleanup when used as a wakeup source
  2026-03-30 19:01 [PATCH RESEND] Input: atkbd - skip cleanup when used as a wakeup source Henry Barnor via B4 Relay
@ 2026-03-30 21:56 ` Dmitry Torokhov
  2026-04-05  5:36   ` Henry Barnor
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2026-03-30 21:56 UTC (permalink / raw)
  To: hbarnor; +Cc: linux-input, linux-kernel

Hi Henry,

On Mon, Mar 30, 2026 at 12:01:50PM -0700, Henry Barnor via B4 Relay wrote:
> From: Henry Barnor <hbarnor@chromium.org>
> 
> In systems using suspend-to-idle, the serio core calls atkbd_cleanup()
> during the suspend transition. Currently, this function unconditionally
> calls atkbd_disable(), setting atkbd->enabled to false.
> 
> This creates a race condition during wakeup: when a key is pressed to
> wake the system, atkbd_receive_byte() is triggered. It correctly signals
> a wakeup event to the PM core, but then checks atkbd->enabled. Because
> the driver was disabled during suspend, the scancode is discarded.
> The system wakes up, but the initial keystroke is lost.
> 
> This is particularly problematic for platforms like Android that rely on
> the input event itself to complete the wakeup transition and turn on the
> screen. On these systems, the device wakes up but remains in a dim state
> because the initial interaction was lost.

This is really for the Android system layer to solve.

> 
> This patch modifies atkbd_cleanup() to skip disabling and resetting
> the keyboard if the device is configured as a wakeup source. This
> preserves atkbd->enabled = true through the sleep duration, ensuring
> the wake-up scancode is reported to the input subsystem.
> 
> Note that this also affects the shutdown path. However, if a device is
> configured for wakeup, skipping the reset to "default" state is
> consistent with the goal of allowing the hardware to trigger a
> system-state transition. Modern BIOS/UEFI implementations perform their
> own keyboard initialization, so skipping the legacy reset on reboot
> for these devices poses minimal risk.

We unfortunately need to support devices much older than that, so we can
not be sure that this change is safe. Historically there we a lot of
instances where systems were unhappy if we attempted to enter shutdown
or suspend paths with devices in state other than freshly reset.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND] Input: atkbd - skip cleanup when used as a wakeup source
  2026-03-30 21:56 ` Dmitry Torokhov
@ 2026-04-05  5:36   ` Henry Barnor
  0 siblings, 0 replies; 3+ messages in thread
From: Henry Barnor @ 2026-04-05  5:36 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: hbarnor, linux-input, linux-kernel

Hi Dmitry,

> We unfortunately need to support devices much older than that, so we can
> not be sure that this change is safe. Historically there we a lot of
> instances where systems were unhappy if we attempted to enter shutdown
> or suspend paths with devices in state other than freshly reset.

Thanks for the feedback and the context on legacy hardware risks. That makes sense. 

I will explore handling this within the Android system layer instead.

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-05  5:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-30 19:01 [PATCH RESEND] Input: atkbd - skip cleanup when used as a wakeup source Henry Barnor via B4 Relay
2026-03-30 21:56 ` Dmitry Torokhov
2026-04-05  5:36   ` Henry Barnor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox