Received: by 10.223.176.46 with SMTP id f43csp2325821wra; Thu, 25 Jan 2018 08:12:25 -0800 (PST) X-Google-Smtp-Source: AH8x2246kyz62I/8B7EQM37LEZf5qiQts4d9FdvedmBdFvJGX9mKNFeUUEyHdAC6qNujrZOSb2cB X-Received: by 10.99.66.68 with SMTP id p65mr13091093pga.384.1516896745401; Thu, 25 Jan 2018 08:12:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516896745; cv=none; d=google.com; s=arc-20160816; b=UZRFq/iYhzIigb1JU1r1C+mVJ0VxHiP3D3ky1jI8Pa8si+9aFZqaGrzkGpkl+cBB2h 5FIAWkKwarBPm1t8pRwHQ5/6I4WB/+GIGMh5W85uAng3RY0BzYwhKKm6xfYdfFaE7JPe 4DsUFUm+0mqztIlrRHW2Ru4TX8h4aqtpaB8Rz2XaZPBci+rrnhnaxJNH+osRYSl4RlNT +sswCXehUx5t/aAiBoAOxy8RukRe0i/0JVpOFlWiwW54e+PQdxdI577XIlqVWjl22prG hHP6FH9bj5opwo8azXM6/UiKIz1RuKrXATnG6Y1BNunf/pTt5jLK6IoAIGLVWPCTe1Ie VP1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature :arc-authentication-results; bh=wflcV3ZtpkxG3d9cUvTH69rLh2trItIyGzAzrHGcqW0=; b=q13fxyzsXpnqcvVHyNbfp1SrSIACn+4rSKd5PX/2+DderP9s66YfN/zSsKo8ZzxVRN iSCJkW7GGV6uzkrWxQcdBowqAeH/VvDWrQjSze/hsL5pjFMmOS2Kul9VpJU/czF0duJD 4diuNOdXDAFNqwcvKu4OA8W2MtGmtJaQfMQTliz1WIAQEGwSMph685i/Z+2lCPE8uRWP O2q4mGDFooHeA/7obnFPFFdzJcPdFLHb/ofhDsn9FmL2QElvQvqMNDA7Q/VsQOpHsQvX YLlie5KogGpib04RPNOPb8GFgTCjY7wK2Q7PqwmdouC8R9INxHxIZbpsZZEJmZ4eeTLY sMFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=jjvyBZ2q; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4-v6si1732597plb.124.2018.01.25.08.12.10; Thu, 25 Jan 2018 08:12:25 -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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=jjvyBZ2q; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751200AbeAYQLm (ORCPT + 99 others); Thu, 25 Jan 2018 11:11:42 -0500 Received: from lelnx193.ext.ti.com ([198.47.27.77]:24028 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750992AbeAYQLl (ORCPT ); Thu, 25 Jan 2018 11:11:41 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id w0PGBcQo032685; Thu, 25 Jan 2018 10:11:38 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1516896698; bh=xCOVdF2/3K3ki3gI/l8qMF8Rr8BvLM/eJHebrmRldxY=; h=Subject:From:To:CC:References:Date:In-Reply-To; b=jjvyBZ2qbglD/rHST2U/SZapsBgyaU0EXfr3Q4MITRmW3yXhUvNxviUempAq/FfiN DkrXeChzTXK0EImNyX81nl7egCGHVHuLB5sZ+K1rTEvvXn8m/0TB/6BMSDkqb3Pd54 1u0EDDRHywg1B0lbA1dyUEfLZ0nc4f8wga88xmKk= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0PGBckN009510; Thu, 25 Jan 2018 10:11:38 -0600 Received: from DFLE106.ent.ti.com (10.64.6.27) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Thu, 25 Jan 2018 10:11:37 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Thu, 25 Jan 2018 10:11:37 -0600 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0PGBamM031322; Thu, 25 Jan 2018 10:11:36 -0600 Subject: Re: [PATCH 2/2] usb: dwc3: drd: Fix lock-up on ID change during system suspend/resume From: Roger Quadros To: Manu Gautam , CC: , References: <1516626103-1969-1-git-send-email-rogerq@ti.com> <1516626103-1969-3-git-send-email-rogerq@ti.com> <522f639a-466f-ae72-745e-61cbcc6fbfc7@codeaurora.org> <557afc49-712d-9e70-7e4a-b7b3e74b7a50@ti.com> <8c4da216-7468-df31-01e3-644601421049@ti.com> Message-ID: Date: Thu, 25 Jan 2018 18:11:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <8c4da216-7468-df31-01e3-644601421049@ti.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-GB Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 24/01/18 14:19, Roger Quadros wrote: > On 23/01/18 14:41, Roger Quadros wrote: >> Hi Manu, >> >> On 23/01/18 05:45, Manu Gautam wrote: >>> Hi, >>> >>> >>> On 1/22/2018 6:31 PM, Roger Quadros wrote: >>>> Adding/removing host/gadget controller before .pm_complete() >>>> causes a lock-up. Let's prevent any dual-role state change >>>> between .pm_prepare() and .pm_complete() to fix this. >>> >>> What kind of lock-up are you seeing? Some hardware lockup or software deadlock? >>> IMO using a freezable_wq for drd_work should address that? >>> >> >> I was seeing a software deadlock. freezable_wq is a good idea. I'll try it out. > > using freezable_wq doesn't get rid of the deadlock. > If I use freezable_wq plus add some delay before I do a dwc3_host_init() > in the work function then it starts to work. > > As dependence on delay looks fragile so I'll stick to the current implementation > based on .pm_prepare/complete(). > So I was able to reproduce the lock up with my series as well. On further investigation this is what I see. There are 2 different scenarios. 1) controller in host mode prior to system suspend and switches to device mode during resume. In this case when we call dwc3_host_exit() before tasks are thawed xhci_plat_remove() seems to lock up at the second usb_remove_hcd() call. This issue is resolved by using system_freezable_wq for the _dwc3_set_mode() function. 2) controller in device mode prior to system suspend and switches to host mode during resume. In this case we sleep indefinitely in _dwc3_set_mode due to dwc3_set_mode()->dwc3_gadget_exit()->usb_del_gadget_udc()->udc_stop()->dwc3_gadget_stop()->wait_event_lock_irq() This is not resolved by moving the dwc3_set_mode() call to .pm_complete() nor via the system_freezable_wq. One way I could fix this is like so. Felipe, could you please suggest a better way? Maybe we need to do this in dwc3_gadget_exit() before calling usb_del_gadget_udc() ? diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index b417d9a..0c903c1 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -109,6 +109,7 @@ static void __dwc3_set_mode(struct work_struct *work) struct dwc3 *dwc = work_to_dwc(work); unsigned long flags; int ret; + int epnum; if (!dwc->desired_dr_role) return; @@ -124,6 +125,17 @@ static void __dwc3_set_mode(struct work_struct *work) dwc3_host_exit(dwc); break; case DWC3_GCTL_PRTCAP_DEVICE: + spin_lock_irqsave(&dwc->lock, flags); + for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) { + struct dwc3_ep *dep = dwc->eps[epnum]; + + if (!dep) + continue; + + dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING; + } + spin_unlock_irqrestore(&dwc->lock, flags); + dwc3_gadget_exit(dwc); dwc3_event_buffers_cleanup(dwc); break; -- -- cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki