Skip to content

soc: apple: rtkit: allocate endpoint 7 buffers only for clients that ask for them - #2776

Open
funkzy wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
funkzy:pr/rtkit-ca-endpoint
Open

funkzy wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
funkzy:pr/rtkit-ca-endpoint

Conversation

@funkzy

@funkzy funkzy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The endpoint map starts endpoint 7 only for clients that set APPLE_RTKIT_NEEDS_COREANALYTICS and for registry-v2
PMP firmware. apple_rtkit_rx_dispatch() still hands every other endpoint-7 message to
apple_rtkit_coreanalytics_rx(), so a buffer request from any co-processor is allocated, zeroed and kept until the
session is torn down, at whatever size the request names (up to 255 MiB). Nothing on the host reads that buffer for
those clients.

Why this shape

Whether endpoint 7 is in use was decided twice. The endpoint map starts it only for registry-v2 PMP firmware and for
clients that set APPLE_RTKIT_NEEDS_COREANALYTICS. The dispatcher served it for every client. A narrower alternative,
capping the size of a CoreAnalytics request, would bound each buffer, but it would still allocate for clients that
never asked, and it needs a size the hardware does not provide. The change makes both places use one predicate,
apple_rtkit_ep7_served(), so the dispatcher serves the endpoint exactly when the endpoint map starts it. A message
on it otherwise is reported like one to any unknown endpoint, as the debug endpoint already is. The PMP, which asks
for CoreAnalytics, and registry-v2 PMP firmware are handled as before. Every other RTKit client (DCP, SMC, ANS, AOP,
the GPU and the rest) no longer allocates anything for endpoint 7. The predicate is the client's declared need, not "was
the endpoint started": a session taken over from an earlier owner (apple_rtkit_mark_running()) records no started
endpoints. Which system endpoints a session runs is kept in three lists (the start loop, the dispatcher and
apple_rtkit_mark_running()); one per-endpoint table could replace them, and can follow separately.

Change

The endpoint is served only for the clients the endpoint map starts it for: one predicate,
apple_rtkit_ep7_served(), now decides both. A message there from any other co-processor is reported as one to an
unknown endpoint, as the debug endpoint already is without sync_syslog_ack.
Clients that ask for CoreAnalytics (today the PMP) and the registry-v2 auxiliary buffer are handled as before. It
applies to every RTKit client on every SoC.

A second commit rate-limits what the receive path prints about firmware messages, so firmware that sends events
periodically cannot flood the log now that unserved endpoint-7 messages are reported. The dispatcher's three
unknown-endpoint warnings (the debug endpoint without sync_syslog_ack, endpoint 7 when it isn't served, and any
other endpoint) share one helper, apple_rtkit_unserved_ep_msg(). That helper, the "Message from undiscovered
endpoint" warning and the per-endpoint warnings for a message the handler doesn't know (management, CoreAnalytics,
crash log, ioreport, syslog, oslog, and an application endpoint with no receiver) use dev_warn_ratelimited(), as
the kdebug and syslog-record warnings already did, and the registry-v2 PMP's "refused auxiliary buffer request"
error uses dev_err_ratelimited(). Only logging changes.

Testing

  • New host test tools/asahi/rtkit-coreanalytics-tests.py (registered in run-host-tests.py). It compiles the
    dispatcher and the CoreAnalytics handlers from rtkit.c unchanged, under ASan and UBSan. A client that asked gets its
    buffer and its acknowledgements; registry-v2 PMP firmware gets its auxiliary buffer; any other client's request
    allocates nothing and gets no reply, at any size. Its --old-ref run requires the code before this change to fail,
    and it does: that code allocates for a client that did not ask.
  • The same test checks that an unserved endpoint-7 message, and a message to a system endpoint nobody serves, go
    through the shared rate-limited warning.
  • The host tests that compile these functions with stand-ins (display-sleep-merge-tests.py, rtkit-oslog-tests.py,
    and the apple-dcp ordered-rx and oslog-events fixtures) get stand-ins for apple_rtkit_ep7_served(), the
    helper or dev_warn_ratelimited(); all pass.
  • run-host-tests.py in the build VM, at this head: 451 of 451 pass on the base, 453 of 453 with this series (the new test and its --old-ref run are the 2
    added). KUnit, built in: 375 of 377 cases pass in 76 suites and 2 skip, the same as the base.
  • J775D (Mac Studio, M5 Ultra): kit rtkit-ca-endpoint-1 (integration/aurora 000ab96 plus both commits of
    this PR, d91a256) against kit rtkit-ca-endpoint-1b (the same base alone), window
    ryan2775a@20261122-1147. One boot each through the 27.0 firmware and Aura main dff1235d, default kernel command
    line, read-only root. Both boot, and the same co-processors come up on both: SMC, NVMe, both DCPs, both AVD
    decoders. Integration doesn't yet bring up the J775D's AOP or GPU.
    • 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), and
      systemd-networkd-persistent-storage because the test boots mount the root read-only.
    • Kernel errors at err level and above: the same 4 lines on both (two from a DCP, two from the KVM's USB
      receiver), 0 new. No WARNING, BUG or Oops. ALARM has no SELinux, so there is no AVC count.
    • No co-processor on the J775D sends on endpoint 7 without asking: no "message to unknown endpoint" line, nor
      "undiscovered endpoint", on either boot.
  • Extra row, not this PR's own: kit trackh-i60 (integration/aurora cacf355 plus the first commit,
    5c41538, only) against kit trackh-ib (that base alone), through the 27.2 firmware with our daily Aura
    build. Both boot with the same co-processors, the same 2 failed units and the same err-level lines.
  • One rear port's DP PHY firmware starts twice during probe on some boots, each time with that port's xHCI added,
    removed and added again: on 6 of 8 boots without the first commit and 1 of 3 with it. Both patterns show with and
    without it, and no boot sees a message on endpoint 7, so this change takes no different path there; it is probe
    order.
  • Extra row, not this PR's own: our daily kit (integration cacf355 plus 34 open or local patches, among them
    drm/asahi: t6050: identify the K114/K116 27.2 (26B8125) G17S firmware (on #1173) #1650 and arm64: dts: apple: t6050-j775d: Give the Mac Studio (M5 Ultra) a working GPU, and its M and P core capacities (754/1024) to the scheduler #1973 for the GPU, and the AOP bring-up) with this change and two other changes of ours (RTKit crash log pages,
    GEM_USERPTR accounting), against the same kit without them. The AOP, the GPU and every other RTKit co-processor
    come up as on that base. Failed units: 1 on both. Kernel errors: the same lines, plus one USB enumeration retry of the KVM's keyboard receiver on the kit
    with the changes. The AOP and GPU lines of this row depend on those carried patches.
  • Builds: on integration/aurora cacf355 with integration's own config (defconfig plus asahi.config), and
    as the J775D kernel; no warning in rtkit.c.
  • checkpatch --strict: no errors.

Still to run

  • A PMP row on a Mac that runs the PMP with CoreAnalytics, to show that path unchanged.
  • Rows from M1-M4 Macs are welcome: a boot with this change and dmesg | grep "unknown endpoint 07", which names
    any co-processor there that uses the endpoint without asking for it.

Assisted-by: LLM (Claude:Opus 5.5)

…ask for them

The endpoint map starts endpoint 7 only for clients that set
APPLE_RTKIT_NEEDS_COREANALYTICS and for registry-v2 PMP firmware, but
apple_rtkit_rx_dispatch() hands every other endpoint-7 message to
apple_rtkit_coreanalytics_rx(). Any co-processor's buffer request is
therefore allocated, zeroed and kept until the session is torn down,
at whatever size the request names (up to 255 MiB), although nothing on
the host reads that buffer for it.

Decide this once: apple_rtkit_ep7_served() is the one predicate the
endpoint map and the dispatcher both use, so the endpoint is served
exactly for the clients it is started for. A message there from any
other co-processor is reported as one to an unknown endpoint, as the
debug endpoint already is without sync_syslog_ack. Clients that ask for
CoreAnalytics, today the PMP, and the registry-v2 auxiliary buffer are
handled as before.

This applies to every RTKit client on every SoC. The new host test,
tools/asahi/rtkit-coreanalytics-tests.py, compiles the dispatcher and
the CoreAnalytics handlers from this file and checks both sides; the
code before this change allocates for a client that did not ask. The
two host tests that compile the dispatcher with stand-ins get one for
apple_rtkit_ep7_served().

Fixes: 2aff1b9 ("soc: apple: rtkit: describe and adopt retained system buffers")
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 change itself is small and the predicate matches what the endpoint map already starts. Notes:

  • drivers/soc/apple/rtkit.c:438 and :1514-1521: which sessions start endpoint 7 doesn't change. Only the dispatcher does. The one client that asks is pmp.rs:993-1001 (T6041 PMP and the retained J713 PMP), plus registry-v2 PMP firmware. pmp_registry_v2 is set at init (rtkit.c:2354) before RX is claimed, so the predicate is stable for the whole session.
  • Adopted sessions: apple_rtkit_mark_running() (rtkit.c:2167) is used for ANS and for the MTP live handoff in rtkit-helper.c:340-347. If the earlier owner had started endpoint 7 there, the old dispatcher answered the firmware's CoreAnalytics buffer request and acknowledged its events, and the new one doesn't answer at all. I don't think any current firmware does this, and the old code would already have logged "Message from undiscovered endpoint 0x07" (rtkit.c:1713) for it. Still, a boot on a Mac with an adopted MTP (M4 Air, A18 Pro) with dmesg | grep -e "endpoint 07" -e "endpoint 0x07", keyboard and trackpad working, would settle it.
  • rtkit.c:1515-1517: the new warning is driven by the firmware and isn't rate-limited. Firmware that sends CoreAnalytics events periodically would now log one warning per event, where it used to be acknowledged silently. dev_warn_ratelimited() (or _once) would be safer here.
  • For the "PMP row" under Still to run: the M4 Air (J713) runs the retained PMP with CoreAnalytics, so a PMP probe there at this head, with the CoreAnalytics buffer and readiness unchanged, is the row that shows the opted-in path still works.

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 5c415384582bc0888c2d1dc443771c9bc7baf831 (CI: 7/7 checks green — host-tests, source, rust-build, kunit, and all three DWC3/ATC builds).

Code Audit

  • drivers/soc/apple/rtkit.c: Unifying the endpoint 7 predicate into apple_rtkit_ep7_served() (rtk->pmp_registry_v2 || apple_rtkit_needs_coreanalytics(rtk)) ensures apple_rtkit_rx_dispatch() serves endpoint 7 strictly for the same clients that apple_rtkit_management_rx_epmap() starts it for, without breaking adopted sessions (apple_rtkit_mark_running()).
  • Verified pmp_ca_event_ack is only ever set when pmp_registry_v2 is true (rtkit.c:2356), so apple_rtkit_pmp_aux_rx() remains reachable for all registry-v2 PMP sessions.
  • Non-blocking note: dev_warn on unserved endpoint 7 matches APPLE_RTKIT_EP_DEBUG and the default: branch right beside it (ratelimiting could be a future hardening follow-up across all three if a co-processor spams unknown endpoints).
  • Host test fixtures: tools/asahi/rtkit-coreanalytics-tests.py compiles the production dispatcher and CoreAnalytics handlers unchanged under ASan/UBSan and catches --old-ref cacf35543b4d; both existing dispatcher fixtures (display-sleep-merge-tests.py and apple-dcp/run.py) are updated and pass CI.

Pre-PR Checklist (§1–§6)

  • §1 No model gating: Pass — no new SoC/board/firmware gates (reuses existing APPLE_RTKIT_NEEDS_COREANALYTICS and pmp_registry_v2).
  • §2 Production-ready: Pass — default command line, no hacks.
  • §3 Safety: Pass — eliminates unrequested up-to-255 MiB kernel allocations from arbitrary co-processors without introducing hardcoded caps.
  • §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 positive-path & multi-generation hardware rows. The stock-base J775D A/B row cleanly proves no regression on non-EP7 clients, but as noted in ## Still to run, we still need:
    1. A PMP hardware row on a Mac running CoreAnalytics / pmp_registry_v2 to prove the served endpoint 7 path is unchanged.
    2. M1–M4 regression row(s) checking dmesg | grep "unknown endpoint 07" to confirm no co-processor there silently relies on endpoint 7 without setting APPLE_RTKIT_NEEDS_COREANALYTICS.
  • §6 Naming: Pass.

Zero code, policy, or CI blockers — holding as COMMENT only for the remaining §5 PMP positive-path and M1–M4 hardware rows.

Assisted-by: LLM (Gemini 4 Neon)

…t flood the log

Since the previous commit, an endpoint-7 message from a co-processor that
did not ask for CoreAnalytics is reported as one to an unknown endpoint
instead of being acknowledged silently. How often such a message arrives
is up to the firmware: one that sends CoreAnalytics events periodically
would log a warning per event.

The same holds for every warning the receive path prints about a
firmware message. The dispatcher printed the unknown-endpoint warning in
three places (the debug endpoint without sync_syslog_ack, endpoint 7
when not served, and any other endpoint); they now share
apple_rtkit_unserved_ep_msg(). That helper, the receive path's "Message
from undiscovered endpoint" warning (printed for the same kind of
message on an adopted session) and the per-endpoint warnings for a
message the handler doesn't know (management, CoreAnalytics, crash log,
ioreport, syslog, oslog, and an application endpoint with no receiver)
all use dev_warn_ratelimited(), as the kdebug and syslog-record warnings
already did, and the registry-v2 PMP's "refused auxiliary buffer
request" error uses dev_err_ratelimited(). Warnings about what the AP
sends, and the endpoint map's one-time report of an unknown system
endpoint, are unchanged.

Only logging changes. rtkit-coreanalytics-tests.py now checks that an
unserved endpoint-7 message, and a message to a system endpoint nobody
serves, go through the shared warning. The host tests that compile
these functions with stand-ins (display-sleep-merge, rtkit-oslog,
apple-dcp ordered-rx and oslog-events) get dev_warn_ratelimited() or a
stand-in for the helper.

Suggested-by: Ryan Murray <ryan@aurorasilicon.org>
Suggested-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
@funkzy

funkzy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, Ryan and dj.

  • Rate limit: added d91a256. The dispatcher printed the unknown-endpoint warning in three places: the debug endpoint without sync_syslog_ack, endpoint 7 when it isn't served, and any other endpoint. As dj suggested, they now share one helper. It, the "Message from undiscovered endpoint" warning (which an adopted session would print for the same message) and the per-endpoint warnings for a message the handler doesn't know (management, CoreAnalytics, crash log, ioreport, syslog, oslog, and an application endpoint with no receiver) use dev_warn_ratelimited(), as Ryan suggested and as the kdebug and syslog-record warnings already did, and the registry-v2 PMP's "refused auxiliary buffer request" error uses dev_err_ratelimited(). _once would be once per call site for the whole kernel rather than per session, so a second co-processor's messages would go unreported. Only logging changes. The host test checks that an unserved endpoint-7 message, and a message to a system endpoint nobody serves, go through the shared warning. At this head: host tests 453 of 453 (451 on the base), KUnit 375 of 377 cases pass in 76 suites with 2 skip, the same as the base.
  • The J775D row now runs this head, d91a256, on current integration/aurora alone, against the same base without it, each boot on published Aura main: both boot with the same co-processors, 0 new err-level lines, and no unknown-endpoint line. Its 2 failed units are the same on both kernels: iwd, because integration's defconfig lacks the kernel crypto options it needs, and systemd-networkd-persistent-storage, because the test boots mount the root read-only. The body says both and keeps the first-commit row as extra evidence.
  • Adopted sessions: agreed, that is the one case where behaviour changes, and the old code already logged "undiscovered endpoint" for it. Ryan, could you boot this head on your J713 (adopted MTP) and check dmesg | grep -e "endpoint 07" -e "endpoint 0x07", with the keyboard and trackpad working?
  • PMP row: on the same J713 boot, a PMP probe with the CoreAnalytics buffer and readiness unchanged would be the positive-path row dj asks for. dj, a boot of this head on your J773g with dmesg | grep "unknown endpoint 07" would cover the M1-M4 check for T8132.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks. Re-checked at d91a256. The first commit is unchanged (same SHA), so this is only about the new one.

  • The rate limit is fixed. apple_rtkit_unserved_ep_msg() (rtkit.c:1488) now covers all three unknown-endpoint arms. The "undiscovered endpoint" line and the per-endpoint "unknown message" warnings are rate-limited too. The format strings are unchanged, so the unknown endpoint 07 grep still works. The AP-side warnings and the epmap's one-time report stay as plain dev_warn, which is right.
  • Minor, not blocking: dev_warn_ratelimited() keeps one state per call site, shared by every RTKit instance. With three arms folded into the helper, one chatty co-processor can hide another's unknown-endpoint lines inside the same window, and the "callbacks suppressed" line names the function, not the device. The first burst always prints, so the boot greps still catch anything. A per-rtk ratelimit_state would close this if it ever matters.
  • Still open (hardware): an M4 Air (J713) boot at this head. That one boot covers both remaining items. First, the PMP probe with the CoreAnalytics buffer and readiness unchanged (the opted-in path). Second, the adopted MTP session with dmesg | grep -e "endpoint 07" -e "endpoint 0x07" and the keyboard and trackpad working. An A18 Pro (J700) boot would add a second adopted-MTP row.

The code looks good to me. Only that row is left.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Not on integration/aurora yet: on daa9e2d the dispatcher still hands every endpoint-7 message to the CoreAnalytics handler. Both commits apply cleanly on daa9e2d, and the host tests that compile this code pass on that tree: run-host-tests.py --only rtkit 17/17 (including rtkit-coreanalytics-tests and its --old-ref run), display-sleep-merge 1/1, and the apple-dcp boot group 4/4. The code review is done on both sides; the remaining item is the M4 Air boot at d91a256 (PMP probe with its CoreAnalytics buffer unchanged, and the adopted MTP session with no "endpoint 07" line and working keyboard and trackpad).

@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 d91a256494420f946d29d53943f11ca9c2f6c9a6 (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 5c415384582b)

  • Runtime commit 5c415384582b is unchanged (apple_rtkit_ep7_served() unifies apple_rtkit_management_rx_epmap() and apple_rtkit_rx_dispatch()).
  • Commit d91a25649442 cleanly consolidates all three unknown-endpoint warnings into apple_rtkit_unserved_ep_msg() with dev_warn_ratelimited(), rate-limits all firmware-triggered receive-path unknown-message / undiscovered-endpoint warnings (dev_warn_ratelimited() / dev_err_ratelimited()) while preserving exact log strings, and updates all four host-test harnesses (rtkit-coreanalytics-tests.py, display-sleep-merge-tests.py, rtkit-oslog-tests.py, and apple-dcp/boot.py + run.py).

Pre-PR Checklist (§1–§6)

  • §1 No model gating: Pass — no new SoC/board/firmware gates (reuses existing APPLE_RTKIT_NEEDS_COREANALYTICS and pmp_registry_v2).
  • §2 Production-ready: Pass — default command line, no hacks.
  • §3 Safety: Pass — eliminates unrequested up-to-255 MiB kernel allocations from arbitrary co-processors without hardcoded caps, and rate-limits firmware-triggered RX warnings against log flooding.
  • §4 Clean-room & attribution: Pass — both commits (5c415384582b, d91a25649442) 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 PMP positive-path and adopted-MTP / M1–M4 hardware rows (§5): The refreshed stock-base J775D A/B row at d91a25649442 cleanly covers non-EP7 co-processors there (SMC, NVMe, DCPs, AVDs), but as noted in ## Still to run we still need before merge:
    • A PMP positive-path row on a Mac running CoreAnalytics / pmp_registry_v2 (e.g., M4 Air J713 PMP probe) proving the opted-in endpoint-7 buffer allocation and readiness path is unchanged.
    • An adopted-MTP and M1–M4 regression row (e.g., J713 / J773g / A18 Pro) checking dmesg | grep -e "endpoint 07" -e "endpoint 0x07", working keyboard/trackpad on adopted MTP, and §5 regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors).

Verdict

REQUEST_CHANGES — zero code, logging, test, or CI blockers (all 7 CI checks green at d91a25649442); holding solely for the remaining §5 PMP positive-path and adopted-MTP / M1–M4 hardware row(s).

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