Skip to content

ASoC: apple: macaudio: keep the speaker volumes before any sleep clip - #3915

Closed
Ante042 wants to merge 1 commit into
aurora-silicon:mainfrom
Ante042:fix/macaudio-sleep-volumes
Closed

Ante042 wants to merge 1 commit into
aurora-silicon:mainfrom
Ante042:fix/macaudio-sleep-volumes

Conversation

@Ante042

@Ante042 Ante042 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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_quiesced and has the running streams stopped before it gets there. A stream's stop schedules macaudio_vlimit_update_work(). When that work runs first it finds pm_quiesced set and clips the volumes itself; the notifier then finds them locked and keeps nothing.

The change adds pm_vlimit_quiesced, set in macaudio_vlimit_pm() under volume_lock_mutex once the volumes are kept, and macaudio_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. From pm_quiesced on it no longer renewed the lease while the lease's timer still ran until macaudio_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 Volume controls 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.

Kernel Sleeps Wakes with all six volumes at 201
main 2225082 8 (stopped at the first failure) 7
main 2225082 + this commit before the sign-off (same tree as 81eab72) 20 20
ea7a0bbd0351 = main 2225082 + 81eab72 20 20

At the failing wake the kernel still printed Speaker volumes unlocked 83 ms after PM: 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 from macaudio_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.

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>
@Ante042
Ante042 requested review from a team as code owners December 2, 2026 10:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T10:30:03.630617Z 81eab72 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Ante042

Ante042 commented Dec 2, 2026

Copy link
Copy Markdown
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
Ante042 marked this pull request as draft December 2, 2026 10:21
@Ante042

Ante042 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #2880. The same row that failed on main 2225082 (all six volumes left at 1 after sleep 8) held on main 6162827 with #2880 in and nothing of mine: 20 of 20 s2idle sleeps on the J314s, all six volumes back at 201, 0 kernel warnings. The row is posted on #2880.

@Ante042 Ante042 closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant