From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753230AbcHPHMq (ORCPT ); Tue, 16 Aug 2016 03:12:46 -0400 Received: from mga01.intel.com ([192.55.52.88]:17060 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752215AbcHPHMn (ORCPT ); Tue, 16 Aug 2016 03:12:43 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,529,1464678000"; d="asc'?scan'208";a="1015069776" From: Felipe Balbi To: Nicolas Saenz Julienne Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: dwc3: gadget: don't rely on jiffies while holding spinlock In-Reply-To: <1471290014-6815-1-git-send-email-nicolassaenzj@gmail.com> References: <1471290014-6815-1-git-send-email-nicolassaenzj@gmail.com> User-Agent: Notmuch/0.22.1+63~g994277e (https://notmuchmail.org) Emacs/25.1.1 (x86_64-pc-linux-gnu) Date: Tue, 16 Aug 2016 10:12:23 +0300 Message-ID: <871t1p9oh4.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Nicolas Saenz Julienne writes: > __dwc3_gadget_wakeup() is called while holding a spinlock, then depends on > jiffies in order to timeout while polling the USB core for a link state > update. In the case the wakeup failed, the timeout will never happen and > will also cause the cpu to stall until rcu_preempt kicks in. > > This switches to a "decrement variable and wait" timeout scheme. > > Signed-off-by: Nicolas Saenz Julienne > --- > drivers/usb/dwc3/gadget.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > index 8f8c215..d0c711f 100644 > --- a/drivers/usb/dwc3/gadget.c > +++ b/drivers/usb/dwc3/gadget.c > @@ -1433,7 +1433,7 @@ static int dwc3_gadget_get_frame(struct usb_gadget = *g) >=20=20 > static int __dwc3_gadget_wakeup(struct dwc3 *dwc) > { > - unsigned long timeout; > + int retries; >=20=20 > int ret; > u32 reg; > @@ -1484,14 +1484,16 @@ static int __dwc3_gadget_wakeup(struct dwc3 *dwc) > } >=20=20 > /* poll until Link State changes to ON */ > - timeout =3D jiffies + msecs_to_jiffies(100); > + retries =3D 20000; >=20=20 > - while (!time_after(jiffies, timeout)) { > + while (retries--) { > reg =3D dwc3_readl(dwc->regs, DWC3_DSTS); >=20=20 > /* in HS, means ON */ > if (DWC3_DSTS_USBLNKST(reg) =3D=3D DWC3_LINK_STATE_U0) > break; > + > + udelay(5); let's just drop this udelay() here. It's very likely this will switch the link state much quicker than 100ms anyway. Other than that, nice catch :-) =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXsrzXAAoJEIaOsuA1yqREFp4QAJUFMDyjRTl/+SLIZMz82V/z /B6L0Oma9nrWYgkzAQ1l4lCwnUOrZX6CiPIUpQa5XRgZCMRVKNqUNKO1fqjHa1vm zb3xXVfXtd+FaiW8j/6VbYlGeZnioafXveUx+QsVZ2EGMz6pIbH2djFFzPI7veXL LPLEy0tMzepXCJquWY6DerTq2E4MmkCPfASVK5e5I6eqJE6r77t5JRaLIWrd/Ypm iYyLzO8JlTLs1o3ROGkDdZeGb/ZDUnKVlqjxNG+1u6qczfqGx5ZUC5mWX/i/NY+f e05n4Ewwb+8rWgeoIrx8LG1elt/DjzA1zvdyz6PR7aGJL3ZYhzKKhsWBZ6wnkmxs OaMyf6H4D795SmJ7OVmhzkCm9GhDxFdKbl6BWIqydSaZTs9LFhtR+dwlDY9CiL3t wyjKUbvyiZ/Q3LZM6alWd95MJ6DNoJhVFiz2lDD0yueCgHwylY3qE5EirTQ//6Py lg5/M59cN5i9L3e/r0chFSGFCrksVWia+5bldHUsvGeNsrG8hy7QGvKpkClrvThE dy8i+OShko3WS+zU3o3m65UUbvRGq8VcEcB2c5INMVgM5v4IcMasLiWvdXvPumfp btfSycgn6EKUVGnFW6TsL3dlK6xx2dc2iqpyoREaTLN6QuZRYa7o0Js0fNKv6gMY f1sIutwF1/Lgv2r7q3SA =Q4QL -----END PGP SIGNATURE----- --=-=-=--