android_kernel_oneplus_msm8998/drivers/usb/host
Yoshihiro Shimoda eb1ff5020b usb: host: ohci: fix a race condition between shutdown and irq
commit a349b95d7ca0cea71be4a7dac29830703de7eb62 upstream.

This patch fixes an issue that the following error is
possible to happen when ohci hardware causes an interruption
and the system is shutting down at the same time.

[   34.851754] usb 2-1: USB disconnect, device number 2
[   35.166658] irq 156: nobody cared (try booting with the "irqpoll" option)
[   35.173445] CPU: 0 PID: 22 Comm: kworker/0:1 Not tainted 5.3.0-rc5 #85
[   35.179964] Hardware name: Renesas Salvator-X 2nd version board based on r8a77965 (DT)
[   35.187886] Workqueue: usb_hub_wq hub_event
[   35.192063] Call trace:
[   35.194509]  dump_backtrace+0x0/0x150
[   35.198165]  show_stack+0x14/0x20
[   35.201475]  dump_stack+0xa0/0xc4
[   35.204785]  __report_bad_irq+0x34/0xe8
[   35.208614]  note_interrupt+0x2cc/0x318
[   35.212446]  handle_irq_event_percpu+0x5c/0x88
[   35.216883]  handle_irq_event+0x48/0x78
[   35.220712]  handle_fasteoi_irq+0xb4/0x188
[   35.224802]  generic_handle_irq+0x24/0x38
[   35.228804]  __handle_domain_irq+0x5c/0xb0
[   35.232893]  gic_handle_irq+0x58/0xa8
[   35.236548]  el1_irq+0xb8/0x180
[   35.239681]  __do_softirq+0x94/0x23c
[   35.243253]  irq_exit+0xd0/0xd8
[   35.246387]  __handle_domain_irq+0x60/0xb0
[   35.250475]  gic_handle_irq+0x58/0xa8
[   35.254130]  el1_irq+0xb8/0x180
[   35.257268]  kernfs_find_ns+0x5c/0x120
[   35.261010]  kernfs_find_and_get_ns+0x3c/0x60
[   35.265361]  sysfs_unmerge_group+0x20/0x68
[   35.269454]  dpm_sysfs_remove+0x2c/0x68
[   35.273284]  device_del+0x80/0x370
[   35.276683]  hid_destroy_device+0x28/0x60
[   35.280686]  usbhid_disconnect+0x4c/0x80
[   35.284602]  usb_unbind_interface+0x6c/0x268
[   35.288867]  device_release_driver_internal+0xe4/0x1b0
[   35.293998]  device_release_driver+0x14/0x20
[   35.298261]  bus_remove_device+0x110/0x128
[   35.302350]  device_del+0x148/0x370
[   35.305832]  usb_disable_device+0x8c/0x1d0
[   35.309921]  usb_disconnect+0xc8/0x2d0
[   35.313663]  hub_event+0x6e0/0x1128
[   35.317146]  process_one_work+0x1e0/0x320
[   35.321148]  worker_thread+0x40/0x450
[   35.324805]  kthread+0x124/0x128
[   35.328027]  ret_from_fork+0x10/0x18
[   35.331594] handlers:
[   35.333862] [<0000000079300c1d>] usb_hcd_irq
[   35.338126] [<0000000079300c1d>] usb_hcd_irq
[   35.342389] Disabling IRQ #156

ohci_shutdown() disables all the interrupt and rh_state is set to
OHCI_RH_HALTED. In other hand, ohci_irq() is possible to enable
OHCI_INTR_SF and OHCI_INTR_MIE on ohci_irq(). Note that OHCI_INTR_SF
is possible to be set by start_ed_unlink() which is called:
 ohci_irq()
  -> process_done_list()
   -> takeback_td()
    -> start_ed_unlink()

So, ohci_irq() has the following condition, the issue happens by
&ohci->regs->intrenable = OHCI_INTR_MIE | OHCI_INTR_SF and
ohci->rh_state = OHCI_RH_HALTED:

	/* interrupt for some other device? */
	if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
		return IRQ_NOTMINE;

To fix the issue, ohci_shutdown() holds the spin lock while disabling
the interruption and changing the rh_state flag to prevent reenable
the OHCI_INTR_MIE unexpectedly. Note that io_watchdog_func() also
calls the ohci_shutdown() and it already held the spin lock, so that
the patch makes a new function as _ohci_shutdown().

This patch is inspired by a Renesas R-Car Gen3 BSP patch
from Tho Vu.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: stable <stable@vger.kernel.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/1566877910-6020-1-git-send-email-yoshihiro.shimoda.uh@renesas.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-06 10:18:16 +02:00
..
whci USB: whci-hcd: add check for dma mapping error 2015-12-01 14:45:52 -08:00
bcma-hcd.c USB: bcma: add support for controlling bus power through GPIO 2015-07-22 15:43:34 -07:00
ehci-atmel.c
ehci-dbg.c usb: host: fix incorrect updating of offset 2017-12-09 18:42:44 +01:00
ehci-exynos.c usb: host: ehci-exynos: Decrese node refcount on exynos_ehci_get_phy() error paths 2017-05-14 13:32:56 +02:00
ehci-fsl.c drivers: usb: fsl: Workaround for USB erratum-A005275 2015-08-14 16:50:36 -07:00
ehci-fsl.h drivers: usb: fsl: Define usb control register mask for w1c bits 2015-07-22 16:44:35 -07:00
ehci-grlib.c
ehci-hcd.c usb: ehci: change order of register cleanup during shutdown 2016-09-07 08:32:38 +02:00
ehci-hub.c drivers: usb: fsl: Workaround for USB erratum-A005275 2015-08-14 16:50:36 -07:00
ehci-mem.c
ehci-msm.c usb: host: ehci-msm: fix handling platform_get_irq result 2015-10-04 10:59:03 +01:00
ehci-mv.c
ehci-mxc.c
ehci-omap.c usb: ehci-omap: fix error return code in ehci_hcd_omap_probe() 2018-11-10 07:41:39 -08:00
ehci-orion.c usb: ehci-orion: fix probe for !GENERIC_PHY 2015-10-04 10:45:08 +01:00
ehci-pci.c
ehci-platform.c USB: ehci-platform: Add ACPI bindings for the EHCI platform driver. 2015-10-04 10:47:13 +01:00
ehci-pmcmsp.c
ehci-ppc-of.c
ehci-ps3.c
ehci-q.c
ehci-sched.c
ehci-sead3.c
ehci-sh.c
ehci-spear.c usb: host: ehci-spear: Fix module autoload for OF platform driver 2015-10-04 10:51:58 +01:00
ehci-st.c usb: host: ehci-st: Simplify return statement 2015-08-05 12:37:21 -07:00
ehci-sysfs.c usb: host: ehci-sys: delete useless bus_to_hcd conversion 2015-08-18 10:05:23 -07:00
ehci-tegra.c usb: host: ehci-tegra: Grab the correct UTMI pads reset 2016-07-11 09:31:13 -07:00
ehci-tilegx.c
ehci-timer.c
ehci-w90x900.c
ehci-xilinx-of.c
ehci.h drivers: usb: fsl: Workaround for USB erratum-A005275 2015-08-14 16:50:36 -07:00
fhci-dbg.c
fhci-hcd.c
fhci-hub.c
fhci-mem.c
fhci-q.c
fhci-sched.c
fhci-tds.c
fhci.h
fotg210-hcd.c usb: host: fotg2: restart hcd after port reset 2019-09-06 10:18:14 +02:00
fotg210.h usb/host/fotg210: Fix coding style issues 2015-10-16 23:46:22 -07:00
fsl-mph-dr-of.c usb: host: fsl-mph-dr-of: Fix module autoload for OF platform driver 2015-10-04 10:51:58 +01:00
hwa-hc.c usb: wusbcore: fix unbalanced get/put cluster_id 2019-08-04 09:35:00 +02:00
imx21-dbg.c
imx21-hcd.c usb: imx21-hcd: fix error return code in imx21_probe() 2018-11-10 07:41:39 -08:00
imx21-hcd.h
isp116x-hcd.c
isp116x.h
isp1362-hcd.c
isp1362.h
Kconfig ARM: tegra: select USB_ULPI from EHCI rather than platform 2018-02-25 11:03:51 +01:00
Makefile usb-host: Remove fusbh200 driver 2015-10-16 23:44:33 -07:00
max3421-hcd.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
ohci-at91.c USB: host: ohci-at91: fix a crash in ohci_hcd_at91_overcurrent_irq 2015-12-04 08:19:55 -08:00
ohci-da8xx.c
ohci-dbg.c
ohci-exynos.c usb: host: ohci-exynos: Decrese node refcount on exynos_ehci_get_phy() error paths 2017-05-14 13:32:56 +02:00
ohci-hcd.c usb: host: ohci: fix a race condition between shutdown and irq 2019-09-06 10:18:16 +02:00
ohci-hub.c
ohci-jz4740.c
ohci-mem.c
ohci-nxp.c usb: host: lpc32xx: don't unregister phy device 2015-10-24 19:53:53 -07:00
ohci-omap.c
ohci-omap3.c
ohci-pci.c
ohci-platform.c
ohci-ppc-of.c
ohci-ps3.c
ohci-pxa27x.c
ohci-q.c usb: ohci: Proper handling of ed_rm_list to handle race condition between usb_kill_urb() and finish_unlinks() 2018-02-28 10:17:22 +01:00
ohci-s3c2410.c
ohci-sa1111.c
ohci-sm501.c
ohci-spear.c usb: host: ohci-spear: Fix module autoload for OF platform driver 2015-10-04 10:51:58 +01:00
ohci-st.c
ohci-tilegx.c
ohci-tmio.c USB: OHCI: fix bad #define in ohci-tmio.c 2015-07-22 14:49:42 -07:00
ohci.h
oxu210hp-hcd.c dma: remove external references to dma_supported 2015-11-09 15:11:24 -08:00
oxu210hp.h
pci-quirks.c usb: pci-quirks: Correct AMD PLL quirk detection 2019-08-04 09:35:00 +02:00
pci-quirks.h
r8a66597-hcd.c usb: r8a66597: Fix a possible concurrency use-after-free bug in r8a66597_endpoint_disable() 2019-01-13 10:05:29 +01:00
r8a66597.h
sl811-hcd.c
sl811.h
sl811_cs.c
ssb-hcd.c
u132-hcd.c usb: u132-hcd: fix resource leak 2019-05-16 19:44:58 +02:00
uhci-debug.c
uhci-grlib.c
uhci-hcd.c
uhci-hcd.h
uhci-hub.c
uhci-pci.c USB: UHCI: report non-PME wakeup signalling for Intel hardware 2017-01-06 11:16:08 +01:00
uhci-platform.c usb: host: uhci-platform: Fix module autoload for OF platform driver 2015-10-04 10:51:58 +01:00
uhci-q.c
xhci-dbg.c usb: host: xhci-dbg: HCIVERSION should be a binary number 2017-03-18 19:09:57 +08:00
xhci-ext-caps.h
xhci-hub.c xhci: Don't prevent USB2 bus suspend in state check intended for USB3 only 2019-01-13 10:05:26 +01:00
xhci-mem.c xhci: xhci-mem: off by one in xhci_stream_id_to_ring() 2018-07-17 11:31:43 +02:00
xhci-mvebu.c
xhci-mvebu.h
xhci-pci.c xhci: Add missing CAS workaround for Intel Sunrise Point xHCI 2018-10-13 09:11:32 +02:00
xhci-plat.c Revert "xhci: plat: Register shutdown for xhci_plat" 2018-04-13 19:50:27 +02:00
xhci-rcar.c
xhci-rcar.h
xhci-ring.c xhci: Fix port resume done detection for SS ports with LPM enabled 2019-04-03 06:23:28 +02:00
xhci-trace.c
xhci-trace.h
xhci.c usb: xhci: avoid null pointer deref when bos field is NULL 2019-06-11 12:24:08 +02:00
xhci.h xhci: Fix port resume done detection for SS ports with LPM enabled 2019-04-03 06:23:28 +02:00