Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp276196pxb; Wed, 27 Oct 2021 02:53:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsgmfliJTNV45a9uNQG264T++w/fV0mFSh8OKTsrI7PFl864DegCqBpPLDdQcdtIvZn2/M X-Received: by 2002:a50:950b:: with SMTP id u11mr43259770eda.121.1635328385933; Wed, 27 Oct 2021 02:53:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635328385; cv=none; d=google.com; s=arc-20160816; b=BMr05lCOEv4pI5JvYLDKuq2kPrtv1kHjL8vzGGEexgAfXvvyuWxbJkOe9JQvYiXbqQ 7bJyvLOhAxSqbX6oeNKoPlMN9eYEoO/CcneeG2ZS9Sdd/zDSMt0CX7IwUeoAzsXM3ik8 /5j9gghYKIElhBWBs0QXTyQHniGpKOzYxWq9dJXzw/1ecK7E8LbWObUu8ez8Tw5dZQlt 0kg3yjCmsfgXgORqaktXG+9qAAdG7HKKJksRs5qjG1CYTwZQ69wMv3h75Qb0kRaDRyCP Uz/mHX2rZedukAyE2e68M8wz+v5k+yvunI6OpTqL4MQCSSdjbH4Cp7K1ixBoEUwcXoqD H4ZQ== 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=jboiSRwJvMy7cqpSJRQcRDRWWEZYJWSw9hlVM10klyQ=; b=Is/teiK32YXJwKpv8xqGmFOpHHx0CmaXQ//I+aaZqoSJ6DOQjO/7YKWWMmBDC9gflQ 39Rf4AnJFdTcahIjIeqL1m9h2427O1PxVjia9Edcf4GM/A9x3OskQGbkarWSO0RTVUX8 TbSGGt2gF2liHRQzoh8E+KNdgLI1jSi3AXulL6nUTHPnSOOanHQhM8lKMTaZIbpBOziM hELpUDVywih0jgJ0/tPzDP1l1OoaYagyqmRp5fEPLkcjEr5R1wnXu/KgsqHXGKqRZVC1 zU5ki9rQAC45PSPce3ofo4vc/MVNjfFJrVK66jOzc3gRCxAn/Mc9C+bGe02Cbl3qXf7m HXlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=ubncl7lj; 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 j10si25394960edw.91.2021.10.27.02.52.40; Wed, 27 Oct 2021 02:53: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=@quicinc.com header.s=qcdkim header.b=ubncl7lj; 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 S236893AbhJZTml (ORCPT + 99 others); Tue, 26 Oct 2021 15:42:41 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:44225 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236859AbhJZTmi (ORCPT ); Tue, 26 Oct 2021 15:42:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1635277214; x=1666813214; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=jboiSRwJvMy7cqpSJRQcRDRWWEZYJWSw9hlVM10klyQ=; b=ubncl7lj6sE9ThQtDdrVYIExYpNWGituSLFbKzE/EvNWyQaoB9U/Zv0T /+4HrKwK9vdQapkGnTF1VIgIBcU51S5Ju613wMFFWa9r/EMaxl1k4B0m9 ET0F5zHCt+/utnN2SBL0FI3zBSNjDeF1Lt25QfQ4k8iMbEZ9GTIW2AyDq Y=; Received: from ironmsg07-lv.qualcomm.com ([10.47.202.151]) by alexa-out.qualcomm.com with ESMTP; 26 Oct 2021 12:40:13 -0700 X-QCInternal: smtphost Received: from nalasex01b.na.qualcomm.com ([10.47.209.197]) by ironmsg07-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2021 12:40:13 -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 12:40:12 -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> From: Wesley Cheng Message-ID: <81fc3f6d-f747-736b-32db-aecbca77dd31@quicinc.com> Date: Tue, 26 Oct 2021 12:40:04 -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: <20211026144140.GA1288435@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: nasanex01a.na.qualcomm.com (10.52.223.231) 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 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 :) Thanks Wesley Cheng