Repository navigation
Conversation
|
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
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)
|
Not on integration/aurora yet: on daa9e2d apple_rtkit_crashlog_map() still steps by PAGE_SIZE from the buffer's start. The commit applies cleanly on daa9e2d and its host tests pass there (run-host-tests.py --only rtkit-crashlog, 10/10, including the --old-ref run). Both reviews found no code issue; the one thing still open is the regression row on a Mac whose AOP comes up on integration/aurora (the A18 Pro: AOP probe and an s2idle cycle at this head with no new error lines). |
…ps it Several drivers map for the CPU a buffer that a co-processor's firmware names by its DVA, and each resolves it through the IOMMU by hand first: RTKit's crash log, the DCP's walks in drm/apple (dcp.c, iomfb_m4.c, iomfb_v14_7.c, iomfb_v26_6.c, afk.c), aop.rs, ave-fw.c and the ANE firmware loader. They differ in the stride (the IOMMU's smallest page, a fixed 16 KiB, or the CPU's page), in which mappings count (Linux's, those the firmware kept from the boot loader, or both) and in what the target may be (DRAM, a DT memory-region, or anything). Separate from the walk, dcp_fw_phys_in_dram() in drivers/gpu/drm/apple/dcp-internal.h (used by afk.c and dcp.c) carries its own copy of the "registers sit below the first System RAM" check. Add apple_dart_fw_range(). It resolves every IOMMU page the buffer touches, at the domain's smallest page and from page boundary to page boundary, through the mappings the caller names (APPLE_DART_FW_LINUX on a paging domain so identity domains never treat an unmapped DVA as a translation or shadow retained mappings, and APPLE_DART_FW_RETAINED). It returns the range's start only when the pages are contiguous and the CPU-page-rounded range is DRAM outside System RAM: at or above the first System RAM, as every device's registers on these SoCs sit below it, and not memory the kernel allocates from, which its linear map also covers with other attributes. A firmware carveout passes. A stub returns -ENODEV when the driver isn't reachable. RTKit's crash log is the first user. Converting the other walks and dcp_fw_phys_in_dram() is left to their owners. Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
…DRAM apple_rtkit_crashlog_map() maps a crash log buffer the co-processor placed at its own address. It stepped by PAGE_SIZE from the buffer's address, which need not be page aligned, so the page holding its last bytes could go unchecked. It mapped whatever physical range the IOMMU named, without checking what memory that is. And it mapped it cacheable, although the co-processor's writes need not be coherent with the CPU's caches (the T6050 AOP's node isn't dma-coherent), while apple_rtkit_crashlog_late() polls the buffer, with no cache maintenance for a placed buffer, for a log written after the request. Take the range from apple_dart_fw_range(), through Linux's mappings and those the firmware kept, and map it write-combined. Whether such a buffer is mapped also had three answers, by how the firmware asked: a client flag kept it unmapped, a request on an announced crashlog endpoint was refused, and the crash report on an endpoint the firmware left out of its map was mapped, flag or not. apple_rtkit_maps_placed_crashlog() is now the one rule for both paths: unmapped when the client says the firmware owns the buffer, set up by the client when it has shmem_setup, and otherwise mapped through the checks above. A request on an announced endpoint from a client with neither is now mapped and acknowledged rather than refused. The host test tools/asahi/rtkit-crashlog-map-tests.py builds the functions unchanged against a 4 KiB-granular stand-in IOMMU and resource map. Aligned and unaligned buffers on contiguous pages, through either kind of mapping, are mapped write-combined; buffers that reach a page mapped elsewhere or not at all (at 16 KiB or 4 KiB stride), reach System RAM (including a carveout strictly past RAM sharing a 16 KiB CPU page with it), lie on registers, or run on an identity domain are refused. Routing via apple_rtkit_maps_placed_crashlog() is checked too. The code before this change fails the test. 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>
831aa36 to
8301fc4
Compare
|
Thanks, Ryan and dj.
Assisted-by: LLM (Gemini:Neon) |
…parse In Aura's RTKit driver, a placed buffer request carrying an IOP DVA (syslog, crash log, ioreport) was translated only at its first page via dart_translate(), leaving later 16 KiB DART pages unchecked for contiguity or validity. Meanwhile, rtkit_handle_oslog_request() and dart_search_range() each carried separate multi-page contiguity loops, and dart_translate_internal() printed TTBR/L1 errors even when called silently. Separately, rtkit_crashed() walked crash-log entries without checking crashlog_bfr.sz, allowing zero-length entries to loop, oversized lengths to read past the buffer, odd lengths to create unaligned struct pointers, and unterminated Cstr payloads to read past the entry. Honor the silent flag on dart_translate_internal()'s TTBR/L1 error paths, and add dart_translate_range() in src/dart.c using dart_translate_silent() to validate every 16 KiB DART page from iova through iova + size - 1 (with NULL-dart, zero-size, IOVA-wrap, 256 GiB window-crossing, and one-past-end pointer-wrap guards, while preserving high window tag bits used by callers such as Gen3 vm_base and display segment remaps). Reuse dart_translate_range() across rtkit_handle_buffer_request(), rtkit_handle_oslog_request(), and dart_search_range(). Refuse zero-size placed buffer requests on DART paths and only populate the buffer struct on success. Bound every header, entry, and Cstr read in rtkit_crashed() against crashlog_bfr.sz using memcpy() into aligned locals, strnlen(), and an INT_MAX precision cap. Add a host test (tests/run-rtkit-placed-buffer.sh, compiled with ASan and UBSan against the extracted production functions, including 4-TTBR 256 GiB boundary crossing, bit-40-tagged IOVAs, 1-TTBR silent crossing, and pointer wrap) and run it in CI. Linux's RTKit maps the crash log the same way and gets the equivalent check in aurora-silicon/linux#2775. Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Re-review of 8301fc463c47f39d2f29d3b062bf8e1c76466a0c against pre-pr-checklist.md (§1–§6) following the apple_dart_fw_range() redesign (CI: 8/8 checks green — host-tests, kunit ×2, source, rust-build, DWC3/ATC ×3; MERGEABLE / CLEAN, non-draft).
Confirmed clean
- Design & §1–§3: Moving the IOMMU-granularity contiguity walk into shared
apple_dart_fw_range()(with__IOMMU_DOMAIN_PAGINGguardingAPPLE_DART_FW_LINUXagainst identity domains,APPLE_DART_FW_RETAINEDviaapple_dart_fw_remote(), CPU-page-roundedapple_dart_fw_phys_shareable()checking DRAM outside System RAM, andMEMREMAP_WCinapple_rtkit_crashlog_map()) is a strong architectural upgrade with no chip gating and thorough ASan/UBSan host-test coverage (tools/asahi/rtkit-crashlog-map-tests.py, including--old-ref cacf35543b4d). - §4 & §6: Both commits (
e15fd8252721,8301fc463c47) carry human author/committer and humanSigned-off-by:only, zero AI trailers in commits, PR body disclosesAssisted-by:, naming clean.
Blockers before approval
- Code bug —
drivers/soc/apple/rtkit.c:615-683(apple_rtkit_common_rx_get_buffer()): On the newly added announced-endpoint placed-crashlog path (ep == APPLE_RTKIT_EP_CRASHLOG && request.iova && apple_rtkit_maps_placed_crashlog(rtk)), the first request callsapple_rtkit_crashlog_map()(settingbuffer->is_mapped = true,rtk->crashlog_placed = true) and sends the ACK. However, if firmware re-sends the sameGET_BUFFERrequest whilebuffer->size != 0, line 615 jumps togoto reply;, where theelse ifbranch (apple_rtkit_coproc_places_buffers(rtk) || (apple_rtkit_firmware_owns_crashlog(rtk) && ep == APPLE_RTKIT_EP_CRASHLOG)) does not matchrtk->crashlog_placed, silently dropping the ACK for clients withoutAPPLE_RTKIT_COPROC_PLACES_BUFFERS. Add(rtk->crashlog_placed && ep == APPLE_RTKIT_EP_CRASHLOG)to thereply:ACK condition so re-sent requests behave consistently with the first request and withAPPLE_RTKIT_FIRMWARE_OWNED_CRASHLOG. - §5 Evidence — missing affected-hardware regression row: The PR now introduces a new exported DART helper (
apple_dart_fw_range()), switches crashlog mappings toMEMREMAP_WC, and adds the announced-endpoint placed-crashlog path, yet the only hardware row at8301fc463c47is J775D wheret6050-aopis not bound on stockintegration/aurora(ALARM/RO-root, no SELinux, 2 failed units). The stock-base T8140 (J700) row (AOP probe exercising retained DART mappings +s2idlecycle, 0 new kernel errors, failed units / SELinux AVC counts) requested by both reviewers and noted as pending is still required before merge.
Assisted-by: LLM (Gemini 4 Neon)
|
Thanks for the re-review, @DjDeveloperr. On Blocker 1 (
Keeping Blocker 2 (the stock-base T8140 / J700 row exercising AOP retained DART mappings + Assisted-by: LLM (Claude:Opus 5.5), LLM (Gemini:Neon) |
Change of approach
The earlier version fixed the page walk inside
apple_rtkit_crashlog_map(): it stepped byPAGE_SIZEfrom anunaligned address and now stepped from page to page, as
dcp_check_iova_contiguous()does. That made the walkright, but as one more hand-written copy of it, and the function still mapped whatever physical range the IOMMU
named, cacheable. The cause is that no shared check exists for "does this firmware-named DVA range map to memory
the CPU may map". This version adds that check to the DART driver,
apple_dart_fw_range(), and RTKit's crash loguses it, mapped write-combined. It also gives RTKit one rule for when a placed crash log is mapped.
Problem
apple_rtkit_crashlog_map()maps a crash log buffer that a co-processor placed at its own address.PAGE_SIZEfrom the buffer's address, which need not be page aligned, so the page holding its lastbytes could go unchecked and the mapping could reach memory the IOMMU doesn't translate for the buffer.
name registers or memory the kernel allocates from, and on an identity domain
iommu_iova_to_phys()returns theDVA verbatim.
MEMREMAP_WB). The co-processor's writes need not be coherent with the CPU's caches (theT6050 AOP's node isn't
dma-coherent), andapple_rtkit_crashlog_late()polls the buffer, with no cachemaintenance for a placed buffer, for a log written after the request, so it could keep reading a stale header.
APPLE_RTKIT_FIRMWARE_OWNED_CRASHLOGkept it unmapped, a request on an announced crashlog endpoint was refused, and the crash report on an endpoint the
firmware left out of its map was mapped, flag or not.
Why this shape
The question "does this firmware-named DVA range map to one physical range the CPU may map" was answered by hand in
about a dozen places: this function;
dcp_check_iova_contiguous()and the placed-buffer walks iniomfb_m4.c,iomfb_v14_7.candiomfb_v26_6.c;afk.c's remote-buffer copy;aop.rs,ave-fw.cand the ANE firmwareloader; and Aura's RTKit. Separate from the walk,
dcp_fw_phys_in_dram()(drivers/gpu/drm/apple/dcp-internal.h,used by
afk.canddcp.c) carries another copy of the "registers sit below the first System RAM" check. Theydiffer in the stride (the IOMMU's smallest page, a fixed 16 KiB, or the CPU's page), in which mappings count, and
in what the target may be. Fixing only the stride here would leave the memory check and the cache attribute wrong
and add one more copy. The DART driver already resolves the firmware's kept mappings (
apple_dart_fw_remote()), sothe one check goes there:
apple_dart_fw_range()walks every IOMMU page at the domain's smallest page, through themappings the caller names (
APPLE_DART_FW_LINUXon paging domains only so identity domains never treat an unmappedDVA as mapped, and
APPLE_DART_FW_RETAINED), and returns a range only when it iscontiguous DRAM whose CPU-page-rounded span lies outside System RAM. RTKit's crash log is its first user. The other
walks and
dcp_fw_phys_in_dram()are named under Still to run as conversions for their owners, offered rather thanmade here.
Change
apple_dart_fw_range(dev, iova, size, flags, &phys)inapple-dart.c, next toapple_dart_fw_remote(), with astub when the driver isn't reachable.
APPLE_DART_FW_LINUXresolves through Linux's mappings when the domain isa paging domain (
__IOMMU_DOMAIN_PAGING), andAPPLE_DART_FW_RETAINEDthrough those the firmware kept. A rangepasses when every page translates at the same offset as its first byte and the CPU-page-rounded span is DRAM
outside System RAM: at or above the first System RAM (every device's registers on these SoCs sit below it), and
not memory the kernel allocates from, which its linear map also covers. A firmware carveout passes. Unlike
afk.c's check, a no-map reserved-memory region passes too: the kernel neither uses nor maps it.apple_rtkit_crashlog_map()takes the range from it, through both kinds of mapping, and maps it write-combined.apple_rtkit_maps_placed_crashlog()is the one rule for both paths: unmapped when the client says the firmwareowns the buffer, set up by the client when it has
shmem_setup, otherwise mapped through the check above. Arequest on an announced crashlog endpoint from a client with neither is now mapped and acknowledged rather than
refused. None in this row triggers that branch: the base logs
no refused crashlog request, and
t6050-aopis not bound on this stock kit.e15fd8252721,8301fc463c47): the helper, then RTKit's use of it. Shared code with no chipselection.
Testing
tools/asahi/rtkit-crashlog-map-tests.py(registered inrun-host-tests.py). It buildsapple_rtkit_crashlog_map(),apple_rtkit_maps_placed_crashlog()andapple_dart_fw_range()with its twohelpers unchanged, under ASan and UBSan, against a 4 KiB-granular stand-in IOMMU and resource map. Aligned and
unaligned buffers on contiguous pages, through Linux's paging mappings or the firmware's kept mappings, are
mapped write-combined. Buffers that reach a page mapped elsewhere or not at all (including a last byte on byte 0
of a bad page, and a 4 KiB subpage discontinuity inside a 16 KiB block), reach System RAM (including a 4 KiB
carveout strictly past System RAM sharing a 16 KiB CPU page with it), lie on registers, or run on an identity
domain are refused. Routing via
apple_rtkit_maps_placed_crashlog()is checked too. Its--old-refrun requires the base to fail, and it does.
run-host-tests.pyin the build VM (integration/aurora377060f3688a): 463 of 463 pass on the base, 465 of465 with this change (only the 2 new
rtkit-crashlog-map-testsruns differ). KUnit, built in (kitspr2775-r5kvs
pr2775-r5bkon377060f3688a): 77 suites, 385 of 387 cases pass, 0 fail, 2 skip, identical to the base.pr2775-r5(windowr2775r5@20261123-0837, auraaura-main-59b8b977:integration/aurora377060f3688aplus both commits of this PR at8301fc463c47) against kitpr2775-r5b(window
r2775r5@20261123-0837, auraaura-main-59b8b977: the same base alone). One boot each through thedefault 27.0 firmware stub and published Aura main
59b8b977, default kernel command line, read-only root(ALARM has no SELinux). Both arms boot to SSH with 0 WARNING/BUG/Oops, the same bound co-processors (
macsmc,nvme-apple, bothapple-dcpinstances, bothavdinstances,apple-display-crossbar;t6050-aopis notbound on this stock base), 4 err-level kernel lines (0 new vs base), and the same 2 failed units on both
(
iwd.servicemissing kernel crypto options in integration's defconfig, andsystemd-networkd-persistent-storage.serviceon the read-only root).--strict:0 errors.
Still to run
firmware's kept mappings (the J700 AOP), and any Mac whose co-processor announces its crashlog endpoint with its
own buffer would exercise the rule's announced path.
apple_dart_fw_range(), for their owners:dcp_check_iova_contiguous(),dcp_fw_phys_in_dram()(
dcp-internal.h), and the walks iniomfb_m4.c,iomfb_v14_7.candiomfb_v26_6.c(fixed 16 KiB strides),afk.c's remote copy (CPU-page chunks, kept mappings only),aop.rs,ave-fw.cand the ANE firmware loader.We're glad to send them if wanted.
separate Aura PR fixes it.
Assisted-by: LLM (Claude:Opus 5.5), LLM (Gemini:Neon)