linux/drivers/usb
Wesley Cheng 02435a739b usb: dwc3: gadget: Stall and restart EP0 if host is unresponsive
It was observed that there are hosts that may complete pending SETUP
transactions before the stop active transfers and controller halt occurs,
leading to lingering endxfer commands on DEPs on subsequent pullup/gadget
start iterations.

  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

The sequence shows that the USB gadget disconnect (dwc3_gadget_pullup(0))
routine completed successfully, allowing for the USB gadget to proceed with
a USB gadget connect.  However, if this occurs the system runs into an
issue where:

  BUG: spinlock already unlocked on CPU
  spin_bug+0x0
  dwc3_remove_requests+0x278
  dwc3_ep0_out_start+0xb0
  __dwc3_gadget_start+0x25c

This is due to the pending endxfers, leading to gadget start (w/o lock
held) to execute the remove requests, which will unlock the dwc3
spinlock as part of giveback.

To mitigate this, resolve the pending endxfers on the pullup disable
path by 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.

Fixes: c96683798e ("usb: dwc3: ep0: Don't prepare beyond Setup stage")
Cc: stable@vger.kernel.org
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Link: https://lore.kernel.org/r/20230413195742.11821-2-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-04-20 11:20:00 +02:00
..
atm usb: move from strlcpy with unused retval to strscpy 2022-08-19 11:08:54 +02:00
c67x00 USB: c67x00: remove unnecessary check of res 2022-05-12 11:36:46 +02:00
cdns3 Merge 6.3-rc6 into usb-next 2023-04-10 08:56:59 +02:00
chipidea usb: chipidea: fix missing goto in ci_hdrc_probe 2023-04-20 11:16:42 +02:00
class tty: Call ->dtr_rts() parameter active consistently 2023-01-19 16:04:35 +01:00
common Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
core usb: acpi: Switch to use acpi_evaluate_dsm_typed() 2023-03-16 12:15:10 +01:00
dwc2 usb: dwc2: platform: add support for utmi optional clock 2023-04-20 10:17:06 +02:00
dwc3 usb: dwc3: gadget: Stall and restart EP0 if host is unresponsive 2023-04-20 11:20:00 +02:00
early usb: early: xhci-dbc: Use memcpy_and_pad() 2023-01-31 10:40:54 +01:00
fotg210 USB: fotg210: fix memory leak with using debugfs_lookup() 2023-02-06 13:46:42 +01:00
gadget usb: gadget: udc: core: Prevent redundant calls to pullup 2023-04-20 11:16:33 +02:00
host usb: xhci-mtk: add optional frame count clock 2023-04-20 10:13:39 +02:00
image usb/image: fix repeated words in comments 2022-07-27 14:33:53 +02:00
isp1760 usb: isp1760: Fix out-of-bounds array access 2022-05-19 18:10:59 +02:00
misc usb: move config USB_USS720 to usb's misc Kconfig 2023-03-29 10:34:08 +02:00
mon mm: replace vma->vm_flags direct modifications with modifier calls 2023-02-09 16:51:39 -08:00
mtu3 usb: mtu3: add optional clock xhci_ck and frmcnt_ck 2023-04-20 11:17:05 +02:00
musb usb: musb: ux500: Convert to platform remove callback returning void 2023-04-05 19:07:42 +02:00
phy usb: phy: twl6030: Convert to platform remove callback returning void 2023-03-23 17:35:27 +01:00
renesas_usbhs usb: renesas_usbhs: drop of_match_ptr for ID table 2023-03-16 12:15:23 +01:00
roles driver core: make struct device_type.uevent() take a const * 2023-01-27 13:45:36 +01:00
serial USB-serial updates for 6.4-rc1 2023-04-20 08:59:38 +02:00
storage uas: Add US_FL_NO_REPORT_OPCODES for JMicron JMS583Gen 2 2023-03-16 12:44:17 +01:00
typec usb: typec: ucsi: don't print PPM init deferred errors 2023-04-20 11:04:47 +02:00
usbip Including fixes from bpf, netfilter and can. 2022-12-21 08:41:32 -08:00
Kconfig usb: move config USB_USS720 to usb's misc Kconfig 2023-03-29 10:34:08 +02:00
Makefile usb: host: u132-hcd: Delete driver 2023-03-21 14:06:11 +01:00
usb-skeleton.c usb: add usb_set_intfdata() documentation 2022-11-29 08:56:09 +01:00