Skip to content

ASoC: apple: speaker protection ownership for in-graph protection - #922

Merged
RyanTheTide merged 36 commits into
integration/aurorafrom
sgv2-kernel-interface
Nov 7, 2026
Merged

RyanTheTide merged 36 commits into
integration/aurorafrom
sgv2-kernel-interface

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Draft: a new kernel interface for speaker protection that runs in the speaker signal path. Do not merge until the matching userspace (speakerguardd v2) exists and has been proven on hardware.

What changes

  • macaudio: "Speaker Protection" ownership. This replaces the "Speaker Volume Unlock" lock, its magic ping, its 250 ms lease and the volume ceiling.
    • The owner is the control file that holds the element lock on "Speaker Protection".
    • Writing a lease of 10-100 ms grants protection: the amps go to their fixed 0 dB operating point (full scale on the J700's software gain) and speaker playback may start. Writing again renews it.
    • Writing 0, unlocking the control or closing the file withdraws protection at once.
    • Expiry runs on a high-priority work. After a lapse, the next write returns -ETIMEDOUT and grants nothing.
    • The speaker volume controls become read-only to userspace, so the amps' gain never changes during playback.
  • The hardware floor applies without protection. The speaker back-ends refuse to start, running speaker streams are stopped, and the amps go to their safe level: muted on the TAS5770 and SN012776, -20 dB on the J700.
    • The floor is set before the card registers and again before a system sleep.
    • A floor that fails on any amp is permanent until the driver reloads.
  • tas2764: a read-only "Amp Fault Status" per amp. It holds the latched INT_LTCH0 fault bits, an event count and the SDZ-group shutdown flag, and is notified from the fault IRQ.
  • aop_spkr: speaker sense in 2.5 ms chunks (120 frames x 32), so 512-frame sense periods complete promptly on the J614s, J616s and J713.
  • mca: cacheable capture buffers. These are SNDRV_DMA_TYPE_NONCOHERENT with explicit sync.
    • The CPU view is invalidated in the pointer callback, before ALSA publishes the new hw_ptr.
    • The whole buffer is handed back to the device at start.
    • The buffer is allocated at hw_params to its own size.

This is incompatible with speakersafetyd and speakerguardd 0.1 by design: kernels with this series run only with the new userspace.

Tests

  • KUnit apple-speaker-protection (9 cases) and apple-speaker-admission (1 case): 10/10 pass on arm64 qemu with PROVE_LOCKING. The cases cover:
    • the floor from binding onwards;
    • a grant only for the owner, and only with a valid lease;
    • release and owner loss;
    • lease expiry and its -ETIMEDOUT;
    • renewal;
    • system sleep;
    • failed floors and failed grants;
    • the J700 levels.
  • W=1: no warnings on macaudio.o, tas2764.o or snd-soc-aop.o.
  • run-host-tests: 180/180 pass. The apple-dcp selftests: 85/85 pass. The alsa macaudio-fixed-controls selftest: 0 failures in 590 attempts, with input validation both off and on.
  • A full build as 7.3.0-aurora-sgv2k1 (the fleet recipe, Fedora Asahi base config plus asahi.config) passes.
  • Hardware: J316 (M1 Pro), one-shot boots of 7.3.0-aurora-sgv2k1, silent (zero-sample streams only), SELinux enforcing, 0 AVCs.
    • The card registers at the floor: every speaker DVC is 0 (mute), the volume controls are read-only, "Speaker Protection" reads 0, and the boot log is clean.
    • A speaker start without a grant is refused (-EPERM).
    • With a grant: every DVC is 201, a zero-sample stream runs, and 3 s of 10 ms renewals of a 30 ms lease had no failures.
    • When renewals stop, protection is withdrawn 30.7-31.0 ms after the last write. The running stream XRUNs and its restart is refused. The amps return to 0, and the next write returns -ETIMEDOUT and grants nothing.
    • Killing the owner withdraws protection at once ("owner gone").
    • The sense capture runs at 512-frame periods: 12 channels, idle noise only.
    • "Amp Fault Status" reads 0,0,0 on all six amps.
    • Copy cost per 512-frame sense period (perf, 20 s of capture): read() 21.9 µs before, 4.5 µs after; mmap 15.1 µs before, 1.8 µs after.
    • Stale-data check: in 2 x 480 000 frames, no 64-byte line repeats the previous lap of the buffer.
    • After the test the machine is back on its default kernel, with speakerguardd 0.1 governing.

🤖 Generated with Claude Code

Replace the speaker volume lock with ownership by a protection engine
that runs in the speaker signal path, as macOS does: the amps sit at a
fixed, known gain while it owns them, and it does all attenuation
itself. The amps' volume is not changed during playback.

The owner is the control file that holds the element lock on the new
"Speaker Protection" control. Writing a lease length of 10 to 100 ms
grants protection for that long: every speaker volume goes to the
amp's 0 dB operating point (full scale on the J700's software gain) and
speaker playback may start. The owner renews it by writing again.
Writing 0, unlocking the control or closing the file withdraws it at
once. A lease that runs out withdraws it from a high-priority work, and
the owner's next write fails with -ETIMEDOUT and grants nothing, so an
owner that stalled learns of it before it plays again. Reads return 1
while protection is granted; every change is notified.

Without protection the speakers are at the hardware floor: the speaker
back-ends refuse to start, a running speaker stream is stopped, and
every amp is at its safe level (muted on the TAS5770 and SN012776, 20 dB
down on the J700's software gain). The floor is set before the card is
registered and again before a system sleep. A floor that cannot be set
on every amp refuses speaker playback until the driver is reloaded.

The speaker volume controls become the driver's: userspace can read
them but no longer write them. The "Speaker Volume Unlock" control,
its magic ping and 250 ms lease, the volume ceiling, the volumes kept
over a system sleep, the software-gain epoch, the "Speaker Sample Rate"
control and the please_blow_up_my_speakers parameter all go: nothing
uses them with the new ownership.

The KUnit cases go through the control callbacks and the PM notifier
on a card of fake controls: the floor from the binding on, a grant only
for the owner with a valid lease, release, owner loss, lease expiry and
its -ETIMEDOUT, renewal, a system sleep, failed floors and grants, and
the J700's levels.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The fault interrupt only logs what the amp latched. Give each amp a
read-only "Amp Fault Status" control, so that a speaker protection
engine learns of its faults without parsing the kernel log:

  [0] the INT_LTCH0 bits the interrupt reported since probe: over
      temperature, over current, bad TDM clock, limiter active, PVDD
      below the limiter inflection point, limiter at maximum
      attenuation, BOP infinite hold, BOP mute;
  [1] how many such interrupts there were, saturating;
  [2] 1 once the amp's SDZ group was forced off.

The interrupt notifies the control on every report. The expected clock
fault after a stream's end is not reported, as it is not logged.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The sense ring hands frames to the sense front-end once per ring
period, 480 frames (10 ms). A front-end period of 512 frames then
completes up to 10 ms after its last frame arrived. Use 120-frame
periods, 32 of them: the same 80 ms ring, delivered within 2.5 ms.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The capture buffers came from coherent DMA memory, which the CPU maps
uncached on these machines. Copying one 512-frame period of the J316's
speaker sense (12 channels, 12 KiB) out of it cost 22 us through read()
and 15 us through mmap.

Allocate them as SNDRV_DMA_TYPE_NONCOHERENT: cacheable, with ALSA's
explicit sync. The CPU's view of what the DMA wrote is invalidated in
the pointer callback, before the position that covers it is returned
and so before ALSA publishes it as hw_ptr: no reader can see a frame
before its cache lines were invalidated after the DMA wrote it. A line
still being written at the reported position is invalidated again with
the next range, which starts on it. A start hands the whole buffer back
to the device first. The CPU never writes a capture buffer, so no dirty
line can be written back over the DMA's data. The buffer is allocated
at hw_params to its own size: ALSA syncs the whole allocation on every
read, and a 3 MiB preallocation made that cost milliseconds. Playback
buffers are unchanged.

On a J316, with a zero-sample speaker stream, the copy now costs 4.5 us
per period through read() and 1.8 us through mmap. 20 s of capture
through each path holds no 64-byte line that repeats the previous lap
of the buffer.

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

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed at 79af0ba. This is a COMMENT review focused on speaker safety.

I read the four commits against KERNEL.md and checked the ALSA core in this tree (control.c, pcm_native.c, pcm_memory.c, memalloc.c) wherever a claim depends on it. I did not build or run the KUnit suite. The tests cover the state machine with a fake card, so they cannot catch the scheduling and DMA issues below.

What looks sound.

  • The lock order is consistent. put, lock and unlock run under controls_rwsem and then take spk_mutex. The lease work and the PM notifier take only spk_mutex. macaudio_spk_set_gain calls the codec's ->put directly, so nothing takes controls_rwsem under spk_mutex. There is no RCU in this series.
  • Ownership comes from the core. A non-owner's write gets EPERM in snd_ctl_elem_write, and snd_ctl_release calls ->unlock under controls_rwsem, so a crash or SIGKILL of the owner floors at once.
  • Every withdrawal clears spk_granted before it touches the amps. A failed grant floors, and a failed floor latches spk_floor_failed, which the trigger refuses.
  • The lease value is range checked before the mutex, and the ktime and jiffies arithmetic cannot overflow at 100 ms. A timer that fires early is re-armed from spk_lease_end.
  • Removal is safe. snd_card_disconnect_sync waits for every control file to close before the card's remove runs, so the owner's unlock floors while the codecs still exist.
  • On mca, a START trigger cleans the whole capture buffer for the device, and a line that straddles the reported position is invalidated again with the next range.

Findings, most important first.

1. Lease expiry can be starved by the very stall it guards against (high). macaudio_spk_lease_work and spk_stop_work are ordinary items on system_highpri_wq (macaudio.c 465, 516, 616), driven by a jiffies timer. Highpri kworkers are nice -20 CFS threads, not RT. If a SCHED_FIFO thread spins on the CPU that the timer fired on, the lease work does not run until RT throttling or the fair server lets CFS in. That thread could be a stuck PipeWire data thread, or the supervisor, which the user-space side now runs at RT priority. By default that wait can be up to about 950 ms of every second. During that time spk_granted stays true and the speaker stream keeps running at operating gain. If the writer has stopped and the stop threshold is at the boundary, it keeps replaying the ring. macaudio_be_trigger (1252) also checks only spk_granted, never spk_lease_end, so a start after the lease has run out is still admitted. At HZ=100 the 10 to 30 ms leases also round to 1 to 3 jiffies, plus a jiffy of slack. Suggested fix:

  • an hrtimer in HRTIMER_MODE_REL_HARD that clears spk_granted at the deadline;
  • the floor and stop work on a dedicated kthread_worker raised with sched_set_fifo() above PipeWire;
  • in the trigger, refuse a start when ktime_get() is past READ_ONCE(spk_lease_end).

A KUnit or stress test that pins a FIFO spinner to the timer's CPU would show it.

2. Anyone who can open the control device can own the speakers (high). snd_ctl_elem_lock has no privilege check, and macaudio_spk_lock (623) always accepts. A seat user who gets /dev/snd/controlC* through uaccess can lock "Speaker Protection" before the supervisor starts, or in its restart gap. That user can then grant 100 ms leases forever with no engine in the path, and the supervisor only ever gets EBUSY. Suggest refusing the lock in macaudio_spk_lock unless capable(CAP_SYS_ADMIN) (or a dedicated capability), returning -EPERM.

3. A quick regrant can race the stop work (medium). macaudio_spk_floor only queues spk_stop_work (465). It does not wait for it. If the owner writes 0 and then a lease, or gets its ETIMEDOUT and writes again, macaudio_spk_grant (490) can raise the amps to operating gain before the stop work has run. That window is wide under finding 1. The stream that the withdrawal was meant to stop then never stops, never XRUNs, and never passes the start gate again. Suggest flush_work(&ma->spk_stop_work) at the top of macaudio_spk_grant. That is safe, because the stop work takes stream locks but neither spk_mutex nor controls_rwsem. Alternatively, refuse the grant while any speaker front-end is still running.

4. A cacheable capture buffer can hand out data from the previous lap (medium). mca_capture_sync (mca.c 1037) invalidates only [capture_synced, to). When the DMA has advanced exactly one buffer between two pointer calls, to == from and nothing is invalidated (1047, 1052). When it has advanced more than a buffer, only the modulo remainder is invalidated. ALSA can still publish the full advance: on a late interrupt snd_pcm_update_hw_ptr0 adds whole buffers by jiffies, and a stop threshold at the boundary turns off the XRUN. The reader then gets cache lines left over from the previous lap as fresh V/I data, which is the stale sense this change must rule out.

The core's own whole-buffer sync does not back this up for mmap readers. Allocating at hw_params (snd_pcm_set_managed_buffer(..., 0, SIZE_MAX), 1181) means substream->dma_buffer.dev.need_sync is still 0 at open (pcm_memory.c preallocate_pages with size 0). So SNDRV_PCM_INFO_EXPLICIT_SYNC is never set (pcm_native.c 2846), and the status and control pages stay mmappable. A reader like PipeWire that uses the mmapped status page never reaches snd_pcm_dma_buffer_sync, and mca_capture_sync is the only invalidation it gets. Suggest tracking the advance in frames from the runtime's unbounded hw_ptr, or from the time since the last sync, and invalidating the whole buffer when it could reach a lap. Also either set EXPLICIT_SYNC in the capture open or say in the comment why it is not wanted.

A related question I could not settle from the code: does ADMAC's residue guarantee that the bytes it covers have reached memory, rather than still being in flight in the fabric? An uncached buffer re-reads on every access, but a stale line fetched once stays cached until the next lap's invalidate.

5. The start gate runs only for the first front-end on a back-end (low). DPCM calls the back-end trigger only when be_start goes from 0 to 1, so a second front-end that joins an already running speaker back-end is never checked by macaudio_be_trigger. While a grant is held that is fine. But macaudio_stop_speaker_playback walks the front-ends in order, and a front-end it has already passed can join while a later one is still running. That stream then keeps the back-end alive across the floor, and through the next grant (see 3). A front-end trigger op with the same check would close it.

6. The aop_spkr ring has no lap detection (low). sense_ring_done (aop_spkr.rs 686) computes the new bytes modulo the 80 ms ring. If the ADMAC tasklet runs more than 80 ms late, a whole lap is lost without any sign, and an exact lap returns early with bytes == 0. The sense stream is then shifted against playback with no XRUN, which closed-loop V/I alignment depends on. The callback rate also goes from 100/s to 400/s with this change. Suggest checking elapsed time (or a completed-period count) against the ring length and calling snd_pcm_stop_xrun on the sense front-end when a lap may have been lost. The fence(SeqCst) comment raises the same device-visibility question as finding 4.

7. Resume regrants without the stall signal (low). The PM path floors but never sets spk_lapsed (550). An owner that was frozen across sleep is therefore granted on its first write after resume, without the ETIMEDOUT that tells it the engine state is unknown. If that is intended, the supervisor has to re-verify the engine before writing after a resume, and KERNEL.md should say so.

8. Amp Gain Volume stays writable (low). Only the DVC is taken away from userspace. "Amp Gain Volume" is capped at the configured gain, so it can only be lowered, but any change moves the operating point the engine's VoltsFullScale assumes. Making it read-only alongside the DVC would make that operating point fixed, rather than something the supervisor must check (KERNEL.md 2.3). The supervisor does not do that check yet; see aurora-silicon/speakerguardd#33.

tas2764: "Amp Fault Status" is read-only and updated under the fault lock, and its counter saturates. The bits are sticky from probe and include reports (limiter, PVDD, BOP) as well as faults, so user space has to mask OT and OC itself. A grant refused in kernel while OT or OC is latched would be cheap defence in depth.

Review of the "Speaker Protection" lease found that its end could be
starved by the stall it guards against, and that the control could be
owned by anyone with the seat's control device. Fix both, and the
smaller gaps the review found next to them.

The lease ran out from a delayed work on system_highpri_wq: a per-CPU
kworker at nice -20, not a real-time thread. A SCHED_FIFO thread spinning
on that CPU (a stuck audio thread, or the supervisor, which runs at RT
priority) held it off for up to about 950 ms of every second, and the
speaker stream played on at the operating gain all that time. The start
gate only looked at the grant, never at the lease's end.

- The lease's end is now an hrtimer in HRTIMER_MODE_REL_HARD. Its
  callback runs in hard IRQ context and closes the start gate itself; a
  renewal that raced it re-arms it from the new end.
- The stream stop and the safe level run on two kthread workers at
  SCHED_FIFO 90, above PipeWire's data threads (88) and the supervisor.
  They are not bound to a CPU, so a spinner on one CPU cannot keep them
  from waking on another. The stop worker never takes spk_mutex or the
  card's controls_rwsem; the floor worker does.
- Every start checks the lease's end as well as the grant
  (macaudio_spk_admitted()), so a start after the end is refused even
  before the timer has run. Reads report the same. A renewal that comes
  after the end is a stall: the speakers are floored and the write
  returns -ETIMEDOUT.
- A grant waits for the stop that a withdrawal queued
  (kthread_flush_work()) before the amps go back to the operating gain.
  Otherwise a quick release and regrant could raise them under a stream
  that the withdrawal was meant to stop, which then never stopped. The
  stop has a worker of its own, so the flush cannot wait behind a floor
  that needs the caller's mutex.
- Only a CAP_SYS_ADMIN process can take ELEM_LOCK on the control, and
  every write needs CAP_SYS_ADMIN too, so an owner's file handed to
  another process grants nothing. Before this, a seat user could take the
  lock before the supervisor started, or in its restart gap, and grant
  100 ms leases forever.
- DPCM triggers a back-end only for the first front-end that starts on
  it. A front-end trigger now applies the same gate, so a second
  front-end cannot join a speaker back-end that was left running across
  a withdrawal. It runs before the front-end's DMA, so a refused start
  starts nothing.
- After a system sleep, the owner's first write returns -ETIMEDOUT. The
  owner was frozen with the rest of userspace and must re-check its
  engine before it plays, as after any stall.
- "Amp Gain Volume" is held at the machine's configured gain and made
  read-only, like the speaker volumes. Before, it was capped there but
  still writable downwards, which moved the operating point the engine's
  tuning assumes.

KUnit apple-speaker-protection gains seven cases:
- the gate follows the lease's end without the timer;
- the timer closes the gate while the floor worker is held off;
- SCHED_FIFO 99 spinners on every CPU, with the gate still closing at
  the lease's end (0.35-0.66 ms late on 4-CPU qemu, 3.5 ms on 1 CPU);
- the workers are SCHED_FIFO 90;
- the CAP_SYS_ADMIN checks on lock and write;
- a regrant that waits for a held stop worker;
- the fixed amp gain.

The sleep case now expects the -ETIMEDOUT. 20 of 20 cases pass on arm64
qemu, with PROVE_LOCKING and DEBUG_ATOMIC_SLEEP and no lockdep report,
on 1 and 4 CPUs. The macaudio-fixed-controls selftest takes the shared
write-denial helper from the source, as it did the loop before.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
… lapped

mca_capture_sync() invalidated only the range between the last synced
position and the new one. When the DMA had gone exactly one buffer round
between two pointer calls, the positions matched and nothing was
invalidated. When it had gone further, only the remainder was. ALSA can
still publish the whole advance: on a late interrupt it adds whole buffers
from the jiffies, and a stop threshold at the boundary turns off the
XRUN. A reader would then get the previous lap's cache lines as new
speaker sense data.

The position cannot tell a lap from no advance, but time can. Keep when
each sync happened. If the time since the last one could hold a lap (a
buffer's time less a period, which covers the reported position's lag),
invalidate the whole buffer. Otherwise invalidate the range as before.

The capture stays without SNDRV_PCM_INFO_EXPLICIT_SYNC, and a comment
now says why. hw_ptr only ever moves through mca_pointer(), so with laps
handled, an mmap reader of the status page never sees a frame before it
was invalidated. Setting the flag was measured on a J316: 12-channel
sense, 512-frame periods, zero-sample playback, the audio server
stopped, 10 s of arecord per run. The CPU time per period, as the mean
of three runs:

  per period   no flag   flag
  read()       30.8 us   32.8 us
  mmap         34.8 us   40.5 us

The flag costs about 16% on mmap, with no gain in correctness. The lap
check itself is within noise of 79af0ba. Nothing in 480 000 frames
through either path repeats the previous lap.

KUnit apple-mca-capture-sync (3 cases) covers the lap test and the
ranges, including an exact lap and two and a bit laps.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The sense ring's callback took the new bytes as the advance modulo the
80 ms ring. A tasklet more than a lap late lost a whole lap without a
sign, and an exact lap looked like no advance. Either way the sense was
then shifted against the playback with no XRUN, and closed-loop V/I
alignment depends on it.

Keep the time of the last callback. When the time since then could hold
a lap (the ring's time less one 2.5 ms period), stop the attached sense
front-end with an XRUN instead of delivering what the position shows.
The reader re-prepares and starts again aligned.

KUnit apple_aop_sense_ring (3 cases) covers the lap test.

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

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Three new commits on top of 79af0ba address all eight findings; nothing was force-pushed.

  • 6ff98c6 ASoC: apple: macaudio: Withdraw speaker protection from a hard timer
  • 9d69355 ASoC: apple: mca: Sync the whole capture buffer when the DMA may have lapped
  • 865ee49 ASoC: apple: aop_spkr: Stop the sense on a ring lap

1. Starved lease expiry (high), 6ff98c6

  • The lease's end is an hrtimer in HRTIMER_MODE_REL_HARD. Its hard-IRQ callback clears spk_granted itself. A renewal that races it re-arms it from the new end.
  • The stream stop and the safe level run on two unbound kthread_workers at SCHED_FIFO 90 (sched_setattr_nocheck). That is above PipeWire's 88 and the supervisor's 70. system_highpri_wq is gone from this path.
  • macaudio_spk_admitted() checks spk_lease_end as well as the grant. Every start uses it (the FE and BE triggers), and so does every read. A renewal written after the end counts as a stall: it floors and returns -ETIMEDOUT.
  • KUnit:
    • the gate follows the lease's end with the timer cancelled;
    • the timer closes the gate while the floor worker is blocked on spk_mutex;
    • SCHED_FIFO 99 spinners on every CPU, including the timer's: the gate closes 0.35-0.66 ms after the end on 4-CPU qemu, and 0.8-3.5 ms on 1 CPU under TCG;
    • both workers are SCHED_FIFO 90.

2. No privilege check (high), 6ff98c6

  • macaudio_spk_lock() and every write require capable(CAP_SYS_ADMIN), or they return -EPERM. An owner's fd that is passed to an unprivileged process grants nothing.
  • KUnit covers both, with CAP_SYS_ADMIN dropped through override_creds().
  • Userspace follow-up: the speakerguardd unit's CapabilityBoundingSet and its SELinux module need sys_admin added before the supervisor can run on this.

3. Regrant racing the stop (medium), 6ff98c6

  • macaudio_spk_grant() calls kthread_flush_work(&spk_stop_work) before it raises the amps.
  • The stop has a worker of its own that never takes spk_mutex or controls_rwsem. So the flush cannot end up waiting behind the floor work, which needs the caller's mutex.
  • KUnit holds the stop worker and shows that a regrant waits for it.

4. mca lap (medium), 9d69355

  • mca_capture_sync() records when each sync happened. When the elapsed time could hold a lap (a buffer's time less a period), it invalidates the whole buffer.
  • On EXPLICIT_SYNC, I took your second option: it stays unset, and a comment says why. hw_ptr only ever moves through mca_pointer(), so once laps are handled a status-page reader is covered.
  • A/B on the J316 (mean of 3 runs, audio server stopped): mmap went from 34.8 to 40.5 us per period with the flag, read() from 30.8 to 32.8 us. That is +16% on mmap for no gain in correctness.
  • The ADMAC residue-visibility question stays open, as it does for the uncached case.
  • KUnit apple-mca-capture-sync covers an exact lap and two and a bit laps.

5. Second front-end (low), 6ff98c6

  • A front-end link trigger (macaudio_fe_trigger) applies the same gate to every FE that drives the speakers. It runs before the FE's DMA and its BEs.
  • A refused start now logs two ASoC lines instead of three.

6. aop_spkr lap (low), 865ee49

  • The callback records the time of the last call. When the time since then could hold a lap (80 ms less one 2.5 ms period), it stops the attached sense FE with an XRUN instead of delivering the remainder.
  • Rust KUnit apple_aop_sense_ring has 3 cases. This is not yet tested on a J616s.

7. Resume (low), 6ff98c6

  • At PM_POST_SUSPEND an owner gets spk_lapsed, so its first write after a resume returns -ETIMEDOUT and the next one grants.
  • The quiesce check now comes before the lapse check, so a write during sleep cannot consume the report.

8. Amp Gain Volume (low), 6ff98c6

  • macaudio_set_fixed_volume() sets it to cfg->amp_gain and clears WRITE, as it does for the DVC.
  • The macaudio-fixed-controls selftest takes the shared write-denial helper from the source.

Gates at 865ee49

  • KUnit apple-*: 20/20 on arm64 qemu, with PROVE_LOCKING and DEBUG_ATOMIC_SLEEP, on 1 and 4 CPUs, with no lockdep report.
  • Rust apple_aop_sense_ring: 3/3.
  • W=1: 0 warnings on macaudio.o, mca.o, tas2764.o and snd-soc-aop.o.
  • run-host-tests 180/180, apple-dcp selftests 85/85, macaudio-fixed-controls 0/1180 failures.

M1 Pro (J316), test kernel built from 865ee49
One-shot boots, zero-sample streams only, SELinux enforcing, 0 AVCs.

  • At boot: DVC 0, and the speaker volumes and Amp Gain (15) are read-only.
  • An unprivileged ELEM_LOCK gets EPERM. A start without a grant is refused.
  • With a 30 ms lease held for 3 s: 0 failed renewals, DVC 201, and sense at period 512 works. 480 000 frames through read and through mmap hold no stale lap.
  • When renewals stop:
    • the gate closes at 30.1 ms;
    • the stream XRUNs at 30.07-30.16 ms;
    • all six DVCs reach 0 at 31.83-32.03 ms (six serial I2C writes, about 0.3 ms each);
    • the next write returns -ETIMEDOUT, and the one after grants.
  • Starvation test: after its last renewal, the owner becomes a SCHED_FIFO 99 spinner on its own CPU (the timer's CPU) for 300 ms. Over 10 runs:
    • this series: the stream XRUNs at 30.06-30.16 ms and the DVCs are floored at 31.82-32.03 ms;
    • the previous head (79af0ba) on the same test: the floor came at 301.8-302.1 ms, when the spin ended.
  • Killing the owner floors at once.

On tas2764: a kernel-side refusal of grants while OT or OC is latched would be good extra defence. I left it out of this round so the fault control stays telemetry-only. The supervisor already releases and never re-grants on those bits.

RyanTheTide added a commit to aurora-silicon/speakerguardd that referenced this pull request Nov 4, 2026
…resume

Kernel sgv2k2 (aurora-silicon/linux#922 at 865ee493):
- The kernel now requires CAP_SYS_ADMIN for ELEM_LOCK and every write on
  "Speaker Protection". The unit keeps CAP_SYS_ADMIN in its bounding set
  (the service runs as root), and the SELinux module allows sys_admin. A
  lock EPERM now says the capability is missing.
- The first write after a resume returns ETIMEDOUT, as after a lapse. That
  tick's observation was clean, so it counts as the first of the two clean
  ticks, and the grant comes back on the next clean tick, not two later.
- Amp Gain Volume is read-only at amp_gain; the supervisor only reads it.

sgv2-supervisor tests build on their own again (sgv2-core std for tests).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under pm_test=freezer on a J616s, protection was withdrawn 5.1 s after
"PM: suspend entry". The PM_SUSPEND_PREPARE notifier took spk_mutex
before it touched anything. Meanwhile the supervisor's own release write
sat in the kernel and logged nothing, and systemd's watchdog killed it.
The floor came 1 ms after that kill. Only then was the withdrawal logged,
and its reason was "system sleep". If the lease timer closed the gate
during the wait, the log could not show it.

At PM_SUSPEND_PREPARE and PM_HIBERNATION_PREPARE:
- The notifier marks the card quiesced, closes the start gate and queues
  the stream stop before it waits for anything. It is the same lockless
  close that the lease timer uses. The safe level then follows under
  spk_mutex. A wait for the lock longer than 50 ms is logged, with its
  length.
- The notifier is registered at INT_MAX, so no other driver's sleep
  preparation runs before the floor.
- The notifier still runs before tasks freeze and not from a device
  suspend callback, so a sleep that stops short of the devices
  (pm_test=freezer) withdraws protection too.
- A grant that is raising the amps when the sleep begins floors them
  again and returns -EBUSY.
- The lease timer is only ever cancelled together with a floor, so a
  lease still ends at its deadline while the floor waits.

A card without speakers, the J616s jack card, now ignores sleep. Before,
its notifier "floored" no amps and latched spk_floor_failed, with a
dev_crit at every suspend.

A withdrawal whose gate was already closed now names what closed it and
how long before: the lease's end or system sleep. The timer's action is
visible in the log even when the floor that follows waits.

After a resume, an owner's first write is still -ETIMEDOUT, then the
next one grants.

KUnit apple-speaker-protection gains four cases:
- the gate closes while a writer holds spk_mutex across the sleep's
  start, then the floor, -EBUSY, -ETIMEDOUT after the resume, and a
  re-grant;
- the hibernation path;
- the notifier's priority;
- a card without speakers.

24 of 24 cases pass on arm64 qemu, on 1 and 4 CPUs, with PROVE_LOCKING
and no lockdep report.

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

Copy link
Copy Markdown
Contributor Author

One more fix, from a J616s sleep test: 8d0c348 ASoC: apple: macaudio: Close the speaker gate first at system sleep.

The problem. Under pm_test=freezer on a J616s, protection was withdrawn 5.1 s after "PM: suspend entry". The PM_SUSPEND_PREPARE notifier took spk_mutex before it did anything else. The supervisor's own release write sat blocked in the kernel, and systemd's watchdog killed the supervisor. The floor came 1 ms after that kill, and the log could not show whether the lease timer had closed the gate in the meantime.

The fix.

  • Gate first. The notifier marks the card quiesced, closes the start gate and queues the stream stop before it waits for anything. This is the same lockless close the lease timer uses. The safe level then follows under the mutex.
    • A grant that is raising the amps when the sleep begins floors again and returns -EBUSY.
    • A floor that takes more than 50 ms is logged, split into the lock wait and the time spent setting the safe level.
  • First in the chain. The notifier is registered at INT_MAX. It still runs at PREPARE, before tasks freeze and not from a device callback, so pm_test=freezer is covered.
  • The lease timer still fires on time. It is cancelled only together with a floor, so a lease still ends at its deadline while the floor waits.
  • Clearer log line. A withdrawal whose gate was already closed names what closed it and how long before, for example withdrawn: system sleep (start gate closed by system sleep 1729 us before) or ... by the lease's end ....
  • Jack card. A card without speakers (the J616s jack card) now ignores sleep. Before, its notifier latched spk_floor_failed and logged a crit at every suspend.
  • Unchanged. After a resume, the first write returns -ETIMEDOUT, then the next one grants.

KUnit. Four new cases:

  • the gate closes while a writer holds spk_mutex across the sleep's start, then the floor, -EBUSY, -ETIMEDOUT after the resume, and the re-grant;
  • hibernation;
  • the notifier's priority;
  • a card without speakers.

All 24 cases pass on 1 and 4 CPUs, with PROVE_LOCKING and no lockdep report. W=1 shows 0 warnings, run-host-tests 180/180, apple-dcp 85/85, macaudio-fixed-controls 0 failures.

M1 Pro, pm_test=freezer only. The value was read back as [freezer] before every trigger. Three cycles, each with a 30 ms lease held and a zero-sample stream, SELinux enforcing, 0 AVCs:

Event Cycle 1 Cycle 2 Cycle 3
Filesystem sync (runs before PREPARE) 234 ms 16 ms 13 ms
Gate closed, after suspend entry 244.4 ms 17.4 ms 14.3 ms
Amps floored, after suspend entry 249.0 ms 19.1 ms 16.0 ms
  • The gate closes 1.3 to 9.4 ms after the sync ends.
  • The owner sees -EBUSY until the resume, then one -ETIMEDOUT, then a grant.

The M1 Pro did not reproduce the 5 s stall even on the previous head, so whatever blocks on the J616s is specific to that machine. The new warning should show where the time goes.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Correction to my diagnosis in 8d0c348, after the J616s retest on the sgv2k3 kernel built from it, with pm_test=freezer read back before every trigger:

  • The 5.1 s on sgv2k2 was not a blocked write. It was the pm_test freezer's own 5 s wait.
    • A stack sampler got no samples from +0.00 to +5.22 s, so user space really was frozen.
    • The printk timestamps on that machine put "Freezing user space processes" after the gap, so they misrepresent the order of events.
    • The old notifier's withdrawal was logged after the thaw.
  • The watchdog kill also comes from pm_test. CLOCK_MONOTONIC keeps running under pm_test, so systemd's 1 s WatchdogSec fires once user space thaws. A real s2idle stops that clock.
  • The commit's changes stand. Closing the gate first, the INT_MAX priority, the jack-card fix and the logging are all still right.
  • J616s results on sgv2k3 (3 cycles):
    • the gate closes 23.0 to 25.9 ms after suspend entry, and the amps are floored 1.7 to 2.0 ms later;
    • every withdrawal logs "(start gate closed by system sleep …)";
    • no slow-floor warning and no jack-card crit appeared.
  • The resume rule holds. In a cycle with the watchdog relaxed (test-only drop-in, since removed), the supervisor's first write after resume got -ETIMEDOUT, and it re-granted 11.7 ms later.

While protection is withdrawn, an audio server's speaker sink retries its
start from the data loop. Each refused start went through ASoC's DPCM
trigger, which logs every failure as an error:

  Secondary: ASoC error (-1): at soc_link_trigger() on Secondary
  Secondary: ASoC error (-1): trigger FE cmd: 1 failed

On an M1 Pro that came to about 41 refusals for a 400 ms stall of the
protection supervisor, about 190 for a 2 s stall, and dozens at every
cold start before the first grant. The J616s showed the same. A refused
start is the floor working, not a DAI failure.

The card's late probe now puts a gate in front of each front-end PCM's
own trigger (rtd->ops.trigger, which ALSA calls). Its PCMs exist by then
and are not yet registered. The gate refuses a speaker start with the
same -EPERM and the same admission check (macaudio_spk_admitted()), and
it does so before the DPCM trigger runs, so nothing is logged and nothing
has been touched. Stops, capture, and front-ends that do not drive the
speakers pass straight through. The link-trigger and back-end checks stay
behind the gate.

Each refusal is counted. debugfs asoc/<card>/speaker_starts_refused holds
the exact total, and the next grant logs the run in its one line:
"Speaker protection granted (N speaker starts refused before)". The
-EPERM that userspace sees is unchanged, and the supervisor and the
engine see no difference.

KUnit apple-speaker-protection gains a case on a front-end PCM wired to a
speaker back-end. It checks the gate install (idempotent), the refusals
and their count, the pass-through, the grant and its reset, a lease past
its end, and a front-end not connected to the speakers. 25 of 25 cases
pass on arm64 qemu on 1 and 4 CPUs, with PROVE_LOCKING, DEBUG_FS and no
lockdep report.

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

Copy link
Copy Markdown
Contributor Author

Log noise fix: 3d61274 ASoC: apple: macaudio: Refuse speaker starts without an error per try.

Problem. Every speaker start refused while protection is withdrawn logged two or three ASoC error (-1) lines from the DPCM trigger. PipeWire's sink retries from its data loop, so this came to about 41 refusals for a 400 ms stall, about 190 for a 2 s stall, and dozens at every cold start.

Fix.

  • The card's late probe puts a gate in front of each front-end PCM's own trigger (rtd->ops.trigger). At that point the PCMs exist but are not yet registered.
  • The gate refuses a speaker start with the same -EPERM and the same admission check, before the DPCM trigger runs. So nothing is logged and nothing has been touched.
  • Stops, capture, and front-ends that don't drive the speakers pass straight through.
  • The link-trigger and back-end checks stay behind the gate.
  • Userspace sees the same errno, so the supervisor and engine see no change.

Counting.

  • debugfs asoc/<card>/speaker_starts_refused holds the exact total.
  • The next grant logs the run in its one line, for example Speaker protection granted (30 speaker starts refused before).

Tests.

  • New KUnit case: a front-end PCM wired to a speaker back-end. It covers installing the gate (twice, idempotent), refusals and their count, pass-through, grant and reset, a lease past its end, and a front-end not connected to the speakers.
  • 25/25 pass on 1 and 4 CPUs, with PROVE_LOCKING and DEBUG_FS, no lockdep report.
  • W=1: 0 warnings. run-host-tests 180/180, apple-dcp 85/85, macaudio-fixed-controls 0 failures.

M1 Pro, with sgv2k4 booted once as a one-shot entry. Zero-sample streams only, SELinux enforcing, 0 AVCs.

Case Refused (counter) ASoC error lines
Boot 0 0
Cold start: 30 start attempts, no owner +30 0
400 ms owner stall with a retrying player (lapse, -ETIMEDOUT, re-grant) +2 0

The only kernel lines are one per state change, for example:

Speaker protection granted (30 speaker starts refused before)
Speaker protection withdrawn: lease expired (start gate closed by the lease's end 1931 us before)
Speaker protection granted (1 speaker starts refused before)

A machine driver can admit a stream only while it is allowed to play.
The case here is speakers that may start only while a protection engine
holds them. Such a driver refuses the start from its link trigger with
-EPERM. That is the driver working as intended, but ASoC logs it as an
error at two levels:

  Secondary: ASoC error (-1): at soc_link_trigger() on Secondary
  Secondary: ASoC error (-1): trigger FE cmd: 1 failed

An audio server retries a refused start from its data loop, so the
error lines reach dozens to hundreds per refusal period.

Add a dai_link flag, quiet_trigger_eperm. On a link that sets it, -EPERM
from a trigger still fails the trigger exactly as before, but
soc_link_trigger(), dpcm_be_dai_trigger() and the DPCM front-end trigger
do not log it. Every other error, and every link without the flag, is
logged as before. snd_soc_link_trigger_refused() is the test, with a
KUnit case in soc-utils.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Drop the stand-in for the front-end PCM's trigger that 3d61274
added: it reached into rtd->ops from the machine driver. Use the
ASoC core's quiet_trigger_eperm instead: every link of a card with
speakers sets it. The gate's -EPERM from the front-end and back-end link
triggers then fails the start without a log line, and errors other than
-EPERM are logged as before.

Behaviour is otherwise unchanged:
- userspace sees the same -EPERM;
- each refusal is counted in debugfs asoc/<card>/speaker_starts_refused;
- the next grant logs the run in its one line ("Speaker protection
  granted (N speaker starts refused before)").

KUnit:
- the refusal case now drives macaudio_fe_trigger() and
  macaudio_be_trigger() directly, covering the counter, the pass-through,
  the reset at grant, a lease past its end and an unconnected front-end;
- a new case checks that every link of a speaker card is marked quiet;
- apple-* has 26 of 26 cases, and soc-utils 3 of 3, on arm64 qemu on 1
  and 4 CPUs, with PROVE_LOCKING and no lockdep report.

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

Copy link
Copy Markdown
Contributor Author

Replaced the rtd->ops.trigger stand-in from 3d61274 with an ASoC core flag. These are two new commits, the core change first:

  • a1232a6 ASoC: soc-pcm: Let a link mark trigger -EPERM as a quiet refusal
  • 459c031 ASoC: apple: macaudio: Refuse speaker starts through quiet_trigger_eperm

ASoC core

  • A new snd_soc_dai_link bit, quiet_trigger_eperm. On a link that sets it, -EPERM from a trigger still fails the trigger exactly as before. It is just not logged.
  • The check is snd_soc_link_trigger_refused(), used in soc_link_trigger(), dpcm_be_dai_trigger() and the DPCM FE trigger.
  • Every other error, and every link without the flag, is logged as before.
  • KUnit case in soc-utils.

macaudio

  • Every link of a speaker card sets the flag. The stand-in is gone.
  • The gate in the FE and BE link triggers is unchanged and still returns -EPERM.
  • The refusal counter (debugfs asoc/<card>/speaker_starts_refused) and the one-line messages ("granted (N speaker starts refused before)") are kept.

Gates

  • KUnit apple-* 26/26 and soc-utils 3/3, on arm64 qemu with 1 and 4 CPUs, PROVE_LOCKING, no lockdep report.
  • W=1: 0 warnings on soc-link.o, soc-pcm.o and macaudio.o.
  • run-host-tests 180/180, apple-dcp 85/85, macaudio-fixed-controls 0 failures.

M1 Pro (J316), sgv2k5 one-shot
Zero-sample streams only, SELinux enforcing, 0 AVCs.

Case Refused (counter) ASoC error lines
Boot 0 0
Cold start, 30 attempts +30 0
400 ms stall with a retrying player +2 0

The full lease, floor, starvation, kill and sense set also matches the earlier runs:

  • stream XRUN at 30.07-30.11 ms, DVC floor at 31.80-31.85 ms, including under the FIFO 99 spinner;
  • -ETIMEDOUT, then a re-grant;
  • the unprivileged lock is refused.

The whole boot logged 0 ASoC error lines.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge-train review for the speakerguardd v2 cutover (release lane).

  • The head 459c031 is the gated sgv2k5 tip: KUnit 26/26 + 3/3, W=1 clean, host tests 180/180, dcp 85/85. It is hardware-proven on the M1 Pro and J616s, silent and audible, with the v2 userspace now merged (speakerguardd v2 3c18a35). Merging into integration/aurora is CLEAN (41 behind), and no Kconfig changes, so the universal config is unaffected.
  • Held, not merged. The series replaces "Speaker Volume Unlock" on every macaudio board, the J700 included. With one universal kernel, merging it moves the whole fleet off speakerguardd 0.1 and speakersafetyd at once. The Neo (lsm2) and the atsp Macs are not at v2 parity yet, so they would be left at the kernel floor. This needs a decision: hold until lsm2/atsp parity, or make the interface per board through the macaudio match data for the transition.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Decision (Ryan, 2026-11-05): option A. This stays held until lsm2 and atsp reach parity with macOS (Daybreak t-4670, lane B3), and then the whole fleet cuts over at once. The kernel will not keep a per-board legacy unlock interface.

macaudio fixes the playback high-pass filter of every SN012776 tweeter
amp at 800 Hz, a safety net from before any speaker protection ran in
userspace. On machines where the protection runs in the PipeWire graph
and measures each voice coil with a low-frequency pilot tone, that
filter sits after the protection stage and removes the pilot from the
tweeter outputs. The tweeters' V/I sense then never carries the pilot,
so their closed-loop temperature never leaves its calibration value
and only the open-loop model protects them. The woofers, filtered at
2 Hz, track as expected. The amp's sense-path DC blockers are separate
and unchanged.

On those machines the graph's crossover, which keeps program bass off
the tweeters, comes before the protection stage, so the amp filter adds
nothing to the tweeters' protection there but takes away their sense.

Add a tweeter_hpf field to the platform match data, "800 Hz" when
unset, and set it to the woofers' 2 Hz on the J413 and the J616s/J616c,
both of which run the in-graph protection with a tweeter pilot. Every
other machine keeps 800 Hz. The control stays fixed and read-only, and
the speaker gate is unchanged: no amp plays unless the protection owner
grants it.

KUnit apple-speaker-hpf: woofers stay at 2 Hz, the default tweeter
corner stays 800 Hz on every machine that does not set it, the two
pilot machines get the woofer corner below the pilot, and no machine
selects "Disabled".

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide and others added 2 commits November 5, 2026 14:31
…granted

The previous change fixed the tweeter playback high-pass at the woofers'
2 Hz on the J413 and J616 for good. That opens the tweeters even when no
protection engine owns the speakers, which is exactly when the 800 Hz
filter is the only thing keeping program bass off them.

Tie it to the grant instead. The tweeter corners become the driver's,
like the speaker volumes: read-only to userspace, 800 Hz from the card's
binding on, and set to the machine's granted corner
(tweeter_hpf_granted) in macaudio_spk_grant(), before the amps go up to
the operating gain. Every withdrawal (an explicit release, the owner's
file closing, a new owner, the lease running out, system sleep) goes
through macaudio_spk_floor(), which brings the amps to the safe level
first and then restores 800 Hz. A corner that cannot be restored is a
failed floor: speaker playback is refused until the driver reloads. A
corner that cannot be opened fails the grant and floors.

The machines that open the tweeters while granted are the J316, J413
and J616s/J616c, the boards whose protection engine runs the crossover
ahead of its protection stage and a low-frequency pilot on every voice
coil. Every other machine keeps 800 Hz throughout.

KUnit apple-speaker-hpf, now 7 cases: a grant opens the tweeters, an
explicit release, the owner going and a lease timeout restore 800 Hz,
a refused renewal opens nothing, a failed restore is a failed floor, a
failed open floors, other machines stay at 800 Hz, woofers stay at 2 Hz,
and no machine ever selects "Disabled".

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
ASoC: apple: macaudio: Open the tweeter HPF only while protection is granted
…nt snapshot

At the end of a period the controller runs the residue down to 0, posts
the period's report, and only then loads the next descriptor. A residue
read in between (report counted, residue still 0) put the position a whole
period ahead. The PCM core then saw the hardware pointer past the
application pointer and stopped the stream for an underrun.

On the J316s (M1 Pro) speakers this hit two to three times in each
five-minute full-volume run. PipeWire's timer wakes a few microseconds
before the period interrupt, and the protection supervisor reads the PCM
status every millisecond, so the reads land at period ends. ftrace showed
the playback position jump from 11242 to 11776 frames (a period end plus
512) in 0.36 ms, with the PCM stopped in XRUN by the same read. Both data
loop wakes and the DMA interrupt were on time, and no thread was
preempted.

The old check caught only a descriptor load between the two residue reads.
It also counted a report posted before the first ring read twice.

So read again until the snapshot is consistent: the report ring the same
on both reads, and the residue non-zero, not reloaded and within a period.
A controller that stays at a period's end (stalled, with no descriptor
to load) is reported at the periods done or the last position, whichever
is later. That position is never ahead of the transfer and never behind
an earlier report, since a pointer that goes back reads as a wrap of the
whole buffer. KUnit covers the cases from the trace.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Merge integration/aurora (#981 amp values from the ADT) into sgv2-kernel-interface
On J316, J413 and J616 a protection grant opens every tweeter amp's
playback high-pass from the 800 Hz safe corner to the amp's DT corner.
That is right only when the engine ahead of the amps already splits the
band the way the machine does: the tweeters then see no low-frequency
content but the engine's own thermal pilot. An engine without that
crossover would drive the full band into the tweeters with nothing in
the way.

Make the grant fail closed. Add "Speaker Protection Crossover", a
boolean card control on which the owner of "Speaker Protection"
declares that its engine passes every speaker channel through the
machine's own crossover and high-pass ahead of the amps. A grant opens
the tweeter high-pass only while that declaration is 1; otherwise the
tweeters stay at the safe corner for the whole grant and the woofers
are unchanged.

The control is the owner's alone. Locking it needs CAP_SYS_ADMIN and
ownership of "Speaker Protection"; a write needs CAP_SYS_ADMIN and that
lock held by the owning file (-EPERM otherwise). A grant latches the
declaration: a write while granted fails with -EBUSY. The declaration
goes back to 0 when the owner unlocks "Speaker Protection" or closes
its file, and when a new owner takes it. A lease that runs out keeps
it, as the owner is the same; the floor still restores the safe corner.

The control is appended after the existing card controls, so no
control is renumbered. Machines that never open the tweeter high-pass
ignore it.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
ASoC: restore DT tweeter HPF on grant and protect amp sense switches
ASoC: macaudio: open the tweeter high-pass only for an engine that runs the Mac's crossover
Keep linux#922 current with integration/aurora for the speakerguardd v2
cutover (option A: every Mac at once).

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Keep linux#922 current with integration/aurora (#992 rust bindgen
layout) for the speakerguardd v2 cutover (option A).

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

Copy link
Copy Markdown
Contributor Author

Kept current with integration/aurora for the speakerguardd v2 cutover (option A). Both are merge commits, with no force push: 55affee merged integration 11eccbe, and 23832b0 merged 0943983 (#992, rust bindgen layout). integration brought no sound/ changes.

Gates at 23832b0 (buildbox, fleet recipe, 7.3.0-aurora-sgv2cut, 5887 modules, asahi.config 0 mismatches):

  • KUnit apple-*: 44/44
  • AOP rust: 47/48 (1 skip)
  • W=1 on macaudio, mca, tas2764, tas2770 and apple-admac: 0 warnings
  • host tests: 185/185
  • apple-dcp selftests: 86/86
  • macaudio-fixed-controls: 660 attempts, 0 failures

The same gates passed at 55affee. This stays DRAFT and unmerged until lsm2 is at parity (option A). The cutover runbook is in the speakerguardd-v2 CUTOVER notes.

"Speaker Playback Mux" picks the front-end that drives the speakers.
The owner of "Speaker Protection" grants playback for the front-end its
protection engine runs on, but the mux stays writable by any user of
the card. On the MCA machines (J316, J413, J274, J293, J313 and their
siblings) both front-ends are real PCMs, so a write under a running
grant routes the other one, which carries no protection, to the amps.
The owner notices on its next check of the route and withdraws, but
until then that stream plays at the granted operating point.

Refuse writes to the speaker mux with -EBUSY while protection is
granted. Before a grant the route may change as before: the owner
checks it before it grants.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
ASoC: macaudio: keep the speaker route while protection is granted

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Bring the speaker protection series up to date with integration/aurora
e5ed737. No sound/ changes came in from integration.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
macaudio_protect_sense() now also sets a write check on "Speaker
Playback Mux" (macaudio_route_write_check()), so the harness must extract
it and its helper, or the test no longer builds. Add a scenario: the
route is writable while protection is withdrawn, any write (owner or
not) returns -EBUSY while it is granted, before the DAPM callback runs,
and it is writable again after the withdrawal.

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

Copy link
Copy Markdown
Contributor Author

Head 7b90611 is 0 behind integration/aurora e5ed737. It contains:

Gates at tree 8308dbbf (kernel 7.3.0-aurora-sgv2cut2, 5887 modules, asahi.config 0 mismatches):

Gate Result
KUnit apple-* 46/46 on 2 of 3 reruns. The first run and one rerun each failed one different lease-timing case (lease_expires, then timer_beats_a_fifo_spinner) while the buildbox load was about 58 (TCG qemu). No code change between the runs.
AOP rust KUnit 47/48, 1 skip
W=1 (macaudio, mca, tas2764, tas2770, apple-admac) 0 warnings
run-host-tests 189/189
apple-dcp selftests 86/86
macaudio-fixed-controls 664/664 in both validation modes. A mutation that drops the route check fails 3 cases.

Hardware, J700 (Neo), silent: a one-shot with speakerguardd v2 fc227db6 installed.

  • The gate keeps lsm2 off.
  • The kernel floor holds: Speaker Protection 0, no Speaker Volume Unlock.
  • 0 AVCs and 0 failed units.
  • Touch ID restored and the os_uuid pin present.
  • Afterwards the Neo went back to fleet16.

Still a draft on purpose. Merge only after the distro packages carrying v2 are published (final-round/MORNING-RUNBOOK.md, step 4). Merged earlier, the next integration kernel leaves Macs running 0.1 at the floor.

RyanTheTide and others added 2 commits November 7, 2026 10:32
Bring linux#922 up to date with integration/aurora (33bec40) before the
speakerguardd v2 Plan B cutover merge. No conflicts.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bring linux#922 up to date with integration/aurora (f9ce365, linux#1055
Bluetooth MT7932 build rule) before the speakerguardd v2 Plan B cutover
merge. No conflicts.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 7, 2026 00:47
@RyanTheTide
RyanTheTide merged commit 68db611 into integration/aurora Nov 7, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the sgv2-kernel-interface branch November 27, 2026 13:21
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