Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2288971pxb; Fri, 17 Sep 2021 06:36:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1fCBS3TBB5a6+D02Yy36R5rJHil/AauJFjCUOlzKGmPp/wmiOzX+K/xpGlha1yfXQp1nZ X-Received: by 2002:a05:6402:3459:: with SMTP id l25mr12405275edc.55.1631885765061; Fri, 17 Sep 2021 06:36:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631885765; cv=none; d=google.com; s=arc-20160816; b=a+xVmaLgx28jjjsjg/Rja/FScO3ejbg3ryGDAdwjm2USp6KCcMNdCfmZ72/rR6rRS7 EO2W0BXCEVKHF3bLopIkuxJKHtzBB7tVWYutY7QGYCK4uOt9emFqXgykxLJWtIGjkdat bH+VI/CNFyRnuQrOeMGVFLcdZ2YsP88wum2rlc7xwaM7Yknl5cQba+DYdHtWDrdSjltP ddz8SNRiRlzYT8aBQQOEUdKT1C58oDjQS4YXSU48pLxJsimUR/qEL+0/UOiD/4qD2bTS A4GwY2r7Mw8fdrmT76Mw4HesBGKAUCRmVAUliXhxyQncucsqWNadVEsyXoI7BJdd9Twv XmsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=LhlOWpW+kAjLdZm55TdOLKF9bUHaxhFeeSrLSxSBUtw=; b=nW5H22yKei5v09fP/RrCofwKO4gq1KAmkMVC07kDO2BMi8/Mso0feD5Zehv3xGwoAB ac2atxc0z0wF4B41rss4SVxelAMLYoSYYode+3KImleoitp5tJhkaxQpAdsXp5bKWzoR jtbeT1OyejwNZx+zYBwTHT2ku4w2Y0Y//Uqx5skBlOJRZfveIDGBLneG59F2RaOTNGjJ i/uSVLfSpuHdAXf6bLIM0r34rjr3Ek1qo9TJyBHaVutorZBKtXyBCONgR729vkZ3r6kF k/+UuxNLIlK5xypBDs6hgGfgtTiJ+cm3gE7YMwRhZoNl0JrsXIhh6HYrcBoTraHQYexm 25BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RYAlaM3s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a10si7014803ejf.122.2021.09.17.06.35.39; Fri, 17 Sep 2021 06:36:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RYAlaM3s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240978AbhIQJjj (ORCPT + 99 others); Fri, 17 Sep 2021 05:39:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:53622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234265AbhIQJji (ORCPT ); Fri, 17 Sep 2021 05:39:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 488CD60EB6; Fri, 17 Sep 2021 09:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631871496; bh=LcaAXhsUQp+yLFCh3WEuiolKi8ixI5lQSBUjEkFCBZc=; h=References:From:To:Cc:Subject:Date:In-reply-to:From; b=RYAlaM3sRsan4glS7tFrIMOkVlhVTzxYLp2FcP3LKubgwwyfKEXzsAelVt3QCpPkg iXymoK+8LDjDE3QdUV/gkVVEK16KBki5XLgh7CZ3vAL/uuJjBO5kHcCK3x/aPZhN0P RQyHa2QaBeBW3SiVctuL5+ooWxTa1b+OOebf8ncta3mNezscsBHvVvYEjPmlmo6FQe WYXqJG2M8QzqRQItmWjLC9yR2yEfU+zgvZ3RofVzN1LuDJrtv0XUTb/0WqmAFYAat7 hj0bwM4B2mjxYAp2n7En+R/UOeo3h/f9nMv7Xy7YY8N4jIZZyRxdEf6apR1MkqTUJb o1MQsorrXdI0Q== References: <20210917021852.2037-1-wcheng@codeaurora.org> <87y27vai3p.fsf@kernel.org> <474148e5-37e2-ea0c-7d78-9e71155314d9@codeaurora.org> User-agent: mu4e 1.6.5; emacs 27.2 From: Felipe Balbi To: Wesley Cheng Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: dwc3: gadget: Avoid starting DWC3 gadget during UDC unbind Date: Fri, 17 Sep 2021 12:37:55 +0300 In-reply-to: <474148e5-37e2-ea0c-7d78-9e71155314d9@codeaurora.org> Message-ID: <87h7eja6ey.fsf@kernel.org> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wesley Cheng writes: > Hi, > > On 9/16/2021 10:17 PM, Felipe Balbi wrote: >> >> Hi, >> >> Wesley Cheng writes: >> >>> There is a race present where the DWC3 runtime resume runs in parallel >>> to the UDC unbind sequence. This will eventually lead to a possible >>> scenario where we are enabling the run/stop bit, without a valid >>> composition defined. >>> >>> Thread#1 (handling UDC unbind): >>> usb_gadget_remove_driver() >>> -->usb_gadget_disconnect() >>> -->dwc3_gadget_pullup(0) >>> --> continue UDC unbind sequence >>> -->Thread#2 is running in parallel here >>> >>> Thread#2 (handing next cable connect) >>> __dwc3_set_mode() >>> -->pm_runtime_get_sync() >>> -->dwc3_gadget_resume() >>> -->dwc->gadget_driver is NOT NULL yet >>> -->dwc3_gadget_run_stop(1) >>> --> _dwc3gadget_start() >>> ... >>> >>> Fix this by tracking the pullup disable routine, and avoiding resuming >>> of the DWC3 gadget. Once the UDC is re-binded, that will trigger the >>> pullup enable routine, which would handle enabling the DWC3 gadget. >>> >>> Signed-off-by: Wesley Cheng > > Thanks, Felipe! > >> >> This looks okay to me, but needs to be tested by a few folks ;-) >> >> Acked-by: Felipe Balbi >> > Yes, would be good to get some functions using > usb_gadget_activate/deactivate(). It should be OK for those situations > as well, but just to make sure :) IIRC, the UVC function relies on those. You could give it a shot ;-) -- balbi