Skip to content

Commit 5840f46

Browse files
Michal Pecioheftig
Michal Pecio
authored andcommitted
usb: xhci: Fix host controllers "dying" after suspend and resume
A recent cleanup went a bit too far and dropped clearing the cycle bit of link TRBs, so it stays different from the rest of the ring half of the time. Then a race occurs: if the xHC reaches such link TRB before more commands are queued, the link's cycle bit uintentionally matches the xHC's cycle so it follows the link and waits for further commands. If more commands are queued before the xHC gets there, inc_enq() flips the bit so the xHC later sees a mismatch and stops executing commands. This function is called before suspend and 50% of times after resuming the xHC is doomed to get stuck sooner or later. Then some Stop Endpoint command fails to complete in 5 seconds and this shows up xhci_hcd 0000:00:10.0: xHCI host not responding to stop endpoint command xhci_hcd 0000:00:10.0: xHCI host controller not responding, assume dead xhci_hcd 0000:00:10.0: HC died; cleaning up followed by loss of all USB decives on the affected bus. That's if you are lucky, because if Set Deq gets stuck instead, the failure is silent. Likely responsible for kernel bug 219824. I found this while searching for possible causes of that regression and reproduced it locally before hearing back from the reporter. To repro, simply wait for link cycle to become set (debugfs), then suspend, resume and wait. To accelerate the failure I used a script which repeatedly starts and stops a UVC camera. Some HCs get fully reinitialized on resume and they are not affected. Link: https://bugzilla.kernel.org/show_bug.cgi?id=219824 Fixes: 36b972d ("usb: xhci: improve xhci_clear_command_ring()") Cc: [email protected] Signed-off-by: Michal Pecio <[email protected]>
1 parent 13f25cb commit 5840f46

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/usb/host/xhci.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,12 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
779779
struct xhci_segment *seg;
780780

781781
ring = xhci->cmd_ring;
782-
xhci_for_each_ring_seg(ring->first_seg, seg)
782+
xhci_for_each_ring_seg(ring->first_seg, seg) {
783+
/* erase all TRBs before the link */
783784
memset(seg->trbs, 0, sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1));
785+
/* clear link cycle bit */
786+
seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= cpu_to_le32(~TRB_CYCLE);
787+
}
784788

785789
xhci_initialize_ring_info(ring);
786790
/*

0 commit comments

Comments
 (0)