Re: [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks
From: Alan Stern
Date: Mon Nov 30 2026 - 13:18:58 EST
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