From: sashiko-bot@kernel.org
To: "Emfox Zhou" <emfox@debian.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v9 2/5] HID: intel-thc-hid: intel-ipts: receive reports
Date: Thu, 19 Nov 2026 09:31:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-222839@kernel.org> (raw)
In-Reply-To: <20261119091152.470384-3-emfox@debian.org>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] HID: intel-thc-hid: intel-ipts: invalid wait context in
thc_ipts_hardirq()
- [Medium] HID: intel-ipts: thc_ipts_thread() claims foreign shared IRQs
when recovering
- [Medium] HID: intel-thc-hid: intel-ipts: premature IRQ mask in
thc_ipts_thread()
--
commit e3ecea8c718b8bb20502f799773e9526e0beb0ef
Author: Emfox Zhou <emfox@debian.org>
HID: intel-thc-hid: intel-ipts: receive reports
This commit configures the receive and transmit DMA engines, requests the
port interrupt with error recovery, and decodes incoming report frames.
> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> index 2d14e5278f986..e7896b16f1ada 100644
> --- a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
[ ... ]
> @@ -129,6 +144,283 @@ static int thc_ipts_touch_set(struct thc_ipts *idev, bool enable)
[ ... ]
> +irqreturn_t thc_ipts_hardirq(int irq, void *data)
> +{
> + struct thc_ipts *idev = data;
> +
> + /* Nothing of ours is pending: the cause belongs to a sharer. */
> + if (!READ_ONCE(idev->dma_ready))
> + return IRQ_NONE;
> +
> + /* Level triggered and shared: mask first, or it stays asserted. */
> + thc_interrupt_enable(idev->thc, false);
[Severity: Medium]
Can calling thc_interrupt_enable() from thc_ipts_hardirq() trigger an
invalid wait context warning under lockdep (and sleep in hardirq context on
PREEMPT_RT)?
thc_ipts_probe() requests a shared PCI_IRQ_INTX vector with
IRQF_SHARED | IRQF_COND_ONESHOT. When the line is shared with an
IRQF_ONESHOT handler, __setup_irq() promotes this action to IRQF_ONESHOT,
so __handle_irq_event_percpu() runs thc_ipts_hardirq() in LD_WAIT_SPIN
context without calling lockdep_hardirq_threaded(). thc_interrupt_enable()
then calls regmap_write_bits() on dev->thc_regmap, which is initialized
with .fast_io = true but without .use_raw_spinlock = true:
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c:
static const struct regmap_config thc_regmap_cfg = {
...
.cache_type = REGCACHE_NONE,
.fast_io = true,
.use_single_read = true,
.use_single_write = true,
};
Because .use_raw_spinlock is not set, __regmap_init() protects the regmap
with a regular spinlock_t (LD_WAIT_CONFIG) rather than a raw_spinlock_t.
> +
> + /*
> + * A reset or a teardown in flight still gets the thread: the status it
> + * drains is where a pending transmit completion is delivered, and a
> + * write waiting for that one holds the bus lock the reset needs.
> + */
> + return IRQ_WAKE_THREAD;
> +}
[ ... ]
> +void thc_ipts_recover(struct work_struct *work)
> +{
> + struct thc_ipts *idev = container_of(work, struct thc_ipts,
> + recover_work);
> +
> + /*
> + * From here the status registers belong to the reset: the threaded
> + * handler must not acknowledge a frame it is not going to read, or the
> + * interrupt that would announce it again never comes. The flag alone
> + * is only a snapshot to a run that is already inside, so the mask and
> + * the wait below are what keeps that run out.
> + */
> + WRITE_ONCE(idev->recovering, true);
> + thc_interrupt_enable(idev->thc, false);
> + synchronize_irq(idev->irq);
> + /* A run that unmasked just before synchronize_irq() returned leaves
> + * the line open: mask it again, the write is idempotent.
> + */
> + thc_interrupt_enable(idev->thc, false);
> +
> + if (thc_rxdma_reset(idev->thc)) {
> + /* Nothing left: keep the port masked until it restarts. */
> + dev_err(idev->dev, "cannot reset the receive engine\n");
> + return;
> + }
[ ... ]
> +irqreturn_t thc_ipts_thread(int irq, void *data)
> +{
> + struct thc_ipts *idev = data;
> + irqreturn_t ret = IRQ_NONE;
> + bool need_recover = false;
> + bool reported = false;
> + int pass;
> +
> + /* Reports are handed to the HID core from here, and a driver callback
> + * that sends a request would wait for a completion this very thread
> + * delivers: it is recorded so the send path can tell.
> + */
> + WRITE_ONCE(idev->irq_thread, current);
> +
> + /* A sharer can queue a second run of this thread with no hardirq of
> + * ours in between: mask again, the write is idempotent.
> + */
> + thc_interrupt_enable(idev->thc, false);
> +
> + /* The port stays masked, so a cause that arrives meanwhile leaves only
> + * its status bit: read until the core reports none.
> + */
> + for (pass = 0; pass < THC_IPTS_IRQ_PASSES; pass++) {
> + int mask;
> +
> + /*
> + * The reset owns the status registers while it runs: a frame
> + * acknowledged here but not read is never announced again.
> + */
> + if (READ_ONCE(idev->recovering)) {
> + /* Nothing acknowledged, but the line is still ours. */
> + ret = IRQ_HANDLED;
> + break;
> + }
[Severity: Medium]
Does returning IRQ_HANDLED here when idev->recovering is true on the first
pass claim every foreign interrupt on the shared INTx line?
While idev->recovering is set (which stays true permanently if
thc_rxdma_reset() fails in thc_ipts_recover() because idev->dma_ready is
left set), every interrupt from another device sharing the line causes
thc_ipts_hardirq() to mask the already-masked port and return
IRQ_WAKE_THREAD. thc_ipts_thread() then sees idev->recovering on pass 0
and returns IRQ_HANDLED without checking any status registers, adding a
thread wakeup and two MMIO writes to every shared interrupt and preventing
note_interrupt() from detecting a stuck screaming interrupt on a peer
device.
[ ... ]
> + /* A reset unmasks when it is done and a teardown masks on its own, so
> + * the line only stays open here while neither runs: a write already
> + * on the wire needs the completion this handler delivers.
> + */
> + if (!READ_ONCE(idev->recovering) && !READ_ONCE(idev->stopping))
> + thc_interrupt_enable(idev->thc, true);
> +
> + return ret;
> +}
[Severity: Medium]
Can checking !READ_ONCE(idev->stopping) before re-enabling the port
interrupt leave the line masked while an in-flight TXDMA transfer is still
waiting for its completion interrupt?
In the next patch in the series ("HID: intel-thc-hid: intel-ipts: exchange
commands with the controller"), thc_ipts_port_stop() sets idev->stopping to
true and then waits on idev->tx_lock for any active thc_ipts_send() ->
thc_dma_write() call to finish before masking the interrupt:
Thread A Thread B IRQ / thread
thc_ipts_send()
mutex_lock(&idev->tx_lock)
thc_dma_write()
write_dma_buffer()
thc_ipts_port_stop()
idev->stopping = true
mutex_lock(&idev->tx_lock)
<shared/RX IRQ>
thc_ipts_hardirq()
thc_interrupt_enable(false)
thc_ipts_thread()
sees idev->stopping
(leaves IRQ masked)
wait_event_interruptible_timeout(
dev->write_complete_wait, ...)
<-- stalls for 1s timeout
Unlike recovery, which splits idev->recover_pending and idev->recovering so
the interrupt stays enabled until thc_ipts_recover() acquires
idev->tx_lock, setting idev->stopping before waiting on idev->tx_lock
causes any intervening run of thc_ipts_thread() to leave the port masked
before the TXDMA completion interrupt arrives.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119091152.470384-1-emfox@debian.org?part=2
next prev parent reply other threads:[~2026-11-19 9:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:11 [PATCH v9 0/5] HID: intel-thc-hid: intel-ipts: support THC IPTS ports Emfox Zhou
2026-11-19 9:11 ` [PATCH v9 1/5] HID: intel-thc-hid: intel-ipts: bring up the port Emfox Zhou
2026-11-19 9:11 ` [PATCH v9 2/5] HID: intel-thc-hid: intel-ipts: receive reports Emfox Zhou
2026-11-19 9:31 ` sashiko-bot [this message]
2026-11-19 9:11 ` [PATCH v9 3/5] HID: intel-thc-hid: intel-ipts: add the HID device Emfox Zhou
2026-11-19 9:11 ` [PATCH v9 4/5] HID: intel-thc-hid: intel-ipts: handle system sleep Emfox Zhou
2026-11-19 9:24 ` sashiko-bot
2026-11-19 9:11 ` [PATCH v9 5/5] HID: intel-thc-hid: intel-ipts: document the IPTS mode Emfox Zhou
2026-11-20 2:47 ` [PATCH v9 0/5] HID: intel-thc-hid: intel-ipts: support THC IPTS ports Xu, Even
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=sashiko-outbox-222839@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=emfox@debian.org \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.