Hi Takashi,

This revision replaces v11 and carries the unmerged prerequisites.
Apply patches 1-12 to sound.git for-next at
a4311e9447bbb219044db38897f95be112f46a8a.
Targeting 7.5 or later still works for me.

Previous revision:
https://lore.kernel.org/linux-sound/[email protected]/T/

The series adds staged capture for shared clients such as dsnoop,
lifecycle recovery and synchronized PCM RESET accounting. Capture
compatibility options remain opt-in and disabled by default.

Changes since v11

The ACK path tried buffer_mutex while holding the PCM lock. That mutex
can already be held during normal RESET, refinement and linked prepare.
ACK then returned -EBADFD despite a valid stream. Private accounting can
also change before the indirect helper sees the ACK error.

Patch 10 uses the PCM lock for ACK and prepare accounting, with a
preparing gate lasting until the RESET callback completes. The core
keeps that same lock through its public pointer rebase. Playback RESET
rebases private accounting while preserving queued TX ownership. Both
capture modes synchronize their private pointers with the common reset,
including RESET from PREPARED. Queue-to-substream lock order is retained.

Paused native capture accepts RX completions from the live prepared
epoch even when transfers are disabled. Refill remains gated by transfer
state. Resume preserves the notification floor, so real missed periods
retain their PCM timer ticks and synthetic progress adds none. Device
events and failed STOP latch XRUN and wake readers. ACK rejects invalid
or stopped streams. Failed PREPARE preserves the previous accounting.

Ordinary RX validates status and payload before advancing counters.
Empty STOP responses contribute zero frames. Full-ring XRUN detection
remains enabled: sample checks showed a real overwritten ring after a
220 ms observation delay. A candidate that suppressed the error returned
frame 31680 where frame 24000 was expected. That candidate was discarded.
The final code reports -EPIPE and recovers through prepare. Normal drain
returns the expected 64-frame tail. The full-ring check in v11 remains
valid; the corrected issue is frame accounting for empty STOP responses.

Byte alignment uses gcd(frame_bits, 8), preserving byte-aligned queue
boundaries for packed 4-bit formats. Broader format runtime coverage is
still pending.

Several findings reproduce before v11, including ACK mutex contention
in the earlier lifecycle implementation and playback RESET accounting.
The ACK mutex findings share one synchronization cause. The staged
pause-tail and missed-period failures reproduce in both v10 and v11.
The local comparison retains original, earlier and final results.

Patch layout and dependencies

  1-6: ACK errors, START/RELEASE recovery and request/DMA lifetime.
  7:   Core stop-threshold accesses used by capture policy sampling.
  8:   Partial-progress notification under the PCM stream lock.
  9:   Optional PCM reset operation under the stream lock.
  10:  Staged capture, lifecycle serialization and driver RESET users.
  11:  Staged capture work priority.
  12:  Capture compatibility option documentation.

Patches 1-8 are unchanged from v11. The previous core patch 12 moves to
patch 9 without a code change. Previous driver patches 9, 13 and 14 are
combined in patch 10 with the corrections above. ACK's preparing gate
and its RESET completion must arrive together; separating them would
leave an intermediate driver with no matching completion path.
Previous patches 10 and 11 become patches 11 and 12.

The core API stays separate from its driver users. Drivers without a
reset callback retain the ioctl path. Linked RESET and prepare stop at
the first error and can leave earlier members completed. Applications
must recover the group after partial failure. A zero callback result
allows the core rebase; later I/O can report XRUN. The internal
snd_pcm_ops change requires out-of-tree users to be rebuilt.

Validation

The final source matches the corrected candidate byte for byte across
all 15 touched files. The comparison includes 43 ARM64 QEMU runs, with
56 transition checks across ordinary/staged capture and KASAN/KCSAN,
and four linked prepare/ACK checks. Faults include ACK contention,
failed PREPARE/STOP, paused RX, status-only RX and invalid ACK states.
KASAN, lockdep and KCSAN_STRICT reported no diagnostics in those runs.

Uninstrumented RW and MMAP captures ran for 70 seconds per mode and
capture policy, with pause, RESET and reopen. All 14 segments,
14,208,000 mono S16 frames at 48 kHz, matched independent sequence
hashes. Native-pause tail checks and PCM timer tests compared v11 with
the correction. Core compatibility tests include 72 callback/legacy,
atomic/nonatomic and linked-failure checks, plus snd-dummy playback and
capture. Test hooks are excluded from the submitted source.

Each of the 12 reconstructed intermediate sources is checked by applying
its mail patch to the pinned baseline and comparing the postimage.
ARM64 W=1 Image/modules builds and additional intermediate-stage runtime
checks are recorded in the local submission package. Fifteen additional
VM runs passed, including 28 injected transition checks at patch 10.

These are ARM64 QEMU TCG tests with two vCPUs and 512 MiB. Physical
VZ/MOTU acceptance for this revision and broader format, multichannel
and architecture runtime coverage remain pending. Earlier high-load
TCG XRUN results limit performance conclusions; this revision does not
claim a general CPU or scheduling improvement. The optional core APIs
and linked RESET partial-failure policy still need maintainer review.

Coding assistance was used for analysis, implementation, fixtures and
this explanation. The patches carry Assisted-by: LLM.

Thanks,
Joonho

base-commit: a4311e9447bbb219044db38897f95be112f46a8a

Reply via email to