Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4468104ybz; Tue, 28 Apr 2020 11:48:16 -0700 (PDT) X-Google-Smtp-Source: APiQypJ7XVyzwacmUY6jCG9Pm6ZXaz+0uq9G6UCD6W3dpyOTDd3xsWqVtoSgBtWwyFFipztWNsIs X-Received: by 2002:a17:906:3e44:: with SMTP id t4mr26402824eji.337.1588099696761; Tue, 28 Apr 2020 11:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588099696; cv=none; d=google.com; s=arc-20160816; b=fKvteBMreTmjUWg7k/Cs6E1vi37x9/7Ir9qbe8Bg4/IdZTe8Xbh2hHoehEgggXu1Q1 HSEZRsBc7drDLSOIQYVtvr1ncNeFB+r42gNCXDX5JvOzdglFoMzSabX9kylpr6zO3OR/ 6Hkn4Qepts4UFEWAMMQa4HkTih3IpzsLK2qeJeIlhnb7b5j5Qf8vcj+e7XfeSKNKxvda /reiaNyOnrjm6xcby6zlYH+SzwTNnq/UiqbjSFzo6XQo0AlQ3IytLK8uvCjJsoqLMRTb JmcLfNuUB6E07yCJJSj/yX49s8316yvQ61smrO1hmPD0nYqOKk/1iu64E9eVwg/qP0hc bybA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hFeKi2KdufswDgUOZOQnXzp6vJIiSZzEXun+bbrCUoU=; b=jPR0qm3KKhLIl3vgwUDIQx8aL+KSHlFZtQHjjbhiQq0G7/6xhMIeicW4F/xP0Th93R Nzmq4BwL1vE7KlUIQOhI69pAi6vVsKQKvlHMHdlMXy/VZ+gZvihVWubR+WKHYoidI35s 9pKqycpghPCN2SBmagvL60DjyIWb+9j2/qIv+geTBTjO0Yi9lYrs7ZbJazTBNgFjmwSf t/lb4Kx72qASUdUejiss7nZYWh0Tx5q8up4kYGmxrdHyk1xn/0oxXbGRyz8KcGiPaGKe 71GyOSFleRxjNG964TxsXubkFO3RiYvc6tytpXAinGsEHQGDzgsv+FKd5sbdoyJnvL+R EZcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TmAOsZZu; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v23si2288311ejo.321.2020.04.28.11.47.53; Tue, 28 Apr 2020 11:48:16 -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=@kernel.org header.s=default header.b=TmAOsZZu; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731253AbgD1Sne (ORCPT + 99 others); Tue, 28 Apr 2020 14:43:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:35938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730284AbgD1Snb (ORCPT ); Tue, 28 Apr 2020 14:43:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 29C8E20730; Tue, 28 Apr 2020 18:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588099410; bh=c9H+qpd47HYJ1J9D3GTa+VjseQBJ8oDJHKlKlFAPWDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TmAOsZZubuC+FUTpLa3CsxpKeBPaWqrhFXP+HMD2HFDiVAQbQzu3c2eBsEfDL8L6f oNZ9mqxyEKjBe2rsgD0Zv2dEQV86ZYtxUPxLi4lfI2VaLRksvrwGsj4up70x9vPxe+ iXPx6fGJ70S1I/3nUpEr1nNtdBWzNEgMV+aTchAM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn Subject: [PATCH 5.4 097/168] USB: early: Handle AMDs spec-compliant identifiers, too Date: Tue, 28 Apr 2020 20:24:31 +0200 Message-Id: <20200428182244.617311979@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200428182231.704304409@linuxfoundation.org> References: <20200428182231.704304409@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jann Horn commit 7dbdb53d72a51cea9b921d9dbba54be00752212a upstream. This fixes a bug that causes the USB3 early console to freeze after printing a single line on AMD machines because it can't parse the Transfer TRB properly. The spec at https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf says in section "4.5.1 Device Context Index" that the Context Index, also known as Endpoint ID according to section "1.6 Terms and Abbreviations", is normally computed as `DCI = (Endpoint Number * 2) + Direction`, which matches the current definitions of XDBC_EPID_OUT and XDBC_EPID_IN. However, the numbering in a Debug Capability Context data structure is supposed to be different: Section "7.6.3.2 Endpoint Contexts and Transfer Rings" explains that a Debug Capability Context data structure has the endpoints mapped to indices 0 and 1. Change XDBC_EPID_OUT/XDBC_EPID_IN to the spec-compliant values, add XDBC_EPID_OUT_INTEL/XDBC_EPID_IN_INTEL with Intel's incorrect values, and let xdbc_handle_tx_event() handle both. I have verified that with this patch applied, the USB3 early console works on both an Intel and an AMD machine. Fixes: aeb9dd1de98c ("usb/early: Add driver for xhci debug capability") Cc: stable@vger.kernel.org Signed-off-by: Jann Horn Link: https://lore.kernel.org/r/20200401074619.8024-1-jannh@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/early/xhci-dbc.c | 8 ++++---- drivers/usb/early/xhci-dbc.h | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) --- a/drivers/usb/early/xhci-dbc.c +++ b/drivers/usb/early/xhci-dbc.c @@ -728,19 +728,19 @@ static void xdbc_handle_tx_event(struct case COMP_USB_TRANSACTION_ERROR: case COMP_STALL_ERROR: default: - if (ep_id == XDBC_EPID_OUT) + if (ep_id == XDBC_EPID_OUT || ep_id == XDBC_EPID_OUT_INTEL) xdbc.flags |= XDBC_FLAGS_OUT_STALL; - if (ep_id == XDBC_EPID_IN) + if (ep_id == XDBC_EPID_IN || ep_id == XDBC_EPID_IN_INTEL) xdbc.flags |= XDBC_FLAGS_IN_STALL; xdbc_trace("endpoint %d stalled\n", ep_id); break; } - if (ep_id == XDBC_EPID_IN) { + if (ep_id == XDBC_EPID_IN || ep_id == XDBC_EPID_IN_INTEL) { xdbc.flags &= ~XDBC_FLAGS_IN_PROCESS; xdbc_bulk_transfer(NULL, XDBC_MAX_PACKET, true); - } else if (ep_id == XDBC_EPID_OUT) { + } else if (ep_id == XDBC_EPID_OUT || ep_id == XDBC_EPID_OUT_INTEL) { xdbc.flags &= ~XDBC_FLAGS_OUT_PROCESS; } else { xdbc_trace("invalid endpoint id %d\n", ep_id); --- a/drivers/usb/early/xhci-dbc.h +++ b/drivers/usb/early/xhci-dbc.h @@ -120,8 +120,22 @@ struct xdbc_ring { u32 cycle_state; }; -#define XDBC_EPID_OUT 2 -#define XDBC_EPID_IN 3 +/* + * These are the "Endpoint ID" (also known as "Context Index") values for the + * OUT Transfer Ring and the IN Transfer Ring of a Debug Capability Context data + * structure. + * According to the "eXtensible Host Controller Interface for Universal Serial + * Bus (xHCI)" specification, section "7.6.3.2 Endpoint Contexts and Transfer + * Rings", these should be 0 and 1, and those are the values AMD machines give + * you; but Intel machines seem to use the formula from section "4.5.1 Device + * Context Index", which is supposed to be used for the Device Context only. + * Luckily the values from Intel don't overlap with those from AMD, so we can + * just test for both. + */ +#define XDBC_EPID_OUT 0 +#define XDBC_EPID_IN 1 +#define XDBC_EPID_OUT_INTEL 2 +#define XDBC_EPID_IN_INTEL 3 struct xdbc_state { u16 vendor;