From patchwork Wed Apr 12 17:43:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97338 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp374538qgf; Wed, 12 Apr 2017 10:45:04 -0700 (PDT) X-Received: by 10.99.9.66 with SMTP id 63mr70382424pgj.22.1492019104550; Wed, 12 Apr 2017 10:45:04 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z21si18652409pgh.397.2017.04.12.10.45.04; Wed, 12 Apr 2017 10:45:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752369AbdDLRo5 (ORCPT + 6 others); Wed, 12 Apr 2017 13:44:57 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:34208 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755307AbdDLRoz (ORCPT ); Wed, 12 Apr 2017 13:44:55 -0400 Received: by mail-pf0-f180.google.com with SMTP id c198so16984343pfc.1 for ; Wed, 12 Apr 2017 10:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4FgTjXrKB+1qieC2Ko4wiZ96yYb+24Bg8mgSFe1+KO4=; b=X9H6mvxZJPQk6w+I6Q4FC0wKLIA9IclwupIFXGQ8gSSuQAYaAIyPJAZdvtEwZq2ldY 77HyWV97b8QD5jnl1ezFCRxDfPU0K2ImB7U43Xsv/VZaKY8146P9o5KU5iAGrwyPYmE7 1k+//b+eSRdmnq+kQK2QIGgayDbGOAZBUtnOI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4FgTjXrKB+1qieC2Ko4wiZ96yYb+24Bg8mgSFe1+KO4=; b=NsN4+cbSduVkTTFjOyMASwVh5IMeMD0YTKAos+YEALp7HBSuXJLwRnHImmXsJF+4vs hGpruOxfdP9Itdn/rMH1j01tRJ7C0Xlh72JtrPOSDTBA8gYSMMA6qyLC2WW6FdUkhiTo 6yDodpdWk8V/mRZLBBw2qBp1p0i8tI8ncb0STggmsc5xWqnqQDpFX4ScnRLs0Ol00S1h LvFY1HkHTuq8WM8HVMqsBzLvsRZF6ljCy5A5PkdDSCw/RPBcD7zohNAeHnmy1xjCX2xc U76wDJWA6C0//sS8yIU9vCrBgS7C0bZ++XgGncVuhNPyrDD43SdNzjKR4I8mf7RVsKX4 vMXA== X-Gm-Message-State: AFeK/H0zxsu2wdzQXJB0jshVmPHf2nyXuLl3shN5cq2xKqJxtGrBpg+pDdtjSD1M0Dco3VM6 X-Received: by 10.99.119.69 with SMTP id s66mr68769968pgc.196.1492019089312; Wed, 12 Apr 2017 10:44:49 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id r17sm37750019pfa.13.2017.04.12.10.44.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Apr 2017 10:44:48 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Guenter Roeck , Douglas Anderson , Greg Kroah-Hartman , Sumit Semwal Subject: [v2 PATCH for-4.4 16/16] usb: hub: Wait for connection to be reestablished after port reset Date: Wed, 12 Apr 2017 23:13:50 +0530 Message-Id: <1492019030-13567-17-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492019030-13567-1-git-send-email-sumit.semwal@linaro.org> References: <1492019030-13567-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Guenter Roeck [ Upstream commit 22547c4cc4fe20698a6a85a55b8788859134b8e4 ] On a system with a defective USB device connected to an USB hub, an endless sequence of port connect events was observed. The sequence of events as observed is as follows: - Port reports connected event (port status=USB_PORT_STAT_CONNECTION). - Event handler debounces port and resets it by calling hub_port_reset(). - hub_port_reset() calls hub_port_wait_reset() to wait for the reset to complete. - The reset completes, but USB_PORT_STAT_CONNECTION is not immediately set in the port status register. - hub_port_wait_reset() returns -ENOTCONN. - Port initialization sequence is aborted. - A few milliseconds later, the port again reports a connected event, and the sequence repeats. This continues either forever or, randomly, stops if the connection is already re-established when the port status is read. It results in a high rate of udev events. This in turn destabilizes userspace since the above sequence holds the device mutex pretty much continuously and prevents userspace from actually reading the device status. To prevent the problem from happening, let's wait for the connection to be re-established after a port reset. If the device was actually disconnected, the code will still return an error, but it will do so only after the long reset timeout. Cc: Douglas Anderson Signed-off-by: Guenter Roeck Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- drivers/usb/core/hub.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 9e62c93..7c2d87b 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2602,8 +2602,15 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, if (ret < 0) return ret; - /* The port state is unknown until the reset completes. */ - if (!(portstatus & USB_PORT_STAT_RESET)) + /* + * The port state is unknown until the reset completes. + * + * On top of that, some chips may require additional time + * to re-establish a connection after the reset is complete, + * so also wait for the connection to be re-established. + */ + if (!(portstatus & USB_PORT_STAT_RESET) && + (portstatus & USB_PORT_STAT_CONNECTION)) break; /* switch to the long delay after two short delay failures */