Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1059797rwe; Thu, 1 Sep 2022 11:49:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR6B9SQs6zUUsGmYHovhW3g0yYfNTLlpOOCpK0Ck4oe2SHbwkgDmZccSxmYfHAJ5IFqjoUNp X-Received: by 2002:a05:6a00:1705:b0:52f:6028:5c33 with SMTP id h5-20020a056a00170500b0052f60285c33mr32392959pfc.29.1662058182983; Thu, 01 Sep 2022 11:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662058182; cv=none; d=google.com; s=arc-20160816; b=yrrtgoQ2tkDZCW4zSz3Br4nrAWYKWASaaVTsY+3s02g7EiemZye79DsBh/m3tSSqCc FT9TVYAtYAOaS6+VnccfQfEKuSWjyQhI7Mgaq6dX+gNCW/FAk4+HO7NoLoCEGmy0gH+t 4ktDpdC8AfWwy+lFu0PY5U9tjArlImPc7EKC1aViSN93SjNYX85Xb4HNFdffqGL9T1js AqxYz35h5zwaKwaljxVrNRNdCq6UMummUzAdfgV5S8idB9Rv+8AXiINv5U/dIwsbZV3v rWHOMl3LbM4XU1Y2NTHPxj4iyt1z85w9WJbfYkbhjmqxvK6C2SmmwTz/m68YGJwruxM2 aSiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gp/T7TTkgcWqynczYADUodBy760l62/++KKW+CN21Fo=; b=y0Gw7KamDoH53pi9sFYd8eRQEEPQNsOyl+Vz+etlqkpPcJWIaYAj1RVTymWx0WfETJ 8rFcAW4WIDMnMrjKyiYR3GMpUw2sXnYMYZ2gDvTnMXI+RF/8mQ6avqtV4hxXnfSshf7K IsHZG2y8O4XbWbTiW1+ue6khystZlnq6uXJ+Im/4Dfs4w+QvlAF6UgP2ADiwtz0yvNUQ A/pGHGV70TR9lWaXmLKUKatTL8iqN4ict66Gtr2RyNZYbZMNmkbORVC134eyMX6nh2rs c8A74oImHgn7IZyec4uugyDMEtA4Rp3bZS97XiQb7TKOI745OehcOgvZEspiw8eNLFYd H3yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MErEtr+l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p3-20020a170902eac300b001726dfa0765si17500857pld.575.2022.09.01.11.49.30; Thu, 01 Sep 2022 11:49:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MErEtr+l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229892AbiIASny (ORCPT + 99 others); Thu, 1 Sep 2022 14:43:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234216AbiIASni (ORCPT ); Thu, 1 Sep 2022 14:43:38 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3A0657571; Thu, 1 Sep 2022 11:43:37 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 281G4TOJ023386; Thu, 1 Sep 2022 18:43:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=gp/T7TTkgcWqynczYADUodBy760l62/++KKW+CN21Fo=; b=MErEtr+lrkMTOD90YOXHVrkiXGZtRjBlju7efIOQJ/wEMbxBzZaQg8quOF1ONpnpUkCM rEFv6w4TRfjP1g8fxwm4GTnSUokvOIe/Fjcjtd0qQxYV4f5HJ1SNo/DegDXnyId+bjH9 UdChQOI+kTTILC1jdn8e0IWyk6GrXSLVV9UTd042wbLcpsUQ0/f7Lf4y1r4AwpSiq1If WdlSEjpn92y3qBrBZJOomCARgxziufc183p/7EasbZDAOZgcoXpia5DP0SxvcHKBtvD/ Y88w7b9YiQHgYD3+nkskpmz2LMHXQHrJH7dSLO8eosthQeaZfK1iwbqatZNdloB+0hO3 jQ== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jab5gmvqu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Sep 2022 18:43:27 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 281IhQqV019930 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 1 Sep 2022 18:43:26 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) 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.986.29; Thu, 1 Sep 2022 11:43:26 -0700 From: Wesley Cheng To: , , CC: , , , Wesley Cheng Subject: [PATCH v6 1/5] usb: dwc3: Avoid unmapping USB requests if endxfer is not complete Date: Thu, 1 Sep 2022 11:43:10 -0700 Message-ID: <20220901184314.30481-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220901184314.30481-1-quic_wcheng@quicinc.com> References: <20220901184314.30481-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: aUQGL2_sAn208r1H_5M6HIprpyGDD4UZ X-Proofpoint-GUID: aUQGL2_sAn208r1H_5M6HIprpyGDD4UZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-09-01_12,2022-08-31_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=887 bulkscore=0 spamscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 adultscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209010080 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If DWC3_EP_DELAYED_STOP is set during stop active transfers, then do not continue attempting to unmap request buffers during dwc3_remove_requests(). This can lead to SMMU faults, as the controller has not stopped the processing of the TRB. Defer this sequence to the EP0 out start, which ensures that there are no pending SETUP transactions before issuing the endxfer. Reviewed-by: Thinh Nguyen Signed-off-by: Wesley Cheng --- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/ep0.c | 5 ++++- drivers/usb/dwc3/gadget.c | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 4fe4287dc934..7d5d2507244b 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1560,6 +1560,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd, int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd, u32 param); void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc); +void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status); #else static inline int dwc3_gadget_init(struct dwc3 *dwc) { return 0; } @@ -1581,6 +1582,8 @@ static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc, { return 0; } static inline void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc) { } +static inline void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep) +{ } #endif #if IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 33cee0089609..61de693461da 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -293,7 +293,10 @@ void dwc3_ep0_out_start(struct dwc3 *dwc) continue; dwc3_ep->flags &= ~DWC3_EP_DELAY_STOP; - dwc3_stop_active_transfer(dwc3_ep, true, true); + if (dwc->connected) + dwc3_stop_active_transfer(dwc3_ep, true, true); + else + dwc3_remove_requests(dwc, dwc3_ep, -ESHUTDOWN); } } diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index d6c0cb79ace3..6f2491fc109e 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -965,12 +965,16 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action) return 0; } -static void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) +void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) { struct dwc3_request *req; dwc3_stop_active_transfer(dep, true, false); + /* If endxfer is delayed, avoid unmapping requests */ + if (dep->flags & DWC3_EP_DELAY_STOP) + return; + /* - giveback all requests to gadget driver */ while (!list_empty(&dep->started_list)) { req = next_request(&dep->started_list);