Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796264766; b=bsSUxHQbVUcCgs6S6+ndDRO7Q5Fv9RobYCbMGiJx65aHSNxLkJZUYrxHufsQv1KdjVm7 DG/cUEYw2PZkTyVV/czcSoDCvpnUBluprHGWAu3SLn7K4u9eepo8umn/I8eb69XsZ6Yes Z1jl7Z6to8oP8phori56SBkVSg5TMaAERfnC+zQmokm7AMediC63EUn5sIhPopysmey+7 9kZJv/TOTdDHzDNsddWb7ad+P0wPEZS/3ChpJJJpoyP91ySi9RD/rTXHntLgez3FasG3P QwHa1464TK1Nq7tyi3DSMyZuQQgWIPVVRHgal/098b27FemIX5pOKuth5Ujngz0Wvfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796264766; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=b4v1BrlVeDA9F1yKmu0YcJSmo3/4UEiYEh4yFZfIK8c=; b=5o0enUgXEKe1x7w68f+lkw44pfVd6aSzSTaX0Fe2SgCl9pttqvcWf8smhXbOLeWi2v0r BdPgYpbfWWpx5VWz4huNvgRJqxtFnLEzZEI/yKeXuHqUBn1lLJ67pcWof2+OnXm7x6DTi 6etY+hAV5QnEXNdSi/podvruhSaoP16eZsFAG1Dt3g4+7s9VGY3Gl5H3K0ilJ1zYLXF96 L3ty0cmDOQA4ODW15tCNYiV1xeVo4xl3/lTfgYtsb2uLGOsRUe19U2y79jhI9cj0+85YD m1hSNeInKEjACMYgsNZjlUflQ+cUSRS54zmKXTlYu5jizp/V3vbYDcXzUFQQaqApf3Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QSXqflLp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E42EE606A322 for ; Thu, 3 Dec 2026 02:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QSXqflLp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C2701F00893; Thu, 3 Dec 2026 02:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796264765; bh=b4v1BrlVeDA9F1yKmu0YcJSmo3/4UEiYEh4yFZfIK8c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QSXqflLpcqy5f9foizC6tlffEj9zdWnx4LvddqOH8sAaxx4+cgO67oyqRWxt0xLRF Fg1UwR5HeIObzMntFB5Hre6re/ZHZT5x5Xn4CGNgp8rXcNWWrae0sq1fzMURaRTDBq malPrAAyjVqcZMB2fMSv3+LyX2B40h+bv9DJtsIMMykO9fuCc0LMVEAGj6Q9DTpySr lPWYR3o0YKKnFE2cbw5RGT3LxeETWTyVG74jE8sQLNvIqddy8cfHzKwmV/rG+uWU/v 51k3Dr2fsctWlnxO9IxVcebl+4qRJHTT9KMTlwYhTznDC0SQo5w38bsu7aTtLD6xzR gwGr/5AXXipdw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v11 3/6] HID: intel-thc-hid: intel-ipts: receive reports Reply-To: sashiko-reviews@lists.linux.dev To: "Emfox Zhou" Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261203020433.2631656-3-emfox@debian.org> References: <20261203020433.2631656-3-emfox@debian.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 02:26:04 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] HID: intel-thc-hid: intel-ipts: IRQ storm and livelock in error recovery - [High] HID: intel-thc-hid: intel-ipts: race with IRQ and recovery in thc_ipts_port_stop() - [Medium] HID: intel-thc-hid: intel-ipts: invalid wait context in thc_ipts_hardirq() -- commit 660d26f61a97da206cffff0edd97b71c4183c0c7 Author: Emfox Zhou HID: intel-thc-hid: intel-ipts: receive reports This commit adds DMA configuration, threaded interrupt handling, frame transmission and reception, and error recovery work to the Intel IPTS transport driver. > diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts-protocol.c b/drive= rs/hid/intel-thc-hid/intel-ipts/ipts-protocol.c > index 5d3d8d4005b8f..9ef4b3cfa733c 100644 > --- a/drivers/hid/intel-thc-hid/intel-ipts/ipts-protocol.c > +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts-protocol.c [ ... ] > +irqreturn_t thc_ipts_hardirq(int irq, void *data) > +{ > + struct thc_ipts *idev =3D data; > + > + /* > + * Nothing of ours is pending: the cause belongs to a sharer. A reset > + * in flight owns the status registers and acknowledges nothing. > + */ > + if (READ_ONCE(idev->state) < THC_IPTS_DMA || > + READ_ONCE(idev->recovering)) > + return IRQ_NONE; > + > + /* Level triggered and shared: mask first, or it stays asserted. */\ > + thc_interrupt_enable(idev->thc, false); > + > + /* > + * A teardown still needs this thread: it delivers the completion a > + * pending write holds the bus lock for. > + */ > + return IRQ_WAKE_THREAD; > +} [Severity: Medium] Can calling thc_interrupt_enable() from thc_ipts_hardirq() trigger an invalid wait context warning under CONFIG_PROVE_RAW_LOCK_NESTING or sleep in hardirq context on PREEMPT_RT? thc_ipts_probe() requests a legacy PCI_IRQ_INTX vector with IRQF_SHARED | IRQF_COND_ONESHOT. When the line is shared with another handler that uses IRQF_ONESHOT, __setup_irq() propagates IRQF_ONESHOT to this action, so __handle_irq_event_percpu() does not mark the hardirq as threaded for lockdep and leaves the wait context at LD_WAIT_SPIN. thc_interrupt_enable() then calls regmap_write_bits() on dev->thc_regmap, which is configured without .use_raw_spinlock =3D true and therefore takes a non-raw spinlock_t: drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c: static const struct regmap_config thc_regmap_cfg =3D { ... .cache_type =3D REGCACHE_NONE, .fast_io =3D true, }; [ ... ] > +void thc_ipts_recover(struct work_struct *work) > +{ > + struct thc_ipts *idev =3D container_of(work, struct thc_ipts, > + recover_work); > + > + /* > + * A write on the wire needs the interrupt this reset is about to mask: > + * let it finish first. > + */ > + mutex_lock(&idev->tx_lock); > + WRITE_ONCE(idev->recovering, true); > + mutex_unlock(&idev->tx_lock); > + > + /* > + * Mask, then wait out a run already inside: the status registers belong > + * to the reset. > + */ > + thc_interrupt_enable(idev->thc, false); > + synchronize_irq(idev->irq); > + /* > + * A run may have unmasked on its way out: mask again. > + */ > + thc_interrupt_enable(idev->thc, false); > + > + if (thc_rxdma_reset(idev->thc)) { > + /* > + * Nothing left to reset: stay masked and fail with -ENODEV. > + */ > + dev_err(idev->dev, "cannot reset the receive engine\n"); > + WRITE_ONCE(idev->state, THC_IPTS_CONFIG); > + WRITE_ONCE(idev->recover_seq, READ_ONCE(idev->recover_seq) + 1); > + WRITE_ONCE(idev->recover_pending, false); > + WRITE_ONCE(idev->recovering, false); > + wake_up(&idev->wq); > + return; > + } > + > + /* > + * Clear the queued flag before the running one. > + */ > + WRITE_ONCE(idev->recover_seq, READ_ONCE(idev->recover_seq) + 1); > + WRITE_ONCE(idev->recover_pending, false); > + WRITE_ONCE(idev->recovering, false); > + > + /* A request waiting out the reset is looking at that flag. */ > + wake_up(&idev->wq); > + > + if (!READ_ONCE(idev->stopping)) > + thc_interrupt_enable(idev->thc, true); > +} > + > +irqreturn_t thc_ipts_thread(int irq, void *data) > +{ > + struct thc_ipts *idev =3D data; > + irqreturn_t ret =3D IRQ_NONE; > + bool need_recover =3D false; > + bool reported =3D false; > + int pass; > + > + /* > + * Remember this thread: a request from it would wait for a completion > + * only it delivers. > + */ > + WRITE_ONCE(idev->irq_thread, current); > + > + /* > + * A sharer can queue a second run: mask again. > + */ > + thc_interrupt_enable(idev->thc, false); > + > + /* > + * The port stays masked while reading: causes only leave status bits. > + */ > + for (pass =3D 0; pass < THC_IPTS_IRQ_PASSES; pass++) { > + int mask; > + > + /* > + * A reset owns the status registers: acknowledge nothing here. > + */ > + if (READ_ONCE(idev->recovering)) > + break; > + > + mask =3D thc_interrupt_handler(idev->thc); > + > + if (mask =3D=3D BIT(THC_UNKNOWN_INT)) > + break; > + > + ret =3D IRQ_HANDLED; > + if (mask & (BIT(THC_FATAL_ERR_INT) | BIT(THC_TXN_ERR_INT))) { > + /* > + * An overrun repeats until the reset: report the first one. > + */ > + if (!reported && !READ_ONCE(idev->recover_pending)) { > + dev_err(idev->dev, > + "transfer error, resetting the engine\n"); > + reported =3D true; > + } > + /* The teardown has its own reset to wait for. */\ > + if (!READ_ONCE(idev->stopping)) > + need_recover =3D true; > + /* > + * The core stops at the first cause; a completion behind it would ti= me > + * out. > + */ > + continue; > + } > + > + /* > + * A reset is queued or running: read the status, not the ring. > + */ > + if (need_recover || READ_ONCE(idev->recover_pending) || > + READ_ONCE(idev->recovering) || > + READ_ONCE(idev->stopping)) > + continue; > + > + if (mask & BIT(THC_RXDMA2_INT) && thc_ipts_read_frames(idev)) > + need_recover =3D true; > + } > + > + /* > + * Only queue the reset: a frame read now would corrupt the ring. > + */ > + if (need_recover) > + thc_ipts_request_recover(idev); > + > + /* > + * Keep the line open unless a reset is running: a write on the wire ne= eds > + * this handler to deliver its completion. > + */ > + if (!READ_ONCE(idev->recovering)) > + thc_interrupt_enable(idev->thc, true); > + > + return ret; > +} [Severity: High] Can error recovery trigger a level-triggered hardirq storm or starve recover_work behind the threaded IRQ handler? kworker / irq/thc_ipts thc_ipts_thread() need_recover =3D true thc_ipts_request_recover() recover_pending =3D true schedule_work(&recover_work) if (!idev->recovering) thc_interrupt_enable(..., true) thc_ipts_recover() WRITE_ONCE(idev->recovering, true) (overrun still asserted) thc_ipts_hardirq() if (idev->recovering) return IRQ_NONE; (line stays asserted) thc_ipts_hardirq() return IRQ_NONE; <-- IRQ storm thc_interrupt_enable(..., false) First, thc_ipts_thread() re-enables hardware interrupts on exit whenever idev->recovering is still false, even after queuing recover_work with need_recover / recover_pending set. Because an RxDMA overrun or stall persists in hardware until thc_rxdma_reset() runs, unmasking the port immediately re-triggers the interrupt and wakes the SCHED_FIFO IRQ thread again (or spins while thc_ipts_recover() waits on idev->tx_lock), preempting and starving the SCHED_NORMAL system_percpu_wq worker on the same CPU. Also, continuing across all 10 passes of THC_IPTS_IRQ_PASSES on a repeating overrun does not reach the TxDMA completion check in thc_interrupt_handler(), because thc_interrupt_handler() returns early on THC_TXN_ERR_INT and logs an unratelimited dev_err() on each pass. Second, thc_ipts_recover() sets idev->recovering =3D true while hardware interrupts are still enabled in THC_M_PRT_INT_EN_OFFSET (or while a concurrent thc_ipts_thread() is about to call thc_interrupt_enable(thc, true)). If the level-triggered INTx line asserts before thc_interrupt_enable(idev->thc, false) runs, thc_ipts_hardirq() sees idev->recovering =3D=3D true and returns IRQ_NONE without masking the port, re-entering thc_ipts_hardirq() until the spurious IRQ detector disables the shared interrupt line. [ ... ] > @@ -202,11 +638,38 @@ int thc_ipts_port_start(struct thc_ipts *idev) > */ > void thc_ipts_port_stop(struct thc_ipts *idev) > { > + /* > + * Refuse requests, then wait for one inside thc_dma_write(): its > + * completion comes through this handler. > + */ > + WRITE_ONCE(idev->stopping, true); > + wake_up(&idev->wq); > + mutex_lock(&idev->tx_lock); > + mutex_unlock(&idev->tx_lock); > + > + thc_interrupt_enable(idev->thc, false); > + synchronize_irq(idev->irq); > + cancel_work_sync(&idev->recover_work); > + > + /* A run that was already in flight may have unmasked on its way out. *= /\ > + thc_interrupt_enable(idev->thc, false); > + > + /* Stop the controller and keep it in reset until the next start. */\ > if (READ_ONCE(idev->state) >=3D THC_IPTS_CONFIG) > thc_ipts_touch_set(idev, false); > =20 > - /* Keep the touch IC in reset until the next start. */ > thc_port_reset(idev->thc, true); > - thc_interrupt_quiesce(idev->thc, true); > + > + /* > + * The tables are not devm-managed; release them even if the engine did > + * not stop. > + */ > + if (thc_interrupt_quiesce(idev->thc, true)) > + dev_warn(idev->dev, "engine did not stop, releasing anyway\n"); > + thc_ipts_dma_stop(idev); > WRITE_ONCE(idev->state, THC_IPTS_DOWN); > + > + /* Wait for a handler that may still look at the ring. */ > + synchronize_irq(idev->irq); > + thc_interrupt_enable(idev->thc, false); > } [Severity: High] Can thc_ipts_thread() and thc_ipts_recover() race with teardown in thc_ipts_port_stop() after idev->tx_lock has been drained? CPU0 CPU1 (shared INTx / IRQ thread) thc_ipts_port_stop() WRITE_ONCE(idev->stopping, true) mutex_lock(&idev->tx_lock) mutex_unlock(&idev->tx_lock) thc_interrupt_enable(..., false) synchronize_irq(idev->irq) cancel_work_sync(&recover_work) thc_interrupt_enable(..., false) (sharer on INTx line) thc_ipts_hardirq() /* state =3D=3D THC_IPTS_DMA */ return IRQ_WAKE_THREAD; thc_ipts_touch_set(..., false) thc_port_reset(..., true) thc_ipts_thread() thc_interrupt_handler(idev->thc) if (!idev->recovering) thc_interrupt_enable(..., true) thc_ipts_dma_stop(idev) <-- concurrent MMIO & IRQ re-enabled Once mutex_unlock(&idev->tx_lock) completes, no write is in flight, yet idev->state remains THC_IPTS_DMA until thc_ipts_dma_stop() and idev->recovering is false. Because the INTx line is requested with IRQF_SHARED, any interrupt from a device sharing the line causes thc_ipts_hardirq() to return IRQ_WAKE_THREAD. thc_ipts_thread() also unmasks hardware interrupts on exit when idev->recovering is false (even when idev->stopping is true), so a run finishing during the first synchronize_irq() can re-enable interrupts before the second thc_interrupt_enable(idev->thc, false), which has no synchronize_irq() after it. In addition, if recover_work is already running when cancel_work_sync() is called, thc_ipts_recover() does not check idev->stopping before calling thc_rxdma_reset(idev->thc), which resets and restarts RxDMA2 and unquiesces device interrupts in the middle of teardown. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796215044.gi= t.emfox@debian.org?part=3D3