Repository navigation
Conversation
For a system sleep the volume lock keeps the speaker volumes, clips them and sets them again at the first unlock after the wake. The keep and the clip are done from the PM notifier, in macaudio_vlimit_pm(). The notifier sets pm_quiesced and has the running streams stopped before that, and a stream's stop schedules macaudio_vlimit_update_work(). When the work runs before macaudio_vlimit_pm() it finds pm_quiesced set and clips the volumes itself. The notifier then finds them locked and keeps nothing, so nothing is set again after the wake: the speakers stay at the locked level, which is silence on a J314s, until the protection daemon is started again. It takes a stream that plays, or has just stopped, when the sleep starts. Give the volume lock a mark of its own, set in macaudio_vlimit_pm() under volume_lock_mutex once the volumes are kept, and let macaudio_vlimit_update() go by it. A work that runs before it sees no sleep and treats the stop as at any other time, and one that runs after it finds the volumes locked. The daemon's ping goes by the same mark. From pm_quiesced on it no longer renewed the lease, while the lease's timer ran until macaudio_vlimit_pm() cancelled it: a lease that ran out in between locked the volumes unkept as well. Signed-off-by: Andreas Fernandez <andreas.fernandez@hotmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
Author
|
#2880 was merged into main a few minutes before I opened this, and it fixes the same race another way: the volumes are kept wherever the sleep lock is taken. I had not seen it, sorry for the duplicate. This PR now conflicts with main, so I'm setting it to draft. I'm running the same row on the J314s on main with #2880 in (20 s2idle sleeps with a stream before each). If that holds I'll close this one and post the row on #2880. |
Ante042
marked this pull request as draft
December 2, 2026 10:21
Contributor
Author
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.
What: After a system sleep that starts while a stream plays or has just stopped, the speakers can stay silent until the protection daemon is started again. The stream's stop schedules a work that clips the speaker volumes before the PM notifier has kept them, so nothing is set again after the wake. The volume lock now goes by a mark of its own, set once the volumes are kept. Only the "Speaker Volume Unlock" interface is affected.
Tested: J314s M1 Pro at 81eab72 (candidate ea7a0bbd0351 on main 2225082): boots, 0 kernel warnings, 0 failed units at the end of the run, and after 20 of 20 s2idle sleeps with a stream before each all six speaker volumes were back. Plain main 2225082 on the same Mac: volumes left at the locked level after the 8th of 8 sleeps.
Risk: two-way door · Macs whose speakers run under the "Speaker Volume Unlock" volume lock (speakersafetyd, speakerguardd 0.1). Under a "Speaker Protection" lease
macaudio_vlimit_update()returns before the changed lines.Not yet: any Mac but the J314s. The "Speaker Protection" lease with speakerguardd v2 was read, not run. A sleep that starts while a stream is still audible: the streams here played at sink volume 0.
This is my sixth open PR. The other five are drafts waiting for rows; this one is a single commit with its row in.
Details
For a system sleep the volume lock keeps the speaker volumes, clips them and sets them again at the first unlock after the wake. Both the keep and the clip are done from the PM notifier, in
macaudio_vlimit_pm().The notifier sets
pm_quiescedand has the running streams stopped before it gets there. A stream's stop schedulesmacaudio_vlimit_update_work(). When that work runs first it findspm_quiescedset and clips the volumes itself; the notifier then finds them locked and keeps nothing.The change adds
pm_vlimit_quiesced, set inmacaudio_vlimit_pm()undervolume_lock_mutexonce the volumes are kept, andmacaudio_vlimit_update()goes by it. A work that runs before it treats the stop as at any other time; one that runs after it finds the volumes locked.The daemon's ping (
macaudio_slk_put()) goes by the same mark. Frompm_quiescedon it no longer renewed the lease while the lease's timer still ran untilmacaudio_vlimit_pm()cancelled it, so a lease that ran out in that window locked the volumes unkept as well.Evidence
Setup, the same for every run: MacBook Pro 14" M1 Pro (J314s). The installed userspace does not select the volume lock on main, so the test wrote "Speaker Volume Unlock" to "Speaker Protection Interface" and started speakersafetyd, which then held the lock. Before each sleep a tone pattern was played to the speakers with the sink at volume 0; each sleep was 25 s of s2idle ended by an RTC alarm. The six
Speaker Volumecontrols were read 6 s after each wake; 201 is the unlocked value, 1 the locked one. Each test kernel also carries one local commit that only gives the GPU driver the name my installed Mesa looks for. "0 kernel warnings" counts WARNING, BUG and Oops lines; error lines were not compared with plain main one by one.At the failing wake the kernel still printed
Speaker volumes unlocked83 ms afterPM: suspend exit; the controls read 1. A regmap trace of an earlier catch of the same fault (on main e77d745 with other changes of mine on top) showed the clip coming frommacaudio_vlimit_update_work()before the notifier's keep.W=1 build of
sound/soc/apple/macaudio.o: no line that main 2225082 does not also print. checkpatch --strict: clean.