Skip to content

ASoC: apple: macaudio: Serve both speaker protection interfaces - #1279

Merged
RyanTheTide merged 1 commit into
integration/aurorafrom
sgupki/dual-speaker-interface
Nov 9, 2026
Merged

RyanTheTide merged 1 commit into
integration/aurorafrom
sgupki/dual-speaker-interface

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

One kernel for both speaker protection stacks. The default is the interface users run today.

Why

integration/aurora carries only the "Speaker Protection" lease/grant interface (speakerguardd v2). Every distro kernel (kernel-aurora / linux-aurora / nixos, -27 and -28) reverts it with 0001-restore-legacy-speaker-protection.patch to get "Speaker Volume Unlock" back for speakersafetyd and speakerguardd 0.1. That leaves fleet and distro kernels with different code, and v2 cannot come back on the boards it qualifies on without locking out everyone else.

What

macaudio carries both interfaces. A new control, Speaker Protection Interface, says which one owns the speakers:

  • Speaker Volume Unlock (default at every card bind). The legacy volume lock, behaving exactly as the distro kernels do with 0001: Speaker Sample Rate, the ELEM_LOCK + magic-ping lease (250 ms), the ceiling (TAS/SN012776 at 1, MAX98360A at the safe level), the system-sleep handling, the J700 software-gain epoch, Amp Gain Volume limited but writable, and the deprecated please_blow_up_my_speakers no-op. Here the lease does nothing: a v2 owner may hold Speaker Protection, but a grant fails with -EBUSY and its lock/unlock touch no amp.

  • Speaker Protection (lease). Only after a CAP_SYS_ADMIN write. The handover goes through both floors in order:

    1. the legacy ceiling first (whatever was unlocked goes down);
    2. speaker starts refused and the running streams stopped;
    3. the lease's safe level and every amp gain fixed at its limit;
    4. only then the ceiling is lifted, with every volume still at the safe level;
    5. on the J700, the full-scale table.

    While leased, the legacy ping fails with -EBUSY and userspace writes to the speaker volumes and amp gains fail with -EPERM.

  • Back to Speaker Volume Unlock. By an admin write, or automatically after 30 s with no owner of Speaker Protection (the engine died, or never came). The path: the lease's floor (ramped), the J700 back to the legacy table, then the legacy ceiling over the safe level. The speakers unlock only on a fresh ping, as after a cold bind. A daemon that still holds the lock gets -ETIMEDOUT once ("lock lost").

The control is INACTIVE + VOLATILE, so alsactl never saves or restores it, and nothing reads it from the cmdline. Making the choice persist is the job of the userspace upgrade tool (lane SGUP): it writes the control at boot or in v2's ExecStartPre. A v2 restart within 30 s keeps the lease.

aop_t8140 (J700): a new register REG_SPKR_FULL_SCALE with no control. It defaults to the legacy table (ceiling 1<<30, the exact literal from 0001), and macaudio selects the 1<<31 table only while leased.

Tests:

  • KUnit: the protection and HPF suites run leased.
  • KUnit: the legacy apple-speaker-pm-volumes suite from 0001 is back.
  • KUnit: the new apple-speaker-interface suite covers bind = lock, the switch through the floor, the revert starting at the floor (unlock only on a ping), the unowned revert and its grace, CAP_SYS_ADMIN, and INACTIVE.
  • Rust: the_volume_lock_keeps_the_legacy_ceiling.
  • selftests/alsa/macaudio-fixed-controls.py updated.

For userspace (v2's gate): a card with Speaker Protection Interface is a dual kernel. Read that control instead of treating the presence of Speaker Protection as v2-only.

Proof

Build: 7.3.0-aurora-sgupki1 = integration/aurora 7d03e42 (fleet43's source) + this commit (same tree), fleet config.

  • KUnit (qemu arm64, PROVE_LOCKING): 61/61. Suites: apple-speaker-protection, -hpf, -pm-volumes, -interface, -admission, -amp-level, apple-mca-capture-sync.
  • Rust kunit snd_soc_t8140_aop_audio_speaker: 6/6.
  • macaudio-fixed-controls.py: 678 attempts, 0 failures in both validation modes.
  • M2 (J413) user-path row (RULES 11-09, published stack: aurora-audio 4.1-12 + speakersafetyd 2.0.1-1.aurora1, no versionlocks, one-shot): PASS. speakersafetyd active with 0 restarts and 0 errors, sense PCM RUNNING, "Speaker volumes unlocked" before and after a 3 s zero-sample stream, 0 AVC, 0 failed units, Enforcing.
  • M2 switch proof (lab v2 stack, one-shot, silent): PASS.
    • At boot: Speaker Volume Unlock, volumes at the ceiling (1).
    • Root switch: the volumes go to 0. speakerguardd-v2 is granted and the volumes go to 201 (0 dB). A root write to a speaker volume fails with EPERM.
    • kill -9 of v2: lease 0 and volumes 0 at once. The systemd restart is re-granted within 1 s and the interface is kept.
    • systemctl stop of v2: the floor at once, and the interface reverts after 30 s with the volumes still at 0 and still locked.
    • speakersafetyd then unlocks the volumes with 0 errors. 0 AVC.
  • M1 Pro (J316) user-path row (published stack: aurora-audio 4.1-12 + speakersafetyd 2.0.1-1.fc45.aurora1, one-shot): PASS. speakersafetyd active with 0 restarts and 0 errors, sense RUNNING, unlocked before and after the zero stream, 0 AVC, 0 failed units, Enforcing.
  • Both Macs were restored afterwards: default kernel, v2 granted, packages as before, Stage 2 unchanged, test kernel removed.

Heads-up for fleet kernels

From this merge on, a fleet kernel starts every boot on "Speaker Volume Unlock". On the lab Macs that run v2, the speakers then stay at the lock's ceiling until the v2 packaging writes "Speaker Protection Interface" before taking the lease. That change is in speakerguardd v2 (lane SGUP2), and it has to land before the next fleet promotion on the v2 boards. Users are unaffected: this default is what the distro kernels already run.

Not covered on hardware: the J700 (Neo) side. In the default mode it uses DJ's 1<<30 table, as -27/-28 do, and the Rust kunit covers it.

Logs: lane SGUP-KI notes (internal).

Assisted-by: LLM

🤖 Generated with Claude Code

The tree carries only the "Speaker Protection" lease, which a
protection engine in the signal path (speakerguardd v2) owns. The
distribution kernels revert it to get "Speaker Volume Unlock" back,
the volume lock that speakersafetyd and speakerguardd 0.1 use, so the
fleet and distribution kernels differ, and the lease cannot return on
the boards it is qualified for without locking every other Mac out.

Carry both. "Speaker Protection Interface" says which one owns the
speakers:

- "Speaker Volume Unlock", at every card bind: the volume lock exactly
  as on a lock-only kernel ("Speaker Sample Rate", the ELEM_LOCK and
  ping lease, its ceiling, the system-sleep handling, the J700
  software-gain epoch, "Amp Gain Volume" limited but the amp's to set).
  An owner may hold "Speaker Protection", but nothing is granted, and
  its locks and releases touch no amp.

- "Speaker Protection", after a CAP_SYS_ADMIN write only. The handover
  passes through both floors: the lock's ceiling first, then no
  speaker start and the running streams stopped, the lease's safe
  level, every amp gain fixed at its limit, and only then the ceiling
  lifted with every volume still at the safe level. While leased the
  lock's ping fails with -EBUSY and userspace writes to the speaker
  volumes and amp gains with -EPERM.

Back to "Speaker Volume Unlock" by a write, or after 30 s without an
owner of "Speaker Protection" (the engine died, or never came): the
lease's floor, then the lock's ceiling over the safe level. The
speakers go up only once a daemon holds the lock and pings it, as
after a cold bind, and a daemon still holding it learns once, with
-ETIMEDOUT, that it lost it. An engine that restarts within the grace
keeps the lease.

The switch is state for the boot: INACTIVE keeps alsactl off it, and
whatever makes it persist writes it again at every boot.

On the J700 the software gain's table top follows the interface
through a new register of the AOP component, which no control exposes:
half the amplifier's full scale under the lock, the scale its daemon
was calibrated against, and the full scale only while leased.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge-train: KUnit 61/61 + Rust 6/6, the selftest, host-tests CI SUCCESS, and user-path rows PASS on the M1 Pro (J316) and the M2 (J413) with the published speakersafetyd stack. The v2 switch/kill/revert proof passes on the M2. The default (Speaker Volume Unlock) is the interface users already run, so this changes no user default. Merging per the 11-09 rule.

@RyanTheTide
RyanTheTide merged commit 98cb6a8 into integration/aurora Nov 9, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the sgupki/dual-speaker-interface branch November 9, 2026 03:05
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