Repository navigation
soc: apple: pmp: bound the memory held for the firmware - #2905
Conversation
The PMP firmware asks the driver for DMA buffers (OPC_MALLOC) and for register slots (OPC_REGISTER_IOREG). Every request was granted and kept until the firmware freed it, so the number of buffers held for it, their total size and the register list had no bound. Count the live allocations and their size, and refuse one that would go over 64 buffers or four of the largest buffer a single request can ask for (its size field is 24 bits, so just under 64 MiB). The driver takes the size out of a request with the same constant. These are sanity bounds well above normal use: the driver's lists are sized for ten buffers and 340 registers, which is what a normal boot uses. A freed buffer gives its room back. Refuse a register once the list has 0xffff entries. The reply carries the new entry's index in 16 bits below the opcode, so a larger index cannot be returned without corrupting the reply. A refused request gets no reply and is logged, as other requests the driver cannot handle are. On the board that keeps the display bridge, that also stops display power commands, as any request the driver cannot handle does there. The bounds are in pmp_alloc.rs with host tests, run by tools/asahi/run-host-tests.py as pmp-alloc-tests.rs. Signed-off-by: Ryan Murray <[email protected]>
|
Row for the open question (does a wake register again?): J713 on its production default kernel (fleet81, default cmdline), runtime kprobes on |
|
Review at aa132a2. Follow-up to the #2894 review, PMP part. The code is correct at this head; what is left is rows and two small points. Fixed from #2894:
Still open:
Rows owed at this head (none run): default command line, PMP probe, s2idle x2, with allocation count/bytes and register count after boot and after each wake, on J713, Neo (t8140-j700.dts:501) and J616s (t604x-j614-j616.dtsi:2769 also enables |
There was a problem hiding this comment.
Formal adversarial §1–§6 pre-PR checklist review at aa132a243fcd05c7a738252dc8af0ff06f66a351 (REQUEST_CHANGES — 0 code blockers; pending CI and owed §5 exact-head hardware rows).
Checklist Summary
- §1 (No model gating): Pass — no chip, SoC, board, or firmware-version gates.
- §2 (Production-ready, no hacks): Pass — no new parameters; bounds derive from the wire format (24-bit size mask, 16-bit ioreg reply index) rather than board tables.
- §3 (Safety — integer bounds, locking, rollback): Pass —
MALLOC_SIZE_MASKsharespmp_alloc::MALLOC_SIZE_MAX = 0xff_ffff(pmp.rs:90,pmp_alloc.rs:7).AllocBudget::claim()(pmp_alloc.rs:140-148) checkssize > MALLOC_SIZE_MAX || self.count >= MAX_ALLOCS || size > MAX_ALLOC_BYTES - self.bytes, maintainingself.bytes <= MAX_ALLOC_BYTESwithout overflow, andrelease()usessaturating_sub. InPmpData::malloc()(pmp.rs:324-357),self.state.lock()(sleepableMutex, already held across coherent DMA allocation inget_iova_table()) serializesclaim(),Coherent::<u8>::zeroed_slice(), andallocs.push(), and every error path afterclaim()callsrelease(size).free()(pmp.rs:360-362) releasesfreed.alloc.size() as u64.ioreg_fits()(pmp_alloc.rs:158-160,pmp.rs:397) enforcesregistered < 0xffff, ensuring the pushed 1-based reply index<= 0xffffnever collides withOPC_SHIFT(48). - §4 (Clean-room & attribution): Pass — commit
aa132a243fcdcarries human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:only (zero AI trailers in commits); PR body includesAssisted-by:. - §5 (Evidence): Blocked — see Blockers below.
- §6 (Naming): Pass.
Blockers
- §5 (Owed exact-head hardware rows): While the kprobe measurement on J713
fleet81confirming 0MALLOC/FREE/REGISTER_IOREG/SET_IOREGtraffic across s2idle×2 + deep sleep is valuable supporting evidence, no boot + sleep/wake row has been run at this head (aa132a243fcd) yet. Owed on the default command line: PMP probe +s2idle×2 with measured peak live allocation count/bytes and register count (at boot and after each wake) plus regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors) on J713, Neo (t8140-j700), and J616s (t604x-j614-j616.dtsialso enables&pmp). - CI pending: 5/7 green (
source,host-tests,kunit,rust-build,DWC3/ATC builtin-no-atc); 2/7 stillqueued(DWC3/ATC modular-no-atc,DWC3/ATC builtin-modular-atc).
Non-blocking Notes
- Refused
OPC_MALLOC/OPC_REGISTER_IOREGrequests currently emit two unratelimiteddev_err!messages per request (pmp.rs:329/398, thenpmp.rs:858); ratelimiting refusals would prevent log flooding on a misbehaving firmware. - Pre-existing 1-based
register_ioreg()reply (len()after push,pmp.rs:466) vs 0-basedset_ioreg()lookup (get(index),pmp.rs:475) is unchanged here; logging the indices firmware returns during the boot row will confirm whether that is a separate bug to fix.
|
Thanks. Rows on J713, Neo and J616s (PMP probe, s2idle x2, live allocation count/bytes and register count at boot and after each wake, regression counts) will run on a kernel at this head; the kprobe counter is ready. On the non-blocking note: the Rust kernel crate here has no ratelimited |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at aa132a243fcd: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: as you said on 11-23: J713, Neo and J616s at this head, each with a PMP probe and s2idle ×2, with the live allocation count and bytes and the register count at boot and after each wake. One of them is enough to merge; the others come after.
Checked: no Apple material, no hardcoded limit from one machine: the bounds cap what the firmware can make the kernel hold, and a request past them is refused. The host test passes 5/5 and fails 4 of 5 with the bounds removed. The J713 kprobe run shows no MALLOC/FREE/REGISTER traffic across sleeps. CI green. This replaces my earlier review.
Evidence
Read aa132a24 (pmp_alloc.rs, pmp.rs, the host test).
Superseded by the review at aa132a2
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
aa132a2 J713 (M4 Air T8132, macOS 27.2 fw) + J616s (M4 Pro T6040, macOS 26.6.2 fw) PASS: guarded one-shot 7.3.0-aurora-pr2905+ (exact aa132a2 on ef1c985, default cmdline, boot-ctxr.bin untouched); live PmpState read read-only from /proc/kcore via pmp.o DWARF offsets + runtime kprobe on apple_rtkit_send_message (ep 0x20) across 2x rtc1 s2idle wakes:
|
What
Bound the memory and register entries the Apple PMP driver holds for the firmware. Freeing a buffer returns its allocation budget. Register entries are accepted while their index fits the firmware reply.
Tested
J713 (M4 Air) and J616s (M4 Pro), exact
aa132a243fcd, on the default kernel command line. Both passed normal PMP probe and two short RTC wakes. Live allocation counts, allocation bytes and register counts remained stable. Both returned to their saved kernels with SELinux enforcing and zero failed units. The arm64 build passed, and the allocation host suite passed 5/5.Risk
Two-way door for Macs using Apple PMP. A request outside the driver's allocation or register budget is rejected. Test counts on both machines stayed well within the budget.
Not yet
Repeat the same ordinary PMP probe and wake checks on Neo.
Review and test details
Exact hardware rows · Independent review