Skip to content

drm/apple: afk: retire a superseded singleton only after its successor is admitted - #3177

Merged
DjDeveloperr merged 2 commits into
mainfrom
m2mdf/afk-supersede-after-admit
Nov 26, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
m2mdf/afk-supersede-after-admit

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Follow-up to #3175, fixing the failure path M2MINI-ORACLE found in its review (#3175 (review)). afk_recv_handle_init() retired the live singleton as soon as its replacement was announced, before the replacement had a slot. If no slot was reclaimable, or the replacement failed admission or OPEN, the replacement was dropped while the audio owner kept a reference to a disabled, retired service and no successor was ever handed over. Now the previous instance is retired only once the replacement holds its slot and has been admitted and opened, right before it is published and its init takes over. A rejected replacement leaves the previous instance usable. The successful path is unchanged.

Tested:

  • Host: a new service-rebind scenario drives the real afk_recv_handle_init() with every other slot retired and owing a reply. The replacement is rejected, and the previous instance stays enabled, unretired and owned. Once a slot comes back, the replacement is admitted and only then retires it. The scenario fails on main's order (assertion on the previous instance) and passes with this change. run-host-tests.py --only apple-dcp, --only dcp (65/65) and --only afkv2 pass.
  • KUnit apple-afk-service-lifetime 13/13; its announcement model now admits first, then supersedes.
  • J473 (M2 Mac mini, T8112, 27.2) at 63f53f29d771 pass: exact-head kernel, 18 DPMS-off batches + 3 RTC wakes, both monitor audio routes kept jack/ELD/sink at all 8 checkpoints, 42 announcements, 0 slot errors, 0 timeouts (row comment below).
  • J473 at 63f53f29d771 pass, physical cable replug: Acer (HDMI) then MSI (USB-C/DP) unplugged and replugged with a 1 Hz connector/sink/kernel-log capture (98 samples). Each connector went disconnected then connected and both monitor audio routes were back at the end (drm/apple: afk: retire a superseded singleton only after its successor is admitted #3177 (comment)). The USB-C route's PipeWire label falls back to a generic name, which is also seen on the fleet kernel without this change; that is tracked separately as a userspace late-ELD naming issue.

Risk: two-way door. Reaches every singleton service announced through the classic afk_recv_handle_init() path: the classic AV video/audio services on M1/M2-generation DCPs (J473 27.2, 12.3/13.5 firmware), and the compact-profile AV and CEC singletons that newer Macs (M3/M4/M5 externals on firmware 27) announce through the same path. The previous instance is now retired slightly later, after the replacement's OPEN instead of before slot allocation. During that window both are live, which is the state the firmware itself reports.

Not yet: nothing for this change; both generations and both reconnect kinds are covered above.

…r is admitted

afk_recv_handle_init() retired the live instance of a singleton service
as soon as its replacement was announced, before the replacement had a
slot. When no slot was reclaimable (every slot pinned by a user or
waiting for a reply) or the replacement failed admission or its OPEN,
the replacement was dropped while the previous instance was already
disabled and retired. Its owner (the audio service) kept a reference to
a service it could no longer use, and no successor's init ran to hand
it a new one.

Retire the previous instance only once the replacement holds its slot,
has been admitted and opened, right before it is published and its init
takes over. A rejected replacement now leaves the previous instance
usable.

Add a host scenario that runs the real announcement path with every
other slot pinned: the rejected replacement leaves the previous
instance enabled and owned, and an admitted one retires it. Order the
KUnit announcement model the same way.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 26, 2026 00:19
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (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 63f53f29: 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 63f53f29
Conflicts ok none
PR text ok Risk: two-way · . Reaches every singleton service announced through the classic afkrecvhandleinit() path: the classic AV video/audio services on M1/M2-generation DCPs (J473 27.2, 12.3/13.5 firmware), and the compact-profile AV and CEC singletons that newer Macs (M3/M4/M5 externals on firmware 27) announce through the same path. The previous instance is now retired slightly later, after the replacement's OPEN instead of before slot allocation. During that window both are live, which is the state the firmware itself reports.

Areas: area:display

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

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

The replacement-admission finding from #3175 is resolved in this host check. With the other service slots pinned, a rejected announcement leaves the current AV service enabled and owned. Once a slot is available, the retry admits its successor and retires the old service.

I ran the service-rebind host test at 63f53f2 with Clang, AddressSanitizer and UndefinedBehaviorSanitizer. It passed. Running the same test with the merged #3175 afk.c failed at the assertion that the original service remains usable. Both native startup checks and all three mutation controls also passed. The J473 hardware check remains pending.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

63f53f2 J616s (T6040, M4 Pro) PASS: guarded one-shot combined batch (0aa9d658ff34 over main bc9b4c0, 0 merge-tree diffs on 4 changed files, default cmdline, stock Stage 2 1.0.0b17, boot 2546a528-6d7f-434e-b679-90a87d626c2e): 0 failed units, Enforcing, 0 new AVC, 0 GPU faults, 0 new kernel/subsystem errors, eDP connected pre/post, sep+mtp RTKit v12 clean, Borealis VK api.smoke 8/8 pre/post + glsl.loops 624/624, Wi-Fi 3/3 ping pre/post, 2/2 rtc1 s2idle; stock 7.3.0-aurora-fleet89 restored.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 26, 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.

Verdict: FINISH, then merge at 63f53f29d771

Blockers: The change still needs an external-display reconnect with audio on J473 and a reconnect on a second generation using the compact AV or CEC services. The J616s row checks the internal panel and s2idle.

Checked: If the replacement has no reusable slot, fails admission, or fails OPEN, the old service stays usable. The host test covers a rejected replacement and then a successful handover. The retirement loop also serves compact AV and CEC on newer Macs, so the Risk line should include those paths.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J473 (M2 Mac mini, T8112, 27.2) at 63f53f29d771 pass. Full kernel from this exact head (main 7c0c2fc + this PR), signed m2combo19 Stage 2, fleet default options. One deviation: CONFIG_APPLE_CENTAURI_T6050_WIFI was off because main currently does not build it (reported separately); the J473 does not use it.

  • One boot ran 6 DPMS rows (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 (16/16), ELD with the monitor name (8/8 each) and a sink (8/8 each) at every checkpoint.
  • 42 audio-service announcements, 40 supersedes, 0 "no reusable service slots". Both outputs back 24/24, 42 pipe-offs with 0 timeouts, 3/3 wakes on the same boot.

The success path behaves as before. The failure path is covered by the new host scenario, which fails on main's order.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Thanks. I updated the Risk line to cover the compact AV and CEC singletons on newer Macs.

On the J473: the exact-head row above reattached the external AV services 42 times through DPMS on and RTC wake on both monitors, and both kept their audio (jack, ELD and sink at every checkpoint). The firmware re-announces the services on each of those reattaches. That is not a cable replug, though. I've asked for a physical HDMI and USB-C replug with audio. The second-generation reconnect (compact AV/CEC) needs a monitor on a J616s, J713 or J615; none has one attached right now. Both are listed under Not yet, and I'll post the rows here when they're done.

@github-actions github-actions Bot added blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) labels Nov 26, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Physical hot-plug row, J473 (M2 mini), exact head 63f53f2 (7.3.0-aurora-m2mdfsup, one-shot, default cmdline, signed Stage 2 e1073db5).

Unplugged the HDMI monitor (Acer, HDMI-A-1) for ~10 s and replugged, then the USB-C-to-HDMI monitor (MSI, DP-2) the same way, with a 1 Hz capture of DRM connector state and PipeWire sinks plus the kernel log.

  • Both connectors went disconnected and came back connected (HDMI-A-1 ~4 s, DP-2 ~13 s).
  • Both monitor audio outputs came back: two HDMI/DP sinks at the end (Acer by name; the USB-C one keeps the existing generic label, tracked separately).
  • On replug the firmware re-announced the AV services and the driver logged DCPAVSimpleVideoInterface on channel 5 supersedes channel 1 and DCPAVAudioInterface on channel 7 supersedes channel 3, then starting audio service, plugged:1. No slot-exhaustion messages.

Result: PASS for the J473 reconnect-with-audio item. The second-generation external reconnect row is still to come.

@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: MERGE at 63f53f29 once Dj's reconnect rows are in (no code blockers)

Blockers: none in the code. The open items are Dj's rows: an external-display reconnect with audio on J473 (Ryan's hot-plug capture is armed for that) and one reconnect on a second generation that uses the compact AV/CEC path. This is a non-author review; GitHub records it as a comment because this account opened the PR.

Checked:

  • afk_recv_handle_init() now runs the supersede loop only after the successor has a slot, passed admission and is opened. Every rejection path above it is a goto free, so a rejected successor never retires the old instance. old != service keeps the new instance out of its own loop.
  • One trade-off: the successor can no longer reuse the slot of the instance it replaces in the same announcement, so each re-attach holds one extra slot until the old owner lets go. ORACLE's J473 row bounds that in practice: 40 replacements with zero slot exhaustions.
  • The KUnit model (afk_test_announce) and the host selftest now follow the driver's order. The new host case pins every other slot, checks that the rejected replacement leaves the old instance enabled with users==1, then frees a slot and checks the handover.
  • No gate, parameter or delay. The loop is shared by classic and compact singleton services, so the Risk line should name compact AV/CEC, as Dj noted.
Evidence
  • ORACLE host replay at 63f53f2: traces/ci/20261124-m2mini-oracle/afk-3177-host-confirmed-20261126T112200.txt. The same test with merged #3175 afk.c fails on SIGABRT.
  • J473 audio row: traces/ci/20261124-m2mini-oracle/j473-3177-hardware-audio-verdict-20261126T125948.json

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J616s (M4 Pro, T6040, second generation) physical reconnect row at the exact head 63f53f2: guarded one-shot on the default cmdline, saved fleet89 restored afterwards (saved entry fleet89, next empty, Enforcing, 0 failed units, trial kernel removed).

  • MSI on USB-C/DP: connected at 19:12:51. Then one unplug for about 14 s and a replug at 19:13:32. The connector went connected, then disconnected, then connected again.
  • On each plug, the DCP AV, audio and DP services were re-announced and the old instance superseded (the replacing compact service ... new compact service path this PR adds). There were 0 DCP crashes and 0 slot-exhaustion lines.
  • Not covered: the capture's PipeWire sink and ELD columns are empty, because the root capture had no access to the user session. The capture also stopped 9 s after the replug. So sink-name and CEC re-enumeration are not proven by this row.

Evidence (lab): traces/display/20261126-3177-second-gen-hotplug/cap-j616s.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

63f53f2 J616s (M4 Pro, T6040, no-hands simulated replug + DPMS + seat-user PipeWire) PASS: 3/3 DRM off->detect on card2-DP-3 + 3/3 GNOME Mutter DPMS off/on cleanly re-announced 33/33 compact AV/DP services and restored seat-user PipeWire sink [Built-in Audio HDMI / DisplayPort Output [MPG 325CQRXF] (Stereo)] ([Out] HDMI1) every cycle, muted /dev/zero paplay OK, 0 DCP crashes/slot exhaustion/flip timeouts, Enforcing, 0 failed, 0 AVC, 0 new display/audio kernel errors; fleet89 restored.

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

Verdict: approve at 63f53f29d771.

Blockers: none.

Checked:

  • afk_recv_handle_init() now runs the supersede loop only after the new instance holds its slot and has passed admission and OPEN, and it skips the new instance itself (old != service). A replacement rejected for a missing slot, failed admission or a failed OPEN takes one of the goto free paths before that loop, so the audio owner keeps a live instance.
  • The successful path keeps its order: retire, then publish, then the successor's init drops the old reference.
  • The KUnit model and the new host scenario follow the same order, and the scenario fails on the old order.
  • Rows at this head cover both generations: on the J473, the classic path with 18 DPMS-off batches, RTC wakes and a physical replug of both monitors; on the J616s, the compact path with a physical reconnect, 3/3 forced reconnects and DPMS, and the sink back each time with 0 DCP crashes.

One note, not a blocker: an unowned old instance can no longer donate its own slot to its replacement, because it's only retired afterwards. With every slot full, such a replacement is now refused where it used to succeed. The rows saw 42 announcements and 0 slot errors, so this doesn't happen in practice. If it ever shows up as a slot-exhaustion line, that's where to look.

@DjDeveloperr
DjDeveloperr merged commit b127813 into main Nov 26, 2026
28 of 32 checks passed
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) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 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) 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.

2 participants