Skip to content

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

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

funkzy wants to merge 1 commit 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

  • 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.

Testing

The behaviour change is shown by two new tests:

  • KUnit suite apple_aop_services (6 cases): first announcements get their device, unknown names nothing, an
    unchanged repeat nothing, a name or channel that already has a device is refused, at most one device per table
    entry over 64 channels, and a released claim can be taken again.
  • Host test tools/asahi/aop-service-tests.py (registered in run-host-tests.py): it builds register_service()
    from aop.rs unchanged against host stand-ins and counts the device registrations it queues and the dropped
    messages it logs. Its --old-ref run requires the code before this change to fail, and it does: that code queues
    one device per announcement.

J775D (Mac Studio, M5 Ultra), a no-regression row for a service announced once, as this board's firmware does. One
boot each with and without this change (fbfeb11), through the 27.2 firmware, read-only root, the usual J775D
command line plus the test boot's watchdog dead-man.

  • Base: integration/aurora 24dc422 plus soc: apple: aop: take the setup-port boot only with a "setup" mailbox #2556 and a J775D device-tree change of ours (below). Without them this
    board's AOP doesn't come up on integration, so no announcement would reach the changed code.
  • Both boots: the AOP binds and announces its audio service, which gets one child (audio.0.auto on the AOP's
    audio node) with its driver bound, and no dropped-message lines. The same sound card (AppleJ775D, the same 17
    controls, headphone and headset jacks), and the same co-processors (SMC, NVMe, both DCPs, both AVD decoders).
  • Failed units: 2 on both, the same two. iwd fails because integration's defconfig lacks the kernel crypto options it
    needs (CRYPTO_USER_API_HASH, CRYPTO_USER_API_SKCIPHER, KEY_DH_OPERATIONS). systemd-networkd-persistent-storage
    fails because the test boots mount the root read-only. The Hyprland session doesn't start on either: integration
    has no J775D GPU node yet.
  • Kernel errors at err level and above: the same 4 lines on both. No WARNING, BUG or Oops on either. ALARM has no
    SELinux, so there is no AVC count.
The J775D device-tree change in the row's base (4c1e148e352f, not posted)

This board's AOP firmware never services the setup port, so the row gives the AOP its RTKit mailbox alone. It
overrides two properties, and with #2556 the driver then takes the boot without the setup port. How the Studio's AOP
should be described is still being discussed, so it isn't part of this PR.

--- a/arch/arm64/boot/dts/apple/t6050-j775d.dts
+++ b/arch/arm64/boot/dts/apple/t6050-j775d.dts
@@ -55,6 +55,16 @@ &sound {
 	model = "Mac Studio J775D";
 };
 
+/*
+ * This board's AOP firmware boots over its RTKit mailbox alone and never services the setup
+ * port: started through both, it sends nothing on the setup port and leaves the AP's message
+ * there unread. The AOP gets only its RTKit mailbox, and the setup mailbox stays disabled.
+ */
+&aop {
+	mboxes = <&aop_mbox>;
+	mbox-names = "mbox";
+};
+
Builds, host tests, KUnit totals, checkpatch, other open PRs

Still to run

  • Rows from other AOP Macs (M1-M4 and the M5 laptops, whose AOPs announce more services): the AOP's child devices
    and their drivers with and without this change, and dmesg | grep "dropped a message". A firmware that announced
    one service name on two channels would now log a dropped message naming the service and the second channel,
    instead of getting a second device.
  • For the T8140 owners: does the AOP announce its services again after waking from system sleep (the endpoint start in
    sleep_undo())? If it does, the code before this change added children on every resume, and with it the repeats
    are ignored.

Assisted-by: LLM (Claude:Opus 5.5)

…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)

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