Repository navigation
soc: apple: pmp: fix IovaTableEntry layout and validate pio-ranges bounds - #4863
Conversation
IovaTableEntry is DMA-shared with PMP firmware and implements AsBytes/FromBytes, but lacked #[repr(C)], allowing Rust to reorder fields. In get_iova_table(), apple,pio-ranges was also parsed without checking for odd element counts, more than 170 entries, zero/oversized/ wrapping PIO ranges, or a NULL IOMMU domain, and failed iommu_map() calls leaked earlier mappings. Mark IovaTableEntry #[repr(C)] with a compile-time size/alignment assertion and explicit SAFETY comments, validate PIO range counts and per-entry bounds via pmp_alloc helpers (with unit tests in pmp_alloc.rs), guard against a NULL IOMMU domain, and roll back prior iommu_map() entries on failure. Signed-off-by: Stepan Gulyaev <stepanoid2005@users.noreply.github.com>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
Reviewed 2b604973a192 (code-only; apple,pio-ranges hardware path untested here):
IovaTableEntrynow carries#[repr(C)]with compile-timesize_of == 24 && align_of == 8assertions matching theAsBytes/FromBytesinvariants.pmp_alloc::iova_table_entries()rejects odd element counts and entries exceedingIOVA_TABLE_MAX_ENTRIES(170),pio_entry_next_base()rejects zero/oversized (> PIO_GRANULARITY) and overflowing ranges, NULLiommu_get_domain_for_dev()returnsENODEV, and both validation andiommu_map()error paths cleanly unmap prior&table[..i]mappings.- Unit tests in
drivers/soc/apple/pmp_alloc.rscover the boundary cases cleanly.
RyanTheTide
left a comment
There was a problem hiding this comment.
Ran all seven exact allocation helper tests and checked the mapping failure exits. Both roll back entries already mapped. The current T600x DT ranges fit the entry and slot bounds. The J713 hardware report covers the path without PIO ranges.
There was a problem hiding this comment.
Verdict: MERGE at 2b60497
Checked: The table layout fixes field order, size, and alignment. Error cleanup walks only successfully mapped entries. All seven exact PMP allocation tests passed and the shipped T6000/T6001/T6002 entries meet the new count and size limits.
Follow-ups: The contributor reports a clean J713 boot on the combined candidate. That DT leaves the PIO property absent, so live PIO mapping remains open.
|
Verified exact merge-tree against
Triple-approved ( |
What: Fix wire-ABI layout and
apple,pio-rangesbounds handling indrivers/soc/apple/pmp.rsanddrivers/soc/apple/pmp_alloc.rs: markIovaTableEntry#[repr(C)]with compile-time size/alignment assertions andAsBytes/FromBytessafety documentation, validateapple,pio-rangescount/sizes/overflow viapmp_allochelpers with unit tests, check for a NULL IOMMU domain, and unmap prioriommu_map()entries on partial failure.Tested: J713 (MacBook Air 13" M4, T8132) at
2b604973a192(default kernel command line withuser4k=on, candidate7.3.0-j713-20261206+containing2b604973a192unchanged onupstream/main9d46508f02b6): boots with 10/10 CPUs online, 0 failed units, 0 PMP errors;apple_pmp,apple_pmp_thermal, andapple_pmp_powerbind cleanly (PMP firmware and endpoint ready,J713 PMP vote bridge ready; retained existing PMP owner,pmp_sum_w=0.080 Wmedian,pmp_hotspot_c=50.0 Cmedian);tools/asahi/run-host-tests.py --only pmp-alloc1/1 PASS and--only pmp24/24 PASS.Risk: two-way door · Apple Silicon Macs using
apple_pmp(M1 Pro/Max/Ultra,M2–M5,Neo);apple,pio-rangesvalidation applies onT6000/T6001/T6002(M1 Pro/Max/Ultra) where that DT property is present, while boards withoutapple,pio-rangeskeep the unchanged empty-table path.Not yet: Hardware boot on
T6000/T6001/T6002(M1 Pro/Max/Ultra) exercisingapple,pio-rangesmapping at runtime (J713 DT omitsapple,pio-ranges).Details
IovaTableEntry: adds#[repr(C)]plus compile-timesize_of == 24/align_of == 8assertions so DMA-coherent table entries match the firmware wire layout and satisfyAsBytes/FromBytesinvariants.apple,pio-ranges: validates even element count and<= 170entry limit, rejects zero/oversized (> PIO_GRANULARITY) or wrapping ranges via pure helpers indrivers/soc/apple/pmp_alloc.rs(covered by host unit tests), guards against a NULLiommu_get_domain_for_dev()return, and rolls back earlieriommu_map()calls viaiommu_unmap()on error.Evidence
2b604973a192onupstream/main(9d46508f02b6).scripts/checkpatch.pl --strict --codespell0 errors / 0 warnings;rustfmt --checkPASS;ARCH=arm64 LLVM=1 CLIPPY=1 drivers/soc/apple/pmp.o0 warnings on touched lines.python3 -I tools/asahi/run-host-tests.py --only pmp-alloc1/1 PASS;--only pmp24/24 PASS.T8132,7.3.0-j713-20261206+):apple_pmp,apple_pmp_thermal, andapple_pmp_power(hwmon0/hwmon8) active withpmp_sum_w=0.080 Wmedian andpmp_hotspot_c=50.0 Cmedian,0PMP errors,10/10CPUs online,0failed units.