Skip to content

ASoC: apple: macaudio: Keep the speaker volumes wherever the sleep lock is taken (carry #2880) - #3597

Closed
RyanTheTide wants to merge 4 commits into
mainfrom
closeout/2880-macaudio-vlimit-keep
Closed

RyanTheTide wants to merge 4 commits into
mainfrom
closeout/2880-macaudio-vlimit-keep

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Carries #2880 by @IronsideXXVI with the fixes below.

The three commits of #2880 are unchanged (head d5d2cff, authorship kept). On top of them is one forward merge of main (d2532e9), because main's 11-28 speaker rework (opt-in legacy volume lock, spk_legacy_selected) conflicted in macaudio_vlimit_update():

I could not push this merge to the fork branch from the build host (fetches from GitHub kept stalling, and the fork does not have main's history), so it is carried here. If the fork branch gets the same merge, close this PR in favour of #2880.

Tests: kunit.py run --arch=arm64 --make_options LLVM=1 --kunitconfig=sound/soc/apple/macaudio.kunitconfig 'apple-speaker-*' on the merged tree: 77/77 passed (admission, protection, hpf, pm-volumes, volume-unlock, interface, amp-level).

Still needed: Dj's review of the merged result, App review, and silent rows before merge: J615 with the legacy lock explicitly selected + speakersafetyd, music playing, s2idle, amp volumes read back after resume over several boots, plus the regression triad; a second family (J604 or J313) if possible.

IronsideXXVI and others added 4 commits November 24, 2026 23:18
…ck is taken

The system-sleep lock clips the speaker volumes to the lock's ceiling,
and the unlock after the resume sets back the volumes kept for it. They
were kept only in macaudio_vlimit_pm(), after macaudio_spk_close_gate()
in the same PM_SUSPEND_PREPARE. With a speaker stream still running,
the stop that the gate queues triggers the back-ends, lock_update_work
reaches macaudio_vlimit_update() with pm_quiesced already set and takes
the lock first. macaudio_vlimit_pm() then finds the volumes locked and
keeps nothing, and the unlock has nothing to set back. speakersafetyd
writes a volume only when its gain changes, so the six amps stay at 1
of 201 (DVC 0xc8) for the rest of the boot.

Keep the volumes in macaudio_vlimit_update() itself, at the transition
to the system-sleep lock, so it does not matter which path takes it. If
the unlock still finds nothing kept (an allocation or a read failed),
report the lock as lost so that the daemon sets the volumes again, as it
does after a lease timeout. The flag that marks the sleep lock is
cleared wherever the kept volumes go, in macaudio_pm_volumes_drop(). Log
at debug level how many volumes were kept and set back.

Keeping them walks the card's controls, so every path into
macaudio_vlimit_update() must hold controls_rwsem. All do but the lease
timeout work, which can expire the lease between pm_quiesced being set
and macaudio_vlimit_pm(): take the rwsem for reading there too, before
volume_lock_mutex, in the order the other holders use. The
lockdep_assert_held() checks in macaudio_pm_volumes_save() were reached
only from macaudio_vlimit_pm(); they are now reachable from every caller
of macaudio_vlimit_update(): the lock control put, lock and unlock
callbacks, the Speaker Protection enter and leave paths,
lock_update_work and the lease timeout work. Each holds controls_rwsem
and volume_lock_mutex there.

Fixes: 911d47c ("ASoC: apple: macaudio: Set the speaker volumes again after a system sleep")
Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
Add KUnit cases for the sleep lock taken through lock_update_work before
macaudio_vlimit_pm() (the volumes must come back at the first ping after
resume), for a failed keeping (the unlock sets nothing back and the next
ping reports the lost lock once), and for a switch to Speaker Protection
and back between the resume and the unlock (the way back reports the
lost lock, and the unlock after it no second time).

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
macaudio_pm_notify() sets and clears pm_quiesced with WRITE_ONCE()
before it takes volume_lock_mutex, so macaudio_vlimit_update() can run
while the flag changes. It read the flag three times: for the lock
reason, for the lost-lease flag and for keeping the volumes. A change
between those reads could lock the volumes for system suspend without
keeping them, or mark a lost lease for the kernel's own sleep lock.

Read the flag once with READ_ONCE() into a local and use it at all
three places. Use READ_ONCE() in macaudio_slk_put() too, as the other
readers outside the notifier already do.

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
main made the legacy volume lock opt-in (spk_legacy_selected, only after
an administrator's "Speaker Volume Unlock" selection), which conflicted
with this branch's pm_quiesced snapshot in macaudio_vlimit_update().
Keep both: the snapshot is read after the lease-only return, then main's
selection check, and the rest of the function uses the snapshot as
before. The new lease-after-sleep KUnit case selects the volume lock
first, as main's other interface cases now do.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

code-owner ping @DjDeveloperr: speaker area. This carries #2880 with main merged in. Please review the merged macaudio_vlimit_update() and confirm that both the opt-in legacy lock check and the quiesced snapshot hold. This will not merge without your review, the App and the J615 rows.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 4bfd12e

Checked: The merge keeps the lease-only early return and explicit volume-lock selection before the legacy unlock decision. The test fixture selects that path in the mock. The proposed hardware plan requires speakersafetyd and audible playback, which are outside the current v2-only lab rule. Please update the PR with the v2 validation scope and get the speaker owner’s disposition for the legacy-only path before landing.

@github-actions github-actions Bot added area:audio Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Merge readiness at 4bfd12e6: not ready yet

Check Detail
CI at head no failing: host-tests, pr-text / pr-text
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head no no line with the head SHA 4bfd12e6, a Mac and a result in the PR body or a comment
Conflicts no merge conflicts with main: merge it in (no force push)
PR text no add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:audio

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 29, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 4bfd12e65568

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: Code reviewed in the earlier App review at this head (6101678036).

Follow-ups (not blocking): state v2 validation scope in PR, speaker owner disposition for legacy-only path

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Dec 1, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the merged macaudio_vlimit_update(). Both rules hold. The legacy-lock check ("Speaker Volume Unlock not selected") still runs first. pm_quiesced is read once, so the lock reason, the lost-lease flag and the save all see the same value.

The fix itself is right. Saving wherever the system-sleep lock is taken covers the case where a running stream's close gate reaches lock_update_work before macaudio_vlimit_pm(). A second call can't overwrite the saved volumes with the clipped ones: macaudio_pm_volumes_save() returns once speaker_volume_unlocked is false. pm_lock_taken is cleared on every unlock through drop(). The timeout work now takes controls_rwsem before volume_lock_mutex, the same order as the other two paths, and teardown cancels it without holding either.

Nit, not blocking: if the lease had already locked the volumes before the sleep, the save is skipped but pm_lock_taken is still set. The resume unlock then logs "No speaker volumes kept" even though the daemon was already told. That's harmless, since the daemon just sets its volumes again.

Gates left: a merge-up (it conflicts with main again), then the silent J615 rows you listed: legacy lock selected plus speakersafetyd, a stream running into s2idle, amp volumes read back after resume over several boots, and the regression triad. A second family (J604 or J313) if possible.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Heads-up: #2880 merged at a0ad259 as 6162827 (receipt: #2880 (comment)). The three commits this PR carries are now on main, so the silent J615/J604/J313 rows requested here aren't needed anymore. I'm leaving the PR open so you can close it or repurpose it.

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Closing in favour of #2880, which merged on 12-02 as 6162827f5bf2. The three macaudio commits this PR carries are on main: the first is patch-identical, and on main macaudio_vlimit_update() takes the pm_quiesced snapshot and then runs the "Speaker Volume Unlock not selected" check, as the merge here did. The macaudio_iface_lease_after_sleep KUnit case is byte-identical. Nothing is left to add. The branch stays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:audio Area from CODEOWNERS (bot) ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants