Skip to content

soc: apple: pmp: fix IovaTableEntry layout and validate pio-ranges bounds - #4863

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
stepanoid2005:fix/pmp-iova-table-layout-and-bounds
Dec 6, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
stepanoid2005:fix/pmp-iova-table-layout-and-bounds

Conversation

@stepanoid2005

Copy link
Copy Markdown
Contributor

What: Fix wire-ABI layout and apple,pio-ranges bounds handling in drivers/soc/apple/pmp.rs and drivers/soc/apple/pmp_alloc.rs: mark IovaTableEntry #[repr(C)] with compile-time size/alignment assertions and AsBytes/FromBytes safety documentation, validate apple,pio-ranges count/sizes/overflow via pmp_alloc helpers with unit tests, check for a NULL IOMMU domain, and unmap prior iommu_map() entries on partial failure.
Tested: J713 (MacBook Air 13" M4, T8132) at 2b604973a192 (default kernel command line with user4k=on, candidate 7.3.0-j713-20261206+ containing 2b604973a192 unchanged on upstream/main 9d46508f02b6): boots with 10/10 CPUs online, 0 failed units, 0 PMP errors; apple_pmp, apple_pmp_thermal, and apple_pmp_power bind cleanly (PMP firmware and endpoint ready, J713 PMP vote bridge ready; retained existing PMP owner, pmp_sum_w=0.080 W median, pmp_hotspot_c=50.0 C median); tools/asahi/run-host-tests.py --only pmp-alloc 1/1 PASS and --only pmp 24/24 PASS.
Risk: two-way door · Apple Silicon Macs using apple_pmp (M1 Pro/Max/Ultra, M2–M5, Neo); apple,pio-ranges validation applies on T6000/T6001/T6002 (M1 Pro/Max/Ultra) where that DT property is present, while boards without apple,pio-ranges keep the unchanged empty-table path.
Not yet: Hardware boot on T6000/T6001/T6002 (M1 Pro/Max/Ultra) exercising apple,pio-ranges mapping at runtime (J713 DT omits apple,pio-ranges).

Details
  • IovaTableEntry: adds #[repr(C)] plus compile-time size_of == 24 / align_of == 8 assertions so DMA-coherent table entries match the firmware wire layout and satisfy AsBytes/FromBytes invariants.
  • apple,pio-ranges: validates even element count and <= 170 entry limit, rejects zero/oversized (> PIO_GRANULARITY) or wrapping ranges via pure helpers in drivers/soc/apple/pmp_alloc.rs (covered by host unit tests), guards against a NULL iommu_get_domain_for_dev() return, and rolls back earlier iommu_map() calls via iommu_unmap() on error.
Evidence
  • Commit: 2b604973a192 on upstream/main (9d46508f02b6).
  • Static/compile checks: scripts/checkpatch.pl --strict --codespell 0 errors / 0 warnings; rustfmt --check PASS; ARCH=arm64 LLVM=1 CLIPPY=1 drivers/soc/apple/pmp.o 0 warnings on touched lines.
  • Host tests: python3 -I tools/asahi/run-host-tests.py --only pmp-alloc 1/1 PASS; --only pmp 24/24 PASS.
  • Live J713 (T8132, 7.3.0-j713-20261206+): apple_pmp, apple_pmp_thermal, and apple_pmp_power (hwmon0/hwmon8) active with pmp_sum_w=0.080 W median and pmp_hotspot_c=50.0 C median, 0 PMP errors, 10/10 CPUs online, 0 failed units.

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>
@stepanoid2005
stepanoid2005 requested review from a team as code owners December 6, 2026 15:10
@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 6, 2026
@github-actions

github-actions Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Merge readiness at 2b604973: ready to merge

Check Detail
CI at head ok 6 checks passed
Review ok approved by RyanTheTide, satchlj
Requested changes ok none
Hardware row at head ok the PR body at 2b604973
Conflicts ok none
PR text ok Risk: two-way · Apple Silicon Macs using applepmp (M1 Pro/Max/Ultra, M2–M5, Neo); apple,pio-ranges validation applies on T6000/T6001/T6002 (M1 Pro/Max/Ultra) where that DT property is present, while boards without apple,pio-ranges keep the unchanged empty-table path.

Areas: area:platform
Merge: gh pr merge 4863 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2b604973a192 (code-only; apple,pio-ranges hardware path untested here):

  • IovaTableEntry now carries #[repr(C)] with compile-time size_of == 24 && align_of == 8 assertions matching the AsBytes/FromBytes invariants.
  • pmp_alloc::iova_table_entries() rejects odd element counts and entries exceeding IOVA_TABLE_MAX_ENTRIES (170), pio_entry_next_base() rejects zero/oversized (> PIO_GRANULARITY) and overflowing ranges, NULL iommu_get_domain_for_dev() returns ENODEV, and both validation and iommu_map() error paths cleanly unmap prior &table[..i] mappings.
  • Unit tests in drivers/soc/apple/pmp_alloc.rs cover the boundary cases cleanly.

@RyanTheTide RyanTheTide 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.

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.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 6, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Verified exact merge-tree against origin/main (ca9993483846, post-#4864) locally (Hosted CI override for skipped checks):

  • ./scripts/checkpatch.pl --strict --git 2b604973a192: 0 errors, 0 warnings
  • make ARCH=arm64 LLVM=1 drivers/soc/apple/pmp.o: clean build

Triple-approved (satchlj + RyanTheTide + aurora-silicon-review) and readiness green; merging.

@DjDeveloperr
DjDeveloperr merged commit 077c557 into aurora-silicon:main Dec 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants