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

Guan-Yu Lin posted 2 patches 1 week, 2 days ago
There is a newer version of this series
drivers/usb/core/driver.c         |  23 ++++---
drivers/usb/core/offload.c        | 107 ++++++++++++++++++------------
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, 99 insertions(+), 70 deletions(-)
[PATCH v3 0/2] usb: offload: Decouple interrupter lifecycle and refactor usage tracking
Posted by Guan-Yu Lin 1 week, 2 days ago
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 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/20260309022205.28136-1-guanyulin@google.com/

Changes in v2:
- Collect the <Tested-by> tag from the OPPO team
- Link to v1: https://lore.kernel.org/all/20260225064601.270301-1-guanyulin@google.com/

Changes in v1:
- Fix build error when building sound/usb/qcom/qc_audio_offload.o
- Link to RFC v2: https://lore.kernel.org/all/20260213100736.2914690-1-guanyulin@google.com/

Changes in RFC v2:
- Move device locking to callers 
- Decouple sideband from offload counting.
- Link to RFC v1: https://lore.kernel.org/all/20260130074746.287750-1-guanyulin@google.com/
---
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        | 107 ++++++++++++++++++------------
 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, 99 insertions(+), 70 deletions(-)

-- 
2.53.0.1018.g2bb0e51243-goog
Re [PATCH v3 0/2] usb: offload: Decouple interrupter lifecycle and refactor usage tracking
Posted by hailong 1 week ago
Hi,
We, OPPO kernel team, have thoroughly verified this patch on our devices.
The test results confirm that it effectively resolves a critical headset
hot-plugging issue and the subsequent system deadlock.

Impact:
This issue is currently a blocker for our upcoming product shipping.
We have observed a high reproduction rate on our latest platforms,
and this patch is essential for our production stability.

Test Environment:
Devices: OPPO devices based on SM8850 and SM8845 platforms.
OS/Kernel: Android 16.0 / Linux Kernel 6.12.

Background:
High reproduction rate (typically within 10 cycles) before
applying this patch.

Original Reproduction Path (Verified fixed):
Open music player and enable USB exclusive mode.
Connect a Type-C digital headset and start playback.
Repeatedly plug/unplug the headset.

Observation:
Within 10 cycles, the headset icon would persist after
unplugging, followed by no audio upon reconnection and a system deadlock.

Stress Test Results with This Patch (Phone A & B):
Test Case 1: USB Exclusive Mode Hot-plug
Steps: Enable USB exclusive mode -> Play music -> Plug/unplug 100 cycles.
Result: PASS. Audio functions normally; no deadlock observed.

Test Case 2: Standard Mode Hot-plug
Steps: Disable USB exclusive mode -> Play music -> Plug/unplug 100 cycles.
Result: PASS. Audio and system stability remain normal.

Test Case 3: Mixed Accessory Switching (Headset/Charger)
Steps: Play music -> Unplug headset -> Plug in charger -> Unplug charger
-> Re-plug headset. Repeated for 30 cycles.
Result: PASS. No issues observed.

The patch looks solid and is critical for our project. We hope these
results help expedite the upstreaming process.

Free to add
Tested-by: hailong.liu@oppo.com