Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11802947pjo; Thu, 2 Jan 2020 14:32:54 -0800 (PST) X-Google-Smtp-Source: APXvYqy9qkbvOzaFS9e/a/M9hK9gK1s50RgGL/xpu7EBTh/uMQOv1OmD8hl5cK4+rN1NQLF8B2tX X-Received: by 2002:aca:cf11:: with SMTP id f17mr3197787oig.40.1578004374316; Thu, 02 Jan 2020 14:32:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578004374; cv=none; d=google.com; s=arc-20160816; b=a57qgdeedch9ZMlycYuOcIs58w5QOnL9KougKEFb58SS84cq/KmgYmCRzQ0X1RyMdw TCyeQM9exUjNIRYXvMyW1Ob+refz6Flf/9VTqH+FywvxlF30+Mktqsf0MFA/YOJ/tbrz DOxuDDbhbJRKwGSVUOyG3pbR8ZMTChSsWKLbKjKZ0zVnPM4Nzs6OJefWsBnTDrEYoERE VnclewFu7OhIyQ1KJ7TOJyAtJ0W1XQgelxfKziRY8wgxtisjzKkDdSVkqbZe8mwPpw59 StveXgZBvJJrfwZr75CBwj6NTPWv2pSEU+gVWmcL5v+2Wu8viC5HN3rvAYSFb1JObuUQ KhxQ== 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=iuKZ6AI1xrSaVLNRSU1aV6QCpHGSMz06iYwsxazDlXE=; b=iFHgA2yK0jnlwo8Pa1cSF4EkO0c2ZMqrhqFrV/PGZQaOFE9V+Mf7ttzfC62zhaPdXL TpTDAJ84pbTXGKAGHVtDCxNqQVQMvc8Nccto5iWhJv5SrZn/7AyBg//HJ0ahCbCacYez wgltus3wsKc9zXHgxKw7GrMWHrO2F5JNJAeafG2Qs4nqYuIyskGAecsslBWe6Y5cmqnI TBcvAHM6a+cLqsjLIZOzvZv1uhkJmzIVk3v7k+/bcB4yULmKVQ1IrS7ejSbAEAUKt8SJ I9drdkiYsZPOKshk0/kPF1E5Zm9OTYlbfzCL2QHBJ2RqUiLMplBNy5Cb/RDHi5RkXxlX mPBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lIu3HAHi; 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 l14si27010134oii.37.2020.01.02.14.32.42; Thu, 02 Jan 2020 14:32:54 -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=lIu3HAHi; 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 S1730356AbgABWcC (ORCPT + 99 others); Thu, 2 Jan 2020 17:32:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:37680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730165AbgABWb7 (ORCPT ); Thu, 2 Jan 2020 17:31:59 -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 076E821835; Thu, 2 Jan 2020 22:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004318; bh=hMuYONIPat+I+chEyHUq+cw42nC2MRM3jeSxDsdr5L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lIu3HAHim+QM3iVJI5z3ZKaapaINgraMHVe94Y3s6O5RahpCUwQicXRAUROcwnC9U A5BtAQ2utw0dy2pEZUyImsESzCBpMbJqd/X09LadRrNp50Qkl1ipAQ0MgalSUTyphi 9RHLv+qn8f0vm5E6Uv7+ZJ0mhKEJogAUjxMsLnj8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erkka Talvitie , Alan Stern Subject: [PATCH 4.9 103/171] USB: EHCI: Do not return -EPIPE when hub is disconnected Date: Thu, 2 Jan 2020 23:07:14 +0100 Message-Id: <20200102220601.455772886@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@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 @@ -40,6 +40,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 @@ -203,7 +207,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 */ @@ -219,6 +223,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;