usb: xhci: workaround for bogus SET_DEQ_PENDING endpoint state
authorJonathan Bell <jonathan@raspberrypi.com>
Wed, 11 Aug 2021 14:33:57 +0000 (15:33 +0100)
committerDom Cobley <popcornmix@gmail.com>
Mon, 21 Mar 2022 16:04:21 +0000 (16:04 +0000)
See https://github.com/raspberrypi/linux/issues/3981

An unknown unsafe memory access can result in the ep_state variable
in xhci_virt_ep being trampled with a stuck SET_DEQ_PENDING state
despite successful completion of a Set TR Deq Pointer command.

All URB enqueue/dequeue calls for the endpoint will fail in this state
so no transfers are possible until the device is reconnected.

As a workaround, clear the flag if we see it set and issue a new Set
TR Deq command anyway - this should be harmless, as a prior Set TR Deq
command will only have been issued in the Stopped state, and if the
endpoint is Running then the controller is required to ignore it and
respond with a Context State Error event TRB.

Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
drivers/usb/host/xhci-ring.c

index d0b6806..45b8404 100644 (file)
@@ -677,9 +677,9 @@ deq_found:
        }
 
        if ((ep->ep_state & SET_DEQ_PENDING)) {
-               xhci_warn(xhci, "Set TR Deq already pending, don't submit for 0x%pad\n",
-                         &addr);
-               return -EBUSY;
+               xhci_warn(xhci, "WARN A Set TR Deq Ptr command is pending for slot %u ep %u\n",
+                         slot_id, ep_index);
+               ep->ep_state &= ~SET_DEQ_PENDING;
        }
 
        /* This function gets called from contexts where it cannot sleep */