Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5995082pxb; Mon, 14 Feb 2022 12:40:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzQsSpIVc/hylj0CBCZDILdkwgvTWa8eRnof4ntQdz5Es3olYzhxAGObzxnXvZKPVO9c+2 X-Received: by 2002:a63:5641:: with SMTP id g1mr632235pgm.579.1644871201568; Mon, 14 Feb 2022 12:40:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644871201; cv=none; d=google.com; s=arc-20160816; b=CFkaUID8f+nUt3IodrCqTMB+bobAletRinlGTlIvSts7mXke2coQa9QPvDiRGuzu/e hRkrv2jbvtftUd8DUnzQtPy1msIKU4IkRzmU8oHoUf6LLDUAEOk9KVT9AMaOJdHVxAZZ 7YbFmcXQU1XgnyT76XOzcxA6IkSjRJiV0ayfXihIEAhV8zLdH110sUugbULnjGeX205G o5Gz9hqhybRP82SHOW1fzv2sjoEiGmBg2z7WyBCPJj3JAemQ19m2Y/u9418Ayj6E9DVi H1qJxe5uz/fNacMaSo8DmQIGcgIzXjCzAizQqgI3vMVC8rfSeQL3kq236E7rq9QXPggp GeOQ== 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=/dIMzHgRYPeAHKlp1gSE85gsovkd6HJEC49C72DomKI=; b=oU/eK6H0IbxxI+QfOEDv0AGZN6H/7Rpv1yvXB2NFgHTj9ohxDfuEEQpoXtcKcn6hjn gnac3JfF77ONMnO33U9glxooKq7NgT+yREI3W8D4CeZBAf3lzJ0b8ZkDo7zf9O1GsH/D KnFyG4+QTRDOzYfA9Cfb39iuxL1xY4gscC0w8zvYL8D4UBw4olU6ZIOCWu4xL1Qs+CKS jYlpkC3eUH3Qx347lBNqYAKrGIiCCcTrp1kG646T1xwIiNWllTyh5BMhwv8GnKv0DOtZ ez+zgy7DX/XWfKDVCaXCDYofnpWXLhEcw/TIqaAgjL73Ewb0Ds/vu4SdX5b3MHsGRXix 8S9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vTuk6Zz+; 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 u10si16173932plh.227.2022.02.14.12.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 12:40:01 -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=vTuk6Zz+; 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 7C68D1B1241; Mon, 14 Feb 2022 12:08:20 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343852AbiBNJz2 (ORCPT + 99 others); Mon, 14 Feb 2022 04:55:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344722AbiBNJvz (ORCPT ); Mon, 14 Feb 2022 04:51:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFF616D39A; Mon, 14 Feb 2022 01:43:10 -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 969ABB80DC4; Mon, 14 Feb 2022 09:43:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D028BC340F1; Mon, 14 Feb 2022 09:43:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831788; bh=LzpzpbXuAXBVxXgaTfhdtBconWX5rylvXkzDq4epIPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vTuk6Zz+najX446C0/4xDFjveNSiHEjRdtJ6R4+DOJeMebb6SGKvXcmcw4jfjvpRu NTaFYe94UvwRWhKhRsHxqn5Zoo0PrWqXxskTjVo15oZ16ZVO2wzHKt7e8dtf2vULfy 9CVQfdk+ljp3c/h66PMIs/X7SSL4aoMzu2oSyYpY= 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.10 096/116] usb: dwc3: gadget: Prevent core from processing stale TRBs Date: Mon, 14 Feb 2022 10:26:35 +0100 Message-Id: <20220214092502.091779498@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092458.668376521@linuxfoundation.org> References: <20220214092458.668376521@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 @@ -1072,6 +1072,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);