Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3019450pxb; Mon, 18 Oct 2021 06:44:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyb04WlXq4H1NX/fEZEMAd9cCILRKkdFTns5Hm44dVprmLas8ZUADgF5ikRYu5L/UbD6bOF X-Received: by 2002:a17:902:778a:b0:13f:672c:103a with SMTP id o10-20020a170902778a00b0013f672c103amr27699274pll.55.1634564641184; Mon, 18 Oct 2021 06:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564641; cv=none; d=google.com; s=arc-20160816; b=QQQrbpOsKAftsCOn5ckcuYK4LVoIeCvodk+UUN99xQqyp5YYXs5wHuv01PGJ0n5hBO MCR5q0mfHHgG75ATOQxjeVTZ9XS28Plnol/1NgnssPHqcCSi1YwjlbIgf0MmMCAc1775 2gxEUqSpQqi46SS7sFmbNOP5eSKr1kZQ0HK6wrhiONfwcN6hkhkD2JNFszXc4EfCm33r He30cQ8oYdMWBo2i9z98OJ+E043nGiOSRRvS39/aqJ/kjgDR8FHGDUfBNO31JuSSoHlI uthDavH/jSObO242ClyUwnS05PV/8lsbuTq1UO4F6K4Vrjj9WQasYK12mIOgbDNHaAAF MWTw== 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=Ngv8aIekEFqUkh0vPnY6/YmLIKpIIwA8xqgeCuDqYZ4=; b=b9JzukSqZorU1GH8uDUTD7iRY5jEmc2kxxt8yX45T7tcr6sFMDmxiTK9Xtw443M+Bv DY/u6acXzKToB9g7hKQablgc9tWjwWwQ566MxF6DnzCeu+2xIPHIGZCtj6KIAWt25zzX WWIzO1Xz/NEyFKnCv6cbdTpl+Hx0Xvmuo5CKTdDxBcYtt6ncX99IZsMC6TOPinATYrj4 0v6ur7dhBnn42WSODWckHHIE4Fh05v7ClQ6hYD0wWBuRRWttfVVdt1CowwDYfMXwkQpI AKdEK+N9Y9uEhG9WnPCIzPPs4trhBvjmtz5FpSoeUw/GQWZQvaaK3WrUzH0A0DVEG0wy I7pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WGxhNejT; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e8si14225968pgh.242.2021.10.18.06.43.46; Mon, 18 Oct 2021 06:44:01 -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=@linuxfoundation.org header.s=korg header.b=WGxhNejT; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231878AbhJRNmr (ORCPT + 99 others); Mon, 18 Oct 2021 09:42:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:54296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233544AbhJRNkn (ORCPT ); Mon, 18 Oct 2021 09:40:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 371516141B; Mon, 18 Oct 2021 13:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564006; bh=pDu/IPnPapPSK6jz7xzmTWYUqFAKslTvZWZMu84OoVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGxhNejTD16Slb67xKGKDe259knVqpdsmNaM+SnQZqKBAAJC7fozauLyYD6KfKHUa hx1+4oO00Ne8J+F2cMJH5P+RKKtROMVPsDNBOadP1pqY4rRwP1AbVyGDq3O1wsxddQ SW2SB2Bg4bpknnD1luobO5ErOstrRpwV4XYQQle8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavankumar Kondeti , Mathias Nyman Subject: [PATCH 5.10 029/103] xhci: Fix command ring pointer corruption while aborting a command Date: Mon, 18 Oct 2021 15:24:05 +0200 Message-Id: <20211018132335.696362149@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132334.702559133@linuxfoundation.org> References: <20211018132334.702559133@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavankumar Kondeti commit ff0e50d3564f33b7f4b35cadeabd951d66cfc570 upstream. The command ring pointer is located at [6:63] bits of the command ring control register (CRCR). All the control bits like command stop, abort are located at [0:3] bits. While aborting a command, we read the CRCR and set the abort bit and write to the CRCR. The read will always give command ring pointer as all zeros. So we essentially write only the control bits. Since we split the 64 bit write into two 32 bit writes, there is a possibility of xHC command ring stopped before the upper dword (all zeros) is written. If that happens, xHC updates the upper dword of its internal command ring pointer with all zeros. Next time, when the command ring is restarted, we see xHC memory access failures. Fix this issue by only writing to the lower dword of CRCR where all control bits are located. Cc: stable@vger.kernel.org Signed-off-by: Pavankumar Kondeti Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20211008092547.3996295-5-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-ring.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -342,16 +342,22 @@ static void xhci_handle_stopped_cmd_ring /* Must be called with xhci->lock held, releases and aquires lock back */ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags) { - u64 temp_64; + u32 temp_32; int ret; xhci_dbg(xhci, "Abort command ring\n"); reinit_completion(&xhci->cmd_ring_stop_completion); - temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); - xhci_write_64(xhci, temp_64 | CMD_RING_ABORT, - &xhci->op_regs->cmd_ring); + /* + * The control bits like command stop, abort are located in lower + * dword of the command ring control register. Limit the write + * to the lower dword to avoid corrupting the command ring pointer + * in case if the command ring is stopped by the time upper dword + * is written. + */ + temp_32 = readl(&xhci->op_regs->cmd_ring); + writel(temp_32 | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); /* Section 4.6.1.2 of xHCI 1.0 spec says software should also time the * completion of the Command Abort operation. If CRR is not negated in 5