Repository navigation
drm/apple: audio: no reports to a card that is gone - #3265
themartiano wants to merge 1 commit into
Conversation
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>
32b705c to
40a0708
Compare
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
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.
What: Components unbind in reverse order, so a DP audio interface unbinds before its DCP.
dcpaud_comp_unbind()frees the card but leavesdcpaud->cardset, 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 underdata_lockbefore it is freed, and a report holds a reference on it.stale_workis 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-card1/1 andapple-dcpaud-*24/24 on arm64 QEMU with KASAN. With the pointer left set, the kernel reportsrefcount_t: underflow; use-after-freeand the case fails. Merged with today's main 859e8a2 (no conflict): KUnitapple-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
9177b2d474f8on 2026-12-02; head now40a07087428f. One conflict indcpaud_unbind(): main now stops the replaced-link work there first; this PR's taking of the card underdata_lockfollows it, unchanged. Host checks re-run at the new head: W=1 arm64 build ofdrivers/gpu/drm/apple/, 0 warnings; checkpatch --strict only notes the new test file (MAINTAINERS). KUnitdcp-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 newapple-dcpaud-cardpasses;no-sioskips). The hardware rows above are from before the rebase.Risk: two-way · every Mac with DCP audio (an
apple,dpaudionode): 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
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()anddcpaud_refresh_eld()then use the freed card's controls and jack.dcpaud_shutdown()(every reboot) takes the same path.data_lockbefore freeing it, report with a reference held, drop the sink with the card, and queuestale_workonly while there is a card.dcpaud_sleep_quiesce()still usesdcpaud->substreamif a system sleep runs while the component is unbound but the driver is still bound.drivers/gpu/drm/apple/audio-card-test.c.#includeline 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
audio.c; the branch merges with it with no conflict.tools/testing/kunit/kunit.py run --arch=arm64with KUNIT, DRM_APPLE, DRM_APPLE_AUDIO, DRM_APPLE_DISPLAY_KUNIT_TEST, KASAN, 16K pages; LLVM 18. At the head:apple-dcpaud-card1/1,apple-dcpaud-*24/24. On the merge with 859e8a2: 29/29 (apple-dcpaud-card,-legacy,-no-sio,-release-link).drivers/gpu/drm/apple/audio.o(clang 18): no warning in the touched files.7.3.0-0.next2built from main ba29027 plus our open kernel branches (this one, the other DCP audio fix, Thunderbolt/DART, display and PMP thermal), plus drm/asahi: g16: admit 25G83 on every T8132 Air with one normalized entry #2672, drm/apple: turn framebuffer damage into a commit #2797 and arm64: dts: apple: t8132-j713-j715: DisplayPort alt mode on both USB-C ports #2807. Firmware 26.6.2.