Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp544604pxb; Wed, 27 Oct 2021 07:51:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWFvkz7DYwWMwarn8xvBq/gssYq7Pjnk9bxGmLIqXzWuKb7ZeLFgNHvDnP0bS9CafBHPe+ X-Received: by 2002:a17:90b:1b51:: with SMTP id nv17mr6208117pjb.163.1635346313287; Wed, 27 Oct 2021 07:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635346313; cv=none; d=google.com; s=arc-20160816; b=eviXvdXU/2uDuttq72SGpsyhOmkUOFdjEevMiUoRJQjqHpjhRbJyZ9Mgw1qEqlMQOG C8vcrSh7azd7H5L5nnOOrL7sPquAD9BBi42XaqoOdm3GDkMv5pOVJKvajKtgj6DBiXJm 3PSOzPu6j/lMqRzwu6sVgq54zDm0hjtQOp34dD1IY/qHSPaIRZvXIwH9uGJ0u7FAq7T0 nf4RgSJoV8IsfWGyTF9iksfN6vxNBr6qPaQExfXHPcaPNruJbx4u+vzAM+5WUdM3I13b ZdjOkYr63Q1Tn3crqNORKX22yAYH4r4rVc4tIhCs97S8FUhdePWfJF10AhtRt3NEBKfk 0THw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=CiUcwr+Yg1b8BpUQefDDhnEVBo+pE6kk9p9NELtogrY=; b=gVN4QytnyQxAiL2ZP4t5vfvBTUxpo6Or95aX2ji+ZmOXY/Jvy9b6z/meiJwG9KbyOU JsVV7aF8hZs0kttEnd663IMobfDrYX+Uyc+iaY1wwSTJ/GY2g4asSUMMd87DiopeaPw9 vjTpyRIl1UNDGCSKmuK7icdMcmY70jXdu+xezs2y3S23JwuZxdNjqnTVCxe+PdycFxCt mOreRFaj+FGSym98zX2RtSnaeoNRsdSGw1KalErRGzrbhqAi7tA1g3W6FkuCRy0eWihR St05h/AFwNsVjJdhqOKH42umbJ7RzfHpAzV5h9HCR+2t79kBqPVya/3d26zT1ThWghlV tmrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=kXb+p3vw; 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=quicinc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be2si90670plb.184.2021.10.27.07.51.20; Wed, 27 Oct 2021 07:51:53 -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=@quicinc.com header.s=qcdkim header.b=kXb+p3vw; 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=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237280AbhJ0BVF (ORCPT + 99 others); Tue, 26 Oct 2021 21:21:05 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:22741 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237256AbhJ0BVE (ORCPT ); Tue, 26 Oct 2021 21:21:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1635297520; x=1666833520; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=CiUcwr+Yg1b8BpUQefDDhnEVBo+pE6kk9p9NELtogrY=; b=kXb+p3vwHmLdi8NJzF9gBDiBO1qOurV1LJQUKfHOuyHSUoRZXKW9oM/e MeOzbsBwlY+ZAw3ib8lvTPziOPZo2q/OO2wR3vxupmBqw25B1HYTHmxX+ Rn/9qKopKXthRc7A1mHYk+O/FkWq4X6VJ6AORr5Opc5tvwB68rmbRXFBq Y=; Received: from ironmsg08-lv.qualcomm.com ([10.47.202.152]) by alexa-out.qualcomm.com with ESMTP; 26 Oct 2021 18:18:39 -0700 X-QCInternal: smtphost Received: from nalasex01b.na.qualcomm.com ([10.47.209.197]) by ironmsg08-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2021 18:18:39 -0700 Received: from [10.110.50.18] (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Tue, 26 Oct 2021 18:18:38 -0700 Subject: Re: [PATCH] usb: gadget: f_mass_storage: Disable eps during disconnect To: Alan Stern CC: , , , , Wesley Cheng References: <20211026004456.23054-1-quic_wcheng@quicinc.com> <20211026144140.GA1288435@rowland.harvard.edu> <81fc3f6d-f747-736b-32db-aecbca77dd31@quicinc.com> <20211026205701.GA1300692@rowland.harvard.edu> From: Wesley Cheng Message-ID: <5737f9b3-14e0-8a83-f298-f44dcb57455a@quicinc.com> Date: Tue, 26 Oct 2021 18:18:37 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20211026205701.GA1300692@rowland.harvard.edu> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alan, On 10/26/2021 1:57 PM, Alan Stern wrote: > 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. > Sure, will do that and include it in the next rev. Thanks Wesley Cheng