Skip to content

Commit 117b4e9

Browse files
Udipto Goswamigregkh
authored andcommitted
usb: dwc3: gadget: Prevent core from processing stale TRBs
With CPU re-ordering on write instructions, there might be a chance that the HWO is set before the TRB is updated with the new mapped buffer address. And in the case where core is processing a list of TRBs it is possible that it fetched the TRBs when the HWO is set but before the buffer address is updated. Prevent this by adding a memory barrier before the HWO is updated to ensure that the core always process the updated TRBs. Fixes: f6bafc6 ("usb: dwc3: convert TRBs into bitshifts") Cc: stable <[email protected]> Reviewed-by: Pavankumar Kondeti <[email protected]> Signed-off-by: Udipto Goswami <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5432184 commit 117b4e9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,19 @@ static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb,
12911291
if (usb_endpoint_xfer_bulk(dep->endpoint.desc) && dep->stream_capable)
12921292
trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(stream_id);
12931293

1294+
/*
1295+
* As per data book 4.2.3.2TRB Control Bit Rules section
1296+
*
1297+
* The controller autonomously checks the HWO field of a TRB to determine if the
1298+
* entire TRB is valid. Therefore, software must ensure that the rest of the TRB
1299+
* is valid before setting the HWO field to '1'. In most systems, this means that
1300+
* software must update the fourth DWORD of a TRB last.
1301+
*
1302+
* However there is a possibility of CPU re-ordering here which can cause
1303+
* controller to observe the HWO bit set prematurely.
1304+
* Add a write memory barrier to prevent CPU re-ordering.
1305+
*/
1306+
wmb();
12941307
trb->ctrl |= DWC3_TRB_CTRL_HWO;
12951308

12961309
dwc3_ep_inc_enq(dep);

0 commit comments

Comments
 (0)