kernel-ark/drivers/usb/gadget
Marc Kleine-Budde 001428e487 USB: gadgetfs: gadgetfs_disconnect: fix inconsistent lock state
Under certain circumstances lockdep finds an inconsistent lock state in
gadgetfs. The problem can be reproduced with a hardware using the
ci13xxx_udc driver and the gadgetfs test program (needs a patch to support
the ci13xxx_udc, though):
	http://www.linux-usb.org/gadget/usb.c
Start the test program, wait to initialize, then press Ctrl+c.

This patch fixes the following problem by using spin_lock_irqsave()
instead of spin_lock().

=================================
[ INFO: inconsistent lock state ]
3.1.0-rc6+ #158
---------------------------------
inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage.
usb/113 [HC0[0]:SC0[0]:HE1:SE1] takes:
 (&(&dev->lock)->rlock){?.....}, at: [<bf000340>] gadgetfs_disconnect+0x14/0x80 [gadgetfs]
{IN-HARDIRQ-W} state was registered at:
  [<c00596b8>] mark_irqflags+0x14c/0x1ac
  [<c0059bf8>] __lock_acquire+0x4e0/0x8f0
  [<c005a698>] lock_acquire+0x98/0x1a8
  [<c02f10e0>] _raw_spin_lock+0x54/0x8c
  [<bf000340>] gadgetfs_disconnect+0x14/0x80 [gadgetfs]
  [<c0229104>] _gadget_stop_activity+0xd4/0x154
  [<c022b130>] isr_reset_handler+0x34/0x1c0
  [<c022c320>] udc_irq+0x204/0x228
  [<c0069018>] handle_irq_event_percpu+0x64/0x3a0
  [<c0069390>] handle_irq_event+0x3c/0x5c
  [<c006ae5c>] handle_level_irq+0x8c/0x10c
  [<c0068a34>] generic_handle_irq+0x30/0x44
  [<c0009b2c>] handle_IRQ+0x30/0x84
  [<c0008ef8>] __irq_svc+0x38/0x60
  [<c0009c58>] default_idle+0x30/0x34
  [<c0009e30>] cpu_idle+0x9c/0xd8
  [<c04056f4>] start_kernel+0x278/0x2bc
irq event stamp: 6412
hardirqs last  enabled at (6412): [<c02f1cd0>] _raw_spin_unlock_irqrestore+0x30/0x5c
hardirqs last disabled at (6411): [<c02f1278>] _raw_spin_lock_irqsave+0x20/0xa0
softirqs last  enabled at (6381): [<c002833c>] irq_exit+0xa0/0xa8
softirqs last disabled at (6372): [<c002833c>] irq_exit+0xa0/0xa8

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(&(&dev->lock)->rlock);
  <Interrupt>
    lock(&(&dev->lock)->rlock);

 *** DEADLOCK ***

1 lock held by usb/113:
 #0:  (udc_lock#2){+.+.+.}, at: [<c02286c0>] usb_gadget_unregister_driver+0x34/0x88

stack backtrace:
[<c000d41c>] (unwind_backtrace+0x0/0xf0) from [<c0058e98>] (print_usage_bug+0x144/0x1c4)
[<c0058e98>] (print_usage_bug+0x144/0x1c4) from [<c0059144>] (mark_lock_irq+0x22c/0x274)
[<c0059144>] (mark_lock_irq+0x22c/0x274) from [<c00592d4>] (mark_lock+0x148/0x3e0)
[<c00592d4>] (mark_lock+0x148/0x3e0) from [<c0059668>] (mark_irqflags+0xfc/0x1ac)
[<c0059668>] (mark_irqflags+0xfc/0x1ac) from [<c0059bf8>] (__lock_acquire+0x4e0/0x8f0)
[<c0059bf8>] (__lock_acquire+0x4e0/0x8f0) from [<c005a698>] (lock_acquire+0x98/0x1a8)
[<c005a698>] (lock_acquire+0x98/0x1a8) from [<c02f10e0>] (_raw_spin_lock+0x54/0x8c)
[<c02f10e0>] (_raw_spin_lock+0x54/0x8c) from [<bf000340>] (gadgetfs_disconnect+0x14/0x80 [gadgetfs])
[<bf000340>] (gadgetfs_disconnect+0x14/0x80 [gadgetfs]) from [<c0229104>] (_gadget_stop_activity+0xd4/0x154)
[<c0229104>] (_gadget_stop_activity+0xd4/0x154) from [<c0229240>] (ci13xxx_stop+0xbc/0x17c)
[<c0229240>] (ci13xxx_stop+0xbc/0x17c) from [<c022867c>] (usb_gadget_remove_driver+0x88/0x98)
[<c022867c>] (usb_gadget_remove_driver+0x88/0x98) from [<c02286f4>] (usb_gadget_unregister_driver+0x68/0x88)
[<c02286f4>] (usb_gadget_unregister_driver+0x68/0x88) from [<bf0003e8>] (dev_release+0x14/0x48 [gadgetfs])
[<bf0003e8>] (dev_release+0x14/0x48 [gadgetfs]) from [<c00cc158>] (__fput+0xa4/0x1f0)
[<c00cc158>] (__fput+0xa4/0x1f0) from [<c00c7f28>] (filp_close+0x5c/0x74)
[<c00c7f28>] (filp_close+0x5c/0x74) from [<c00c7fe8>] (sys_close+0xa8/0x150)
[<c00c7fe8>] (sys_close+0xa8/0x150) from [<c00092a0>] (ret_fast_syscall+0x0/0x38)

Tested-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-11-14 11:51:26 -08:00
..
acm_ms.c usb: gadget: add new usb gadget for ACM and mass storage 2011-10-13 20:46:27 +03:00
amd5536udc.c usb: Provide usb_speed_string() function 2011-09-18 01:29:04 -07:00
amd5536udc.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
at91_udc.c usb: gadget: at91_udc: change french comments to english 2011-10-13 20:39:54 +03:00
at91_udc.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
atmel_usba_udc.c usb: Provide usb_speed_string() function 2011-09-18 01:29:04 -07:00
atmel_usba_udc.h
audio.c usb: gadget: add max_speed to usb_composite_driver 2011-07-01 14:27:05 -07:00
cdc2.c usb: Add module.h to drivers/usb consumers who really use it. 2011-10-31 19:31:25 -04:00
ci13xxx_msm.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
ci13xxx_pci.c
ci13xxx_udc.c USB: use usb_endpoint_maxp() instead of le16_to_cpu() 2011-08-23 09:47:40 -07:00
ci13xxx_udc.h USB: gadget: Add test mode support for ci13xxx_udc 2011-02-25 11:33:57 -08:00
composite.c usb: Add module.h to drivers/usb consumers who really use it. 2011-10-31 19:31:25 -04:00
config.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
dbgp.c usb: Add module.h to drivers/usb consumers who really use it. 2011-10-31 19:31:25 -04:00
dummy_hcd.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
epautoconf.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
ether.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_acm.c usb: gadget: use config_ep_by_speed() instead of ep_choose() 2011-06-28 11:14:37 -07:00
f_audio.c usb: gadget: audio: queue wLength-sized requests 2011-09-09 13:06:06 +03:00
f_ecm.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_eem.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_fs.c usb: Add export.h for EXPORT_SYMBOL/THIS_MODULE where needed 2011-10-31 19:31:25 -04:00
f_hid.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_loopback.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_mass_storage.c usb: gadget: storage: check for valid USB_BULK_RESET_REQUEST wLength 2011-11-14 11:51:24 -08:00
f_midi.c usb: gadget: fix MIDI gadget jack allocation 2011-11-14 11:51:25 -08:00
f_ncm.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_obex.c usb: Add module.h to drivers/usb consumers who really use it. 2011-10-31 19:31:25 -04:00
f_phonet.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_rndis.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_serial.c usb: gadget: use config_ep_by_speed() instead of ep_choose() 2011-06-28 11:14:37 -07:00
f_sourcesink.c usb: Add module.h to drivers/usb consumers who really use it. 2011-10-31 19:31:25 -04:00
f_subset.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_uvc.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
f_uvc.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
file_storage.c usb: gadget: storage: check for valid USB_BULK_RESET_REQUEST wLength 2011-11-14 11:51:24 -08:00
fsl_mxc_udc.c usb: gadget/fsl_mxc_udc: Detect the CPU type in run-time 2011-02-04 11:42:52 -08:00
fsl_qe_udc.c USB: use usb_endpoint_maxp() instead of le16_to_cpu() 2011-08-23 09:47:40 -07:00
fsl_qe_udc.h usb: fix a typo in a comment 2011-04-13 16:41:00 -07:00
fsl_udc_core.c usb: gadget: fsl_udc_core: fix compile error. 2011-11-14 11:51:21 -08:00
fsl_usb2_udc.h USB: extend ehci-fsl and fsl_udc_core driver for OTG operation 2011-05-02 16:59:38 -07:00
fusb300_udc.c usb: Add module.h to drivers/usb consumers who really use it. 2011-10-31 19:31:25 -04:00
fusb300_udc.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
g_ffs.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
g_zero.h
gadget_chips.h usb: gadget: introduce gadget_is_dwc3() 2011-08-22 16:00:46 -07:00
gmidi.c usb: Add module.h to drivers/usb consumers who really use it. 2011-10-31 19:31:25 -04:00
goku_udc.c usb: gadget: convert all users to the new udc infrastructure 2011-06-28 11:13:35 -07:00
goku_udc.h
hid.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
imx_udc.c USB: irq: Remove IRQF_DISABLED 2011-09-18 01:39:36 -07:00
imx_udc.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
inode.c USB: gadgetfs: gadgetfs_disconnect: fix inconsistent lock state 2011-11-14 11:51:26 -08:00
Kconfig usb: gadget: add new usb gadget for ACM and mass storage 2011-10-13 20:46:27 +03:00
langwell_udc.c Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb 2011-10-25 12:23:15 +02:00
langwell_udc.h usb: gadget: langwell: convert to new style 2011-10-13 20:39:55 +03:00
m66592-udc.c USB: irq: Remove IRQF_DISABLED 2011-09-18 01:39:36 -07:00
m66592-udc.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
Makefile usb: gadget: add new usb gadget for ACM and mass storage 2011-10-13 20:46:27 +03:00
mass_storage.c usb: gadget: storage: add superspeed support 2011-10-13 20:39:59 +03:00
multi.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
mv_udc_core.c Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb 2011-10-25 12:23:15 +02:00
mv_udc.h usb: gadget: mv_udc: add clock gating support 2011-10-13 20:42:09 +03:00
ncm.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
ndis.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
net2272.c usb: gadget: net2272: convert to new style 2011-10-13 20:39:56 +03:00
net2272.h USB: net2272: driver for PLX NET2272 USB device controller 2011-06-06 16:47:27 -07:00
net2280.c Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb 2011-10-25 12:23:15 +02:00
net2280.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
nokia.c usb: gadget: add max_speed to usb_composite_driver 2011-07-01 14:27:05 -07:00
omap_udc.c USB: irq: Remove IRQF_DISABLED 2011-09-18 01:39:36 -07:00
omap_udc.h
pch_udc.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
printer.c USB: g_printer: fix bug in unregistration 2011-09-18 01:33:06 -07:00
pxa25x_udc.c USB: irq: Remove IRQF_DISABLED 2011-09-18 01:39:36 -07:00
pxa25x_udc.h usb: gadget: pxa25x: is_vbus_present is gone 2011-10-13 20:39:53 +03:00
pxa27x_udc.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
pxa27x_udc.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
r8a66597-udc.c usb: gadget: r8a66597-udc: fix flush fifo handling 2011-11-14 11:51:20 -08:00
r8a66597-udc.h usb: gadget: r8a66597-udc: add support for SUDMAC 2011-10-13 20:38:39 +03:00
rndis.c
rndis.h
s3c2410_udc.c USB: irq: Remove IRQF_DISABLED 2011-09-18 01:39:36 -07:00
s3c2410_udc.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
s3c-hsotg.c usb: Provide usb_speed_string() function 2011-09-18 01:29:04 -07:00
s3c-hsudc.c s3c-hsudc: implement vbus_draw hook 2011-09-18 01:33:06 -07:00
serial.c usb: gadget: add max_speed to usb_composite_driver 2011-07-01 14:27:05 -07:00
storage_common.c usb: gadget: storage: add superspeed support 2011-10-13 20:39:59 +03:00
u_audio.c
u_audio.h
u_ether.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
u_ether.h usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
u_phonet.h
u_serial.c usb: Add export.h for EXPORT_SYMBOL/THIS_MODULE where needed 2011-10-31 19:31:25 -04:00
u_serial.h usb: gadget: add usb_endpoint_descriptor to struct usb_ep 2011-06-28 11:14:36 -07:00
udc-core.c usb: gadget: core: allow everybody to read sysfs attributes 2011-11-14 11:51:17 -08:00
usbstring.c
uvc_queue.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
uvc_queue.h
uvc_v4l2.c Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb 2011-10-25 12:23:15 +02:00
uvc_video.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
uvc.h Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb 2011-10-25 12:23:15 +02:00
webcam.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00
zero.c usb gadget: clean up FSF boilerplate text 2011-09-09 16:00:09 -07:00