Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6013152pxb; Mon, 14 Feb 2022 13:07:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxtrLjOp4QufEV/oKa5b22akFJpCGo8z6aVSzoFFTLsWeJYBEPey54pOHdppIQKtfy5Ntv X-Received: by 2002:a17:90a:dd46:b0:1b8:8:7303 with SMTP id u6-20020a17090add4600b001b800087303mr505786pjv.197.1644872879237; Mon, 14 Feb 2022 13:07:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644872879; cv=none; d=google.com; s=arc-20160816; b=iZ5xR/C1TrxQGEc8NS29PgUAykonUO0s9AS+j4LnZgzuuya566znsYuS5d5VKE/rN9 4mWpYtjLDaOq5EmY5H2gQh9axsdjq36rEqpzuMJBx7AZmsqkuIL0qd/OC0jvIwwI9UPu R5ZNIa/KQKZHDZ0uGDqCTAxsQiaA9ry2vFnGlhRahCa+t5rK0jbDMBoG7Yjeg1pWocVa Styp2D14DwgIP4Vo/faEc1KqHp1r8MCUWbAFiu2I4UaiOEulSXlfr+HWvP5aCWKwn511 3MTDkAD4wrjWEPrlgW8lkt6RUB/aS/qFnWYmGdCX5xv9qkX/3vXCwT4Yp2ChtH/geJaC zoFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1j410O8V1TSAoXLwWNPRD9Oae1BPocgbd6Xay+51TY0=; b=iDvF4ikfq3udtTybuNzTbJnaD/xxUgQpX48WrrWDBYvfscK1WVSEVOFpUWxBitKcvz ib2cB4hcZBsOt3IMbAA88v253XEAc1QKIce5K5XL6xNAAEdm0+a6eDV57MmAUVAoLcDq r0wVhJIGdA0GDOme4V8albGQmBLfattyusZ9h6NhnVkR3WmgDS5ZmworPPzim7mT5Y2w rqs00vsllJwC6VUuTRjFcY1Aw9d4sBKfBR/yAyQz/tzs5w3ktz72KAiKmObVZgbkqB4K LBBeTfXnGDWrOBMt1OpIPJ/kYAXg1nE5ze2DOwJ3o38rL11c9uT7QVOCy4TuzG/8Xe+c DKgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BzJP9sPM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e27si824861pge.40.2022.02.14.13.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:07:59 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BzJP9sPM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DDC6E1FEBF6; Mon, 14 Feb 2022 12:27:14 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346024AbiBNKOg (ORCPT + 99 others); Mon, 14 Feb 2022 05:14:36 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345696AbiBNKNN (ORCPT ); Mon, 14 Feb 2022 05:13:13 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E11E6657A4; Mon, 14 Feb 2022 01:51:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7CD0E60F65; Mon, 14 Feb 2022 09:51:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F140C340E9; Mon, 14 Feb 2022 09:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644832298; bh=t432ehytwEm0n0pKMk01J/w73y/O1PlVDyrqrXrTCqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BzJP9sPMnWvjo/K8/bZuStuJd8l7WX/nQjsI3B6qqvFyd+RqFMT2bzMOaBusPjVMb TPWb1uZDQPutZN+WMHL33rG+RfpfkHwuWAunFFJnvy8iSXfSSbYs59vPmdH4out38n CKcDJJBxW1ISGCU0AuuyE+azr6DRPlt3VSG8u6RE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavankumar Kondeti , Udipto Goswami Subject: [PATCH 5.15 143/172] usb: dwc3: gadget: Prevent core from processing stale TRBs Date: Mon, 14 Feb 2022 10:26:41 +0100 Message-Id: <20220214092511.331365197@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092506.354292783@linuxfoundation.org> References: <20220214092506.354292783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Udipto Goswami commit 117b4e96c7f362eb6459543883fc07f77662472c upstream. With CPU re-ordering on write instructions, there might be a chance that the HWO is set before the TRB is updated with the new mapped buffer address. And in the case where core is processing a list of TRBs it is possible that it fetched the TRBs when the HWO is set but before the buffer address is updated. Prevent this by adding a memory barrier before the HWO is updated to ensure that the core always process the updated TRBs. Fixes: f6bafc6a1c9d ("usb: dwc3: convert TRBs into bitshifts") Cc: stable Reviewed-by: Pavankumar Kondeti Signed-off-by: Udipto Goswami Link: https://lore.kernel.org/r/1644207958-18287-1-git-send-email-quic_ugoswami@quicinc.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1271,6 +1271,19 @@ static void __dwc3_prepare_one_trb(struc if (usb_endpoint_xfer_bulk(dep->endpoint.desc) && dep->stream_capable) trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(stream_id); + /* + * As per data book 4.2.3.2TRB Control Bit Rules section + * + * The controller autonomously checks the HWO field of a TRB to determine if the + * entire TRB is valid. Therefore, software must ensure that the rest of the TRB + * is valid before setting the HWO field to '1'. In most systems, this means that + * software must update the fourth DWORD of a TRB last. + * + * However there is a possibility of CPU re-ordering here which can cause + * controller to observe the HWO bit set prematurely. + * Add a write memory barrier to prevent CPU re-ordering. + */ + wmb(); trb->ctrl |= DWC3_TRB_CTRL_HWO; dwc3_ep_inc_enq(dep);