From patchwork Wed Apr 12 17:36:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97319 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp371903qgf; Wed, 12 Apr 2017 10:36:58 -0700 (PDT) X-Received: by 10.99.113.81 with SMTP id b17mr67618555pgn.180.1492018618811; Wed, 12 Apr 2017 10:36:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i63si21086788pgc.265.2017.04.12.10.36.58; Wed, 12 Apr 2017 10:36:58 -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 S1754312AbdDLRg6 (ORCPT + 6 others); Wed, 12 Apr 2017 13:36:58 -0400 Received: from mail-pg0-f50.google.com ([74.125.83.50]:33834 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753882AbdDLRg5 (ORCPT ); Wed, 12 Apr 2017 13:36:57 -0400 Received: by mail-pg0-f50.google.com with SMTP id 21so18077944pgg.1 for ; Wed, 12 Apr 2017 10:36:56 -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=jQGAjIU16sv/rQ5vQRUxd/WwGo1tNDMQNm29XIHqzW4=; b=SsClJJOnm9E3qXTYYEysX4ADohktc2aUuU9IoUWlHmGbohtllWl/1zb1/EPgSLWyTw Ict/FNEsKtnFXfKXtFT8E3mpbRngwy4i3+kWdzItPOJNQafV9D3jYDQAl5qP8jR6RA0k R4gXmJdkDiINsoxL9o/nCAc7um61ja+u1Yd74= 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=jQGAjIU16sv/rQ5vQRUxd/WwGo1tNDMQNm29XIHqzW4=; b=WR8a15svr68d/gSpDBOcrQAvh15FiKCg+C2HBc9jOYR1mUnwC++tJJVApk2Uo1g9aY g34i3azhRQ400hKTRXU6BMH+kfNZl90+pCqJIe5BDsIaq5eIA35Pn6mtaxW7tNcwjSRT 7mooEyzSvkHDyv4c/Wx6UpTnlxfFPQezBQamUBdi6PauFjahPvw8x+SQJgI04oGVpWwx kbn7QnM6HjuEkh4HgKlUGQvA9cWnd44aWTszciIQ4GTrEfnPEH0i3eOoI1iGAxvHLdbm KaiY4iGI76AxZOp06adhjFte5bKlhyL2xC8vsvIcBFOxFQs/1kpT91BgPlQi91IreW9n +YOw== X-Gm-Message-State: AFeK/H1Cyt11kImWSBdhaxQlcXxi5Wim3nJXgGLpMFq0Dp6eQ3X7qW17eMB56YvqnHY/p/L1 X-Received: by 10.98.144.204 with SMTP id q73mr46629908pfk.179.1492018616222; Wed, 12 Apr 2017 10:36:56 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id 133sm31562648pfy.106.2017.04.12.10.36.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Apr 2017 10:36:55 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Guenter Roeck , Douglas Anderson , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.9 2/5] usb: hub: Wait for connection to be reestablished after port reset Date: Wed, 12 Apr 2017 23:06:32 +0530 Message-Id: <1492018595-13167-3-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492018595-13167-1-git-send-email-sumit.semwal@linaro.org> References: <1492018595-13167-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 c28ccf1..35fb2bef 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2650,8 +2650,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 */