From: Ryan Brue <ryanbrue.dev@gmail.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
stable@kernel.org
Subject: Re: [PATCH RESEND] usb: mtu3: keep interrupts disabled in gadget completion callbacks
Date: Tue, 1 Dec 2026 22:44:31 -0600 [thread overview]
Message-ID: <8c827a28-e424-4a32-8c16-e8389c5c69ce@gmail.com> (raw)
In-Reply-To: <449e050f-4dab-4403-b507-f20514863b26@rowland.harvard.edu>
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
prev parent reply other threads:[~2026-12-02 4:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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
2026-12-02 4:44 ` Ryan Brue [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8c827a28-e424-4a32-8c16-e8389c5c69ce@gmail.com \
--to=ryanbrue.dev@gmail.com \
--cc=chunfeng.yun@mediatek.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@kernel.org \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.