Linux USB
 help / color / mirror / Atom feed
* [RFC PATCH] usb: xhci: report USB2 resume-exit timeout as an error
@ 2026-06-23 14:05 Pengpeng Hou
  2026-06-26 11:06 ` Mathias Nyman
  0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-06-23 14:05 UTC (permalink / raw)
  To: Mathias Nyman, Greg Kroah-Hartman; +Cc: Pengpeng Hou, linux-usb, linux-kernel

xhci_handle_usb2_port_link_resume() waits for the USB2 resume exit
completion after requesting U0. If that wait times out, it only logs a
warning and then continues through the normal resume-done path, ending
the port resume and marking the suspend change as completed.

Return -ETIMEDOUT on resume-exit timeout so the port status path reports
an error instead of a successful resume. The patch still ends the
usbcore port-resume accounting before returning. This is intended as an
RFC patch because xHCI resume state handling is policy-sensitive.

Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 drivers/usb/host/xhci-hub.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index b0264bd85..b7b7d8b31 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -998,21 +998,23 @@ static int xhci_handle_usb2_port_link_resume(struct xhci_port *port,
-		if (time_left) {
-			if (!port->slot_id) {
-				xhci_dbg(xhci, "slot_id is zero\n");
-				return -ENODEV;
-			}
-			xhci_ring_device(xhci, port->slot_id);
-		} else {
+		if (!time_left) {
 			int port_status = xhci_portsc_readl(port);
 
 			xhci_warn(xhci, "Port resume timed out, port %d-%d: 0x%x\n",
 				  hcd->self.busnum, wIndex + 1, port_status);
 			/*
 			 * keep rexit_active set if U0 transition failed so we
 			 * know to report PORT_STAT_SUSPEND status back to
 			 * usbcore. It will be cleared later once the port is
 			 * out of RESUME/U3 state
 			 */
+			usb_hcd_end_port_resume(&hcd->self, wIndex);
+			return -ETIMEDOUT;
 		}
 
+		if (!port->slot_id) {
+			xhci_dbg(xhci, "slot_id is zero\n");
+			return -ENODEV;
+		}
+		xhci_ring_device(xhci, port->slot_id);
+
 		usb_hcd_end_port_resume(&hcd->self, wIndex);
 		bus_state->port_c_suspend |= 1 << wIndex;
 		bus_state->suspended_ports &= ~(1 << wIndex);
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH] usb: xhci: report USB2 resume-exit timeout as an error
  2026-06-23 14:05 [RFC PATCH] usb: xhci: report USB2 resume-exit timeout as an error Pengpeng Hou
@ 2026-06-26 11:06 ` Mathias Nyman
  0 siblings, 0 replies; 2+ messages in thread
From: Mathias Nyman @ 2026-06-26 11:06 UTC (permalink / raw)
  To: Pengpeng Hou, Mathias Nyman, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel

On 6/23/26 17:05, Pengpeng Hou wrote:
> xhci_handle_usb2_port_link_resume() waits for the USB2 resume exit
> completion after requesting U0. If that wait times out, it only logs a
> warning and then continues through the normal resume-done path, ending
> the port resume and marking the suspend change as completed.
> 
> Return -ETIMEDOUT on resume-exit timeout so the port status path reports
> an error instead of a successful resume. The patch still ends the
> usbcore port-resume accounting before returning. This is intended as an
> RFC patch because xHCI resume state handling is policy-sensitive.

Does this resolve some issue you are seeing?

xhci_handle_usb2_port_link_resume() is only called when xhci roothub
responds to hub driver GetPortStatus() request while port is in a xhci resume state.

Returning -ETIMEDOUT here will cause the GetPortStatus() request to complete
with -EPIPE status. This does not seem like the right choice here.

If resuming the port to U0 timed out then there was no xhci port event, and port
should still be in xhci resume state. USB2 does not have a "resume" state so
returning portstatus as USB_PORT_STAT_SUSPEND seems appropriate.

Ee should also reconsider if calling usb_hcd_end_port_resume() is right in
the timeout case.

It also looks like we accept any port event as a successful rexit_done completion.
If the event was due to a disconnect we will incorrectly still report port status
as connected , enabled and non-suspended for this usb2 device.

Thanks
Mathias


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-26 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-23 14:05 [RFC PATCH] usb: xhci: report USB2 resume-exit timeout as an error Pengpeng Hou
2026-06-26 11:06 ` Mathias Nyman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox