Repository navigation
ASoC/dmaengine: wait for stopped capture streams (t8140-aop-audio sync_stop, apple-admac synchronize) - #259
Merged
Merged
Conversation
device_synchronize() must not return while the controller can still access the memory of terminated descriptors, but admac_synchronize() only kills the tasklet and frees the descriptors. terminate_all() posts the channel's STOP write and resets the rings without waiting for the channel to wind down, so a client that reuses or frees its buffer right after dmaengine_synchronize() races the channel's last burst, and nothing even ensures that the STOP write has reached the controller by then. The START registers hold the per-channel enable bits that the STOP registers clear (m1n1's register map calls them TX_EN/RX_EN and TX_EN_CLR/RX_EN_CLR). Poll the channel's bit until it reads back clear before synchronize goes on; the read also pushes out the posted STOP write. A channel only has a burst to finish, so bound the wait generously and warn instead of hanging the caller if it never clears. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
None of the driver's PCMs has a sync_stop op, so after a stop ALSA moves on to hw_params, hw_free or prepare without waiting for the stream to have really stopped. The microphone array and the front-ends stop their ADMAC channel from the trigger with dmaengine_terminate_async(), and the channel is only synchronized at close. hw_free comes first and releases the buffer, which these PCMs allocate at every hw_params, so the channel's last burst and a pending period callback can land after the buffer is gone. Give them the dmaengine helper's sync_stop, as the generic dmaengine PCM does. The low-power microphone has no DMA: its report handler copies each reported span into the ALSA buffer under the stream state lock, after checking the run flag, and the trigger only clears that flag. A report that passed the check before the stop can still be copying when hw_free releases a buffer larger than the preallocated one. Its sync_stop takes the state lock once, which waits for such a copy; any later report sees the flag clear. Fixes: eeb1126 ("ASoC: apple: Add T8140 AOP audio driver") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stopping a capture stream did not wait for the stream to have really stopped before ALSA
went on to
hw_params,hw_freeorprepare, which reallocate or free the buffer.dmaengine: apple-admac: Wait for the channel to stop in synchronize
device_synchronize()must not return while the controller can still access the memory ofterminated descriptors, but
admac_synchronize()only killed the tasklet and freed thedescriptors:
terminate_all()posts the STOP write and resets the rings without waiting.Synchronize now polls the channel's enable bit (the START register; the STOP register
clears it) until it reads back clear, which also pushes out the posted STOP write. The
wait is bounded at 100 ms and warns instead of hanging if a channel never stops.
ASoC: apple: t8140-aop-audio: wait for stopped streams in sync_stop
None of the driver's PCMs had a
sync_stopop.with
dmaengine_terminate_async()and were only synchronized at close, afterhw_freehad already released the buffer these PCMs allocate at every
hw_params. They now usesnd_dmaengine_pcm_sync_stop(), like the generic dmaengine PCM.the stream state lock after checking the run flag, which the trigger clears. Its
sync_stoptakes that lock once, so a copy that was already under way finishes beforethe buffer can go away, and later reports see the flag clear.
Testing
Written for this tree; tested on a MacBook Neo (J700) and a MacBook Air (M2), capture only:
J700: 50 one-second captures each on the low-power microphone, the microphone array and the
headset input (plain, closed early, different buffer sizes): 0 failed, 0 short. Five forced
overruns per device recover. 20 captures per DMA-backed device were terminated 10-300 ms after
open; every one closed cleanly within 204 ms. The final captures carry signal. The base-ns ADMAC RX
enable register reads back the running channel's bit during a headset-input capture. No
still enabled, ADMAC, DART or kernel warnings.M2: capture churn on the internal microphones and the headset input (45 captures, a third of them
closed early, plus forced overruns): 0 failures and no kernel warnings, the same as the stock kernel.
Build: J700 configuration (arm64, LLVM, Rust), no new warnings;
W=1clean fordrivers/dma/apple-admac.oandsound/soc/apple/t8140_aop_audio.o.Capture-only churn on the low-power microphone, the microphone array and the headset
input: open/close, close while running, buffer-size changes and forced overruns, then a
final capture with signal on both microphones; no ADMAC, DART or kernel warnings.
🤖 Generated with Claude Code