Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753487AbbHCOru (ORCPT ); Mon, 3 Aug 2015 10:47:50 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:47687 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751637AbbHCOrs (ORCPT ); Mon, 3 Aug 2015 10:47:48 -0400 Date: Mon, 3 Aug 2015 09:47:42 -0500 From: Felipe Balbi To: CC: , , , , , Subject: Re: [PATCH] usb: gadget: f_printer: fix the bug of deadlock caused by nested spinlock Message-ID: <20150803144742.GB1498@saruman.tx.rr.com> Reply-To: References: <1438600783-22333-1-git-send-email-fupan.li@windriver.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Pd0ReVV5GZGQvF3a" Content-Disposition: inline In-Reply-To: <1438600783-22333-1-git-send-email-fupan.li@windriver.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5146 Lines: 134 --Pd0ReVV5GZGQvF3a Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Mon, Aug 03, 2015 at 07:19:43PM +0800, fupan.li@windriver.com wrote: > From: fli >=20 > Function printer_func_disable() has called spinlock on printer_dev->lock, > and it'll call function chain of >=20 > printer_reset_interface() > | > +---dwc3_gadget_ep_disable() > | > +---__dwc3_gadget_ep_disable() > | > +---dwc3_remove_requests() > | > +---dwc3_gadget_giveback() > | > +---rx_complete() >=20 > in the protected block. >=20 > However, rx_complete() in f_printer.c calls spinlock on printer_dev->lock= again, > which will cause system hang. >=20 > The following steps can reproduce this hang: >=20 > 1. Build the test program from Documentation/usb/gadget_printer.txt as g_= printer > 2. Plug in the USB device to a host(such as Ubuntu). > 3. on the USB device system run: > #modprobe g_printer.ko > #./g_printer -read_data >=20 > 4. Unplug the USB device from the host >=20 > The system will hang later. >=20 > In order to avoid this deadlock, moving the spinlock from printer_func_di= sable() into > printer_reset_interface() and excluding the block of calling dwc3_gadget_= ep_disable(), > in which the critical resource will be protected by its spinlock in rx_co= mplete(). >=20 > This commit will fix the system hang with the following calltrace: >=20 > INFO: rcu_preempt detected stalls on CPUs/tasks: { 3} (detected by 0, t= =3D21006 jiffies, g=3D524, c=3D523, q=3D2) > sending NMI to all CPUs: > NMI backtrace for cpu 3 > CPU: 3 PID: 718 Comm: irq/22-dwc3 Not tainted 3.10.38-ltsi-WR6.0.0.11_sta= ndard #2 > Hardware name: Intel Corp. VALLEYVIEW B3 PLATFORM/NOTEBOOK, BIOS BYTICRB1= =2E86C.0092.R32.1410021707 10/02/2014 > task: f44f4c20 ti: f40f6000 task.ti: f40f6000 > EIP: 0060:[] EFLAGS: 00000097 CPU: 3 > EIP is at _raw_spin_lock_irqsave+0x35/0x40 > EAX: 00000076 EBX: f80fad00 ECX: 00000076 EDX: 00000075 > ESI: 00000096 EDI: ffffff94 EBP: f40f7e20 ESP: f40f7e18 > DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068 > CR0: 8005003b CR2: b77ac000 CR3: 01c30000 CR4: 001007f0 > DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000000 > DR6: ffff0ff0 DR7: 00000400 > Stack: > f474a720 f80fad00 f40f7e3c f80f93cc c135d486 00000000 f474a720 f468fb00 > f4bea894 f40f7e54 f7e35f19 ffffff00 f468fb00 f468fb24 00000086 f40f7e64 > f7e36577 f468fb00 f4bea810 f40f7e74 f7e365a8 f468fb00 f4bea894 f40f7e9c > Call Trace: > [] rx_complete+0x1c/0xb0 [g_printer] > [] ? vsnprintf+0x166/0x390 > [] dwc3_gadget_giveback+0xc9/0xf0 [dwc3] > [] dwc3_remove_requests+0x57/0x70 [dwc3] > [] __dwc3_gadget_ep_disable+0x18/0x60 [dwc3] > [] dwc3_gadget_ep_disable+0x89/0xf0 [dwc3] > [] printer_reset_interface+0x31/0x50 [g_printer] > [] printer_func_disable+0x20/0x30 [g_printer] > [] composite_disconnect+0x4b/0x90 [libcomposite] > [] dwc3_disconnect_gadget+0x38/0x43 [dwc3] > [] dwc3_gadget_disconnect_interrupt+0x3e/0x5a [dwc3] > [] dwc3_thread_interrupt+0x5c8/0x610 [dwc3] > [] irq_thread_fn+0x18/0x30 > [] irq_thread+0x100/0x130 > [] ? irq_finalize_oneshot.part.29+0xb0/0xb0 > [] ? wake_threads_waitq+0x40/0x40 > [] ? irq_thread_dtor+0xb0/0xb0 > [] kthread+0x94/0xa0 > [] ret_from_kernel_thread+0x1b/0x28 > [] ? kthread_create_on_node+0xc0/0xc0 >=20 > Signed-off-by: fupan li Thanks, out of curiosity, do you plan on sending a glue layer for Windriver's DWC3 ? cheers --=20 balbi --Pd0ReVV5GZGQvF3a Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVv38OAAoJEIaOsuA1yqRE/YsQAJzsyUTAFXb4F4NJsJcMh8l1 b+e5zc++WJeSw0hnyCg1C28IVseSoEDuL4+NQzonj3N374cEAKGduTM+ThhizDxu dnEd8ize7juXYFRFbTUlYIVpVB/EdowcAcviiN9AzauaKDYsZbH0QoLxA0PcFJS8 Fo/D7zcRMoEem0wPJhP2YZIuQzDnDMvzWh0bC50a121U2+ZQlHhtoNQILkx4h8Gw aevo6KcupcN76Mj3HMfr/2wjpvI7wtfMzabp0Cr6ZEMVOcPeWXi6bhVtq5fJvRX3 BdnllBnKqkxp9QRAneZ7Kba0g3LSyvM6QTPjUkRhwZ/qRZThxgPl2dKK7zuyEjKL 42lhtwfxS42/K3mRr4n7vj3L4N4YifgSvYEi2vszEKWnqLq0Mvya+WhvNBvxZi5J iCvhz4PUD/OuCziPVSjyW3uWTBw/p3Q/LxNNkS5tHh9Tse+enKcfnwkgv9Q3/uup OCwKfApqeZCAGxDUqaY18Dho4BdMJxdf86hEBrE/b+3Vx/Wskx4V+YlHTMoFdm0x eTYY5Gue0x77VmR/LJ+rYTB3Syok1Z9+/Vfx8jeRoAPhQoYRLLCuiox4zpPre/Rq QVL0yKFCKqAMhRa8n0ccSHFn0LKFbPkbFH/FgS08SAMWP9ljnhFeXF4/GrdAVmRQ jUnawLnaMVQRdL1MKY2R =pgKL -----END PGP SIGNATURE----- --Pd0ReVV5GZGQvF3a-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/