linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Mathias Nyman <mathias.nyman@intel.com>
Cc: oneukum@suse.com, Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	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	[thread overview]
Message-ID: <20190318170038.23914-1-nsaenzjulienne@suse.de> (raw)

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 <nsaenzjulienne@suse.de>
---
 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


             reply	other threads:[~2019-03-18 17:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18 17:00 Nicolas Saenz Julienne [this message]
2019-03-19 11:01 ` [RFC] xhci: clear port_remote_wakeup on device disconnection Oliver Neukum
2019-03-19 14:54   ` Nicolas Saenz Julienne
2019-03-20 13:55     ` Mathias Nyman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190318170038.23914-1-nsaenzjulienne@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=oneukum@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).