linux/drivers/usb
Mathias Nyman 057d476fff xhci: fix USB3 device initiated resume race with roothub autosuspend
A race in xhci USB3 remote wake handling may force device back to suspend
after it initiated resume siganaling, causing a missed resume event or warm
reset of device.

When a USB3 link completes resume signaling and goes to enabled (UO)
state a interrupt is issued and the interrupt handler will clear the
bus_state->port_remote_wakeup resume flag, allowing bus suspend.

If the USB3 roothub thread just finished reading port status before
the interrupt, finding ports still in suspended (U3) state, but hasn't
yet started suspending the hub, then the xhci interrupt handler will clear
the flag that prevented roothub suspend and allow bus to suspend, forcing
all port links back to suspended (U3) state.

Example case:
usb_runtime_suspend() # because all ports still show suspended U3
  usb_suspend_both()
    hub_suspend();   # successful as hub->wakeup_bits not set yet
==> INTERRUPT
xhci_irq()
  handle_port_status()
    clear bus_state->port_remote_wakeup
    usb_wakeup_notification()
      sets hub->wakeup_bits;
        kick_hub_wq()
<== END INTERRUPT
      hcd_bus_suspend()
        xhci_bus_suspend() # success as port_remote_wakeup bits cleared

Fix this by increasing roothub usage count during port resume to prevent
roothub autosuspend, and by making sure bus_state->port_remote_wakeup
flag is only cleared after resume completion is visible, i.e.
after xhci roothub returned U0 or other non-U3 link state link on a
get port status request.

Issue rootcaused by Chiasheng Lee

Cc: <stable@vger.kernel.org>
Cc: Lee, Hou-hsun <hou-hsun.lee@intel.com>
Reported-by: Lee, Chiasheng <chiasheng.lee@intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20191211142007.8847-3-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-12-11 15:32:17 +01:00
..
atm USB: atm: ueagle-atm: add missing endpoint check 2019-12-10 13:11:22 +01:00
c67x00 USB: add SPDX identifiers to all remaining Makefiles 2017-11-07 15:53:48 +01:00
cdns3 USB: changes for v5.5 2019-11-18 08:24:12 +01:00
chipidea usb: chipidea: imx: pinctrl for HSIC is optional 2019-11-18 17:40:27 +08:00
class compat_ioctl: remove most of fs/compat_ioctl.c 2019-12-01 13:46:15 -08:00
common usb: common: usb-conn-gpio: Don't log an error on probe deferral 2019-12-10 11:41:20 +01:00
core USB: Fix incorrect DMA allocations for local memory pool drivers 2019-12-11 09:06:41 +01:00
dwc2 USB: changes for v5.5 2019-11-18 08:24:12 +01:00
dwc3 usb: dwc3: ep0: Clear started flag on completion 2019-12-10 14:52:41 +02:00
early drivers: Remove explicit invocations of mmiowb() 2019-04-08 12:01:02 +01:00
gadget usb: gadget: fix wrong endpoint desc 2019-12-10 14:56:10 +02:00
host xhci: fix USB3 device initiated resume race with roothub autosuspend 2019-12-11 15:32:17 +01:00
image Merge 5.4-rc3 into usb-next 2019-10-14 07:09:59 +02:00
isp1760 usb: isp1760: isp1760-hcd.c: Drop condition with no effect 2019-10-07 13:01:47 +02:00
misc USB: adutux: fix interface sanity check 2019-12-10 13:11:22 +01:00
mon usb: mon: Fix a deadlock in usbmon between mmap and read 2019-12-10 11:41:20 +01:00
mtu3 Merge 5.4-rc6 into usb-next 2019-11-04 06:41:09 +01:00
musb usb: musb: create debugfs directory under usb root 2019-11-21 18:20:29 +01:00
phy usb: phy: mxs: use devm_platform_ioremap_resource() to simplify code 2019-10-22 10:29:10 +03:00
renesas_usbhs usb: renesas_usbhs: Use dma_request_chan() directly for channel request 2019-11-14 11:12:31 +08:00
roles usb: roles: fix a potential use after free 2019-12-10 11:41:18 +01:00
serial USB: serial: io_edgeport: fix epic endpoint lookup 2019-12-10 13:11:21 +01:00
storage USB: Fix incorrect DMA allocations for local memory pool drivers 2019-12-11 09:06:41 +01:00
typec usb: typec: fix use after free in typec_register_port() 2019-12-10 11:41:19 +01:00
usbip usbip: Fix uninitialized symbol 'nents' in stub_recv_cmd_submit() 2019-11-13 18:53:11 +08:00
Kconfig usb: common: create Kconfig file 2019-09-03 19:00:39 +02:00
Makefile USB: Changes for v5.4 merge window 2019-09-02 19:20:57 +02:00
usb-skeleton.c USB: usb-skeleton: drop redundant in-urb check 2019-10-10 12:41:19 +02:00