From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Helge Deller <deller@gmx.de>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
linux-parisc@vger.kernel.org, sashiko-bot@kernel.org
Subject: [PATCH 6/7] Input: gscps2 - serialize concurrent interrupt handlers
Date: Sun, 30 Aug 2026 13:52:51 -0700 [thread overview]
Message-ID: <20260830-gscps2-v1-6-c733d4cae7f9@gmail.com> (raw)
In-Reply-To: <20260830-gscps2-v1-0-c733d4cae7f9@gmail.com>
gscps2_interrupt() may be invoked concurrently from a hardware interrupt
on one CPU and from process context via gscps2_writeb_output() on another
CPU. In gscps2_report_data(), ps2port->lock is released before calling
serio_interrupt() to avoid recursive deadlocks. However, if two execution
contexts run gscps2_report_data() concurrently for the same port, they
could race to acquire serio->lock inside serio_interrupt(), potentially
delivering multi-byte scancodes out of order.
Serialize execution of gscps2_interrupt() using gscps2_interrupt_lock
with ACQUIRE(spinlock_irqsave_try). Using spin_trylock prevents
overlapping executions and guarantees in-order packet delivery without
risking recursive deadlocks if an input driver synchronously sends a
command back via serio_write(). If the lock cannot be acquired, return
IRQ_NONE to preserve spurious interrupt detection on shared IRQ lines.
Reported-by: sashiko-bot@kernel.org
Assisted-by: LLM
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/serio/gscps2.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/input/serio/gscps2.c b/drivers/input/serio/gscps2.c
index 907fb1537595..2afd53a163ff 100644
--- a/drivers/input/serio/gscps2.c
+++ b/drivers/input/serio/gscps2.c
@@ -288,6 +288,8 @@ static bool gscps2_report_data(struct gscps2port *ps2port)
}
}
+static DEFINE_SPINLOCK(gscps2_interrupt_lock);
+
/**
* gscps2_interrupt() - Interruption service routine
* @irq: interrupt number which triggered (unused)
@@ -305,21 +307,31 @@ static irqreturn_t gscps2_interrupt(int irq, void *dev)
{
struct gscps2port *ps2port;
bool handled = false;
+ bool more_data;
+
+ ACQUIRE(spinlock_irqsave_try, lock)(&gscps2_interrupt_lock);
+ if (ACQUIRE_ERR(spinlock_irqsave_try, &lock))
+ return IRQ_NONE;
guard(rcu)();
- list_for_each_entry_rcu(ps2port, &ps2port_list, node) {
- if (gscps2_read_data(ps2port))
- handled = true;
- }
+ do {
+ more_data = false;
- /* all data was read from the ports - now report the data to upper layer */
- list_for_each_entry_rcu(ps2port, &ps2port_list, node) {
- if (gscps2_report_data(ps2port)) {
- /* More data ready - break early to restart interrupt */
- break;
+ list_for_each_entry_rcu(ps2port, &ps2port_list, node) {
+ if (gscps2_read_data(ps2port))
+ handled = true;
}
- }
+
+ /* all data was read from the ports - now report the data to upper layer */
+ list_for_each_entry_rcu(ps2port, &ps2port_list, node) {
+ if (gscps2_report_data(ps2port)) {
+ /* More data ready - restart loop to read new data */
+ more_data = true;
+ break;
+ }
+ }
+ } while (more_data);
return IRQ_RETVAL(handled);
}
--
2.55.0.897.gb25b4bd76c-goog
next prev parent reply other threads:[~2026-08-30 20:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 20:52 [PATCH 0/7] Input: gscps2: cleanups and locking fixes Dmitry Torokhov
2026-08-30 20:52 ` [PATCH 1/7] Input: gscps2 - clean up driver code style and structure Dmitry Torokhov
2026-08-30 20:52 ` [PATCH 2/7] Input: gscps2 - use RCU for ps2port_list and manage it in open/close Dmitry Torokhov
2026-08-30 20:52 ` [PATCH 3/7] Input: gscps2 - protect buffer access in read and report helpers Dmitry Torokhov
2026-08-30 20:52 ` [PATCH 4/7] Input: gscps2 - serialize hardware and buffer access in gscps2_flush() Dmitry Torokhov
2026-08-30 20:52 ` [PATCH 5/7] Input: gscps2 - return IRQ_NONE when interrupt is not handled Dmitry Torokhov
2026-08-30 20:52 ` Dmitry Torokhov [this message]
2026-08-30 20:52 ` [PATCH 7/7] Input: gscps2 - drop busy-wait and manual interrupt pump on transmit Dmitry Torokhov
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=20260830-gscps2-v1-6-c733d4cae7f9@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=deller@gmx.de \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
/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