Skip to content

drm/apple: audio: end a stream whose service instance was replaced - #3286

Merged
RyanTheTide merged 2 commits into
mainfrom
m2mdf/audio-superseded-xrun
Nov 27, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
m2mdf/audio-superseded-xrun

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: When the firmware replaces the DP/HDMI audio service while the sink stays connected, a stream running on the old instance is now ended as an xrun, and userspace prepares it again on the new one. Before, the replacement came up already plugged, so the card saw no unplug. The stream kept waiting on a link that had gone with the old instance: its DMA stopped and playback hung in RUNNING until the PCM was reopened.

On the M2 Mac mini (firmware 27.2) this happens after every short system sleep. The HDMI monitor drops HPD for ~1.7 s as it wakes, and ~10.7 s after the resume the firmware announces DCPAVAudioInterface on a new channel. A stream started in that window stops after ~1.5 s.

How: dcp_audiosrv_startlink() reports the generation of the instance the link starts on, read under the srv_rwsem write lock that picks the instance. Each newly opened instance connects the card (dcpaud_connect()), which queues a work item. Under the PCM stream lock, that work ends a running stream whose recorded generation is no longer the published one. A stream playing into the void (no sink) has no link and is left alone. Native-link PCMs are not touched. No firmware, SoC or board check.

The work is only queued while the card is bound: it starts disabled, is enabled once the card is registered, and is disabled at unbind (waiting for a running one) before the card is freed. The DCP unbinds after its audio and may still connect meanwhile; such a connect queues nothing.

Tested:

  • J473 (M2 Mac mini, T8112, 27.2) at efa19470 pass: same row as below, HDMI 3/3 with the xrun 3/3, USB-C 3/3, no WARN/Oops in the trial boot including its shutdown (card unbind), restore verified.
  • J616s (M4 Pro, T6040, 27.2) at efa19470 pass (peer, same classic DP-audio ops): guarded one-shot with the signed combo23 J616s Stage 2, 3 RTC wakes each followed by an 18 s zero-sample stream on its DP monitor, 3/3 complete, 0 kernel warnings, saved default restored and verified. No service replacement happened during these streams, so this row shows no regression, not the fix firing.
  • J473 (M2 Mac mini, T8112, 27.2) at f923c386 pass: HDMI monitor stream after an RTC s2idle wake 3/3 (pw-cat completes; the xrun fires 3/3 when the successor appears mid-stream, and hw_ptr restarts and advances at 48 kframes/s to the end), USB-C 3/3, restore to the saved default verified.
  • J473 (M2 Mac mini, T8112, 27.2) at 859e8a29 (main, no fix) fail, same row: HDMI 0/3 (pw-cat times out, hw_ptr frozen), successor during each stream 3/3, USB-C 3/3.
  • Both J473 arms use the signed m2combo23 kernel config and Stage 2, the default command line, and zero samples (silent).
  • KUnit apple-dcpaud-* 31/31 on arm64 QEMU, with 3 new legacy-path cases: a replaced instance ends the stream and the next START records the successor; the same instance leaves the stream playing; a void stream is untouched.
  • checkpatch --strict clean.

Risk: two-way door. Only classic-ops DP audio is affected (!native_link). A healthy stream is left alone: the work compares generations under the stream lock that START records them under (KUnit same-instance case). A stream on a replaced instance gets one xrun, which PipeWire recovers from without reopening (J473 rows). Unplug, DPMS and system-sleep paths are unchanged: they stop or suspend the stream before any connect.

Not yet:

Evidence and timeline

Raw rows (store, not public): traces/display/20261127-j473-hdmi-audio-wake-stall/ (README, ab-summary.txt) and traces/display/20261125-j473-dpms-relight/{m2combo23-wa-ctl,m2mdfaw2-wa-fix}.

Kernel timeline of the original stall (m2combo23, monotonic s): 2837.78 resume; 2838.03 HDMI HPD low; 2846.52 stream opens; 2848.19 dcp_hotplug() connected:0; 2848.47 DCPAVAudioInterface on channel 87 supersedes channel 83 + av_service_connect: starting audio service, plugged:1; the stream's hw_ptr stops at 74752 frames (1.56 s). On the saved production kernel (no post-wake HPD low) the same check passes, because no successor appears during the stream.

An earlier version hooked only the native-link ops and did not engage on the J473, which uses the classic ops (0/3 on the same row). That version was dropped. Two race windows found in review (generation read outside the startlink lock; generation read outside the stream lock) and the teardown admission (work queued by a DCP connect after the audio unbind cancelled it) are closed in this head.

The firmware publishes a successor of the DP audio service whenever the
display link is set up again, also with the sink connected throughout.
The successor comes up plugged, so the card sees no unplug and a running
stream is not stopped. The link the stream started on went with the old
instance: its DMA stops and the stream waits in RUNNING until the PCM is
reopened.

On the M2 Mac mini (firmware 27.2) this happens after every short system
sleep. The HDMI monitor drops HPD for ~1.7 s as it wakes, and ~10.7 s
after the resume the firmware announces DCPAVAudioInterface on a new
channel. A stream started in between stops after ~1.5 s.

Record the instance a stream's link starts on, read under the lock the
start call takes the instance with. Each newly
opened instance connects the card; a stream still running on an older
instance then ends as an xrun, and userspace prepares it again on the
successor. A stream playing into the void (no sink) has no link and is
left alone. The instance comes from the service's own generation count,
not from a firmware or board test.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 26, 2026 17:44
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at efa19470: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at efa19470
Conflicts ok none
PR text ok Risk: two-way · . Only classic-ops DP audio is affected (!nativelink). A healthy stream is left alone: the work compares generations under the stream lock that START records them under (KUnit same-instance case). A stream on a replaced instance gets one xrun, which PipeWire recovers from without reopening (J473 rows). Unplug, DPMS and system-sleep paths are unchanged: they stop or suspend the stream before any connect.

Areas: area:display

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

The DCP unbinds after its DP audio component and may still connect the
card meanwhile. Cancelling the work at unbind left it free to be queued
again by such a connect, and the work then acted on the substream of a
card being freed.

Keep the work disabled outside a bound card: it starts disabled, is
enabled once the card is registered, and is disabled (waiting for a
running one) at unbind before the card is freed. A connect while it is
disabled queues nothing.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal non-author review at efa19470: no blocking findings. MERGE once CI is green and the peer row is in (MERGETRAIN6). ORACLE's teardown hold was lifted for this head at 09:18.

Checked the one-commit delta on top of f923c386 (audio.c, +18/-1):

  • Lifecycle balance. disable_work() runs right after INIT_WORK() in probe. enable_work() runs only after dcpaud_init_snd_card() succeeds in bind. Unbind calls disable_work_sync() only if replaced_enabled is set, then clears it. The disable count stays balanced across a bind that fails (unbind doesn't run, and the work stays disabled), across unbind/rebind cycles, and across remove without bind (never queued). replaced_enabled is only touched in bind/unbind, which the component framework serializes.
  • The race it closes. dcpaud_connect() queues after dcpaud_report_hotplug() has dropped data_lock, so the dcpaud->card check there is unlocked. With this change that's safe: once unbind has run disable_work_sync(), a racing connect's schedule_work() returns false and queues nothing. A work that was already queued or running finishes before snd_card_free_when_closed(). schedule_work()'s return value is ignored and no reference is taken, so nothing leaks when it is refused.
  • Work body unchanged. It still checks substream/dcp_dev and stops a running stream as XRUN under the PCM stream lock only when start_gen no longer matches the live instance.
  • Rows: the J473 3/3 silent wake runs with one HDMI service replacement per stream completed 3/3 at this source (ORACLE 09:17), against 3/3 timeouts on combo23.

Still owed before merge: green CI at this head, and the peer row ORACLE named (a second Mac on the same audio path).

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 26, 2026
@RyanTheTide
RyanTheTide merged commit d3552ef into main Nov 27, 2026
22 of 25 checks passed
@RyanTheTide
RyanTheTide deleted the m2mdf/audio-superseded-xrun branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:display Area from CODEOWNERS (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant