* [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks
@ 2026-11-30 16:48 Ryan Brue
2026-11-30 16:55 ` sashiko-bot
2026-11-30 18:18 ` Alan Stern
0 siblings, 2 replies; 3+ messages in thread
From: Ryan Brue @ 2026-11-30 16:48 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, this is a resend of the patch I posted on 2026-11-22 [1], unchanged
apart from the base, which is now v7.4-rc5.
It fixes 625dd9076e35 ("usb: mtu3: don't run gadget completion callbacks
with interrupts disabled"), which is in v7.4-rc5 and tagged for stable.
That commit 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 [2] got no reply, so this is v2's change as a fix on top of
625dd9076e35; the resulting mtu3_irq() is the same as v2's.
Could it go in for 7.4, so that stable picks up both together?
My bad for the original error in v1.
[1] https://lore.kernel.org/all/20261122-usb-mtu3-callbacks-irqs-off-v1-1-27733bb678c4@gmail.com/
[2] 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: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261122-usb-mtu3-callbacks-irqs-off-71bfbb2ed4fc
Best regards,
--
Ryan Brue <ryanbrue.dev@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks
2026-11-30 16:48 [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks Ryan Brue
@ 2026-11-30 16:55 ` sashiko-bot
2026-11-30 18:18 ` Alan Stern
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-30 16:55 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/20261130-usb-mtu3-callbacks-irqs-off-v1-1-b3180defb60c@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks
2026-11-30 16:48 [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks Ryan Brue
2026-11-30 16:55 ` sashiko-bot
@ 2026-11-30 18:18 ` Alan Stern
1 sibling, 0 replies; 3+ messages in thread
From: Alan Stern @ 2026-11-30 18:18 UTC (permalink / raw)
To: Ryan Brue
Cc: Chunfeng Yun, Greg Kroah-Hartman, linux-usb, linux-arm-kernel,
linux-mediatek, linux-kernel, stable
On Mon, Nov 30, 2026 at 10:48:56AM -0600, Ryan Brue wrote:
> 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.
This seems like a strange approach.
Yes, interrupts certainly should be disabled when the request's
completion routine is called. But why explicitly disable bottom halves?
And besides, doesn't spin_lock_irqsave() disable bottom halves already?
Also, why should a networking gadget depend on some particular BH
setting when the completion routine runs? Different UDC drivers will
behave in different ways, and the gadget driver has to work with all of
them. The only real guarantee is the one stated in the API, namely,
that interrupts will be disabled. If the gadget wants more, it has to
take the additional actions itself. The UDC driver isn't responsible.
Alan Stern
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-30 18:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 16:48 [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks Ryan Brue
2026-11-30 16:55 ` sashiko-bot
2026-11-30 18:18 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox