Repository navigation
ASoC: apple: macaudio: Keep the speaker volumes wherever the sleep lock is taken (carry #2880) - #3597
RyanTheTide wants to merge 4 commits into
Conversation
…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>
|
code-owner ping @DjDeveloperr: speaker area. This carries #2880 with main merged in. Please review the merged |
There was a problem hiding this comment.
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.
|
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 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
DjDeveloperr
left a comment
There was a problem hiding this comment.
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.
|
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. |
|
Closing in favour of #2880, which merged on 12-02 as |
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 inmacaudio_vlimit_update():quiesced = READ_ONCE(ma->pm_quiesced)snapshot is taken after the lease-only return, then main's "Speaker Volume Unlock not selected" check runs, and the rest of the function uses the snapshot as in ASoC: apple: macaudio: Keep the speaker volumes wherever the sleep lock is taken #2880. No protection behaviour changes beyond what ASoC: apple: macaudio: Keep the speaker volumes wherever the sleep lock is taken #2880 already does.macaudio_iface_lease_after_sleepKUnit case now selects the volume lock first (macaudio_test_select_legacy()), as main's other interface cases do.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.