Skip to content

soc: apple: rtkit: map a placed crash log only over pages its IOMMU translates - #2775

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

funkzy wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
funkzy:pr/rtkit-crashlog-pages

Conversation

@funkzy

@funkzy funkzy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Problem

apple_rtkit_crashlog_map() checks that the IOMMU translates a crash log buffer the co-processor placed to one
contiguous physical range before it maps the buffer. The walk steps by PAGE_SIZE from the buffer's address, which
need not be page aligned. For a buffer that starts inside a page, the page holding its last bytes can go unchecked,
and the mapping can then reach memory the IOMMU does not translate for the buffer.

Why this shape

Four walks in drm/apple check that a firmware-placed buffer is contiguous: dcp_check_iova_contiguous() and the
placed-buffer checks in iomfb_m4.c, iomfb_v14_7.c and iomfb_v26_6.c. Each covers every page from an unaligned
start. apple_rtkit_crashlog_map() stepped by PAGE_SIZE from the buffer's address. The narrower alternative,
refusing a buffer that does not start on a page boundary, would drop crash logs at legitimate addresses: the request's
size is in 4 KiB units, so a buffer may start inside a 16 KiB page. The change uses dcp_check_iova_contiguous()'s
walk, with the IOMMU's smallest page size. It cannot call that function, because RTKit also resolves mappings the
firmware kept from the bootloader (apple_rtkit_crashlog_phys()). Every RTKit client whose firmware places its own
crash log buffer gets the same check. Clients that set buffers up through shmem_setup are not affected. One shared
helper for all five walks, next to apple_dart_fw_remote(), could follow separately, together with the
memory-type check the DCP's paths make (dcp_fw_phys_in_dram(), region_intersects()).

Change

The walk steps from page to page, using the IOMMU's smallest page size, as dcp_check_iova_contiguous() in drm/apple
already does. Every page the buffer touches is checked. Page-aligned buffers are checked as before. One function in
drivers/soc/apple/rtkit.c, plus a host test.

The function runs for a crash reported by firmware that leaves the crashlog endpoint out of its map, on a client
without a shmem_setup callback; on T6050 the AOP is one. It is shared RTKit code with no chip selection.

Testing

  • New host test tools/asahi/rtkit-crashlog-map-tests.py (registered in run-host-tests.py). It compiles the two
    functions from rtkit.c unchanged, against a stand-in IOMMU, under ASan and UBSan. Aligned and unaligned buffers on
    contiguous pages are mapped; buffers that reach a page mapped elsewhere or not at all are refused, with 16 KiB and
    4 KiB as the smallest IOMMU page. Its --old-ref run requires the code before this change to fail, and it does:
    that code maps such a buffer.
  • 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, plus one USB
    enumeration retry of the KVM's keyboard receiver, which appears on 9 of our last 80 boots, with and without this
    change. ALARM has
    no SELinux, so there is no AVC count.
  • 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 endpoint 7,
    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 the USB enumeration retry above 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.

Still to run

  • The crash path itself needs a co-processor crash and isn't exercised on hardware.
  • Rows from other Macs are welcome; the change is the same on every SoC.

Assisted-by: LLM (Claude:Opus 5.5)

…ranslates

apple_rtkit_crashlog_map() checks that the IOMMU translates a crash log
buffer the co-processor placed to one contiguous physical range before
it maps the buffer. It steps by PAGE_SIZE from the buffer's address,
which need not be page aligned. For a buffer that starts inside a page,
the page holding its last bytes can then go unchecked, and the mapping
can extend into memory the IOMMU does not translate for the buffer.

Step from page to page instead, as dcp_check_iova_contiguous() in
drm/apple does, using the IOMMU's smallest page size, so that every page
the buffer touches is checked. Page-aligned buffers are checked as
before.

The function runs for a crash reported by firmware that leaves the
crashlog endpoint out of its map, on a client without a shmem_setup
callback; on T6050 the AOP is one. The new host test,
tools/asahi/rtkit-crashlog-map-tests.py, maps aligned and unaligned
buffers on contiguous pages and refuses buffers that reach a page
mapped elsewhere or not at all. The code before this change maps the
latter.

Fixes: d9b438c ("arm64: apple: support coordinated suspend-to-RAM on T8140")
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 looks right to me.

  • drivers/soc/apple/rtkit.c:984-990: the walk now covers every IOMMU page the range touches, and the phys + (addr - iova) comparison holds for both translation sources, since iommu_iova_to_phys() and apple_dart_fw_leaf_decode() (apple-dart.c:1165) both keep the in-page offset. With a 44-bit IOVA and at most 255 4 KiB units of size, iova + size can't wrap.
  • rtkit.c:1091-1093: the function only runs for a client whose endpoint map leaves out the crashlog endpoint and that has no shmem_setup. DCP, SMC, ANS and the GPU on M1 to M4 never take this path, so they are unaffected. When the check refuses a buffer, the crash is still reported and ops->crashed still runs. Only the log is lost, which is the right trade.
  • The missing memory-type check before memremap(MEMREMAP_WB) was already there before this change, and the description lists it as a follow-up. Fine to leave it out of this PR.

A T8140 row would be useful, since that AOP leaves out the crashlog endpoint: AOP probe and an s2idle cycle at this head, with no new err-level lines. The crash path itself can't be shown without a co-processor crash, and the host test covers it.

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

Code Audit

  • drivers/soc/apple/rtkit.c (apple_rtkit_crashlog_map()):
    • Moving if (!phys) return -ENOENT; ahead of the walk is cleaner than the prior loop guard.
    • Stepping page-by-page via pgsize = domain->pgsize_bitmap ? 1UL << __ffs(domain->pgsize_bitmap) : PAGE_SIZE and addr = ALIGN_DOWN(addr, pgsize) + pgsize matches dcp_check_iova_contiguous() in drivers/gpu/drm/apple/dcp.c and closes the off-by-last-page gap for unaligned crash log buffers (e.g. 4 KiB-granular buffers crossing a 16 KiB IOMMU page boundary).
    • Overflow safety verified: APPLE_RTKIT depends on APPLE_MAILBOX, which requires ARCH_APPLE || (64BIT && COMPILE_TEST), so dma_addr_t is 64-bit; with 44-bit iova (GENMASK_ULL(43, 0)) and max ~1 MiB size (GENMASK_ULL(51, 44) << 12), neither iova + size nor ALIGN_DOWN(addr, pgsize) + pgsize can overflow.
    • Non-blocking note: as the PR body notes, a follow-up sharing one helper with dcp_check_iova_contiguous() and verifying the resolved physical range is DRAM before memremap(..., MEMREMAP_WB) would be valuable.
  • Host test: tools/asahi/rtkit-crashlog-map-tests.py compiles apple_rtkit_crashlog_phys() and apple_rtkit_crashlog_map() unchanged under ASan/UBSan, verifies aligned/unaligned/non-contiguous/unmapped cases at both 16 KiB and 4 KiB IOMMU page sizes, checks memremap() bounds, and confirms --old-ref cacf35543b4d fails.

Pre-PR Checklist (§1–§6)

  • §1 No model gating: Pass — shared RTKit code using domain->pgsize_bitmap, no chip/board/firmware gates.
  • §2 Production-ready: Pass — default command line, no hacks.
  • §3 Safety: Pass — derives step granularity from the IOMMU domain rather than hardcoding.
  • §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 regression row. The crash path itself is thoroughly covered by the ASan/UBSan host test (and isn't expected to be triggered via a live crash in routine boots), and the stock-base J775D A/B row passes without new errors, but J775D does not bring up AOP on stock integration/aurora (and reports 2 failed units on ALARM/RO-root with no SELinux). A clean regression row on a Mac where AOP boots on integration/aurora (such as T8140, where d9b438c4ca41 introduced apple_rtkit_crashlog_map(), with 0 failed units / 0 SELinux denials where applicable) would complete §5.
  • §6 Naming: Pass.

Zero code, policy, or CI blockers — holding as COMMENT only for a stock-base regression row on an affected Mac where AOP boots on integration/aurora.

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