Skip to content

soc: apple: aop: one child device per service, however often it is announced - #2779

Open
funkzy wants to merge 3 commits into
aurora-silicon:integration/aurorafrom
funkzy:pr/aop-service-once
Open

funkzy wants to merge 3 commits into
aurora-silicon:integration/aurorafrom
funkzy:pr/aop-service-once

Conversation

@funkzy

@funkzy funkzy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When the AOP firmware announces a service whose name is one of the seven this driver knows (aop-audio, las,
als, accel, gyro, devmotion6, als-temp), register_service() queues a work item that registers a platform
device with PLATFORM_DEVID_AUTO. Nothing records which services already have a device. An announcement that arrives
again therefore adds another child, with its driver bound, for the same service, and the number of children has no
bound.

Why this shape

Which announcements become children was a match in register_service(); whether a service already had one was
recorded nowhere. subdevices fills in later, from the work item, under a lock held across the child's probe, so it
can't be checked under the endpoint lock. The listener tables here already refuse a second listener for one
EPICService, and the DCP driver's AFK transport (afk.c) ignores a repeated announcement on a live channel. A cap
on the number of children would be a new constant and would still bind two drivers to one service; checking
subdevices in the work item would miss registrations still queued. So the registration gate, which already orders
queueing against removal, holds the claims, keyed by the listener tables' EPICService and the device name, with the
name table beside it. Every SoC gets at most one child per known service, seven in all, with no per-announcement
allocation.

Change

  • fbfeb1193f4a (soc: apple: aop: one child device per service, however often it is announced):
    • drivers/soc/apple/aop_services.rs (new): the table of service names and device names, and Claims, the record of
      the services that have a device, registered or queued. Its storage is reserved at probe for the whole table.
      • An unchanged repeat of an announcement does nothing.
      • A known name announced on another channel, or a channel announced again under another name, gets no device.
        The endpoint counts it as a dropped message and logs the announced name and channel, under the same throttle as
        its other dropped messages.
    • drivers/soc/apple/aop.rs: registration_gate holds the Claims, and register_service() claims before it
      queues. A registration that fails gives up its claim, so the next announcement of that service tries again.
    • No SoC, board or firmware condition; a service announced once is handled as before.
  • 7709c6ec1217 (soc: apple: aop: run the KUnit suites in CI): adds drivers/soc/apple/aop.kunitconfig and runs
    apple_aop* (apple_aop_services and apple_aop_ring) on arm64 QEMU in .github/workflows/sep-source.yml's
    kunit job.
  • a0837b9f9b42 (soc: apple: aop: cover all three claim-release paths in the host test): extends
    tools/asahi/aop-service-tests.py to extract both AopData::register_service() and AopServiceRegisterWork::run()
    from aop.rs, cover all three claim-release failure paths (AopServiceRegisterWork::new, subdevices.reserve, and
    platform_device_register_full returning ERR_PTR or NULL), assert subdevices is dropped before
    registration_gate is locked, and register --mutation {no-work-release,no-slot-release,no-register-release} runs
    in tools/asahi/run-host-tests.py.

Testing

  • KUnit (local arm64 run): apple_aop_services (6/6 pass) and apple_aop_ring (17/17 pass) in kunit-vz
    (12 suites, 65 of 66 pass, 0 fail, 1 expected skip on apple_mbox_g17_stall/apple_g17_rx_util_min_test without
    CONFIG_UCLAMP_TASK). Standalone drivers/soc/apple/aop.kunitconfig was built and linked from allnoconfig (all
    10 options resolve =y and include both suites); the new CI step will exercise kunit.py run on push.
  • Host tests (tools/asahi/aop-service-tests.py): 6 of 6 checks and 8 of 8 controls pass. --old-ref fails all 6
    checks. Deleting any of the three claim-release lines or either drop(subdevices) line in aop.rs fails its test or
    trips the lock assertion; all three --mutation runs pass in run-host-tests.py. Full run-host-tests.py in the
    build VM: 459/459 pass on the base (24dc422773c9), 464/464 pass with this series (only the 5 new aop-service-tests
    runs differ).
  • J775D (Mac Studio, M5 Ultra) own-base row: kit pr2779-3 (window pr2779r2@20261123-0216, aura
    aura-aopres1c: integration/aurora a4b51cdff0a7 plus #2890, which enables the J775D AOP over its RTKit
    mailbox, plus all three commits of this PR at a0837b9f9b42) against kit pr2779-3b (window
    pr2779r2@20261123-0216, aura aura-aopres1c: the same base and #2890 without this PR). One boot each
    through the default 27.0 firmware stub and Aura carrying aurora-silicon/aura#474 at its earlier head adaf5a5f
    (which reserves the AOP's firmware pages when its DART is locked; aura#474 has since been revised), default
    kernel command line, read-only root (ALARM has no SELinux).
    • Both boots: apple_aop binds 290c00000.aop, announces aop-audio, and registers one child audio.0.auto
      (snd_soc_t8152_aop_audio), bringing up AppleJ775D (15 simple mixer controls from amixer scontrols on both
      arms). 0 dropped a message lines and 0 DART faults on both.
    • Regression: 5 err-level kernel lines on both (0 new vs base), 0 WARNING/BUG/Oops, and the same 2 failed units on
      both (iwd.service missing kernel crypto options in integration's defconfig, and
      systemd-networkd-persistent-storage.service on the read-only root).

Note on #2890: its branch is stacked on #2556's two AOP setup-port commits, so the #2890 need above carries
those commits into both arms.

Builds, checkpatch, and other open PRs
  • Builds: the J775D kernel, integration/aurora defconfig with AOP built in, and standalone allnoconfig +
    drivers/soc/apple/aop.kunitconfig; no warnings.
  • checkpatch --strict: 0 errors across all three commits. Warnings are the Reported-by: without Closes: on
    fbfeb1193f4a and the two new files (aop_services.rs, aop.kunitconfig), both covered by drivers/soc/apple/*
    in MAINTAINERS.
  • Merges cleanly with each open PR touching aop.rs (#2556, #2519, #2351, #2800, #2906).

Still to run

  • A boot and short s2idle row on a Mac whose AOP announces several services and supports s2idle on integration/aurora
    (the J775D announces only aop-audio and does not yet have s2idle upstream on integration/aurora), verifying the
    same bound children and 0 dropped a message lines.

Assisted-by: LLM (Claude:Opus 5.5), LLM (Gemini:Neon)

…nounced

Each service announcement whose name is one of the seven services this
driver knows queues a work item that registers a platform device with
PLATFORM_DEVID_AUTO and adds it to the list of children. Nothing checks
whether the service already has a device, so an announcement that
arrives again adds another child with its driver bound, and the number
of children is not bounded. The DCP driver's AFK transport
(drivers/gpu/drm/apple/afk.c) ignores a repeated announcement on a
channel whose service is still live, and the listener tables here
already refuse a second listener for one service; only the child
registration had no such check.

Keep the record where the decision is made: the registration gate,
which already orders queueing against removal, now holds the services
that have a device, registered or queued, and the name table moves next
to it into aop_services.rs. An unchanged repeat of an announcement is
ignored. A known name announced on another channel, or a channel
announced again under another name, gets no device; the endpoint counts
it as a dropped message and logs it, with the announced name and
channel, under the same throttle as its other dropped messages. The
record holds at most one entry per entry of the table, reserved at
probe, so announcements allocate nothing beyond the seven devices. A
registration that fails gives up its claim, so the next announcement of
that service tries again.

This applies to every SoC this driver supports. The new KUnit suite
apple_aop_services checks the record; tools/asahi/aop-service-tests.py
builds register_service() against host stand-ins and checks the devices
queued and the refusal's log line, and the code before this change
fails it.

Fixes: 3ed935e ("soc: apple: Add support for the AOP co-processor")
Reported-by: Erik Bourget <erik@ebourget.net>
Suggested-by: Erik Bourget <erik@ebourget.net>
Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor

The claim logic and the locking look right to me:

  • drivers/soc/apple/aop_services.rs:39-58: an unchanged repeat does nothing, an unknown name never takes a claim, and the capacity reserved at probe covers the whole table, so push_within_capacity() can't fail.
  • aop.rs:1656 takes the gate under the endpoint lock. The work item drops subdevices before it takes the gate to release a claim (aop.rs:1440-1446, 1455-1462), and remove() drops the gate before drain(). I don't see a lock-order problem, and every failed registration gives its claim back.

Two behaviour questions, both about firmware that announces more than audio:

  • The only hardware row is a board whose AOP announces one service, so neither the refusal path nor the multi-service case has run on hardware. If any current AOP firmware announces a known name on two channels or endpoints, that second instance now silently gets no device, where it used to get one. A before/after on a multi-service AOP (A18 Pro, M4/M3/M2 Air, M1 Pro: the AOP's child devices, mics and ALS working, dmesg | grep "dropped a message") would show that this doesn't happen.
  • After resume, sleep_undo() (aop.rs:1822) restarts the endpoints. If the firmware re-announces a service on a different channel, the child registered at boot keeps the EPICService it was given as platform data (aop.rs:1423-1424), and the new announcement is refused as EEXIST. Before this change that case created a second child, and after it the existing child talks to a stale channel. Neither is right, but the new behaviour is quieter. If the A18 Pro answer to your resume question is "same channel", fine. If not, a changed channel needs the existing child pointed at the new one, not just refused.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pre-PR checklist review on fbfeb1193f4a4068aa078d85e26326911025cc3b (CI: 7/7 checks green — host-tests, source, rust-build, kunit, and all three DWC3/ATC builds).

Code & Locking Audit

  • drivers/soc/apple/aop_services.rs & drivers/soc/apple/aop.rs: Clean design. Claims::new() reserves the full 7-entry capacity at probe time, so service announcements allocate nothing beyond the platform device work item. Claims::claim() enforces a strict bijection between EPICService and the DEVICES index (unchanged repeats return Ok(None), conflicting channel or name returns Err(EEXIST) and routes through ep.drop_message() with escaped BStr logging and power-of-two throttling).
  • Error unwind & lock ordering verified: AopServiceRegisterWork::run() drops subdevices before taking registration_gate to release the claim on reserve() or platform_device_register_full() failure; register_service() releases the claim if AopServiceRegisterWork::new() fails; remove() drops registration_gate before draining registration_queue and taking subdevices. ep.drop_message() takes no locks. No AB-BA lock inversion.
  • Tests: apple_aop_services KUnit suite (gated via #[kunit_tests] -> CONFIG_KUNIT="y") and tools/asahi/aop-service-tests.py (with --old-ref 24dc422773c9 failing checks and passing controls) both pass in CI.

Pre-PR Checklist (§1–§6)

  • §1 No model gating: Pass — no SoC/board/firmware gates.
  • §2 Production-ready: Pass — default command line, no retries/sleeps/magic bounds.
  • §3 Safety: Pass — no hardcoded hardware safety values; bounds child device creation cleanly to the 7 known services.
  • §4 Clean-room & attribution: Pass — human author/committer and Signed-off-by only in commit; Assisted-by: disclosed in PR body.
  • §5 Evidence: Holding for additional hardware rows. The J775D A/B row is helpful, but on J775D AOP does not boot on stock integration/aurora (it required carrying #2556 plus an unposted local DT patch) and only announces a single service (aop-audio), with 2 failed units on ALARM/RO-root. As noted in ## Still to run, we still need §5 regression rows from AOP Macs where AOP boots directly on integration/aurora (M1–M4 / M5 laptops announcing multiple services, plus T8140 suspend/resume re-announcement behavior).
  • §6 Naming: Pass.

Zero code, policy, or CI blockers — holding as COMMENT only for the remaining §5 multi-service / stock-base AOP hardware rows.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-author review of fbfeb1193f4a. I tried to break it and could not; the code looks right to me. One row is still missing before merge, and I have two test requests that can be a follow-up.

Code

  • The record does what the commit message says: an unchanged repeat is ignored, a known name on another channel or endpoint and a claimed channel under another name get no device, and an unknown name takes no claim (aop_services.rs:39-58). The record is reserved for the table at probe, so announcements allocate nothing beyond the table's devices and their work items.
  • Locking: the receive path takes the gate under the endpoint lock (aop.rs:1656); the work item drops subdevices before it takes the gate, and never holds the gate across the child's probe (aop.rs:1440-1446, 1455-1462); remove() drops the gate before the drain. I see no lock-order problem. A release can only remove the claim of the registration that failed, because a present claim refuses every other announcement of that service.
  • A rebind starts with an empty record, so the services get their devices again. There is no firmware restart path in the driver today; if one is added, it has to unregister the children and clear the record.
  • No chip, board or firmware gates, no parameters, no new unsafe.

Tests I ran at this head

  • tools/asahi/aop-service-tests.py: 5 of 5 checks and 4 of 4 controls pass. With --old-ref 24dc422773c9 the old code fails all 5 checks and passes the 4 controls.
  • KUnit on arm64 QEMU with APPLE_AOP=y: apple_aop_services 6/6 and apple_aop_ring 17/17. With the refusal removed from Claims::claim, a_name_or_channel_with_a_device_is_refused fails, so the suite does test the change.

Hardware, before the change

On kernels without this change, where each announcement gets a device, the child list shows what the firmware announces:

Mac AOP children Suspend exits that boot
A18 Pro (T8140) als, audio 2
M4 Pro (T6040) accel, gyro, las, als-temp, devmotion6, als, audio 0
M2 (T8112) the same seven 0
M1 Pro (T6000) the same seven 2

Each known name is announced once, and the two Macs that had resumed twice had no extra children, so their firmware does not announce again after a resume. I expect this change to make no difference on these four.

Still to run before merge

  • This change itself on a Mac whose AOP announces several services: boot and one short s2idle, the same children with their drivers bound, and no dropped a message line. The table above is without the change.

Requests, fine as a follow-up

  • No CI job runs apple_aop_services (or apple_aop_ring): the kunit job uses sep.kunitconfig with the apple_sep* filter, and rust-build compiles apple-sep.o only. A small AOP kunitconfig (KUNIT, ARCH_APPLE, OF, RUST, ARM64_16K_PAGES, IOMMU_SUPPORT, PM, APPLE_RTKIT, APPLE_MAILBOX, APPLE_AOP=y) and a CI step would run both.
  • The three places that give a claim back (aop.rs:1446, 1462, 1683) have no test: deleting any one of them passes the host test and the KUnit suite. The one in register_service is easy to cover in the host test by letting the work-item stand-in fail once and announcing again.

Nits, no change needed: the refusal text at aop.rs:1669 would also be printed for the ENOSPC arm of claim(), which cannot be reached; the "cannot happen" branch at aop.rs:1465 keeps its claim.

Assisted-by: LLM (Claude:Opus 5.5), LLM (Claude:Fable 5.2)

The AOP driver has two KUnit suites (apple_aop_ring and
apple_aop_services), but no CI job builds or runs them: the SEP source
workflow's kunit job uses sep.kunitconfig with an apple_sep* filter,
and its rust-build job compiles only apple-sep.o. A regression in
either AOP suite would not show up on a pull request.

Add drivers/soc/apple/aop.kunitconfig with the minimal options needed
to build APPLE_AOP=y on arm64, and add a step in the sep-source.yml
kunit job that runs both suites on arm64 QEMU with the apple_aop*
filter in a separate build directory (.kunit-aop).

Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
AopData::register_service() and AopServiceRegisterWork::run() release a
service's claim on three failure paths: work-item allocation failure,
subdevice-slot reservation failure, and platform_device_register_full()
returning an error pointer or NULL. Previously
tools/asahi/aop-service-tests.py only built register_service() with an
infallible work-item constructor, so deleting any of those three
releases left both the host test and the KUnit suites green.

Extend tools/asahi/aop-service-tests.py to also build and run the
production AopServiceRegisterWork::run() against host stand-ins, with
fault injection for work-item allocation, subdevice-slot reservation,
and platform device registration (both error pointer and NULL), plus a
lock-order assertion that subdevices is dropped before
registration_gate is locked. Verify that each failed registration
releases its claim so a subsequent announcement registers the device,
while keeping repeats refused once registration succeeds.

Add --mutation modes (no-work-release, no-slot-release,
no-register-release) that drop each release line from the extracted
production source and require its control to fail, and register them in
tools/asahi/run-host-tests.py.

Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
@funkzy

funkzy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, Ryan and dj.

Both test follow-ups are now in this PR (head a0837b9f9b42; the runtime commit fbfeb1193f4a is unchanged):

  • 7709c6ec1217 adds drivers/soc/apple/aop.kunitconfig and adds an apple_aop* step to .github/workflows/sep-source.yml's kunit job. Standalone allnoconfig + aop.kunitconfig compiles and links both suites cleanly; our local arm64 KUnit run (kunit-vz, defconfig + asahi.config) passes apple_aop_services 6/6 and apple_aop_ring 17/17, and the new CI step will exercise kunit.py run on push.
  • a0837b9f9b42 extends tools/asahi/aop-service-tests.py to extract both AopData::register_service() and AopServiceRegisterWork::run() from aop.rs, testing all three claim-release paths (AopServiceRegisterWork::new, subdevices.reserve, and platform_device_register_full returning ERR_PTR or NULL) plus asserting subdevices is dropped before registration_gate is locked. It also registers --mutation {no-work-release,no-slot-release,no-register-release} in run-host-tests.py (464/464 pass vs 459/459 on base).

Refreshed J775D row: re-ran kit pr2779-3 (window pr2779r2@20261123-0216, aura aura-aopres1c: integration/aurora a4b51cdff0a7 plus #2890 plus this PR at a0837b9f9b42) against baseline kit pr2779-3b (window pr2779r2@20261123-0216, aura aura-aopres1c: the same base and #2890 without this PR), with aurora-silicon/aura#474 at its earlier head adaf5a5f (since revised), default 27.0 stub, default kernel command line, read-only root, ALARM has no SELinux. Both arms bind apple_aop (290c00000.aop), register one audio.0.auto (snd_soc_t8152_aop_audio, AppleJ775D, 15 simple mixer controls on both arms), log 0 dropped a message lines and 0 DART faults, with 5 err-level kernel lines (0 new vs base) and the same 2 failed units (iwd.service, systemd-networkd-persistent-storage.service).

Note on #2890: its branch carries #2556's two setup-port commits into both arms.

Because the J775D AOP announces only aop-audio and s2idle is not yet upstream on integration/aurora for J775D, a row on one of the Macs in your table (A18 Pro, M4 Pro, M2, M1 Pro) at this head — boot plus one short s2idle — would finish the multi-service and resume evidence.

Assisted-by: LLM (Gemini:Neon)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Formal §1–§6 pre-PR re-review at a0837b9f9b42021b9ce5c81848b666738ecbb12a (CI: 7/7 green — host-tests, kunit, rust-build, source, and all three DWC3/ATC builds; mergeable=true, clean and not superseded on integration/aurora).

Follow-up Verification (from fbfeb1193f4a)

  • Runtime commit fbfeb1193f4a is unchanged (previously audited: clean Claims bijection, probe-time capacity reservation, proper drop(subdevices) before registration_gate.lock() on all unwind paths, zero AB-BA lock inversion).
  • Commit 7709c6ec1217 cleanly adds drivers/soc/apple/aop.kunitconfig and runs apple_aop* in .github/workflows/sep-source.yml's kunit job — verified in live CI job 137844293684 (apple_aop_services 6/6 passed, apple_aop_ring 17/17 passed on arm64 QEMU).
  • Commit a0837b9f9b42 cleanly extends tools/asahi/aop-service-tests.py to compile production AopData::register_service() and AopServiceRegisterWork::run() together, covering all three claim-release failure paths (AopServiceRegisterWork::new, subdevices.reserve, platform_device_register_full ERR_PTR/NULL), asserting subdevices is dropped before taking registration_gate, and registering --mutation {no-work-release,no-slot-release,no-register-release} plus --old-ref 24dc422773c9 in run-host-tests.py.

Pre-PR Checklist (§1–§6)

  • §1 No model gating: Pass — no SoC/board/firmware gates.
  • §2 Production-ready: Pass — default command line, no hacks.
  • §3 Safety: Pass — bounds child platform-device creation to the 7 known services without hardcoded hardware limits.
  • §4 Clean-room & attribution: Pass — all 3 commits (fbfeb1193f4a, 7709c6ec1217, a0837b9f9b42) carry human author/committer (Jeff Queisser <funkzy@users.noreply.github.com>) and human Signed-off-by: only, zero AI trailers in commits; Assisted-by: disclosed in PR body.
  • §5 Evidence: Incomplete (blocking) — see below.
  • §6 Naming: Pass.

Blocking Finding

  1. Missing multi-service + s2idle stock-base AOP hardware row (§5): The refreshed J775D A/B row at a0837b9f9b42 is helpful, but J775D AOP does not boot on stock integration/aurora (requires #2890/#2556 plus Aura patch), announces only a single service (aop-audio), and lacks upstream s2idle on integration/aurora. As noted in ## Still to run, before merge we still need a boot + short s2idle hardware row on a stock-base integration/aurora Mac whose AOP announces multiple services (e.g. M1 Pro, M2, M4 Pro, or A18 Pro), confirming identical bound children, working sensors/audio, 0 "dropped a message" lines across boot and resume, and §5 regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors).

Verdict

REQUEST_CHANGES — zero code, locking, test, or CI blockers (all 7 CI checks green, including the new arm64 QEMU apple_aop* KUnit step and mutation host tests); holding solely for the remaining §5 multi-service + s2idle stock-base hardware row.

Assisted-by: LLM (Gemini 4 Neon)

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.

3 participants