Repository navigation
Conversation
…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>
Contributor
|
The change looks right to me.
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
left a comment
Contributor
There was a problem hiding this comment.
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_SIZEandaddr = ALIGN_DOWN(addr, pgsize) + pgsizematchesdcp_check_iova_contiguous()indrivers/gpu/drm/apple/dcp.cand 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_RTKITdepends onAPPLE_MAILBOX, which requiresARCH_APPLE || (64BIT && COMPILE_TEST), sodma_addr_tis 64-bit; with 44-bitiova(GENMASK_ULL(43, 0)) and max ~1 MiBsize(GENMASK_ULL(51, 44) << 12), neitheriova + sizenorALIGN_DOWN(addr, pgsize) + pgsizecan 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 beforememremap(..., MEMREMAP_WB)would be valuable.
- Moving
- Host test:
tools/asahi/rtkit-crashlog-map-tests.pycompilesapple_rtkit_crashlog_phys()andapple_rtkit_crashlog_map()unchanged under ASan/UBSan, verifies aligned/unaligned/non-contiguous/unmapped cases at both 16 KiB and 4 KiB IOMMU page sizes, checksmemremap()bounds, and confirms--old-ref cacf35543b4dfails.
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-byonly 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 onintegration/aurora(such as T8140, whered9b438c4ca41introducedapple_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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
apple_rtkit_crashlog_map()checks that the IOMMU translates a crash log buffer the co-processor placed to onecontiguous physical range before it maps the buffer. The walk steps by
PAGE_SIZEfrom the buffer's address, whichneed 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 theplaced-buffer checks in
iomfb_m4.c,iomfb_v14_7.candiomfb_v26_6.c. Each covers every page from an unalignedstart.
apple_rtkit_crashlog_map()stepped byPAGE_SIZEfrom 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()'swalk, 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 owncrash log buffer gets the same check. Clients that set buffers up through
shmem_setupare not affected. One sharedhelper for all five walks, next to
apple_dart_fw_remote(), could follow separately, together with thememory-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/applealready 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_setupcallback; on T6050 the AOP is one. It is shared RTKit code with no chip selection.Testing
tools/asahi/rtkit-crashlog-map-tests.py(registered inrun-host-tests.py). It compiles the twofunctions from
rtkit.cunchanged, against a stand-in IOMMU, under ASan and UBSan. Aligned and unaligned buffers oncontiguous 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-refrun requires the code before this change to fail, and it does:that code maps such a buffer.
run-host-tests.pyin the build VM: 451 of 451 pass on the base, 453 of 453 with this change (the new test andits
--old-refrun are the 2 added).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.
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.
as the J775D kernel; no warning in
rtkit.c.Still to run
Assisted-by: LLM (Claude:Opus 5.5)