Received: by 10.223.185.116 with SMTP id b49csp2490544wrg; Mon, 5 Mar 2018 03:57:35 -0800 (PST) X-Google-Smtp-Source: AG47ELvglfTYTNT3ncyXHCcsRm5eQJsxsDEidXh6w8W5sH/rRLPR3hgdKEnEVSTTimunROavfU8W X-Received: by 2002:a17:902:407:: with SMTP id 7-v6mr12998052ple.9.1520251055516; Mon, 05 Mar 2018 03:57:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520251055; cv=none; d=google.com; s=arc-20160816; b=dSbOBmBfSLAHKyIyuQI2iz1LIn0ipOOoo4DQTHPNVDl9C3pJkehrJDfEqWmw2Hcw/y sDi55//P5xVJ6kh/XkGMOrteImqbaf1vkNO323kIHWdcjj7hyoGH0IBlNoNTRAA4WsZ9 HHHHRKS1Y2xvjMjOxvOESwv6LUOkloMAE20KEa3nHFOM+7N4AsqDly03Tob5i3TgrL1s qkBPEylw1BRbZwpzkVNkRJ/n05iEO/sw7QRFlyBUasdPV+JZXQ/qKXUXm5RSI8FoUHch C9KVHaH/+y0jZ5wOm4QF8A8u3Dy1yUNBrThSXuZrpu01KgHE+qXGEE9oNgWTMG66zfAL s8Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:arc-authentication-results; bh=jQMjdvgyaGySQFUWQmnry7XMSXGwXzUqORsFujlKHog=; b=iM1ya9xLT2oIGgCoEDJx+dbrBWDwie8gva31P7zm/e9D1n/yp4ceqPTnDjlNmakqV+ nrPi0Yw/DbfaBB/IQ7ufCi5Q7rGP88yHqlTHhqetbx7w70RJwMOKRh4Kty/fcTZvMJFu kFVU5y/5IZxa1lSdGH6eCYPKAwiW4HkZ0DVkjJsrWHrK01OZx56UoZONnkqsHIhNLP5L oV5aVtF/0YZeYY723V1rY3j67AZZ+t1G4wmZaAyYs8/viHyZV8gCRIrkkBo8uzHWpTL7 Tg9N9Cu5HiILftVCVOpmwW7sJMrvXGJTnJa8I4HQVyZhT8QUMQYP1RxnXFudBahwoCU8 Igtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m9si10136384pfi.212.2018.03.05.03.57.21; Mon, 05 Mar 2018 03:57:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934542AbeCEL2Y (ORCPT + 99 others); Mon, 5 Mar 2018 06:28:24 -0500 Received: from mga09.intel.com ([134.134.136.24]:5165 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933439AbeCEL2X (ORCPT ); Mon, 5 Mar 2018 06:28:23 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 03:28:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,426,1515484800"; d="asc'?scan'208";a="34695027" Received: from pipin.fi.intel.com (HELO localhost) ([10.237.68.37]) by fmsmga004.fm.intel.com with ESMTP; 05 Mar 2018 03:28:20 -0800 From: Felipe Balbi To: Baolin Wang , Roger Quadros Cc: USB , LKML Subject: Re: [PATCH] usb: dwc3: Prevent indefinite sleep in _dwc3_set_mode during suspend/resume In-Reply-To: References: <1519730526-22274-1-git-send-email-rogerq@ti.com> <87sh9l5z4l.fsf@linux.intel.com> <94cd6377-1327-2309-8d69-6ab0de2bdfd4@ti.com> <87po4i3o1v.fsf@linux.intel.com> <87k1uq3ho6.fsf@linux.intel.com> <8ec0485e-89af-568b-e34a-b0cd490817d0@ti.com> Date: Mon, 05 Mar 2018 13:27:26 +0200 Message-ID: <87h8puwyn5.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, Baolin Wang writes: >>>>>>>>> void dwc3_gadget_exit(struct dwc3 *dwc) >>>>>>>>> { >>>>>>>>> + int epnum; >>>>>>>>> + unsigned long flags; >>>>>>>>> + >>>>>>>>> + spin_lock_irqsave(&dwc->lock, flags); >>>>>>>>> + for (epnum =3D 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) { >>>>>>>>> + struct dwc3_ep *dep =3D dwc->eps[epnum]; >>>>>>>>> + >>>>>>>>> + if (!dep) >>>>>>>>> + continue; >>>>>>>>> + >>>>>>>>> + dep->flags &=3D ~DWC3_EP_END_TRANSFER_PENDING; >>>>>>>>> + } >>>>>>>>> + spin_unlock_irqrestore(&dwc->lock, flags); >>>>>>>>> + >>>>>>>>> usb_del_gadget_udc(&dwc->gadget); >>>>>>>>> dwc3_gadget_free_endpoints(dwc); >>>>>>>> >>>>>>>> free endpoints is a better place for this. It's already going to f= ree >>>>>>>> the memory anyway. Might as well clear all flags to 0 there. >>>>>>>> >>>>>>> >>>>>>> But it won't solve the deadlock issue. Since dwc3_gadget_free_endpo= ints() >>>>>>> is called after usb_del_gadget_udc() and the deadlock happens when >>>>>>> >>>>>>> usb_del_gadget_udc()->udc_stop()->dwc3_gadget_stop()->wait_event_lo= ck_irq() >>>>>>> >>>>>>> and DWC3_EP_END_TRANSFER_PENDING flag is set. >>>>>> >>>>>> indeed. Iterating twice over the entire endpoint list seems >>>>>> wasteful. Perhaps we just shouldn't wait when removing the UDC since >>>>>> that's essentially what this patch will do, right? If you clear the = flag >>>>>> before calling ->udc_stop(), this means the loop in dwc3_gadget_stop= () >>>>>> will do nothing. Might as well remove it. >>>>>> >>>>> >>>>> This means that we will never wait for DWC3_EP_END_TRANSFER_PENDING t= o clear >>>>> in dwc3_gadget_stop() like we used to. This is perfectly fine, right? >>>>> >>>>> It makes sense to me as dwc3_gadget_stop() calls __dwc3_gadget_stop()= which >>>>> masks all interrupts and nobody will ever clear that flag if it was s= et. >>>> >>>> I don't think so. It can not mask the endpoint events, please check >>>> the events which will be masked in DEVTEN register. The reason why we >>>> should wait for DWC3_EP_END_TRANSFER_PENDING to clear is that, >>>> sometimes the DWC3_DEPEVT_EPCMDCMPLT event will be triggered later >>>> than 100us, but now we may have freed the gadget irq which will cause >>>> crash. >>> >>> We could mask command complete events as soon as ->udc_stop() is called, >>> right? Hmm, actually, __dwc3_gadget_stop() already clears DEVTEN >>> completely. >> >> But which bit in DEVTEN says Endpoint events are disabled? > > When we set up the DWC3_DEPCMD_ENDTRANSFER command in > dwc3_stop_active_transfer(), we can do not set DWC3_DEPCMD_CMDIOC, > then there will no endpoint command complete interrupts I think. > > cmd |=3D DWC3_DEPCMD_CMDIOC; I remember some part of the databook mandating CMDIOC to be set. We could test it out without and see if anything blows up. I would, however, require a lengthy comment explaining that we're deviating from databook revision x.yya, section foobar because $reasons. :-) =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEElLzh7wn96CXwjh2IzL64meEamQYFAlqdKZ4ACgkQzL64meEa mQYUMQ/7BWM2yEv+HZ4zQ0HmbWeYiBsoCtwk9jpkaBy/a/2k0cW99l6xMwRSvQlK LUkghq+MbWtn0naRHBpI69kQ1QmIr81rowSBIKr+imAoc4lZQQgnZl0VnXh+OsuB +I56uCKhitmrzF16KBgOy0G8P1bmi8NJmmImyHOy4IFQxQeRMP5X1ETFf10+Ft/s 94irRnGDpyNevg35wW/IVMtJH/jhvy2RZyjp0NICZQLzBMhumjQ8N2Prc+jecPHJ KUpCA/Nh9ByQG5CZgJ0Taioc2E+o30NEvBMEl4698HWmPa54bAyHI9sy5/1pc8kb y9j7s3hBDPoyFEqxnM74no+y8cslI9BcMNpDxy5dItizU2vhSPAQ33fj7e3SFyPg fkhr12VJGKKnPgTc3T5i2Ckc/Jbh9mVC7vYPmHw7ADyLfRBBSVQk830Duvux575r 5FDCjNIXdNvwYpGcxV2eSoB1zhW6xhTwENFppyll3TZeiArFj8RS8YNFiqVvORaj V1NmLI7pAVZ2ajxODG4evtBrRLWGqvMGknysIkkCQipmpw7kH7dHVv43jS1LFbWe Mob9B9Lydpxw3WDoQIZ/Q58J9qxEJBZ9BAbGoNN6CtZrtXGPIGVeBktf7+Q4AC9z tDg4to33j/5qJDPbA35YEur9wHWKDDdKP/isW7VaFKW9IVDShZ8= =HMBs -----END PGP SIGNATURE----- --=-=-=--