patch "xhci: make sure TRB is fully written before giving it to the" added to usb-linus
Subsystems (3)
This is a note to let you know that I've just added the patch titled
xhci: make sure TRB is fully written before giving it to the
to my usb git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
in the usb-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From 576667bad341516edc4e18eb85acb0a2b4c9c9d9 Mon Sep 17 00:00:00 2001
From: Mathias Nyman <[email protected]>
Date: Fri, 15 Jan 2021 18:19:06 +0200
Subject: xhci: make sure TRB is fully written before giving it to the
controller
Once the command ring doorbell is rung the xHC controller will parse all command TRBs on the command ring that have the cycle bit set properly.
If the driver just started writing the next command TRB to the ring when hardware finished the previous TRB, then HW might fetch an incomplete TRB as long as its cycle bit set correctly.
A command TRB is 16 bytes (128 bits) long.
Driver writes the command TRB in four 32 bit chunks, with the chunk containing the cycle bit last. This does however not guarantee that chunks actually get written in that order.
This was detected in stress testing when canceling URBs with several connected USB devices.
Two consecutive "Set TR Dequeue pointer" commands got queued right after each other, and the second one was only partially written when the controller parsed it, causing the dequeue pointer to be set to bogus values. This was seen as error messages:
"Mismatch between completed Set TR Deq Ptr command & xHCI internal state"
Solution is to add a write memory barrier before writing the cycle bit.
--- drivers/usb/host/xhci-ring.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/host/xhci-ring.c +2 -0
@@ -2931,6 +2931,8 @@ static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, trb->field[0 ] =cpu_to_le32 (field1); trb->field[1 ] =cpu_to_le32 (field2); trb->field[2 ] =cpu_to_le32 (field3); +/* make sure TRB is fully written before giving it to the controller */ +wmb (); trb->field[3 ] =cpu_to_le32 (field4);trace_xhci_queue_trb (ring, trb);
Signature · 1 line
2.30.0