From: Wesley Cheng <quic_wcheng@quicinc.com>
To: <gregkh@linuxfoundation.org>, <Thinh.Nguyen@synopsys.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>,
<quic_jackp@quicinc.com>, <quic_ugoswami@quicinc.com>,
Wesley Cheng <quic_wcheng@quicinc.com>
Subject: [PATCH v3 0/3] Avoid having pending end transfers on soft disconnect
Date: Mon, 10 Apr 2023 16:19:51 -0700 [thread overview]
Message-ID: <20230410231954.437-1-quic_wcheng@quicinc.com> (raw)
In case there is a host which takes time to complete a SETUP transaction,
during the soft disconnect sequence multiple DWC3 EPs will have their
DWC3_EP_DELAY_STOP flag set w/o issuing the end transfer command. Once the
controller halt sequence occurs, the soft disconnect is successful, and
the subsequent soft connect will attempt to flush the pending end transfers.
Soft disconnect sequence:
dwc3_gadget_ep_disable name=ep8in flags=0x3009 direction=1
dwc3_gadget_ep_disable name=ep4in flags=1 direction=1
dwc3_gadget_ep_disable name=ep3out flags=1 direction=0
usb_gadget_disconnect deactivated=0 connected=0 ret=0
Soft connect bug:
BUG: spinlock already unlocked on CPU
spin_bug+0x0
dwc3_remove_requests+0x278
dwc3_ep0_out_start+0xb0
__dwc3_gadget_start+0x25c
The bug occurs due to the flush of the pending end transfers, as the gadget
start routine is not held with a spinlock. However, if the DWC3_EP_DELAY_STOP
is set, it will call the giveback API, which attempts to unlock the dwc->lock.
Ideally, the DWC3 gadget should not have pending end transfers on a soft
connect, so fix this by:
1. Re-locating the SETUP phase check after stop active transfers, since
that is where the DWC3_EP_DELAY_STOP is potentially set. This also allows
for handling of a host that may be unresponsive by using the completion
timeout to trigger the stall and restart for EP0.
2. Do not call gadget stop until the poll for controller halt is
completed. DEVTEN is cleared as part of gadget stop, so the intention to
allow ep0 events to continue while waiting for controller halt is not
happening.
Changes in v3:
- Removed fixes tag in the refactor change
Wesley Cheng (3):
usb: dwc3: gadget: Refactor EP0 forced stall/restart into a separate
API
usb: dwc3: gadget: Stall and restart EP0 if host is unresponsive
usb: dwc3: gadget: Execute gadget stop after halting the controller
drivers/usb/dwc3/gadget.c | 101 ++++++++++++++++++++++----------------
1 file changed, 58 insertions(+), 43 deletions(-)
next reply other threads:[~2023-04-10 23:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-10 23:19 Wesley Cheng [this message]
2023-04-10 23:19 ` [PATCH v3 1/3] usb: dwc3: gadget: Refactor EP0 forced stall/restart into a separate API Wesley Cheng
2023-04-11 1:13 ` Thinh Nguyen
2023-04-10 23:19 ` [PATCH v3 2/3] usb: dwc3: gadget: Stall and restart EP0 if host is unresponsive Wesley Cheng
2023-04-11 1:13 ` Thinh Nguyen
2023-04-13 7:47 ` Greg KH
2023-04-10 23:19 ` [PATCH v3 3/3] usb: dwc3: gadget: Execute gadget stop after halting the controller Wesley Cheng
2023-04-11 1:14 ` Thinh Nguyen
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=20230410231954.437-1-quic_wcheng@quicinc.com \
--to=quic_wcheng@quicinc.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=quic_jackp@quicinc.com \
--cc=quic_ugoswami@quicinc.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