* [PATCH] usb: mtu3: keep interrupts disabled in gadget completion callbacks
@ 2026-11-23 2:28 Ryan Brue
2026-11-23 2:30 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Ryan Brue @ 2026-11-23 2:28 UTC (permalink / raw)
To: Chunfeng Yun, Greg Kroah-Hartman, Ryan Brue
Cc: linux-usb, linux-arm-kernel, linux-mediatek, linux-kernel, stable
Commit 625dd9076e35 ("usb: mtu3: don't run gadget completion callbacks
with interrupts disabled") made the threaded mtu3_irq() take mtu->lock
with spin_lock_bh(). mtu3_req_complete() drops the lock with a plain
spin_unlock() around usb_gadget_giveback_request(), so the gadget
function's completion callback now runs with interrupts enabled.
That breaks the gadget API, struct usb_request's @complete "will always
be called with interrupts disabled". u_serial's console relies on it:
gs_console_complete_out() takes cons->lock with spin_lock(), and
gs_console_write() takes the same lock with spin_lock_irqsave() from
printk, which can then interrupt the callback on the same CPU while it
holds the lock.
Keep spin_lock_irqsave() in mtu3_irq() and disable bottom halves around
it instead, as dwc3 does in commit 84918a89d6ef ("usb: dwc3: gadget: Let
the interrupt handler disable bottom halves."). netif_rx() then finds
softirqs disabled and leaves them alone, the completion callbacks run
with interrupts disabled again, and the softirq netif_rx() raises runs
at local_bh_enable(), once the lock is dropped and interrupts are on.
Tested on an MT8173 tablet with PROVE_LOCKING, copying a 21 MB file over
USB ethernet three times per arm: with spin_lock_bh(), all 8,333 completion
callbacks ran with interrupts enabled; with this change, none of about
16,000 did, with no lockdep report and every copy intact.
Fixes: 625dd9076e35 ("usb: mtu3: don't run gadget completion callbacks with interrupts disabled")
Cc: stable@kernel.org
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
---
Greg, commit 625dd9076e35 in usb-linus is v1 of my mtu3 callbacks fix,
the one I asked you on 2026-11-03 not to apply. With spin_lock_bh() the
gadget completion callbacks run with interrupts enabled, which the
gadget API rules out. v2 [1] got no reply, so here is v2's change as a
fix on top of 625dd9076e35; the resulting mtu3_irq() is the same as v2's.
My bad for the original error in v1.
[1] https://lore.kernel.org/all/20261104-usb-mtu3-gadget-completion-callback-fix-v2-1-2769533a39cb@gmail.com/
---
drivers/usb/mtu3/mtu3_core.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c
index fc274646fcde..f6677f58dd1f 100644
--- a/drivers/usb/mtu3/mtu3_core.c
+++ b/drivers/usb/mtu3/mtu3_core.c
@@ -790,9 +790,11 @@ static irqreturn_t mtu3_u2_common_isr(struct mtu3 *mtu)
static irqreturn_t mtu3_irq(int irq, void *data)
{
struct mtu3 *mtu = (struct mtu3 *)data;
+ unsigned long flags;
u32 level1;
- spin_lock_bh(&mtu->lock);
+ local_bh_disable();
+ spin_lock_irqsave(&mtu->lock, flags);
/* U3D_LV1ISR is RU */
level1 = mtu3_readl(mtu->mac_base, U3D_LV1ISR);
@@ -813,7 +815,8 @@ static irqreturn_t mtu3_irq(int irq, void *data)
if (level1 & QMU_INTR)
mtu3_qmu_isr(mtu);
- spin_unlock_bh(&mtu->lock);
+ spin_unlock_irqrestore(&mtu->lock, flags);
+ local_bh_enable();
return IRQ_HANDLED;
}
---
base-commit: b0baaf6cbb16bc773d0c76916aac17c44a6cd557
change-id: 20261122-usb-mtu3-callbacks-irqs-off-71bfbb2ed4fc
Best regards,
--
Ryan Brue <ryanbrue.dev@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] usb: mtu3: keep interrupts disabled in gadget completion callbacks
2026-11-23 2:28 [PATCH] usb: mtu3: keep interrupts disabled in gadget completion callbacks Ryan Brue
@ 2026-11-23 2:30 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-23 2:30 UTC (permalink / raw)
To: Ryan Brue; +Cc: linux-usb
> Commit 625dd9076e35 ("usb: mtu3: don't run gadget completion callbacks
> with interrupts disabled") made the threaded mtu3_irq() take mtu->lock
> with spin_lock_bh(). mtu3_req_complete() drops the lock with a plain
> spin_unlock() around usb_gadget_giveback_request(), so the gadget
> function's completion callback now runs with interrupts enabled.
>
> That breaks the gadget API, struct usb_request's @complete "will always
> be called with interrupts disabled". u_serial's console relies on it:
> gs_console_complete_out() takes cons->lock with spin_lock(), and
> gs_console_write() takes the same lock with spin_lock_irqsave() from
> printk, which can then interrupt the callback on the same CPU while it
> holds the lock.
>
> Keep spin_lock_irqsave() in mtu3_irq() and disable bottom halves around
> it instead, as dwc3 does in commit 84918a89d6ef ("usb: dwc3: gadget: Let
> the interrupt handler disable bottom halves."). netif_rx() then finds
> softirqs disabled and leaves them alone, the completion callbacks run
> with interrupts disabled again, and the softirq netif_rx() raises runs
> at local_bh_enable(), once the lock is dropped and interrupts are on.
>
> Tested on an MT8173 tablet with PROVE_LOCKING, copying a 21 MB file over
> USB ethernet three times per arm: with spin_lock_bh(), all 8,333 completion
> callbacks ran with interrupts enabled; with this change, none of about
> 16,000 did, with no lockdep report and every copy intact.
>
> Fixes: 625dd9076e35 ("usb: mtu3: don't run gadget completion callbacks with interrupts disabled")
> Cc: stable@kernel.org
> Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122-usb-mtu3-callbacks-irqs-off-v1-1-27733bb678c4@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 2:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 2:28 [PATCH] usb: mtu3: keep interrupts disabled in gadget completion callbacks Ryan Brue
2026-11-23 2:30 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox