Skip to content

drm/apple: audio: no reports to a card that is gone - #3265

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
themartiano:fix/dcp-audio-card-gone
Dec 4, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
themartiano:fix/dcp-audio-card-gone

Conversation

@themartiano

@themartiano themartiano commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Components unbind in reverse order, so a DP audio interface unbinds before its DCP. dcpaud_comp_unbind() frees the card but leaves dcpaud->card set, while the DCP's AV endpoint still runs and can report a sink connect or disconnect to it. The shutdown at every reboot takes this path too. Reports now need the card: it is taken away under data_lock before it is freed, and a report holds a reference on it. stale_work is no longer queued again after the unbind cancelled it.

Tested: No Mac runs this code at 32b705c yet (see Not yet). Host side at 32b705c: new KUnit suite apple-dcpaud-card 1/1 and apple-dcpaud-* 24/24 on arm64 QEMU with KASAN. With the pointer left set, the kernel reports refcount_t: underflow; use-after-free and the case fails. Merged with today's main 859e8a2 (no conflict): KUnit apple-dcpaud-* 29/29. Found by reading the code, not seen on hardware. Regression only: J713 M4 Air (26.6.2) at the same diff (04b2e294907e), kernel = main ba29027 plus all our open branches combined: boots, 0 failed units, 0 kernel errors, 10 of 10 deep sleeps. This code does not run there, because main has no DP audio on the J713.

Rebased onto main 9177b2d474f8 on 2026-12-02; head now 40a07087428f. One conflict in dcpaud_unbind(): main now stops the replaced-link work there first; this PR's taking of the card under data_lock follows it, unchanged. Host checks re-run at the new head: W=1 arm64 build of drivers/gpu/drm/apple/, 0 warnings; checkpatch --strict only notes the new test file (MAINTAINERS). KUnit dcp-fabric, dcp-topology, dcp-display (the suites CI picks for these files) on arm64 QEMU: no failures (one case skips in each of two suites). With audio enabled, apple-dcpaud-* 31/32 (the new apple-dcpaud-card passes; no-sio skips). The hardware rows above are from before the rebase.

Risk: two-way · every Mac with DCP audio (an apple,dpaudio node): M1, M2, M1/M2 Pro/Max/Ultra, M3 Pro/Max, M4 Pro/Max, J714s and Neo in main's trees. The paths are unbind, reboot/shutdown and the connect/disconnect reports.

Other Macs: This is shared DCP audio code, not M4 code. On every Mac above it stops a use-after-free when the audio component unbinds before its DCP, which happens at every reboot. While no card exists, a sink report is now dropped instead of going to freed memory. The sink state goes with the card, so a card made by a later bind starts unplugged and the next connect reports the jack as plugged. While the card is bound, reports behave as before, now under the lock and with a reference held.

Not yet: hardware rows. The J713 cannot give one on main today: DP audio there needs a newer aura boot loader and the DT in #3137. Any Mac with working DCP/HDMI audio can: 10 reboots with a monitor that has audio connected and the output off (DPMS), no oops or KASAN report; then a hotplug and a playback check.

Details
  • Why it can happen: component_unbind_all() goes in reverse, so the audio device unbinds before its DCP. The AV audio endpoint keeps running until the DCP's own teardown, and the firmware can publish or withdraw its audio service in that window. dcpaud_connect(), dcpaud_disconnect() and dcpaud_refresh_eld() then use the freed card's controls and jack. dcpaud_shutdown() (every reboot) takes the same path.
  • The fix: take the card away under data_lock before freeing it, report with a reference held, drop the sink with the card, and queue stale_work only while there is a card.
  • Not covered: dcpaud_sleep_quiesce() still uses dcpaud->substream if a system sleep runs while the component is unbound but the driver is still bound.
  • checkpatch --strict: one warning, "does MAINTAINERS need updating?", for the new test file drivers/gpu/drm/apple/audio-card-test.c.
  • The test file's #include line touches the same spot as drm: apple: audio: legacy path: 256 KiB audio elements, PM reference held until the DMA stopped #3128; a one-line conflict if both land.
Evidence

Components unbind in reverse order, so a DP audio interface unbinds
before its DCP, whose AV endpoint still runs then: the firmware can
publish or withdraw its audio service, and the DCP's own teardown ends
it. dcpaud_comp_unbind() frees the card but leaves dcpaud->card set, so
such a report goes to a freed card's controls and jack. The shutdown of
the audio device takes this path too. A disconnect also queues
stale_work again after the unbind cancelled it.

Take the card away under data_lock before it is freed, and report only
with a reference on it. The sink goes with the card: otherwise a card
made by a later bind would keep its jack unplugged, as the next connect
finds the sink connected already. Queue stale_work only while there is a
card.

Found by reading the code, not seen on hardware.

Signed-off-by: Eduardo <git@martiano.me>
@themartiano
themartiano force-pushed the fix/dcp-audio-card-gone branch from 32b705c to 40a0708 Compare December 2, 2026 12:08
@themartiano
themartiano marked this pull request as ready for review December 2, 2026 16:15
@themartiano
themartiano requested review from a team as code owners December 2, 2026 16:15
@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-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at 40a07087: ready to merge

Check Detail
CI at head ok 9 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at 40a07087
Conflicts ok none
PR text ok Risk: two-way · every Mac with DCP audio (an apple,dpaudio node): M1, M2, M1/M2 Pro/Max/Ultra, M3 Pro/Max, M4 Pro/Max, J714s and Neo in main's trees. The paths are unbind, reboot/shutdown and the connect/disconnect reports. Other Macs: This is shared DCP audio code, not M4 code. On every Mac above it stops a use-after-free when the audio component unbinds before its DCP, which happens at every reboot. While no card exists, a sink report is now dropped instead of going to freed memory. The sink state goes with the card, so a card made by a later bind starts unplugged and the next connect reports the jack as plugged. While the card is bound, reports behave as before, now under the lock and with a reference held.

Areas: area:display
Merge: gh pr merge 3265 --merge (Owners and Core through the bypass: add --admin).

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

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

Approve at 40a07087428f. Reports now hold a card reference taken under data_lock (dcpaud_card_get() pairs with the snd_card_unref cleanup), and unbind clears card, connected and the ELD under the same lock before snd_card_free_when_closed(). stale_work can only be queued under the lock while the card exists, so the later cancel_work_sync() in unbind catches anything queued before that. The jack and ELD control a report touches belong to the card, so the reference keeps them alive.

Checked on pc, merged with main 1b95b711bbc2 (no conflict): W=1 drivers/gpu/drm/apple/audio.o (asahi profile) builds with no warnings. I approved the fork CI runs at this head, so the hosted KUnit plan will run apple-dcpaud-card.

Before merge: rows on two generations with DCP audio, as in your Not yet. Do 10 reboots with an audio-capable monitor connected and DPMS off, with no oops or KASAN report, then a hotplug and a playback check.

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

Copy link
Copy Markdown
Contributor

J616s (16" MacBook Pro M4 Pro, T6040, 26.6.2 stub) with an MSI MPG 325CQRXF on its own DCP DP output (USB-C, through a dock's passthrough; DP tunnel dpin0, apple_dcp card USBC) at exact head 40a07087428f: reboot part PASS (11/11). Hotplug and playback capture are still open (they need hands).

  • Kernel 7.3.0-mrp3265 from the head (fleet config), one-shot boot with its own t6040-j616s.dtb via aura-try (aura 70d844e3, U-Boot 5c0d5fe1), re-armed for every cycle. The saved default was not changed. The test entry added modprobe.blacklist=nouveau,snd_hda_intel: a GTX 1080 sits on the same dock, and its drivers stayed unbound so they could not interfere. The tree is not a KASAN build.
  • 11 DPMS-off reboots, each one: the MSI connected and card USBC present → Mutter PowerSaveMode 3 (dpms Off) → reboot → back on 7.3.0-mrp3265 in 62–75 s with the MSI and card present again. Boots (in order): bb3dc1c7 f23b0c48 f180f25e cfe88be4 5ca14d64 f17e3720 a5f1e6a2 070e1dc5 60ce0592 ab24ae53 af8820cf. In every previous boot's kernel log: 0 refcount_t / use-after-free / WARNING / BUG / Oops / call-trace lines. The audio service starts (av_service_connect … plugged:1) and stops (__av_service_disconnect) normally around each DPMS change.
  • Coverage limit: the persistent journal ends when journald stops, and a netconsole capture over the Thunderbolt link (cycle 11) ends when the USB4 session closes at the start of device shutdown. So the very last component unbind at reboot was not captured. What was captured up to that point is clean, and all 11 reboots completed.
  • Hotplug: not done in software. This port's SN201202x refuses the tipd DISC (simulated disconnect) through the debugfs command node (EINVAL with and without the seconds byte; it would need the debug-mode unlock, which I did not use). The port has no replug node, and ddcutil isn't installed. A physical replug is next.
  • Playback: the DP stream runs (card USBC RUNNING, 48 kHz S24_LE, a 1 kHz tone at −26 dBFS with the sink at 100%). However, the MSI's 3.5 mm output reached the capture input at the noise floor (−107 dBFS) on the saved kernel as well, so the loopback cable or monitor setting is being checked. I'll add the capture once it's fixed.

Afterwards the Mac went back to its production default (fleet94, Enforcing, 0 failed units).

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Coverage note from our fleet: neither the J773g (M4 mini) nor the J516s (M3 Pro) can run this path. Main's device trees for both have no apple,dpaudio node (only J713/J715 have one), so no DP audio card ever binds there. A Type-C replug only sends connect/disconnect reports to a card that is still bound; the card goes away only at component unbind (reboot, shutdown or driver unbind). So the J616s reboot row above (11/11) is the row that runs the card-gone path.

For the hotplug part without hands: echo 3 > /sys/kernel/debug/usb/tipd/<hpm>/replug (on main since #4056, 1d4de270) unlocks the port controller with the board key, sends DISC 3, waits for the partner to come back and locks it again, so the partner really detaches for 3 s and DP alt mode drops. A bare DISC written to the command node returns EINVAL on SN201202x controllers, because they refuse it until unlocked.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Hotplug part, J616s + MSI (DCP DP output through the dock's passthrough), no hands: PASS.

  • Kernel: current main 89ec99a075c7 with this head 40a07087428f merged in (clean, fa6216f14f00, 7.3.0-mrpc3265). main is needed for the tipd replug node (usb: typec: tipd: debugfs commands and replug on every Mac #4056). On the J616s the LOCK key is the board fallback (apple,j616s → 616J); there is no DT entry for it, and none is needed. One-shot via aura-try with its own t6040-j616s.dtb; saved default unchanged. boot_id 1d0f9cc2. nouveau/snd_hda_intel blacklisted on that boot (a GTX 1080 sits on the same dock).
  • echo 5 > /sys/kernel/debug/usb/tipd/1-0a/replug on the dock's port, 5 s disconnected, then relocked ("port replugged for its partner (5 s disconnected), locked again (try 1)"). Kernel log, monotonic:
    • 301.758 replug requested; the dock's USB goes
    • 302.791 __av_service_disconnect: stopping audio service
    • 302.848 dcp_dptx_disconnect(port=0)
    • 303.072 drm uevent; connector status disconnected (sysfs poll)
    • 306.462 second audio-service stop (after the tunnel teardown)
    • 307.411 relocked; USB4 PCIe tunnel back at 309.45
    • 311.179 display routed to Thunderbolt DP tunnel dpin0, audio service restarts (plugged:1; compact interface 7 → 11)
    • 312.205 dcp_hotplug() connected:1, uevents, status connected (9.4 s after the disconnect)
  • During the unplug the DP audio service closes in 56 ms, with no close timeout (unlike the J473's HDMI path, drm/apple: DP audio service close times out (-110, 1 s) on HDMI unplug and delays the hotplug report (J473) #4232). 0 refcount_t / use-after-free / WARNING / BUG / Oops / call-trace lines in the whole boot. Card USBC present throughout. A 1 kHz tone into the MSI afterwards ran normally (paplay rc 0, DMA configured).
  • Still open: the silent line-in capture. The MSI's 3.5 mm out still reads at the buildbox's noise floor (−105 dBFS), so I can't show the audio level yet. It's a cable or monitor setting; the J616s side streams.

Afterwards the Mac went back to its production default (fleet94, Enforcing, 0 failed units).

@RyanTheTide

Copy link
Copy Markdown
Contributor

PARTIAL (hands-free parts), J473 (Mac mini M2, T8112, 27.2), 2nd-generation DCP audio on the built-in HDMI: PASS.

  • Kernel 7.3.0-mrpc3265 = current main 89ec99a075c7 with this head 40a07087428f merged in (clean, fa6216f14f00). One-shot through aura-try (aura 70d844e3) with its own t8112-j473-fw27.dtb; saved default unchanged. Userspace: speakerguardd-v2 0.69 (includes speakerguardd#269); 0 failed units on these boots.
  • Sink: an Acer QG270 on HDMI-A-1, card 8 Apple HDMI (dcp-dp-audio 238330000.audio-controller). The monitor has no speakers, so every play was silent.
  • Boot 1 (2af5e983): aplay -l lists card 8 Apple HDMI and card 9 Apple USB-C DisplayPort. A 3 s 1 kHz clip at −26 dBFS through the PipeWire HDMI sink finished in 3.14 s, rc 0, no XRUN, DMA configured normally. 0 Oops/WARN/BUG and 0 refcount/use-after-free lines in the boot.
  • Reboot with the sink connected → boot 2 (2d18b566, same one-shot re-armed). The previous boot's kernel log had 0 refcount/UAF/WARN/BUG/Oops lines (it covers everything until journald stops). The same clip finished in 3.15 s, rc 0; the boot is again clean.
  • Earlier, on the J616s with the MSI on a USB-C DP output: 11 reboots with the display in DPMS off, plus a no-hands tipd replug, all clean (my comments above).
  • Still open (need hands or hardware): the physical HDMI unplug/replug on J473, and the "heard it" step. The Acer has no speakers. The MSI's input to the J473 (DP-2) reads disconnected on the J473 right now, so there is no link to switch it to over DDC (and DDC over the J616s's DCP DP-AUX didn't answer either).

The Mac went back to its production default afterwards (fleet94, Enforcing, 0 failed units).

@DjDeveloperr

Copy link
Copy Markdown
Contributor

The J473 HDMI playback and reboot are clean at 40a07087428f. The J616s replug stopped the DP audio service cleanly, but card USBC stayed bound. The reboot logs end before the final component unbind. Ryan, the remaining row is an exact-head capture of the audio card being removed while DCP sink reports can still arrive, with no warning or use-after-free and clean playback after the card returns.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Captured removal on J616s (M4 Pro, MSI on DP-2 through the dock): PARTIAL. No WARN, no use-after-free, no Oops. The card does not come back, and plain main fails the same way.

This is a software unbind, not a cable pull: the MSI stayed plugged in, and I ran echo audio-controller-2 > /sys/bus/platform/drivers/dcp-dp-audio/unbind as root. Dj, please judge whether that counts as the removal you asked for.

  • PR kernel 7.3.0-mrpc3265 = main 89ec99a075c7 + this head 40a07087428f (fa6216f14f00), one-shot boot 2ea4d32d.
  • Control kernel: plain main 0d55602659df, one-shot boot 96438bbe, same unbind.

What happened on both kernels:

  1. The USBC card went away. The unbind also took down the whole apple-drm component aggregate: card2 and its connectors disappeared, and only card1/renderD128 were left.
  2. While it tore down, 602e00000.dcp (the DCP driving DP-2) logged __av_service_disconnect: stopping audio service three times and dcp_poweroff() done. Then it crashed: RTKit: co-processor has crashed, ASSERT!afk_messenger_common.c:235.
  3. Counts from the unbind onwards: WARN 0, UAF/refcount 0, Oops/BUG 0 (PR and control alike).
  4. Rebinding audio-controller-2 did not bring the card or card2 back on either kernel, so the "clean playback after the card returns" step could not run (aplay: no card). A reboot restores everything.

What was not covered: the tipd replug that was meant to send sink reports while the card was gone did not run. With the aggregate down, /sys/kernel/debug/usb/tipd/1-0a/replug was absent. So the only reports that reached the removed card were the teardown av_service_disconnect calls above.

My reading: #3265's own path is clean here, with no warning or use-after-free on removal. The crash and the failed rebind are already on main. They come from the DCP audio component sharing the display aggregate, not from this PR. A cable pull with the card bound is a different path, and Ryan would need to do it by hand.

Tested: J616s, one-shot boots of the PR head merged into main and a plain-main control, software unbind of the dcp-dp-audio device with the sink connected; restored to the fleet kernel afterwards (default entry, Enforcing, 0 failed units).
Risk: none from this run; the DCP crash on unbind happens on main too.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Thanks Ryan. The software unbind counts as the removal row. It ran this head on J616s, and the DCP sent av_service_disconnect reports to the card while it was being removed. Results: 0 WARN, 0 use-after-free, 0 Oops, which is the path this PR changes.

The RTKit crash (afk_messenger_common.c:235) and the card not coming back after a rebind also happen on plain main (0d55602659df). They come from the DCP audio component sharing the display aggregate and are outside this PR's scope. They won't block the merge.

Merge tree: since your tested base 89ec99a075c7, main changed only dcp-fabric/dcp.c/iomfb.c and added one field to dcp-internal.h. It did not touch audio.c/audio.h, and audio.c doesn't include dcp-internal.h. Hosted apple-build, host-tests and KUnit are green at 40a07087428f. The J473 HDMI playback and reboot rows (05:47Z) are clean at this head.

Merging at 40a07087428f.

@DjDeveloperr
DjDeveloperr merged commit d2a4949 into aurora-silicon:main Dec 4, 2026
12 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:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants