linux/drivers/usb/gadget/udc
Alan Stern ab219221a5 USB: dummy-hcd: Fix deadlock caused by disconnect detection
The dummy-hcd driver calls the gadget driver's disconnect callback
under the wrong conditions.  It should invoke the callback when Vbus
power is turned off, but instead it does so when the D+ pullup is
turned off.

This can cause a deadlock in the composite core when a gadget driver
is unregistered:

[   88.361471] ============================================
[   88.362014] WARNING: possible recursive locking detected
[   88.362580] 4.14.0-rc2+ #9 Not tainted
[   88.363010] --------------------------------------------
[   88.363561] v4l_id/526 is trying to acquire lock:
[   88.364062]  (&(&cdev->lock)->rlock){....}, at: [<ffffffffa0547e03>] composite_disconnect+0x43/0x100 [libcomposite]
[   88.365051]
[   88.365051] but task is already holding lock:
[   88.365826]  (&(&cdev->lock)->rlock){....}, at: [<ffffffffa0547b09>] usb_function_deactivate+0x29/0x80 [libcomposite]
[   88.366858]
[   88.366858] other info that might help us debug this:
[   88.368301]  Possible unsafe locking scenario:
[   88.368301]
[   88.369304]        CPU0
[   88.369701]        ----
[   88.370101]   lock(&(&cdev->lock)->rlock);
[   88.370623]   lock(&(&cdev->lock)->rlock);
[   88.371145]
[   88.371145]  *** DEADLOCK ***
[   88.371145]
[   88.372211]  May be due to missing lock nesting notation
[   88.372211]
[   88.373191] 2 locks held by v4l_id/526:
[   88.373715]  #0:  (&(&cdev->lock)->rlock){....}, at: [<ffffffffa0547b09>] usb_function_deactivate+0x29/0x80 [libcomposite]
[   88.374814]  #1:  (&(&dum_hcd->dum->lock)->rlock){....}, at: [<ffffffffa05bd48d>] dummy_pullup+0x7d/0xf0 [dummy_hcd]
[   88.376289]
[   88.376289] stack backtrace:
[   88.377726] CPU: 0 PID: 526 Comm: v4l_id Not tainted 4.14.0-rc2+ #9
[   88.378557] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014
[   88.379504] Call Trace:
[   88.380019]  dump_stack+0x86/0xc7
[   88.380605]  __lock_acquire+0x841/0x1120
[   88.381252]  lock_acquire+0xd5/0x1c0
[   88.381865]  ? composite_disconnect+0x43/0x100 [libcomposite]
[   88.382668]  _raw_spin_lock_irqsave+0x40/0x54
[   88.383357]  ? composite_disconnect+0x43/0x100 [libcomposite]
[   88.384290]  composite_disconnect+0x43/0x100 [libcomposite]
[   88.385490]  set_link_state+0x2d4/0x3c0 [dummy_hcd]
[   88.386436]  dummy_pullup+0xa7/0xf0 [dummy_hcd]
[   88.387195]  usb_gadget_disconnect+0xd8/0x160 [udc_core]
[   88.387990]  usb_gadget_deactivate+0xd3/0x160 [udc_core]
[   88.388793]  usb_function_deactivate+0x64/0x80 [libcomposite]
[   88.389628]  uvc_function_disconnect+0x1e/0x40 [usb_f_uvc]

This patch changes the code to test the port-power status bit rather
than the port-connect status bit when deciding whether to isue the
callback.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-by: David Tulloh <david@tulloh.id.au>
CC: <stable@vger.kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2017-10-11 13:13:26 +03:00
..
bdc usb: bdc: Add support for USB phy 2017-08-15 14:18:59 +03:00
amd5536udc_pci.c usb: gadget: udc: make debug prints compatible with both pci and platform devices 2017-06-13 13:21:01 +03:00
amd5536udc.h usb: gadget: udc: Add Synopsys UDC Platform driver 2017-06-13 13:21:03 +03:00
at91_udc.c usb: gadget: udc: at91: use PTR_ERR_OR_ZERO() 2016-04-14 09:24:38 +03:00
at91_udc.h usb: Convert pr_warning to pr_warn 2016-11-03 10:38:36 +02:00
atmel_usba_udc.c usb: gadget: udc: atmel: set vbus irqflags explicitly 2017-09-28 12:39:22 +03:00
atmel_usba_udc.h usb: gadget: udc: atmel: Remove unnecessary macros 2017-06-19 09:22:45 +03:00
bcm63xx_udc.c treewide: remove redundant #include <linux/kconfig.h> 2016-10-11 15:06:33 -07:00
core.c usb: gadget: core: fix ->udc_set_speed() logic 2017-09-20 14:57:13 +03:00
dummy_hcd.c USB: dummy-hcd: Fix deadlock caused by disconnect detection 2017-10-11 13:13:26 +03:00
fotg210-udc.c usb: gadget: udc: constify usb_ep_ops structures 2017-01-24 11:04:24 +02:00
fotg210.h
fsl_mxc_udc.c
fsl_qe_udc.c usb: gadget: fsl_qe_udc: constify qe_ep0_desc 2017-08-15 12:46:02 +03:00
fsl_qe_udc.h
fsl_udc_core.c fsl_udc_core: add support for devices provided by fsl-mph-dr-of 2017-04-11 10:58:27 +03:00
fsl_usb2_udc.h usb: Convert pr_warning to pr_warn 2016-11-03 10:38:36 +02:00
fusb300_udc.c usb: gadget: udc: constify usb_ep_ops structures 2017-01-24 11:04:24 +02:00
fusb300_udc.h
goku_udc.c usb: gadget: udc: constify usb_ep_ops structures 2017-01-24 11:04:24 +02:00
goku_udc.h
gr_udc.c usb: gadget: udc: constify usb_ep_ops structures 2017-01-24 11:04:24 +02:00
gr_udc.h
Kconfig usb: gadget: udc: fix snps_udc_plat.c build errors 2017-09-20 14:57:28 +03:00
lpc32xx_udc.c usb: udc: lpc32xx: remove USB PLL and USB OTG clock management 2016-03-04 15:14:49 +02:00
m66592-udc.c usb: gadget: udc: constify usb_ep_ops structures 2017-01-24 11:04:24 +02:00
m66592-udc.h
Makefile usb: gadget: udc: Add Synopsys UDC Platform driver 2017-06-13 13:21:03 +03:00
mv_u3d_core.c usb: gadget: mv_u3d: fix error handling in mv_u3d_probe() 2017-04-11 10:58:27 +03:00
mv_u3d.h
mv_udc_core.c USB: gadget: remove unneeded MODULE_VERSION() usage 2017-07-22 15:56:53 +02:00
mv_udc.h
net2272.c usb: add CONFIG_USB_PCI for system have both PCI HW and non-PCI based USB HW 2017-03-17 13:16:56 +09:00
net2272.h usb: add CONFIG_USB_PCI for system have both PCI HW and non-PCI based USB HW 2017-03-17 13:16:56 +09:00
net2280.c usb: changes for v4.13 merge window 2017-06-20 11:39:34 +08:00
net2280.h usb: gadget: net2280: Replace PCI pool old API 2017-03-16 18:03:31 +09:00
omap_udc.c usb: gadget: udc: constify usb_ep_ops structures 2017-01-24 11:04:24 +02:00
omap_udc.h usb: Convert pr_warning to pr_warn 2016-11-03 10:38:36 +02:00
pch_udc.c usb: gadget: udc: remove pointer dereference after free 2017-03-22 11:21:10 +02:00
pxa25x_udc.c usb: gadget: pxa25x_udc: document endianess better 2016-03-04 15:14:31 +02:00
pxa25x_udc.h usb: Convert pr_warning to pr_warn 2016-11-03 10:38:36 +02:00
pxa27x_udc.c usb: gadget: pxa27x: Remove duplicate function prototype 2017-03-27 10:46:34 +03:00
pxa27x_udc.h usb: gadget: pxa27x_udc: add ep capabilities support 2015-08-04 12:26:52 -05:00
r8a66597-udc.c usb: gadget: udc: constify usb_ep_ops structures 2017-01-24 11:04:24 +02:00
r8a66597-udc.h
renesas_usb3.c usb: gadget: udc: renesas_usb3: Fix return value of usb3_write_pipe() 2017-09-28 12:31:51 +03:00
s3c2410_udc.c USB: gadget: remove unneeded MODULE_VERSION() usage 2017-07-22 15:56:53 +02:00
s3c2410_udc.h
s3c-hsudc.c usb: gadget: udc: constify usb_ep_ops structures 2017-01-24 11:04:24 +02:00
snps_udc_core.c usb: gadget: udc: Add Synopsys UDC Platform driver 2017-06-13 13:21:03 +03:00
snps_udc_plat.c Update extcon for 4.14 2017-08-28 17:01:04 +02:00
trace.c usb: gadget: add tracepoints to the gadget API 2016-06-21 10:38:41 +03:00
trace.h usb: gadget: add tracepoints to the gadget API 2016-06-21 10:38:41 +03:00
udc-xilinx.c usb: gadget: udc-xilinx: clean up a variable name 2017-05-17 14:17:25 +03:00