From: sashiko-bot@kernel.org
To: "Emfox Zhou" <emfox@debian.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v6 2/5] HID: intel-thc-hid: intel-ipts: receive reports
Date: Tue, 17 Nov 2026 08:01:01 +0000 [thread overview]
Message-ID: <sashiko-outbox-218393@kernel.org> (raw)
In-Reply-To: <20261117073554.11557-3-emfox@debian.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] HID: intel-thc-hid: intel-ipts: race between
thc_ipts_thread() and recovery
- [Medium] HID: intel-thc-hid: intel-ipts: invalid wait context in
thc_ipts_hardirq()
--
commit e88c3279dbafcea638f20c7e327484d006236ae1
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 legacy INTx preference and threaded recovery, and
decodes incoming frame headers.
> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> index 696a33d17f703..2265d07355221 100644
> --- a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
[ ... ]
> +irqreturn_t thc_ipts_hardirq(int irq, void *data)
> +{
> + struct thc_ipts *idev = data;
> +
> + /* Level triggered and shared: mask first, or it stays asserted. */
> + thc_interrupt_enable(idev->thc, false);
[Severity: Medium]
Does calling thc_interrupt_enable() from thc_ipts_hardirq() violate the
hardirq wait context when the shared INTx line uses oneshot?
thc_ipts_probe() requests a legacy PCI_IRQ_INTX vector with
IRQF_SHARED | IRQF_COND_ONESHOT. When another device on the shared line
uses IRQF_ONESHOT, __setup_irq() sets IRQF_ONESHOT on this action as well,
and __handle_irq_event_percpu() runs thc_ipts_hardirq() in LD_WAIT_SPIN
context without calling lockdep_hardirq_threaded(). thc_interrupt_enable()
calls regmap_write_bits() on dev->thc_regmap, whose regmap_config sets
.fast_io = true 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,
};
Because regmap protects this map with a non-raw spinlock_t, taking it in
thc_ipts_hardirq() triggers a lockdep invalid wait context warning under
CONFIG_PROVE_RAW_LOCK_NESTING=y and sleeps in hardirq context on PREEMPT_RT.
> +
> + /* Nothing of ours is pending: the cause belongs to a sharer. */
> + if (!READ_ONCE(idev->dma_ready))
> + return IRQ_NONE;
> +
> + /*
> + * 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;
> +}
[ ... ]
> +static void thc_ipts_request_recover(struct thc_ipts *idev)
> +{
> + if (READ_ONCE(idev->recovering))
> + return;
> +
> + WRITE_ONCE(idev->recovering, true);
> + thc_interrupt_enable(idev->thc, false);
> + schedule_work(&idev->recover_work);
> +}
> +
> +/*
> + * From a work item: the reset waits for the bus lock a pending write holds
> + * until the threaded handler delivers its completion.
> + */
> +void thc_ipts_recover(struct work_struct *work)
> +{
> + struct thc_ipts *idev = container_of(work, struct thc_ipts,
> + recover_work);
> +
> + /* A handler may have unmasked after the error; keep it masked. */
> + 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;
> + }
> +
> + /* The reset drops whatever the engines had queued. */
> + WRITE_ONCE(idev->recover_seq, READ_ONCE(idev->recover_seq) + 1);
> + WRITE_ONCE(idev->recovering, false);
> + if (!READ_ONCE(idev->stopping))
> + thc_interrupt_enable(idev->thc, true);
> +}
> +
> +irqreturn_t thc_ipts_thread(int irq, void *data)
> +{
> + struct thc_ipts *idev = data;
> + irqreturn_t ret = IRQ_NONE;
> + bool need_recover = false;
> + int pass;
> +
> + /* A sharer can queue a second run of this thread with no hardirq of
> + * ours in between: mask again, the write is idempotent. The port then
> + * stays masked, so a cause that arrives meanwhile leaves only its
> + * status bit.
> + */
> + thc_interrupt_enable(idev->thc, false);
> +
> + for (pass = 0; pass < THC_IPTS_IRQ_PASSES; pass++) {
> + int mask = thc_interrupt_handler(idev->thc);
> +
> + if (mask == BIT(THC_UNKNOWN_INT))
> + break;
> +
> + ret = IRQ_HANDLED;
> + if (mask & (BIT(THC_FATAL_ERR_INT) | BIT(THC_TXN_ERR_INT))) {
> + dev_err(idev->dev,
> + "transfer error, resetting the engine\n");
> + /* The teardown has its own reset to wait for. */
> + if (!READ_ONCE(idev->stopping))
> + need_recover = true;
> + /* The core stops at the first cause: a Tx completion
> + * behind the error would time out under the bus lock.
> + */
> + continue;
> + }
> +
> + /* A reset is in flight or the port is going away: the ring is
> + * not ours to read, only its status was.
> + */
> + if (need_recover || READ_ONCE(idev->recovering) ||
> + READ_ONCE(idev->stopping))
> + continue;
> +
> + if (mask & BIT(THC_RXDMA2_INT) && thc_ipts_read_frames(idev))
> + need_recover = true;
> + }
> +
> + /* The work item resets the engine and unmasks again; a frame read
> + * meanwhile would corrupt the ring.
> + */
> + if (need_recover) {
> + thc_ipts_request_recover(idev);
> + return IRQ_HANDLED;
> + }
> +
> + if (!READ_ONCE(idev->stopping) && !READ_ONCE(idev->recovering))
> + thc_interrupt_enable(idev->thc, true);
> +
> + return ret;
> +}
[Severity: Medium]
Can a shared interrupt waking thc_ipts_thread() during thc_ipts_recover()
drop post-reset frames or recovery requests?
thc_ipts_hardirq() returns IRQ_WAKE_THREAD whenever idev->dma_ready is true,
so a shared interrupt can run thc_ipts_thread() concurrently with
thc_ipts_recover(). Inside thc_rxdma_reset(), thc_dma_configure() restarts
THC_RXDMA2 and thc_interrupt_quiesce(dev, false) re-enables device interrupts
before thc_ipts_recover() clears idev->recovering:
CPU0 (kworker) CPU1 (irq thread)
thc_ipts_recover()
thc_rxdma_reset()
thc_dma_configure()
thc_interrupt_quiesce(..., false)
<new frame or error arrives>
thc_ipts_thread()
thc_interrupt_handler()
/* clears EOF or error status */
if (READ_ONCE(idev->recovering))
continue; <-- skips frame read
thc_ipts_request_recover()
if (READ_ONCE(idev->recovering))
return; <-- drops recovery
WRITE_ONCE(idev->recovering, false)
thc_interrupt_enable(..., true)
If a frame arrives right after thc_rxdma_reset() restarts the engine,
thc_interrupt_handler() clears THC_M_PRT_READ_DMA_INT_STS_EOF_INT_STS in
hardware, but thc_ipts_thread() still sees idev->recovering == true and skips
thc_ipts_read_frames(), leaving the frame unread in the ring. If a transfer
error occurs in that same window, thc_interrupt_handler() clears the error
status bit and thc_ipts_request_recover() returns early because
idev->recovering is still true, leaving the engine stalled once
thc_ipts_recover() finishes.
Similarly, if thc_ipts_thread() drains a pre-reset error status bit during
thc_rxdma_reset() and reaches thc_ipts_request_recover() just after
thc_ipts_recover() clears idev->recovering, it queues a second reset on the
freshly reset engine, and the trailing thc_interrupt_enable(idev->thc, true)
in thc_ipts_recover() (or in thc_ipts_port_start() after thc_ipts_dma_start()
sets idev->dma_ready) can unmask the port while thc_ipts_thread() or recovery
expects it to stay masked.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117073554.11557-1-emfox@debian.org?part=2
next prev parent reply other threads:[~2026-11-17 8:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 7:35 [PATCH v6 0/5] HID: intel-thc-hid: intel-ipts: support THC IPTS ports Emfox Zhou
2026-11-17 7:35 ` [PATCH v6 1/5] HID: intel-thc-hid: intel-ipts: bring up the port Emfox Zhou
2026-11-17 7:35 ` [PATCH v6 2/5] HID: intel-thc-hid: intel-ipts: receive reports Emfox Zhou
2026-11-17 8:01 ` sashiko-bot [this message]
2026-11-17 7:35 ` [PATCH v6 3/5] HID: intel-thc-hid: intel-ipts: register the HID device Emfox Zhou
2026-11-17 7:55 ` sashiko-bot
2026-11-17 7:35 ` [PATCH v6 4/5] HID: intel-thc-hid: intel-ipts: handle system sleep Emfox Zhou
2026-11-17 8:06 ` sashiko-bot
2026-11-17 7:35 ` [PATCH v6 5/5] HID: intel-thc-hid: intel-ipts: document the IPTS mode Emfox Zhou
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-218393@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox