[PATCH v3 0/2] usb: dwc3: gadget: fix request unmap and linearize SG requests that exceed the TRB cache

From: Faisal Hassan

Date: Tue Nov 24 2026 - 06:13:32 EST


The DWC3 TRB cache holds at most 15 TRBs per transfer, and a packet whose
chain needs more than that is never assembled. An SG IN request built
from small entries, such as a 1024-byte request scattered over 16 pages
of 64 bytes on a SuperSpeed bulk endpoint, stalls with NRDY and never
completes. Patch 2 copies such requests into a contiguous buffer at
queue time.

Patch 1 is new in v3. The sashiko review of v2 pointed out that a
request which is mapped but gets no TRB is never unmapped, and is mapped
again on every kick. This has been the case since requests started being
mapped lazily, but linearized requests make it easier to hit, so fix it
first. Patch 2 no longer needs its own unmap condition.

The review also noted that __dwc3_gadget_start_isoc() errors are
returned from __dwc3_gadget_ep_queue() after the request has been added
to the pending list. That behaviour dates back to 25abad6a0584 and is
not touched here.

Changes in v3:
- Add patch 1 to track the mapped state in req->mapped and unmap
unconditionally on giveback.
- Drop the req->sg_trb_cache_bounced unmap condition from patch 2.

Changes in v2:
- Linearize at queue time so allocation and SG list errors are returned
from usb_ep_queue(), and restore the original request on giveback.
- Apply the workaround unconditionally instead of using a DT quirk.

v2: https://lore.kernel.org/all/20261006172254.1058992-1-faisal.hassan@xxxxxxxxxxxxxxxx/
v1: https://lore.kernel.org/all/20261004031445.1450196-1-faisal.hassan@xxxxxxxxxxxxxxxx/

Faisal Hassan (2):
usb: dwc3: gadget: fix DMA mapping leak of requests without TRBs
usb: dwc3: gadget: linearize SG requests that exceed the TRB cache

drivers/usb/dwc3/core.h | 15 ++++
drivers/usb/dwc3/gadget.c | 145 ++++++++++++++++++++++++++++++++++++--
2 files changed, 153 insertions(+), 7 deletions(-)


base-commit: 8e31dedb9ad496ea7dd7064d77d6f7d459c1c90f
--
2.34.1