Skip to content

drm/apple: afk: retire a superseded singleton AV service - #3175

Merged
RyanTheTide merged 2 commits into
mainfrom
m2mdf/afk-av-singleton
Nov 25, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
m2mdf/afk-av-singleton

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What: On the classic AV endpoint, DCP firmware 27.2 announces DCPAVSimpleVideoInterface and DCPAVAudioInterface again on fresh channels every time the display comes back (DPMS on, wake, re-attach). It never closes the old channels. The old instances stayed enabled, so their service slots were never reclaimed. After eight attaches the endpoint's 16 slots were used up ("no reusable service slots") and monitor audio was gone until reboot. This change marks the two classic AV services as singletons. When a singleton is announced on a new channel, the previous instance is retired, and its slot is reclaimed once its last user lets go. This is the same rule afk_compact_slot() already applies on the compact path. Firmware that closes the old channel first is unaffected, and nothing depends on the SoC, board or firmware version.

Tested:

  • J473 (M2 Mac mini, T8112, 27.2) at 5938e9e5e9b6 pass (kernel code identical to the tested 327fbdaf; later commits only update host-test models). Kernel: signed m2combo19 source (main 02c235a + drm/apple: stop an external firmware-27 pipe on DPMS off #3157) plus this commit, fleet default options. One boot ran 18 DPMS-off batches (6 with an RTC s2idle while off), 6 forced off/detect and 3 RTC wakes. Both monitor audio routes kept jack, ELD and sink at all 8 checkpoints. 46 audio-service announcements, where 8 was the ceiling before, with 0 "no reusable service slots".
  • KUnit apple-afk-service-lifetime 13/13, including the new singleton re-announce test (64 attaches on 4 slots). The new test fails without the fix. Host tests run-host-tests.py --only apple-dcp, --only dcp (65/65) and --only afkv2 pass. checkpatch clean.

Risk: two-way door. Affects the classic AV endpoint's video and audio services on every Mac that uses it (M1/M2 generation DCPs on 12.3/13.5 and 27.2 firmware). The firmware already treats these services as one live instance per endpoint. Compact-path and other services are unchanged.

Not yet: a row on a 13.5-firmware Mac with an external display (J413/M1 Pro with a monitor attached), where the old channel is expected to close first and the change should be a no-op.

Details

Evidence on the J473 before the fix (signed m2combo19, longer boot): the USB-C DCP saw 8 DCPAVSimpleVideoInterface and 8 DCPAVAudioInterface announcements with 0 teardowns and 0 command timeouts, then "no reusable service slots" on the next attach. The HDMI DCP behaved the same way. afk_service_reinit() only reclaims a slot that is torn down, not enabled, without users and without pending commands, and the abandoned instances never got torn down.

The superseded instance is only retired, without its teardown callback. The successor's init already takes over the service's state (for audio, av_audiosrv_init() drops the old instance's owner pin), and calling the video teardown would mark the sink unplugged.

Gate for #3157: real external DPMS made this leak hit after about two screen-offs, so that PR merges with or after this one.

On the classic AV endpoint, DCP firmware 27.2 announces its
DCPAVSimpleVideoInterface and DCPAVAudioInterface again on fresh
channels every time the display comes back (DPMS on, wake, re-attach)
and never closes the previous channels. The old instances stayed
enabled, so their slots were never reclaimed. After eight attaches a
Mac mini (M2) used all 16 service slots of the endpoint, logged "no
reusable service slots" and lost monitor audio until reboot.

The compact path already replaces such re-announced services in place
(afk_compact_slot()). Do the same on the classic path for services
that are singletons, one live instance per endpoint: an announcement
on a new channel retires the previous instance, and its slot is
reclaimed once its last user lets go. The successor's init takes over
the service's state, as before. Firmware that closes the old channel
first is unaffected: its instance is already torn down.

Mark the classic AV video and audio interfaces as singletons, and add
a KUnit test that re-announces them many more times than there are
slots.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 25, 2026 23:00
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (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 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at 5938e9e5: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 5938e9e5
Conflicts ok none
PR text ok Risk: two-way · . Affects the classic AV endpoint's video and audio services on every Mac that uses it (M1/M2 generation DCPs on 12.3/13.5 and 27.2 firmware). The firmware already treats these services as one live instance per endpoint. Compact-path and other services are unchanged.

Areas: area:display, area:gpu

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

DjDeveloperr
DjDeveloperr previously approved these changes Nov 25, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Audited full diff across afk.h, afk.c, av.c, afk-service-test.c, and edid.py: cleanly retires superseded singleton AV instances on fresh channel re-announcement without disturbing pinned active users or non-singleton/different services, with solid KUnit coverage and J473 46-announcement verification. Holding merge until CI completes green and the 13.5-firmware row is posted.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
afk_recv_handle_init() now supersedes the previous instance of a
singleton service and drops its debugfs entry. Give the host model the
ops flag, the helper and a debugfs stub, as the apple-dcp model has.

Signed-off-by: Ryan Murray <[email protected]>
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 25, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-approved at 5938e9e: the host-test stub update in tools/asahi/dcpext26-startup-tests.py cleanly mirrors the new singleton flag, afk_remove_service_debugfs(), and afk_service_supersede().

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

944b9be10bc7 (batched cleanly in J616s Batch #2 5b411e230229 over main 95a983c08be4, 0 merge-tree diffs across all 5 changed files) J616s (MacBook Pro 16" M4 Pro, T6040, Apple M4 Pro (G16S B1), macOS 26.6.2 fw, guarded one-shot 7.3.0-aurora-pr2905+, default cmdline, stock Stage 2 1.0.0b17, boot_id=de17fad3) PASS: 0 failed units, Enforcing, 0 new AVC (1 matching baseline), 0 GPU faults, 0 errors in this subsystem, real rtc1 s2idle 2/2 (success=2 fail=0), eDP connected pre/post-sleep, 406600000.sep + 514600000.mtp RTKit v12 (AppleMTPFirmwareMac-5340.61.4~502, HID keyboard/trackpad/accel/actuator/touch) clean, Borealis VK dEQP-VK.api.smoke.* 8/8 (pre & post-sleep) + glsl.loops.* 624/624, Wi-Fi 3/3 ping pre/post-sleep; stock 7.3.0-aurora-fleet89 restored & verified (b67edc6c).

@RyanTheTide
RyanTheTide merged commit 7c0c2fc into main Nov 25, 2026
22 of 24 checks passed

@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.

Verdict at 5938e9e5

The replacement-admission error path needs a follow-up.

Blocker

afk_recv_handle_init() retires the active singleton before it has reserved a slot for the replacement. When every slot is pinned or has a pending command, the allocation loop can return without a successor. The audio owner still holds the previous service, but that service has been disabled and retired. The successor's init callback never runs to replace the published audio reference.

Retain the active service through replacement admission. Add a regression case that fills the available slots while an audio owner reference and a pending command are still present, rejects the replacement, and verifies the previous service remains usable.

Checked

The standalone host model exercised the current service lifetime helpers. The successful reattach hardware row covers normal admission. The model covers failed admission.

Evidence

The model starts with an enabled audio singleton on channel 7 with one owner reference, and a separate retired slot with an outstanding command. A singleton announcement on channel 11 retires channel 7. Both slots then fail the reclaimability check. The result was zero admitted replacements, zero availability for channel 7, its owner count still one, and its retired flag set.

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) area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants