Skip to contentSkip to conversation

xhci: handle port status events for removed USB3 hcd

PATCH New Jack Pham 1 participant 1 message Sep 28, 2018

Subsystems (2)
lore
Share & tools
lore

Jack Pham

author
#0 lore raw

PATCH 2/2 xhci: handle port status events for removed USB3 hcd

Hi Mathias,

Quoted 31 lines · Peter Chen
Quoted 31 lines
Quoted 17 lines
---
  drivers/usb/host/xhci-ring.c | 7 +++++++
  1 file changed, 7 insertions(+)
(quoted diff) +0 -0

b/drivers/usb/host/xhci-ring.c index f0a99aa..3d314b8 100644

drivers/usb/host/xhci-ring.c +0 -0
@@ -1552,6 +1552,13 @@ static void handle_port_status(struct xhci_hcd *xhci,
  		goto cleanup;
  	}
 

drivers/usb/host/xhci-ring.c static void handle_port_status(struct xhci_hcd *xhci, · line 1564

Quoted 10 lines
drivers/usb/host/xhci-ring.c +7 -0
+	/* We might get interrupts after shared_hcd is removed */
+	if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) {
+		xhci_dbg(xhci, "ignore port event for removed USB3 hcd\n");
+		bogus_port_status = true;
+		goto cleanup;
+	}
+
  	hcd = port->rhub->hcd;
  	bus_state = &xhci->bus_state[hcd_index(hcd)];
  	hcd_portnum = port->hcd_portnum;

This probably only applies from 4.18 onwards, to test on older kernel try something like this instead:

Quoted 10 lines

drivers/usb/host/xhci-ring.c static void handle_port_status(struct xhci_hcd *xhci, · line 1609

Quoted 10 lines
drivers/usb/host/xhci-ring.c index renamed from drivers/usb/host/xhci-ring.c +0 -0

6996235..7925da9 100644

drivers/usb/host/xhci-ring.c +1 -1
@@ -1606,7 +1606,11 @@ static void handle_port_status(struct xhci_hcd *xhci,
         hcd = xhci_to_hcd(xhci);
         if ((major_revision == 0x03) != (hcd->speed >= HCD_USB3))
                 hcd = xhci->shared_hcd;
-
+       if (!hcd) {

For testing on 4.14 I also added the debug print "ignore port event" here as well. Maybe it should be there in the final -stable patch as well.

Quoted 8 lines
Quoted 8 lines
drivers/usb/host/xhci-ring.c +3 -0
+               bogus_port_status = true;
+               goto cleanup;
+       }
         if (major_revision == 0) {
                 xhci_warn(xhci, "Event for port %u not in "
                                 "Extended Capabilities, ignoring.\n",
Quoted 6 lines
Quoted 1 line

Jack, Peter, do these patches solve the remove issues you are seeing?

At my two USB3 platforms, only apply the 1st patch can fix my problem. Maybe my USB3 port change interrupt occurs always before removing USB2 HCD.

Peter

Ditto. I think the xhci_irq() is getting triggered by something during usb_remove_hcd() (usb_disconnect on the root hub?) but is able to complete before it returns. That is, the NULL pointer dereference is resolved yet I don't see that "ignore port event for removed USB3 hcd" message at all.

Regardless, it's good to have here just in case, so

Will you be sending this as separate patches for -rc vs -stable?

Thanks,
Jack