[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a1d064e7-9847-4e2e-b74a-4ae4f39d3f04@rowland.harvard.edu>
Date: Fri, 19 May 2023 11:07:25 -0400
From: Alan Stern <stern@...land.harvard.edu>
To: Badhri Jagan Sridharan <badhri@...gle.com>
Cc: gregkh@...uxfoundation.org, colin.i.king@...il.com,
xuetao09@...wei.com, quic_eserrao@...cinc.com,
water.zhangjiantao@...wei.com, peter.chen@...escale.com,
balbi@...com, francesco@...cini.it, alistair@...stair23.me,
stephan@...hold.net, bagasdotme@...il.com, luca@...tu.xyz,
linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
stable@...r.kernel.org,
Francesco Dolcini <francesco.dolcini@...adex.com>
Subject: Re: [PATCH v2] usb: gadget: udc: core: Offload usb_udc_vbus_handler
processing
On Fri, May 19, 2023 at 10:49:49AM -0400, Alan Stern wrote:
> On Fri, May 19, 2023 at 04:30:41AM +0000, Badhri Jagan Sridharan wrote:
> > chipidea udc calls usb_udc_vbus_handler from udc_start gadget
> > ops causing a deadlock. Avoid this by offloading usb_udc_vbus_handler
> > processing.
>
> Look, this is way overkill.
>
> usb_udc_vbus_handler() has only two jobs to do: set udc->vbus and call
> usb_udc_connect_control(). Furthermore, it gets called from only two
> drivers: chipidea and max3420.
>
> Why not have the callers set udc->vbus themselves and then call
> usb_gadget_{dis}connect() directly? Then we could eliminate
> usb_udc_vbus_handler() entirely. And the unnecessary calls -- the ones
> causing deadlocks -- from within udc_start() and udc_stop() handlers can
> be removed with no further consequence.
>
> This approach simplifies and removes code. Whereas your approach
> complicates and adds code for no good reason.
I changed my mind.
After looking more closely, I found the comment in gadget.h about
->disconnect() callbacks happening in interrupt context. This means we
cannot use a mutex to protect the associated state, and therefore the
connect_lock _must_ be a spinlock, not a mutex.
This also probably means that udc_start and udc_stop callbacks should
not be invoked with the lock held. In fact, you might want to avoid
using the lock at all with gadget_bind_driver() and
gadget_unbind_driver() -- use it only in the functions that these
routines call.
So it appears the whole connect_lock thing needs to be redesigned with
these ideas in mind. However, it's still true that the UDC drivers
shouldn't try to set the connection state from within their udc_start
and udc_stop callbacks, because the core takes care of this
automatically.
Alan Stern
Powered by blists - more mailing lists