Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp601943img; Mon, 18 Mar 2019 10:02:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkz45wZKZ3FETVGIOGigd55ME8KtChNui/YudVKcl2mnb7/yC/S5i6U/NrHeWH70cdgZys X-Received: by 2002:a62:4e8e:: with SMTP id c136mr20029272pfb.254.1552928534598; Mon, 18 Mar 2019 10:02:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552928534; cv=none; d=google.com; s=arc-20160816; b=BVU4qLpeFButJSxaEgs8lsOuU3e2qMHdNh2VffEgC9r4gJTO2aR8C2C41Vi8WQ9oV+ A8bPpxFFgabh4eVBLjDidfySsGQBDiGlvNIPO3V48AQi9S77mST2oY7jTzTSwmP6WXxI siVmYS3i741BRwGaf+7JzSI7IBZQJD4c6M1AI1LI7iziwl6Nb6OLVcs7Yxs6CeOr2h3R 2BF8LPrhQVsrSUCJ28yvJOthWGCl6iwVPb2yTsEaYZB+fNlvfXuGYJCX5bdrHeZHVa/5 ijMzMftl16zdCtFe0Q11KQapxCCgD5vysKKkpKRh+UpOzFbVG3a9G79NiKGCv0MbRTKV Wlxw== 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 :message-id:date:subject:cc:to:from; bh=jS0guoBvMrTq7T0/ZE2bgDbwNm4V3xYBszzDXADjibc=; b=rFW+cgVOt5i6NUSfL1Etd/Vu8N68jBiSOSrR2doFQi/QW7eq7COptW+q185jcLryvJ QBVnUcj8hqtGSsPouXQzqQ3NxMo69OvNm6R2w10wKPInexAWxcvOhoLtNptsE9dCNhye nj6lqyUL0c+Zyc+/cueIlMIPLlx6YSPe1nS1OXdTqQvLphB5mb3322JqnE8JsneWCEjE jJPEJhHDI7R7lGPjLqZxBZeimFRZ5f42GmeHyqqA/BDe+6TJGfEHbQTEK5Hfl2S2/rZj gP2m68hk33dWt0iigc1OhKhQH7hBLwkxsiCxGqGn9iTC+pQF+Wr8JckLAwZB75oie4EV usdw== ARC-Authentication-Results: i=1; mx.google.com; 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 g32si9628367pgg.223.2019.03.18.10.01.59; Mon, 18 Mar 2019 10:02:14 -0700 (PDT) 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; 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 S1727736AbfCRRAr (ORCPT + 99 others); Mon, 18 Mar 2019 13:00:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:58066 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726935AbfCRRAq (ORCPT ); Mon, 18 Mar 2019 13:00:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9AB07AE9D; Mon, 18 Mar 2019 17:00:45 +0000 (UTC) From: Nicolas Saenz Julienne To: Mathias Nyman Cc: oneukum@suse.com, Nicolas Saenz Julienne , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC] xhci: clear port_remote_wakeup on device disconnection Date: Mon, 18 Mar 2019 18:00:37 +0100 Message-Id: <20190318170038.23914-1-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This was reported on a Dell Precision 5520 using it's WD15 dock. The dock's Ethernet device interfaces with the laptop through one of it's USB3 ports. While idle, the Ethernet device and HCD are suspended by runtime PM, being the only active device connected to the bus. They are both generally resumed on behalf of the Ethernet device, which has remote wake-up capabilities. The Ethernet device was observed randomly disconnecting from the USB port shortly after submitting it's remote wake-up request. This causes the PM to busyloop, as the port is in the middle of a remote wake-up operation, waiting for the device to switch to U0. This leaves a bit set in "port_remote_wakeup", which stops any further suspend/resume operations. The logs look like this (I added the port status print in the first one): [28128.472101] xhci_hcd:handle_port_status: xhci_hcd 0000:3e:00.0: port resume event for port 3, port status 0xc4013e3 [28128.472165] xhci_hcd:xhci_hub_control: xhci_hcd 0000:3e:00.0: get port status, actual port 0 status = 0x1e0 [28128.472200] usbcore:hub_event: hub 4-0:1.0: state 7 ports 2 chg 0002 evt 0000 [28128.472221] usb 4-1: USB disconnect, device number 2 In between the first two logs we acknowledge the remote wake-up request, setting the link state as U0 and setting the relevant bit in "port_remote_wakeup". We also call usb_hcd_resume_root_hub() which will wake up the hub device. Note the CCS & PED bits on the port status are still set (see 5.4.8 in spec). In between the second and third log, the hub device finds out about the disconnection (CSS & PED are now 0), which triggers a call to hub_port_connect() which finds an already existing USB device and disconnects it. Runtime PM, seeing no devices connected to the HCD busyloops trying to suspend the device, which fails every time because of "port_remote_wakeup", generating a tangible CPU load. This patch clears "port_remote_wakeup" upon detecting a device disconnection. Making sure the above mentioned situation doesn't trigger a PM busyloop. Signed-off-by: Nicolas Saenz Julienne --- drivers/usb/host/xhci-hub.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index e2eece693655..bea853f45aec 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -942,6 +942,9 @@ static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status, bus_state->suspended_ports &= ~(1 << portnum); } + if (!(portsc & PORT_CONNECT)) + bus_state->port_remote_wakeup &= ~(1 << portnum); + xhci_hub_report_usb3_link_state(xhci, status, portsc); xhci_del_comp_mod_timer(xhci, portsc, portnum); } -- 2.21.0