[PATCH v5 0/4] Add larger page size support for USB audio offload path
From: Wesley Cheng
Date: Tue Nov 03 2026 - 18:43:29 EST
On some environments, 16kB pages can be enabled from the Linux subsystem,
which manages the IOMMU mappings for the audio DSP within the system. In
the current design, the following assumptions break when 16k pages are
utilized:
1. xHCI ring size is equal to PAGE_SIZE
2. Ring addresses start at the beginning of a page
When the USB offload driver maps the rings (w/ the audio DSP SID), it is
set with a 16k granular, which is a problem, as several xHCI rings could
exist on the same page. This is because the rings are currently allocated
from the segment_pool. Hence, potentially mapping non USB audio related
rings into the region accessible by the audio DSP.
To mitigate this, sideband rings are no longer allocated from the
segment_pool. When PAGE_SIZE is larger than TRB_SEGMENT_SIZE, xHCI
allocates the segments of sideband-tagged endpoint rings, and of the
sideband secondary event ring, using dma_alloc_coherent(), which gives
each segment a page of its own. Before the USB audio offload path is
enabled, the USB audio data streams/endpoint are not active. Only when
the class driver issues a usb_set_interface() call (done from
snd_usb_endpoint_prepare()), will the xHCI allocate the transfer ring
resources. The offload client driver therefore tags the endpoints with
xhci_sideband_add_endpoint() before that point. The new ring allocation
flow for sideband/offload clients will be as follows:
handle_uaudio_stream_req()
▼
enable_audio_stream(subs, ..., pcm_card_num)
├─ data_ep = uaudio_find_host_endpoint(subs, subs->data_endpoint)
├─ xhci_sideband_add_endpoint(sb, data_ep) ← ep->sideband = sb; ep->no_pool_alloc = PAGE_SIZE > TRB_SEGMENT_SIZE
├─ snd_usb_endpoint_prepare(chip, sync_endpoint) ─┐
├─ snd_usb_endpoint_prepare(chip, data_endpoint) ├─→ xhci_add_endpoint()
│ ▼
│ xhci_endpoint_init(xhci, virt_dev, ep, ...)
│ new_ring = __xhci_ring_alloc(..., ep->no_pool_alloc, ...)
│ ▼
│ xhci_alloc_segments_for_ring(xhci, ring, flags)
│ ▼
│ xhci_segment_alloc(xhci, max_packet, num, ring->no_pool_alloc, flags)
│ seg->trbs = dma_alloc_coherent(dev, TRB_SEGMENT_SIZE, &dma, flags)
▼
xhci_sideband_get_endpoint_buffer(sb, data_ep) → xhci_ring_to_sgtable()
Similar logic is added for the secondary interrupter path as well. The USB
offload class driver calls xhci_sideband_create_interrupter(), which will
be responsible for allocating the secondary event ring.
xHCI core remains responsible for freeing these rings, once the endpoint
has been dropped or the slot disabled. This also covers disconnecting the
USB audio device while audio offload is active: usb_set_interface()
returns early as the interface is unregistering, and the rings are freed
later, when USB core drops the device's endpoints. As xhci_free_dev()
frees the virt device with interrupts disabled, where dma_free_coherent()
can't be called, those rings are freed after xhci->lock is released.
This was confirmed to work on the SM8350 MTP platform, with the
CONFIG_ARM64_16K_PAGES config enabled, alongside tinyaudio binaries:
tinymix -D 0 set 513 1 (Enables USB_RX multimedia#1 path)
tinyplay -D 0 -d 0.... (Routes PCM data to ASoC platform sound card)
Signed-off-by: Wesley Cheng <wesley.cheng@xxxxxxxxxxxxxxxx>
---
Changes in v5:
- Dropped the offload client owned segment pool, as suggested by Mathias.
xHCI now allocates sideband ring segments with dma_alloc_coherent() when
PAGE_SIZE is larger than TRB_SEGMENT_SIZE.
- Free rings that are not allocated from the segment pool outside of
xhci->lock in xhci_free_dev().
- Modified the xhci_ring_to_sgtable sequence to address an error from Sashiko
where it questioned the safeness of virt_to_page. Leverage
dma_get_sgtable, which will call the appropriate DMA mapping
implementation.
- Link to v4: https://patch.msgid.link/20260909-16k_offload_v1_b4-v4-0-f24a86617597@xxxxxxxxxxxxxxxx
Changes in v4:
- Split xHCI patches from xHCI core and xHCI sideband.
- Make the dedicated offload segment pool optional for secondary
interrupter creation. (xfer rings support this already in previous
revs)
- Fixed some inter-patch build/functionality failures in
qc_audio_offload. Incremental builds between patches now
work on 4k pages. (16k support at end)
- Link to v3: https://patch.msgid.link/20260903-16k_offload_v1_b4-v3-0-135928dc2408@xxxxxxxxxxxxxxxx
Changes in v3:
- Moved sideband segment pool assignment to when a sideband endpoint
is added.
- Address an issue where during USB device disconnect (while offload
active), where the offload client driver is freeing the DMA pool
before xHCI core is able to free the dma allocations.
- Update xhci_ring_to_sgtable to correctly allocate and fill the sg
table which capture rings within page offsets.
- Link to v2: https://patch.msgid.link/20260828-16k_offload_v1_b4-v2-0-8a46369ebbb6@xxxxxxxxxxxxxxxx
Changes in v2:
- Moved from using alignment_req to having the offload driver maintain
its own segment pool.
- Fixed OOB condition seen in xhci_ring_to_sgtable() and will capture
page offsets properly.
- Addressed inter-patch build failures.
- Link to v1: https://patch.msgid.link/20260824-16k_offload_v1_b4-v1-0-49a6be60ca30@xxxxxxxxxxxxxxxx
To: Mathias Nyman <mathias.nyman@xxxxxxxxx>
To: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
To: Jaroslav Kysela <perex@xxxxxxxx>
To: Takashi Iwai <tiwai@xxxxxxxx>
Cc: linux-usb@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-sound@xxxxxxxxxxxxxxx
---
Wesley Cheng (4):
usb: xhci: sideband: fix ring sg table for sub-page TRB segments
usb: xhci: Allocate sideband ring segments with dma_alloc_coherent()
ALSA: usb-audio: qcom: tag sideband endpoints before ring allocation
ALSA: usb-audio: qcom: fix xfer ring IOMMU unmap on 16K+ page kernels
drivers/usb/host/xhci-mem.c | 63 +++++++++++++-----
drivers/usb/host/xhci-sideband.c | 97 +++++++++++++++++-----------
drivers/usb/host/xhci.c | 13 ++++
drivers/usb/host/xhci.h | 5 +-
sound/usb/qcom/qc_audio_offload.c | 131 ++++++++++++++++++++++++++++++--------
5 files changed, 228 insertions(+), 81 deletions(-)
---
base-commit: 69f0645f043feed4dc07690c74597574f43c41b4
change-id: 20260824-16k_offload_v1_b4-3d1460405774
Best regards,
--
Wesley Cheng <wesley.cheng@xxxxxxxxxxxxxxxx>