Re: [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks
From: Ryan Brue
Date: Tue Dec 01 2026 - 23:44:39 EST
Hi Alan, thanks for the look.
On 11/30/26 12:18 PM, Alan Stern wrote:
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?
Not in the sense that matters here. spin_lock_irqsave() turns interrupts off, but it leaves softirq_count() at zero, and mtu3_irq() is a threaded handler (no primary handler) since 13118959cb1a. So the completion runs in task context with interrupts off and neither hardirq_count() nor softirq_count() set. netif_rx() checks exactly those two counts, and when both are zero it does its own local_bh_disable()/local_bh_enable(). local_bh_enable() with interrupts disabled is the WARN that 625dd9076e35 intended to fix:
WARNING: kernel/softirq.c:430 at __local_bh_enable_ip+0x17c/0x188
netif_rx
rx_complete [u_ether]
usb_gadget_giveback_request
mtu3_req_complete
...
mtu3_irq
irq_thread_fn
Disabling bottom halves explicitly, outside the irqsave, means netif_rx() sees softirq_count() set and leaves BH alone. The NET_RX softirq it raises then runs at our local_bh_enable(), after interrupts are back on.
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
I agree that the API only promises interrupts disabled, but I don't think u_ether can take those actions itself. Called with interrupts off from task context, it can't call netif_rx(), and it can't wrap the call in its own local_bh_disable()/local_bh_enable() either, because that hits the same assertion. It would have to defer the receive path to a work item or similar.
The callbacks used to run in hardirq context, where all of this is fine. They stopped doing so when mtu3 moved to a threaded handler. For force-threaded handlers the IRQ core already brackets the handler with local_bh_disable()/local_bh_enable() (irq_forced_thread_fn()) for this reason. mtu3 threads its handler voluntarily, so it doesn't get that. dwc3 had the same problem and fixed it the same way in the controller, in 84918a89d6ef ("usb: dwc3: gadget: Let the interrupt handler disable bottom halves."), which this follows.
Also, the BH part is already in mainline: 625dd9076e35 (in v7.4-rc5) switched mtu3_irq() to spin_lock_bh(). That made the callbacks run with interrupts enabled, which breaks the guarantee you quote: u_serial's console callback takes a lock that printk takes with spin_lock_irqsave() on the same CPU. This patch only restores interrupts-off and keeps the BH disabling.
If you'd rather see the gadget side changed instead, I can look at that, but mtu3 would still need this fix, since 625dd9076e35 breaks the interrupts-disabled guarantee on its own (my bad :|).
Best regards,
Ryan Brue