All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Emfox Zhou" <emfox@debian.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v7 2/5] HID: intel-thc-hid: intel-ipts: receive reports
Date: Wed, 18 Nov 2026 06:06:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-220201@kernel.org> (raw)
In-Reply-To: <20261118054004.363766-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: IRQ unmasking races in stop
  and recover
- [Medium] HID: intel-thc-hid: intel-ipts: invalid wait context in
  thc_ipts_hardirq()
--

commit 993aaa08c813c3f151cc4b084284f9a37d80893f
Author: Emfox Zhou <emfox@debian.org>

HID: intel-thc-hid: intel-ipts: receive reports

This commit configures the THC DMA engines for IPTS, requests the port
interrupt, and adds frame reception and error recovery handling.

> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> index 2d14e5278f986..17f6f664e95b5 100644
> --- a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c

[ ... ]

> @@ -129,6 +144,281 @@ static int thc_ipts_touch_set(struct thc_ipts *idev, bool enable)
>  				 &touch);
>  }

[ ... ]

> +static void thc_ipts_dma_stop(struct thc_ipts *idev)
> +{
> +	if (!idev->dma_ready)
> +		return;
> +
> +	WRITE_ONCE(idev->dma_ready, false);
> +	thc_dma_unconfigure(idev->thc);
> +	thc_dma_release(idev->thc);
> +}

[ ... ]

> +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);
> +
> +	/*
> +	 * 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;
> +}

[Severity: Medium]
Does calling thc_interrupt_enable() from thc_ipts_hardirq() trigger a
lockdep invalid wait context warning when the shared legacy INTx line runs
in oneshot mode?

thc_ipts_probe() allocates a legacy PCI_IRQ_INTX vector and requests the
interrupt with IRQF_SHARED | IRQF_COND_ONESHOT.  When a sharer on the 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() then calls regmap_write_bits() on
idev->thc->thc_regmap, which is configured with .fast_io = true and no
.use_raw_spinlock:

drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c:
static const struct regmap_config thc_regmap_cfg = {
	...
	.fast_io = true,
};

Acquiring that non-raw spinlock_t from hardirq context violates
CONFIG_PROVE_RAW_LOCK_NESTING.

[ ... ]

> +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);
> +
> +	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)
> +{

[ ... ]

> +	/* A reset unmasks when it is done. A teardown masks on its own, so the
> +	 * line stays open here: a write already on the wire needs the
> +	 * completion this handler delivers.
> +	 */
> +	if (!READ_ONCE(idev->recovering))
> +		thc_interrupt_enable(idev->thc, true);
> +
> +	WRITE_ONCE(idev->in_thread, false);
> +
> +	return ret;
> +}

[ ... ]

> @@ -229,6 +531,19 @@ int thc_ipts_port_start(struct thc_ipts *idev)
>   */
>  void thc_ipts_port_stop(struct thc_ipts *idev)
>  {
> +	/*
> +	 * Mask the line, then wait for a handler that may be holding a
> +	 * frame for the HID device which is about to go away.
> +	 */
> +	WRITE_ONCE(idev->stopping, true);
> +	thc_interrupt_enable(idev->thc, false);
> +	synchronize_irq(idev->irq);
> +	cancel_work_sync(&idev->recover_work);
> +
> +	/* A handler that read ->stopping early may have unmasked. */
> +	thc_interrupt_enable(idev->thc, false);
> +
> +	/* Stop the controller before the buffers it writes into go away. */
>  	if (idev->running)
>  		thc_ipts_touch_set(idev, false);
>  
> @@ -237,4 +552,6 @@ void thc_ipts_port_stop(struct thc_ipts *idev)
>  	regmap_write_bits(idev->thc->thc_regmap, THC_M_PRT_CONTROL_OFFSET,
>  			  THC_M_PRT_CONTROL_DEVRST, 0);
>  	thc_ipts_quiesce(idev, true);
> +
> +	thc_ipts_dma_stop(idev);
>  }

[Severity: Medium]
Can a shared interrupt or an in-flight thc_ipts_thread() re-enable the port
interrupt and race with thc_ipts_port_stop() and thc_ipts_recover()?

Because the IRQ is registered with IRQF_SHARED, any interrupt from another
device on the line causes thc_ipts_hardirq() to return IRQ_WAKE_THREAD as
long as idev->dma_ready is true.  In thc_ipts_port_stop(), idev->dma_ready
remains true until thc_ipts_dma_stop(), and thc_ipts_thread() does not
check idev->stopping before re-enabling interrupts:

CPU0                                  CPU1
thc_ipts_port_stop()
  WRITE_ONCE(idev->stopping, true)
  synchronize_irq(idev->irq)
  thc_interrupt_enable(..., false)
                                      <shared IRQ>
                                      thc_ipts_hardirq()
                                        if (!READ_ONCE(idev->dma_ready))
                                        return IRQ_WAKE_THREAD
  thc_ipts_touch_set(idev, false)
  ...
  thc_ipts_dma_stop()
    WRITE_ONCE(idev->dma_ready, false)
    thc_dma_unconfigure(idev->thc)
    thc_dma_release(idev->thc)
                                      thc_ipts_thread()
                                        thc_interrupt_handler(idev->thc)
                                        if (!READ_ONCE(idev->recovering))
                                          thc_interrupt_enable(..., true)
                                            <-- runs during DMA teardown
                                                and leaves IRQ unmasked

Even with commit "HID: intel-thc-hid: intel-ipts: add the HID device"
adding synchronize_irq() and thc_interrupt_enable(idev->thc, false) after
thc_ipts_dma_stop(), thc_dma_unconfigure() and thc_dma_release() still run
before synchronize_irq() waits for a woken thc_ipts_thread(), and the port
interrupt is briefly unmasked during shutdown.

A similar race exists in thc_ipts_recover(): if thc_ipts_thread() checks
!READ_ONCE(idev->recovering) just before thc_ipts_recover() sets
idev->recovering and masks the port, the thread can call
thc_interrupt_enable(idev->thc, true) before synchronize_irq() returns.
Because thc_ipts_recover() does not mask again after synchronize_irq(),
thc_rxdma_reset() runs with the port interrupt unmasked (and leaves it
unmasked if thc_rxdma_reset() fails).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118054004.363766-1-emfox@debian.org?part=2

  reply	other threads:[~2026-11-18  6:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  5:39 [PATCH v7 0/5] HID: intel-thc-hid: intel-ipts: support THC IPTS ports Emfox Zhou
2026-11-18  5:40 ` [PATCH v7 1/5] HID: intel-thc-hid: intel-ipts: bring up the port Emfox Zhou
2026-11-18  5:40 ` [PATCH v7 2/5] HID: intel-thc-hid: intel-ipts: receive reports Emfox Zhou
2026-11-18  6:06   ` sashiko-bot [this message]
2026-11-18  5:40 ` [PATCH v7 3/5] HID: intel-thc-hid: intel-ipts: add the HID device Emfox Zhou
2026-11-18  6:00   ` sashiko-bot
2026-11-18  5:40 ` [PATCH v7 4/5] HID: intel-thc-hid: intel-ipts: handle system sleep Emfox Zhou
2026-11-18  5:40 ` [PATCH v7 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-220201@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.