Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6017469pxb; Mon, 14 Feb 2022 13:14:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGz1fzVzfrEwFSSmFp/7ec0GfYK/Rwcd1ROLSOa4N+p5kfKbOy/udfgbsaoNBG392s4050 X-Received: by 2002:a17:902:8a8d:: with SMTP id p13mr939500plo.80.1644873244045; Mon, 14 Feb 2022 13:14:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644873244; cv=none; d=google.com; s=arc-20160816; b=iERnYWAAd5zdwdZUeujNZUTWN7cevC3+Djf5RoWfrxvN1iiffuimxEW+udcmDKigqJ eBW2g5+JgivpUFkWlFNwFk+X6fxtDy+TKR6c5v8EhFT0WLYyimVMIpJzeEF3O6zd8sSu QvTvnpXvbIZ/2rZm5kcOrbZ644J7fIfpKWNcKsTlYYAjYQL92GC7roESZVaP/zdPvCis +bUlaEuXRTFmr9DKtey0yyCel1PGv+oh63/zOnXWtluqjrTnlO/WIn8zxWPhdViEM0rP vf5j2GDLTE0WZCFmxDWfDoGjJj/RHg5O6/+CAIVSO8Y/95cNurKKCw5y1MtXQXJynRpI F3mw== 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=sfzntI0rstfx7mQ3o9W/zOXRSFp2P48vZxzBzu98hiI=; b=xEwvazaRJiduW5qZNw1bV6PaIVCKH4UFYgmHL8zhgMGF1TpOZ8Io0X8XvcpgNSJtbB wrL8FNUwXkWJE8PADRfsYp7wURRWAtLSzInBEl6iRzw7qfYOqNly83B1pAvzgKi3TG7t j9dmGYnXnYfCxeFRxVVQYlTvoJpln3uf2rRdN+0hFJ4xxFYY5Gh2mnkK3zKxNvRpLl46 iWIxMPKhtCMZuT1Y9vx0E7IArmsQCPZiLT65vKsql2gamoZBqeenw8xWpyUHOCctyFRF 2r1RttEWRJWNJ3nv7lc83eEvLG3y0Yw7f6lBMJQ1W3mab7vvAtccf61pesi4lkzeCVhy sNVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eNjwSNQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g4si819946pgw.101.2022.02.14.13.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:14:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eNjwSNQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 91E1110E544; Mon, 14 Feb 2022 12:32:41 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243808AbiBNJeA (ORCPT + 99 others); Mon, 14 Feb 2022 04:34:00 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243812AbiBNJdZ (ORCPT ); Mon, 14 Feb 2022 04:33:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F509BF6D; Mon, 14 Feb 2022 01:31:51 -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 ams.source.kernel.org (Postfix) with ESMTPS id C3E42B80DD1; Mon, 14 Feb 2022 09:31:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7B2FC340E9; Mon, 14 Feb 2022 09:31:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831108; bh=am5yNQtyIYQDH+bydUQ02sPjeH53/Ufx0EW0u8104+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eNjwSNQgPcfQK0GBYu0Ph1UXXsn3CoNd0Vp47mIVrw31MYjoyEYhMLsub/fzhcR/m E8ALV95eP98XLeSE3TxZ/tUhXwuEnecmOqpvTlo30xom4HN02WeObcmDw16QUaQAia rbsJqBaZ83hHlLLm9GsW1++yOBuYL1Dm1GWtL8qM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavankumar Kondeti , Udipto Goswami Subject: [PATCH 4.14 34/44] usb: dwc3: gadget: Prevent core from processing stale TRBs Date: Mon, 14 Feb 2022 10:25:57 +0100 Message-Id: <20220214092449.011455274@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092447.897544753@linuxfoundation.org> References: <20220214092447.897544753@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 @@ -1004,6 +1004,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);