From patchwork Mon Apr 10 17:44: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: 97211 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456528obc; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) X-Received: by 10.84.217.153 with SMTP id p25mr31251390pli.188.1491846359901; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.59; Mon, 10 Apr 2017 10:45:59 -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 S1754041AbdDJRp5 (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:57 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:32899 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754010AbdDJRp4 (ORCPT ); Mon, 10 Apr 2017 13:45:56 -0400 Received: by mail-pg0-f43.google.com with SMTP id x125so109394705pgb.0 for ; Mon, 10 Apr 2017 10:45: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=4FgTjXrKB+1qieC2Ko4wiZ96yYb+24Bg8mgSFe1+KO4=; b=Pj/fO2DL4/XzF3P63Hu73qNDRsPXGU5eBAOsUTUKXoFaxG7aPHBf/IFgHmfuqdASGM g7AfcspscV//HW/ogOxw6Da2e47TZCjzq6p5LAjGuXOQKb7eLLIEWcuJjvGqGyVzsTUF fJwzSDsawI4kzmd9FGMru8tqEBmkNUws9zZlY= 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=f944xtjBzdMBKBAi3qfKSg0tVRdr4+GlS4oauRxiu7ZE8V2OIK/ZXnSr/AbcDdgVRd abjlGVEu8c1z+wCxSkQAXHIwBlCct9H5KYZ2NyvjSEdyx2eljAdQGASnW/3Fy7bOq0S7 qnD2SQQzD6+rAIINrzjHFImzQcCmkW5lrU4KTAXkF26Pufz5oMDM7uWualuTIc8p7hKz UcbKV4X3cHGYO6w3KjPRe1x0IUz5wSLg3OrGq8SBaB0Uw3AjIfHzqQXiFeIQNLRHR74I /tRx41viEVYLXXbjQdZNvjSBw/6zpYmUFd1Heaq9JcX+kYLAZiqyu5YE3xrZIuKL8LC6 4akA== X-Gm-Message-State: AFeK/H3TBO0Uovx3hIaMs/Vbr2NVLJe9nqQbuS89t395bcQMPhmOiSnNVm3fP/hNNQ/OCnxW X-Received: by 10.98.107.194 with SMTP id g185mr56907525pfc.22.1491846355644; Mon, 10 Apr 2017 10:45:55 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:54 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Guenter Roeck , Douglas Anderson , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 16/16] usb: hub: Wait for connection to be reestablished after port reset Date: Mon, 10 Apr 2017 23:14:32 +0530 Message-Id: <1491846272-14882-17-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-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 */