From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Selvarasu Ganesan <selvarasu.g@samsung.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"jh0801.jung@samsung.com" <jh0801.jung@samsung.com>,
"dh10.jung@samsung.com" <dh10.jung@samsung.com>,
"naushad@samsung.com" <naushad@samsung.com>,
"akash.m5@samsung.com" <akash.m5@samsung.com>,
"h10.kim@samsung.com" <h10.kim@samsung.com>,
"eomji.oh@samsung.com" <eomji.oh@samsung.com>,
"alim.akhtar@samsung.com" <alim.akhtar@samsung.com>,
"thiagu.r@samsung.com" <thiagu.r@samsung.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v2] usb: dwc3: gadget: Prevent EPs resource conflict during StartTransfer
Date: Thu, 20 Nov 2025 02:07:33 +0000 [thread overview]
Message-ID: <20251120020729.k6etudqwotodnnwp@synopsys.com> (raw)
In-Reply-To: <d53a1765-f316-46ff-974e-f42b22b31b25@rowland.harvard.edu>
On Tue, Nov 18, 2025, Alan Stern wrote:
> On Wed, Nov 19, 2025 at 01:49:12AM +0000, Thinh Nguyen wrote:
> > On Mon, Nov 17, 2025, Alan Stern wrote:
> > > > Hi Alan,
> > > >
> > > > Can you help give your opinion on this?
> > >
> > > Well, I think the change to the API was made because drivers _were_
> > > calling these routines in interrupt context. That's what the commit's
> > > description says, anyway.
> > >
> > > One way out of the problem would be to change the kerneldoc for
> > > usb_ep_disable(). Instead of saying that pending requests will complete
> > > before the all returns, say that the the requests will be marked for
> > > cancellation (with -ESHUTDOWN) before the call returns, but the actual
> > > completions might happen asynchronously later on.
> >
> > The burden of synchronization would be shifted to the gadget drivers.
> > The problem with this is that gadget drivers may modify the requests
> > after usb_ep_disable() when it should not (e.g. the controller may still
> > be processing the buffer). Also, gadget drivers shouldn't call
> > usb_ep_enabled() until the requests are returned.
>
> No, they probably shouldn't, although I don't know if that would
> actually cause any trouble. It's not a good idea, in any case --
> particularly if the drivers want to re-use the same requests as before.
Right.
>
> The problem is that function drivers' ->set_alt() callbacks are expected
> to do two things: disable all the endpoints from the old altsetting and
> enable all the endpoints in the new altsetting. There's no way for any
> part of the gadget core to intervene between those things (for instance,
> to wait for requests to complete).
>
> > > The difficulty comes when a gadget driver has to handle a Set-Interface
> > > request, or Set-Config for the same configuration. The endpoints for
> > > the old altsetting/config have to be disabled and then the endpoints for
> > > the new altsetting/config have to be enabled, all while managing any
> >
> > Right.
> >
> > > pending requests. I don't know how various function drivers handle
> > > this, just that f_mass_storage is very careful about taking care of
> > > everything in a separate kernel thread that explicitly dequeues the
> > > pending requests and flushes the endpoints. In fact, this scenario was
> > > the whole reason for inventing the DELAYED_STATUS mechanism, because it
> > > was impossible to do all the necessary work within the callback routine
> > > for a control-request interrupt handler.
> > >
> >
> > If we want to keep usb_ep_disable in interrupt context, should we revise
> > the wording such that gadget drivers must ensure pending requests are
> > dequeued before calling usb_ep_disable()? That requests are expected to
> > be given back before usb_ep_disable().
> >
> > Or perhaps revert the commit above (commit b0d5d2a71641), fix the dwc3
> > driver for that, and gadget drivers need to follow the original
> > requirement.
>
> Function drivers would have to go to great lengths to guarantee that
> requests had completed before the endpoint is re-enabled. Right now
> their ->set_alt() callback routines are designed to run in interrupt
> context; they can't afford to wait for requests to complete.
Why is ->set_alt() designed for interrupt context? We can't expect
requests to be completed before usb_ep_disable() completes _and_ also
expect usb_ep_disable() be able to be called in interrupt context.
>
> The easiest way out is for usb_ep_disable() to do what the kerneldoc
> says: ensure that pending requests do complete before it returns. Can
> dwc3 do this? (And what if at some time in the future we want to start
The dwc3 can do that, but we need to note that usb_ep_disable() must be
executed in process context and might sleep. I suspect we may run into
some issues from some function drivers that expected usb_ep_disable() to
be executable in interrupt context.
> using an asynchronous bottom half for request completions, like usbcore
> does for URBs?)
Which one are you referring to? From what I see, even the host side
expected ->endpoint_disable to be executed in process context.
Perhaps we can introduce endpoint_flush() on gadget side for
synchronization if we want to keep usb_ep_disable() to be asynchronous?
>
> Let's face it; the situation is a mess.
>
Glad you're here to help with the mess :)
Thanks,
Thinh
next prev parent reply other threads:[~2025-11-20 2:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20251117160057epcas5p324eddf1866146216495186a50bcd3c01@epcas5p3.samsung.com>
2025-11-17 15:59 ` [PATCH v2] usb: dwc3: gadget: Prevent EPs resource conflict during StartTransfer Selvarasu Ganesan
2025-11-18 2:21 ` Thinh Nguyen
2025-11-18 3:58 ` Selvarasu Ganesan
2025-11-19 1:56 ` Thinh Nguyen
2025-11-18 4:20 ` Alan Stern
2025-11-19 1:49 ` Thinh Nguyen
2025-11-19 4:09 ` Alan Stern
2025-11-20 2:07 ` Thinh Nguyen [this message]
2025-11-20 3:33 ` Alan Stern
2025-11-21 2:22 ` Thinh Nguyen
2025-11-21 3:08 ` Alan Stern
2025-12-03 5:25 ` Selvarasu Ganesan
2025-12-04 1:51 ` Thinh Nguyen
2025-12-04 13:15 ` Selvarasu Ganesan
2025-12-05 0:37 ` Thinh Nguyen
2025-12-05 1:18 ` Thinh Nguyen
2025-12-05 1:19 ` Thinh Nguyen
2025-12-11 10:38 ` Selvarasu Ganesan
2025-12-12 1:21 ` Thinh Nguyen
2026-02-26 10:59 ` Selvarasu Ganesan
2026-02-26 18:41 ` Thinh Nguyen
2026-03-02 5:56 ` Selvarasu Ganesan
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=20251120020729.k6etudqwotodnnwp@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=akash.m5@samsung.com \
--cc=alim.akhtar@samsung.com \
--cc=dh10.jung@samsung.com \
--cc=eomji.oh@samsung.com \
--cc=gregkh@linuxfoundation.org \
--cc=h10.kim@samsung.com \
--cc=jh0801.jung@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=naushad@samsung.com \
--cc=selvarasu.g@samsung.com \
--cc=stable@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=thiagu.r@samsung.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox