Skip to content

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

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

funkzy wants to merge 1 commit 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. One
function in drivers/soc/apple/rtkit.c; it applies to every RTKit client on every SoC.

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 two host tests that compile the dispatcher with stand-ins (display-sleep-merge-tests.py, and the apple-dcp
    ordered-rx fixture) get a stand-in for apple_rtkit_ep7_served(); both pass.
  • run-host-tests.py in the build VM: 451 of 451 pass on the base, 453 of 453 with this change (the new test and
    its --old-ref run are the 2 added).
  • J775D (Mac Studio, M5 Ultra), on integration/aurora cacf355 plus this change only, against the same base
    alone: one boot each through the 27.2 firmware, default kernel command line, read-only root. Both boot. The same
    co-processors come up on both: SMC, NVMe, both DCPs, both AVD decoders. The AOP doesn't start on either (the same
    timeout on the base: integration doesn't yet bring up the J775D's AOP), and integration has no J775D GPU node yet.
    Failed units: 2 on both, the same two. Kernel errors at err level and above: the same lines on both. ALARM has
    no SELinux, so there is no AVC count.
  • 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 this change 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.
  • No co-processor on the J775D sends on endpoint 7 without asking: no "message to unknown endpoint 07" line on
    the boot with this change, nor on the daily-kit boot.
  • 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)

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