Skip to content

usb: offload: Decouple interrupter lifecycle and refactor usage tracking

Guan-Yu Lin linux-sound linux-usb lkml stable 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 2 repliesIn review
  2. v32 patches 3 repliesSuperseded
  3. v2 posting 2/22 patches 10 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v2 RFC posting 1/22 patches0 repliesSuperseded

Changes in v4 from the cover letter

- remove spinlock in usb_offload_check.
- Collect the <Tested-by> tag from the OPPO team.
- Link to v3: https://lore.kernel.org/all/[email protected]/

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2usb: core: use dedicated spinlock for offload statedrivers/usb/core/driver.c drivers/usb/core/offload.c drivers/usb/core/usb.c +2 more+84 -560 replies
2/2usb: host: xhci-sideband: delegate offload_usage tracking to class driversdrivers/usb/host/xhci-sideband.c sound/usb/qcom/qc_audio_offload.c+10 -140 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchHailong LiuMathias Nyman
SeriesA-b
1/2T-b
2/2T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/2] usb: offload: Decouple interrupter lifecycle and refactor usage tracking

The current USB offload implementation couples the allocation of xHCI sideband interrupters with the device's offload usage counter. This coupling is conceptually incorrect, as hardware resource availability and power management state serve distinct purposes.

Furthermore, the reliance on the coarse USB device lock for offload state updates has led to potential recursive locking issues, especially during device disconnect when the lock is already held by the USB core.

This series refactors the offload synchronization by introducing a dedicated spinlock for offload state, allowing for more granular concurrency control and avoiding deadlocks. It also optimizes power management by ensuring that offload state is only modified when the device is already active, avoiding unnecessary auto-resumes.

Patch 1 introduces the offload_lock spinlock and offload_pm_locked synchronization, replacing the coarse udev->lock and the legacy offload_at_suspend flag. It also updates usb_offload_get/put to use pm_runtime_get_if_active().

Patch 2 removes the implicit usage tracking from the xHCI sideband layer and delegates the responsibility to class drivers, who have the correct context for managing offload data stream activity.

---
Changes in v4:
- remove spinlock in usb_offload_check.
- Collect the <Tested-by> tag from the OPPO team.
- Link to v3: https://lore.kernel.org/all/[email protected]/

Changes in v3:
- Replace the coarse USB device lock with a dedicated offload_lock spinlock to reduce contention and prevent recursive locking.
- Introduce offload_pm_locked to synchronize with PM transitions and replace the legacy offload_at_suspend flag.
- Optimize usb_offload_get/put by switching from auto-resume/suspend to pm_runtime_get_if_active(), avoiding unnecessary power transitions.
- Explicitly delegate offload_usage tracking to USB class drivers (e.g., the Qualcomm USB audio offload driver).
- Link to v2: https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Collect the <Tested-by> tag from the OPPO team.
- Link to v1: https://lore.kernel.org/all/[email protected]/

Changes in v1:
- Fix build error when building sound/usb/qcom/qc_audio_offload.o.
- Link to RFC v2: https://lore.kernel.org/all/[email protected]/

Changes in RFC v2:
- Move device locking to callers.
- Decouple sideband from offload counting.
- Link to RFC v1: https://lore.kernel.org/all/[email protected]/
---
Guan-Yu Lin (2):
usb: core: use dedicated spinlock for offload state
usb: host: xhci-sideband: delegate offload_usage tracking to class
drivers

 drivers/usb/core/driver.c         |  23 ++++---
 drivers/usb/core/offload.c        | 102 +++++++++++++++++-------------
 drivers/usb/core/usb.c            |   1 +
 drivers/usb/host/xhci-sideband.c  |  18 +-----
 include/linux/usb.h               |  10 ++-
 sound/usb/qcom/qc_audio_offload.c |  10 ++-
 6 files changed, 94 insertions(+), 70 deletions(-)
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog