Repository navigation
ASoC: apple: speaker protection ownership for in-graph protection - #922
Conversation
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
left a comment
There was a problem hiding this comment.
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_rwsemand then takespk_mutex. The lease work and the PM notifier take onlyspk_mutex.macaudio_spk_set_gaincalls the codec's->putdirectly, so nothing takescontrols_rwsemunderspk_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, andsnd_ctl_releasecalls->unlockundercontrols_rwsem, so a crash or SIGKILL of the owner floors at once. - Every withdrawal clears
spk_grantedbefore it touches the amps. A failed grant floors, and a failed floor latchesspk_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_syncwaits 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
hrtimerinHRTIMER_MODE_REL_HARDthat clearsspk_grantedat the deadline; - the floor and stop work on a dedicated
kthread_workerraised withsched_set_fifo()above PipeWire; - in the trigger, refuse a start when
ktime_get()is pastREAD_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]>
|
Thanks for the review. Three new commits on top of 79af0ba address all eight findings; nothing was force-pushed.
1. Starved lease expiry (high), 6ff98c6
2. No privilege check (high), 6ff98c6
3. Regrant racing the stop (medium), 6ff98c6
4. mca lap (medium), 9d69355
5. Second front-end (low), 6ff98c6
6. aop_spkr lap (low), 865ee49
7. Resume (low), 6ff98c6
8. Amp Gain Volume (low), 6ff98c6
Gates at 865ee49
M1 Pro (J316), test kernel built from 865ee49
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. |
…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]>
|
One more fix, from a J616s sleep test: 8d0c348 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 The fix.
KUnit. Four new cases:
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
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. |
|
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:
|
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]>
|
Log noise fix: 3d61274 Problem. Every speaker start refused while protection is withdrawn logged two or three Fix.
Counting.
Tests.
M1 Pro, with sgv2k4 booted once as a one-shot entry. Zero-sample streams only, SELinux enforcing, 0 AVCs.
The only kernel lines are one per state change, for example: |
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]>
|
Replaced the
ASoC core
macaudio
Gates
M1 Pro (J316), sgv2k5 one-shot
The full lease, floor, starvation, kill and sense set also matches the earlier runs:
The whole boot logged 0 |
|
Merge-train review for the speakerguardd v2 cutover (release lane).
|
|
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]>
…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
|
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,
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
|
Head 7b90611 is 0 behind integration/aurora e5ed737. It contains:
Gates at tree 8308dbbf (kernel
Hardware, J700 (Neo), silent: a one-shot with speakerguardd v2 fc227db6 installed.
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. |
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]>
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
This is incompatible with speakersafetyd and speakerguardd 0.1 by design: kernels with this series run only with the new userspace.
Tests
apple-speaker-protection(9 cases) andapple-speaker-admission(1 case): 10/10 pass on arm64 qemu with PROVE_LOCKING. The cases cover:🤖 Generated with Claude Code