Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp304164pxb; Wed, 27 Oct 2021 03:24:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydgP5mOeZPyFNq+EKwo2yMsmqUew6Sh7g92A1gpKxvGMO3aEdcfN8Q8T36VcmttOLGUmlQ X-Received: by 2002:a62:7f4a:0:b0:44d:292f:cc24 with SMTP id a71-20020a627f4a000000b0044d292fcc24mr31553737pfd.58.1635330280839; Wed, 27 Oct 2021 03:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635330280; cv=none; d=google.com; s=arc-20160816; b=vxmZ1rwmshckRiQGJ5eek29/gSqzhF3lI2zxbdtlumLorEiFvdeg33lYFeeIN+vRv2 0JZwVejOXqAJmbZ22AeREQRlIPahWBBCIiuZYJc9TmXPUHIJPCbgzEfJxszPU1KFtBSY a7RXMdyglPWTBSucZPfr2Xs/535HvtdCzi2ZufFEso/RVxweO73TEoMo4kOyBnwN5jzq vlKytLfbA5x84pojXXv5yjZhK4papL4HCgunqxmQGEUDhy9gTO+sAmmzi3Zz2BlucPEo F1937GCxLV+A0t25e17b6BLXRLqx4FVeE92NV+ysOjPmLRgEi24JD7YEL4rIGb716oF9 6BmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=5WA/O5yTcIyd2ZS4b5bEHK030uHs2xUZNZAxVxblAUY=; b=Xy3aTE0VlbIjF6dUrBA1Wxt0mjcdyHskAgnTItoRHZxvCf5t3w8aEm8BTCLdFlATN2 +A4V2fF+UGDPJj7gWrIp71cDXN6ypT2yTf9pIb8sTlUR4lf9CRndtycgXQuqm/6t7Bi+ NuN4ArUm37dbqpoQZx2Za4Jgjozie7h+4tWbRl09p3EDtQ7a5iaDDB014UJJXV16SWcS sdI0LRqiQbIU36+puZIZlVqypCymklcy/hIXdEAhloAw+kpvRi2jSRyv/NhwcBxz14l1 z2maFYTDgdZdNB/rP0K5PxV/H6Utu2HbgEcCPm9GA1QYdg9ITGtJRpyVrSLRD+y+rSBD WhQA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c76si13946306pfb.237.2021.10.27.03.24.27; Wed, 27 Oct 2021 03:24:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239328AbhJZU71 (ORCPT + 99 others); Tue, 26 Oct 2021 16:59:27 -0400 Received: from netrider.rowland.org ([192.131.102.5]:50731 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S231396AbhJZU71 (ORCPT ); Tue, 26 Oct 2021 16:59:27 -0400 Received: (qmail 1300783 invoked by uid 1000); 26 Oct 2021 16:57:01 -0400 Date: Tue, 26 Oct 2021 16:57:01 -0400 From: Alan Stern To: Wesley Cheng Cc: balbi@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Wesley Cheng Subject: Re: [PATCH] usb: gadget: f_mass_storage: Disable eps during disconnect Message-ID: <20211026205701.GA1300692@rowland.harvard.edu> References: <20211026004456.23054-1-quic_wcheng@quicinc.com> <20211026144140.GA1288435@rowland.harvard.edu> <81fc3f6d-f747-736b-32db-aecbca77dd31@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <81fc3f6d-f747-736b-32db-aecbca77dd31@quicinc.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 12:40:04PM -0700, Wesley Cheng wrote: > Hi Alan, > > On 10/26/2021 7:41 AM, Alan Stern wrote: > > On Mon, Oct 25, 2021 at 05:44:56PM -0700, Wesley Cheng wrote: > >> From: Wesley Cheng > >> > >> When receiving a disconnect event from the UDC, the mass storage > >> function driver currently runs the handle_exception() routine > >> asynchronously. For UDCs that support runtime PM, there is a > >> possibility the UDC is already suspended by the time the > >> do_set_interface() is executed. This can lead to HW register access > >> while the UDC is already suspended. > >> > >> Signed-off-by: Wesley Cheng > >> --- > >> drivers/usb/gadget/function/f_mass_storage.c | 10 ++++++++++ > >> 1 file changed, 10 insertions(+) > >> > >> diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c > >> index 3cabf7692ee1..752439690fda 100644 > >> --- a/drivers/usb/gadget/function/f_mass_storage.c > >> +++ b/drivers/usb/gadget/function/f_mass_storage.c > >> @@ -2342,6 +2342,16 @@ static void fsg_disable(struct usb_function *f) > >> { > >> struct fsg_dev *fsg = fsg_from_func(f); > >> > >> + /* Disable the endpoints */ > >> + if (fsg->bulk_in_enabled) { > >> + usb_ep_disable(fsg->bulk_in); > > > > According to the kerneldoc, this routine must be called in process > > context. > > > >> + fsg->bulk_in_enabled = 0; > >> + } > >> + if (fsg->bulk_out_enabled) { > >> + usb_ep_disable(fsg->bulk_out); > >> + fsg->bulk_out_enabled = 0; > >> + } > >> + > >> __raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE, NULL); > >> } > > > > Looks like you'll have to find a different way to avoid the problem. > > For example, if an exception is pending then you might prevent the > > gadget from going into runtime suspend until the exception has been > > handled. > > > Thanks for the suggestion. I noticed that a lot of other FDs currently > call usb_ep_disable() in the disable/disconnect path as well. Actually, > f_mass_storage seems to be the only one that doesn't do so. Maybe we > should change the kerneldoc :) You're right; I don't see any real reason why the usb_ep_{en,dis}able routines can't run in an atomic context. So if you to make this change to f_mass_storage, you should first submit a patch changing the kerneldoc. Alan Stern