Repository navigation
ASoC: apple: mca: stop and sync capture DMA before freeing the buffer - #3196
Conversation
The capture buffer is a managed buffer: ALSA allocates it at hw_params and frees it at hw_free. The STOP trigger only asks the DMA engine to stop (dmaengine_terminate_async()), and ADMAC can still write the burst in flight after it returns. ALSA waits for the DMA before it frees or reallocates a buffer only through the sync_stop callback, and the component has none, so hw_free could free the capture pages while the channel was still writing to them. Add a sync_stop that waits for the channel with snd_dmaengine_pcm_sync_stop(), as the AOP audio components already do. ALSA calls it after a stop or a suspend, before hw_free, hw_params and prepare. The channel is then idle whenever the buffer is freed, reallocated or handed to the DMA again, and before a system sleep saves and powers down the clusters. Fixes: 79af0ba ("ASoC: apple: mca: Make the capture buffers cacheable") Signed-off-by: Dj <[email protected]>
A stream suspended while running keeps its DMA transfer, paused, so that RESUME can continue it. If the stream is dropped or prepared from the suspended state instead, ALSA sends no STOP trigger and the paused transfer stays the channel's current one. It still points into the old buffer, which hw_free or a new hw_params may then free. ADMAC starts a new transfer only once the current one has ended, so the next START queues behind it and the stream never runs, and a later PAUSE_RELEASE or RESUME would restart the old transfer instead. ALSA prepares a stream before every START: end any transfer left on the channel there, with dmaengine_terminate_sync(). After a stop the channel has none, so in the usual case there is nothing to end. Signed-off-by: Dj <[email protected]>
|
Verdict at Blockers: none Checked
Evidence
|
|
J516s (MacBook Pro 16" M3 Pro, 27.2 stub) row for |
|
J714s (MacBook Pro 14" M5 Pro) row at
|
|
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 5ddd33a8
Blockers: none
Checked:
- Full 1-file diff (
sound/soc/apple/mca.c,+38/-0),MERGEABLEagainstmain,Fixes: 79af0bae4d0d. mca_sync_stop()guardsrtd->dai_link->no_pcmand callssnd_dmaengine_pcm_sync_stop(substream), ensuring ADMAC finishes any in-flight capture burst and kills its tasklet before ALSA frees or reallocates buffers athw_free/hw_params/prepareor post-suspend.mca_pcm_prepare()guardsrtd->dai_link->no_pcmand callsdmaengine_terminate_sync(snd_dmaengine_pcm_get_chan(substream))in sleepable process context (snd_pcm_action_nonatomic), clearing any stale paused transfer left after suspend-then-drop/prepare.- CI at
5ddd33a8:Host tests,pr-text, andpr-readinesspassed. - Dual-generation exact-head hardware proof at
5ddd33a809df:- J714s (M5 Pro, T6050): 200 capture open/
hw_params/start/stop/hw_freecycles passed (0 stalls, 0 DART/ADMAC errors) plus deep sleep resume and deep sleep drop-and-restart passed (fixing stock-kernel hang). - J516s (M3 Pro, T6030): 200/200
mca-capture-cycle.pycycles passed (0 xruns, 0 stalls, emptydma_klog/warn_klog, 0 failed units).
- J714s (M5 Pro, T6050): 200 capture open/
Evidence
- Checked
sound/soc/apple/mca.c:1069-1115andmca_componentops registration at5ddd33a8. - Both J714s (M5 Pro) and J516s (M3 Pro) silent-capture rows ran cleanly with exact commits unchanged.
|
code-owner ping <@422957901716652033>: merge train at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
What: The MCA capture buffer is allocated at
hw_paramsand freed athw_free. The STOP trigger only asks ADMAC to stop (dmaengine_terminate_async()), and the component had nosync_stop, so ALSA freed the capture pages without waiting for the channel to finish its last burst. This adds async_stopthat callssnd_dmaengine_pcm_sync_stop(), as the AOP audio components already do. ALSA calls it beforehw_free,hw_paramsandprepare, and at the end of a suspend. The second commit covers one path that gets no STOP: a stream suspended while running and then dropped or prepared. Its paused transfer stayed on the channel, still pointing into the old buffer, and the next START queued behind it and never ran.preparenow ends any transfer left on the channel.Tested:
scripts/checkpatch.pl --strictpasses on both commits at5ddd33a809df(0 errors, 0 warnings, 0 checks).sound/soc/apple/mca.obuilds for arm64 (defconfig, LLVM=1,W=1) with rc=0 and no warnings.hw_params, start, stop andhw_freecycles: pass, 0 stalls, 0 DART or ADMAC lines, and no new warnings.Risk: Two-way · every Mac whose built-in audio uses MCA. Only the stop path changes:
hw_free,hw_paramsandpreparenow wait for the channel to stop, normally a single register poll. A stream that is resumed after a sleep is not affected.Not yet
The J516s silent capture row: the same 200 cycles, without a sleep, since s2idle doesn't return on that Mac. The row is required before merge.
Details
snd_dmaengine_pcm_sync_stop()callsdmaengine_synchronize(), which for ADMAC waits until the channel's enable bit clears and kills its tasklet before the descriptors are freed. ADMAC never reportsDMA_PAUSED, so the wait also runs after a suspend.hw_free. Thepreparechange applies to both directions, because a stale paused transfer blocks playback the same way.Fixes: 79af0ba ("ASoC: apple: mca: Make the capture buffers cacheable")