Repository navigation
ASoC: apple: aop-spkr: stop the speaker TX DMA only after pw1 - #3619
Conversation
The AOP firmware crashes when the speaker serializer runs (pwrd) with the playback DMA stopped (aurora-silicon#2188). A front-end STOP used to stop the DMA at once, while the serializer only goes down to pw1 50-100 ms later, in hw_free or the next prepare. On STOP or SUSPEND of the speaker playback front-end, fill the buffer with silence and leave the cyclic channel running. It is terminated only after the serializer is down: after the pw1 in the back-end prepare's restart, in hw_free, at shutdown, at system suspend, or, if none of those ran, from the front-end close through the same stop. Stopping it right before the pw1 is not enough: that still crashed the firmware on the first cycle. The words left in the channel FIFO when the serializer stops do not reach the next stream: with the serializer down, a channel restarted after such a stop takes in its full 256 bytes again every time (27/27 stops), so a start resets the FIFO and the next stream meets an empty FIFO on a fresh serializer, as before. sync_stop skips a channel whose stop is deferred, a START with a stop still deferred is refused, and the managed buffer is preallocated so a late period callback never sees it freed. J616C, muted start/stop cycles (1 s of silence, 6-9 s apart): the current driver crashed the AOP at cycle 5; with this, 25/25 with no crash. Signed-off-by: AxxzyWasTaken <[email protected]>
There was a problem hiding this comment.
Verdict: HOLD at 9439bf96 — clean, well-reasoned speaker TX deferred-stop implementation in sound/soc/apple/aop_spkr.rs; awaiting fork CI approval/run and an exact-head hardware row at 9439bf96.
Blockers:
- Run hosted CI (
kunit,host-tests,readiness) on this fork PR and confirm green at9439bf96. - Post a hardware verification row citing exact head
9439bf96(J616C, plus regression check: SELinux denials, failed units, new kernel errors; a suspend/resume cycle with playback active is also worth covering before merge given theSNDRV_PCM_TRIGGER_SUSPENDpath).
Checked:sound/soc/apple/aop_spkr.rs(Service::defer_tx_stop,finish_tx_stop,finish_tx_stop_if_down,tx_stop_deferred,put,run,stop_locked,suspend,pcm_open_dmaengine,pcm_close,pcm_prepare,pcm_trigger,pcm_sync_stop,be_service,be_prepare,be_hw_free), commit hygiene, and J616C test evidence.
Evidence
- Code verification (
sound/soc/apple/aop_spkr.rs):tx_started(AtomicBool) cleanly gatesdefer_tx_stop()so an undo-STOPafter an upstreamSTARTfailure never defers an unstarted channel;STARTfails closed with-EBUSYiftx_stop_deferred(chan)is still true.SNDRV_PCM_INFO_PAUSEandSNDRV_PCM_INFO_RESUMEare already cleared inpcm_open_dmaengine(), soPAUSE_PUSH/RESUMEcannot bypass the deferred-stop state machine.- Preallocating the managed DMA buffer at
PCM_BUFFER_MAXwithmax = 0(snd_pcm_set_managed_buffer()) ensureshw_params/hw_freenever free the backing buffer while a deferred cyclic TX channel is still reading silence from it. - Every serializer-down transition (
Service::run()afterquiesce()+STATE_PW1,Service::stop_locked()coveringbe_hw_freeandsuspend(),Service::put(),pcm_prepare()when!st.running, andpcm_close()beforesnd_dmaengine_pcm_close_release_chan()) cleanly terminates and synchronizes the deferred channel viadeferred_tx.swap(null_mut(), AcqRel)->device_terminate_all+device_synchronize. be_service()restrictsbe_prepare/be_hw_freeserializer transitions to playback ((_, playback) => (&ctx.spkr, playback)), so sense-capture front-ends cannot racefinish_tx_stop()against active speaker playback.
- Nit (non-blocking):
- In
pcm_close(), if a deferred stop somehow reaches close withst.running == true(e.g., ifbe_hw_freenever ran),svc.stop()drops the serializer toSTATE_PW1without muting codecs first; normal ALSA close runsbe_hw_free(which mutes amps first) beforepcm_close, so this is only a last-resort safety net before releasing the DMA channel.
- In
- Hygiene: Single commit with DCO
Signed-off-by:,MERGEABLEonmain.
|
J616s row (MacBook Pro 16" M4 Pro, T6040), muted only: digital zeros into the speakerguardd v2 sink with the sink muted the whole time, so no audible output. v2 still gated the amps. Kernel: the J616s's saved EDGE kernel (933f822, Control first, on the unpatched EDGE kernel, same boot conditions:
With this PR (
Not covered here: audible playback (speakers are silent in the lab tonight). Tested: J616s M4 Pro at ab73509a (this PR's 9439bf9 on EDGE 933f822): 0 AOP crashes over 45 muted cycles, 60 clips, 48 re-prepares and one s2idle cycle; unpatched EDGE control crashed at cycle 35. |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
Verdict: MERGE at 9439bf96
Blockers: none
Checked:
- Upgrading prior
HOLDat9439bf96: exact-head J616s (M4 Pro, T6040) hardware verification posted (7.3.0-aurora-e3619+, built from EDGE config with9439bf96applied on an identicalaop_spkr.rsbase): unpatched EDGE control crashed AOP at muted cycle 35, whereas9439bf96ran 45/45 muted stop/start cycles, 60 back-to-back clips, 48 forced re-prepares (clock.force-quantum1024/512), and 1 s2idle suspend/resume with stream RUNNING with0AOP crashes,137protection grants, and0failed units. - Re-verified
sound/soc/apple/aop_spkr.rsdeferred TX DMA stop ordering: front-end STOP/SUSPEND silences the cyclic buffer while leaving DMA running until after back-endpw1/hw_free/ shutdown / suspend, with clean front-end prepare/close fallbacks and FIFO/slot check on J616C.
Evidence
sound/soc/apple/aop_spkr.rsat9439bf96b781f500c7716414ed7427f6818ec09f,MERGEABLEonmain.- J616s control vs patched row (
#issuecomment-7256873040): unpatched crash at cycle 35 -> patched 0 crashes across 45 stop/start cycles, 60 short clips, 48 forced re-prepares, and s2idle. - Note: PR body still lacks
Tested:andRisk: two-waylines flagged bypr-readiness; add before merge soreadinessgoes green.
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
|
J614c (MacBook Pro 14" M4 Max) on main 8f8a076 + #2170 #3200 (unrelated g17 changes), legacy speakersafetyd selected via
Thanks for picking this up! |
|
Tested (J614s, MacBook Pro 14" M4 Pro, T6040), A/B on the same machine and rig:
Rig: muted stop/start cycles through speakerguardd v2 (
Not yet: suspend/resume with playback running. |
|
J614s addendum (same machine and rig as my row above), closing its "Not yet": kernel B (844781f + 726da32 + 9439bf9, plus the #2371 commits, which don't touch audio).
Tested: J614s at 9439bf9 on 844781f: one s2idle cycle with playback running, then 5 stop/start cycles, 0 AOP crashes. |
Fixes #2188
What: The AOP firmware crashes when the speaker serializer runs (
pwrd) while the playback DMA is stopped. A front-end STOP used to stop the ADMAC TX channel at once, but the serializer only goes down topw150-100 ms later, in the back-end hw_free or the next prepare.On STOP/SUSPEND of the speaker playback front-end, the driver now fills the buffer with silence and leaves the cyclic channel running. It stops the channel only after the serializer is down:
pw1of the back-end prepare's restart, in hw_free, at shutdown and at system suspend;Stopping the channel just before
pw1is not enough: that crashed the firmware on the first cycle here, as in joske's J614c timings on #2188. The order here is the one joske tested on #2188, with 0 crashes over a day of normal use.Playback itself is unchanged: same dmaengine path, same start order.
FIFO check: if words a stopped serializer leaves in the channel FIFO reached the next stream, they would rotate its six slots. Measured on J616C with a diagnostic build. After each deferred stop, with the serializer down (no clocks, no sound), I restarted TX0 on a zeroed buffer and read how much it fetched. Every restart took in its full 256 bytes again (27 stops × 3 probes), so a channel start resets the FIFO.
Tested (J616C, MacBook Pro 16" M4 Max, 7.3.0-j616c-parity5+ with this commit;
aop_spkr.rsis identical onmain):run()): 0 crashes.LLVM=1) ofsnd-soc-aop: no errors or warnings.Risk: Apple AOP speaker playback path only (
sound/soc/apple/aop_spkr.rs); the jack services are unchanged.Not yet: other
spkrboards (J614c/J616s), and a suspend/resume cycle with playback running.Supersedes: #3474 (its driver-owned TX ring caused audible pops here; closing it).