Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4453949ybz; Tue, 28 Apr 2020 11:33:53 -0700 (PDT) X-Google-Smtp-Source: APiQypJx6TKjLAnnPoFShWiTVV71W2kyikApYf7FF5a6q1jupoeFZ46kl5l0Wxy0w4fQhKsYlJqq X-Received: by 2002:a50:ec95:: with SMTP id e21mr23925848edr.253.1588098833740; Tue, 28 Apr 2020 11:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588098833; cv=none; d=google.com; s=arc-20160816; b=vy/EP9nkAf6wx4DXGRVHyYuPwt/H1DPsbWt3l0+uHJvHumI7agJf/fue6aq/ID1FtV L9b0Wat+rlI1iJ6ctVGiXOcedqc/w0s2BvH+3fpqw0OwlpI9YyQD0phsHI0j6FiK5hnc ZRmvGpsQUfWvdLlrCgB9ihP+hMuFkzN7T/uLLcobFOeRk8kCx2FTZ/aJ9HqicN0MusV0 7gxDH3fUwmbNvAGvPiRP61vlWdXF3s4ANFQEW6Lz4miDqmm5LoxM6EwhmLX+WG7YnHY5 IQnm42B0AVUcLLGEc4EtCmzws2pZE1RbfBPzA27hPfarLdeKawSBsCXIb/oUCD+fpAdk KDZw== 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=AD+5kqzNF9iLimECnIyFowh+9H4Q5QwhzQMe18uKMSmKN3U6TuULoy+DCfqJHPJq+z bzWrTCQ4a9J1ei5wofz5aLH+KLHULBugL/4jvBhuD52vmd2kV+H5Tn+7T0r3XX4+J5bS ODQm5wNddgmDWDj5eONNIXSqMVPVJSRRkoZ8Lp23Dr3547qTvD21dQ3LmNh1zS3U2+Tg nha8CXZ05eRctVTeIFxoy9JE0WbLQxSGBTZMTTl0J93+cAEeVIsJwRWVAcXYTeUYCXzm 1+Tq3KpiNzd6QS7vvXeK9qnpoTewhcPvnLtFylTzb0RA5+nRnXrnJW3bsStwoY8X+ZJV 23FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lkfjG4u5; 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 j12si2124021ejt.110.2020.04.28.11.33.29; Tue, 28 Apr 2020 11:33:53 -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=lkfjG4u5; 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 S1729007AbgD1Sa4 (ORCPT + 99 others); Tue, 28 Apr 2020 14:30:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:46006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729567AbgD1Saw (ORCPT ); Tue, 28 Apr 2020 14:30:52 -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 ED49B21707; Tue, 28 Apr 2020 18:30:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588098651; bh=c9H+qpd47HYJ1J9D3GTa+VjseQBJ8oDJHKlKlFAPWDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lkfjG4u5g2o0b78LFZqtMGA19/Rrz9GmEbnp+/gCB7fScdHolGynslPkJa5MWoAlU YDxtr4PP7WDTzI/cdnPSmA2Io4XDjSIaFoKkYjnIF727IW7GfIzDsxiHkOFBRPXsi2 SwVeWYQiMTDMlwe6WRUQbSTAnT9aOVYBEi3Z7URQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn Subject: [PATCH 5.6 092/167] USB: early: Handle AMDs spec-compliant identifiers, too Date: Tue, 28 Apr 2020 20:24:28 +0200 Message-Id: <20200428182236.615243960@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200428182225.451225420@linuxfoundation.org> References: <20200428182225.451225420@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;