Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13476052ybl; Sun, 29 Dec 2019 12:49:30 -0800 (PST) X-Google-Smtp-Source: APXvYqwve38pXTNxFr5kTIoOZImDcXLBzBWrT6uzpaKz9PpmGbEbAsKWnHl+mR/HuRjr6YiPlGG3 X-Received: by 2002:a05:6830:4a7:: with SMTP id l7mr65125397otd.372.1577652570690; Sun, 29 Dec 2019 12:49:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652570; cv=none; d=google.com; s=arc-20160816; b=uRKpTb9A45WZ62oyp286z7dD781oU2Ax+CTbMYC9CAUAt9QguQ8eMKnAMdMELJL+PT d2izN2e1dCgwLWJ+nMAS8L1FWpWXYvImuO6THsrfr6UcBJEAWhIkfhTFgWrExgSJznwi I/9vvcIy+KWgg9gHOhGZV29S7ehqTsoVQf5aSTkpLo4lZcOt+qJYXUGnotAHEnbkAp2T 5SQ6RNkjhkP6hUz0zeFVqzpFfd+y14BM7II1j8cENDHBtAfjfAlIX9Ne0sKW4/QcvJZt 3p9mJ4af5jGGzO8E5NuzD7+7VqjfXDlEJThPOY58Zaf/fUZwjJkKj0FwsSsh0TfmKcPU sMDQ== 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=rNolufOosiAO2vmW3h43QmHRNLssvHKnOdvrFdDRoTY=; b=NrVaHRVH8TcNUIvGZzsnAdO+uw4MX1+5YNiKU5uAyP6MiP+lNZLhXTZ2W7l3R+f/vO k587AVwdvRSoT/pDDf7NgM0TdMmhvljvW6dloKHKXQQduw+NrpdQQ6+J6UJ9aW97DNUi tcTSz/5KemXNxnquNgRvhqSEWYAHgqbqpaYjuQfiKBg6u5BYQnKflZV8TCA7hGZxJ+U6 TOd6Z/0hL+GV3W37FYScuC4xKkqsIjFmDyRFdfJKdwv4MjsNdiFYaG8tv/urkImC6If9 DvOJHJB8Z099ic28cZ5iF+9N2Fe9ivU6aokcng5nXUAKy+AcwcwcQa4W0toNMUT9VBz8 bCiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aMbF3ThD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d3si4545628oia.236.2019.12.29.12.49.19; Sun, 29 Dec 2019 12:49:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aMbF3ThD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733227AbfL2R5R (ORCPT + 99 others); Sun, 29 Dec 2019 12:57:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:47550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733211AbfL2R5O (ORCPT ); Sun, 29 Dec 2019 12:57:14 -0500 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 2302121D7E; Sun, 29 Dec 2019 17:57:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577642232; bh=ZnWdU30S9z3CTtN6rCguB5pWHppVpSUgJZm9K6xRL/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aMbF3ThDPQT8zFFLNqSNTorFosbNlwYU+cQcb4QdZ6zpEx1Yxn9ddadcNE5wa7TDu /rKl1LsJgFhX7BHXs4+ydo9RndMFMRzbwCCVyeK8VaUED8ZBta9GBSoq+EtQfSsTvJ uMj6SdUkWOdbb7FtxZDGYkVbt115gTJnbSAUF6E0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erkka Talvitie , Alan Stern Subject: [PATCH 5.4 397/434] USB: EHCI: Do not return -EPIPE when hub is disconnected Date: Sun, 29 Dec 2019 18:27:30 +0100 Message-Id: <20191229172728.774680489@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@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: Erkka Talvitie commit 64cc3f12d1c7dd054a215bc1ff9cc2abcfe35832 upstream. When disconnecting a USB hub that has some child device(s) connected to it (such as a USB mouse), then the stack tries to clear halt and reset device(s) which are _already_ physically disconnected. The issue has been reproduced with: CPU: IMX6D5EYM10AD or MCIMX6D5EYM10AE. SW: U-Boot 2019.07 and kernel 4.19.40. CPU: HP Proliant Microserver Gen8. SW: Linux version 4.2.3-300.fc23.x86_64 In this situation there will be error bit for MMF active yet the CERR equals EHCI_TUNE_CERR + halt. Existing implementation interprets this as a stall [1] (chapter 8.4.5). The possible conditions when the MMF will be active + halt can be found from [2] (Table 4-13). Fix for the issue is to check whether MMF is active and PID Code is IN before checking for the stall. If these conditions are true then it is not a stall. What happens after the fix is that when disconnecting a hub with attached device(s) the situation is not interpret as a stall. [1] [https://www.usb.org/document-library/usb-20-specification, usb_20.pdf] [2] [https://www.intel.com/content/dam/www/public/us/en/documents/ technical-specifications/ehci-specification-for-usb.pdf] Signed-off-by: Erkka Talvitie Reviewed-by: Alan Stern Cc: stable Link: https://lore.kernel.org/r/ef70941d5f349767f19c0ed26b0dd9eed8ad81bb.1576050523.git.erkka.talvitie@vincit.fi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/ehci-q.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c @@ -27,6 +27,10 @@ /*-------------------------------------------------------------------------*/ +/* PID Codes that are used here, from EHCI specification, Table 3-16. */ +#define PID_CODE_IN 1 +#define PID_CODE_SETUP 2 + /* fill a qtd, returning how much of the buffer we were able to queue up */ static int @@ -190,7 +194,7 @@ static int qtd_copy_status ( int status = -EINPROGRESS; /* count IN/OUT bytes, not SETUP (even short packets) */ - if (likely (QTD_PID (token) != 2)) + if (likely(QTD_PID(token) != PID_CODE_SETUP)) urb->actual_length += length - QTD_LENGTH (token); /* don't modify error codes */ @@ -206,6 +210,13 @@ static int qtd_copy_status ( if (token & QTD_STS_BABBLE) { /* FIXME "must" disable babbling device's port too */ status = -EOVERFLOW; + /* + * When MMF is active and PID Code is IN, queue is halted. + * EHCI Specification, Table 4-13. + */ + } else if ((token & QTD_STS_MMF) && + (QTD_PID(token) == PID_CODE_IN)) { + status = -EPROTO; /* CERR nonzero + halt --> stall */ } else if (QTD_CERR(token)) { status = -EPIPE;