Repository navigation
memory: map L2 blocks over an armed CTRR range with L3 pages - #411
Conversation
|
Thanks for tracking this down, and for the control run without the commit; the fault and its cause are clearly shown. One change we'd ask for. We select behaviour by a hardware property rather than by the chip it was seen on, and here the property is already in hand:
If you make it unconditional, we can run boot rows on our M1 Pro, M2, M4 Pro and A18 Pro to confirm nothing else moves. |
b7a3dd9 to
10ccc1b
Compare
|
@RyanTheTide done. The head is now The code comment and the commit message now describe it as a property of the armed range. I also retitled the PR to "memory: map an armed CTRR_C with L3 pages". Checks:
J873g: main Thanks for offering the M1 Pro, M2, M4 Pro and A18 Pro rows. |
RyanTheTide
left a comment
There was a problem hiding this comment.
No blockers. The push at 10ccc1b addresses our earlier comment: the chip_id == T8152 gate is gone and the L3 extension now depends only on an armed CTRR_C (src/memory.c:419). The [start, end) handling and the 32 MiB rounding in mmu_map() are correct. ctxr_range() runs under the exception guard installed in startup, before aura_main(), so the first mmu_map() call is safe on chips without the register.
Two hardening points, since this is the stage-wide page table code:
-
src/memory.c:419: only CTRR_C is considered.dt_reserve_secondary_ro()in kboot.c says secondaries on M4 and later enforce CTRR_D as well. On J813 that range sits below the boot object, so today it is covered by the existing_baserule. An iBoot that places CTRR_D above_basewould hit the same L2-block fault on a secondary. Suggested fix: take the maximumendover{CTRR_RANGE_C, CTRR_RANGE_D}inmmu_l3_top(). It costs nothing where neither is armed. -
src/memory.c:416-421: the value read is trusted as is. On a chip where the register reads as a plausible but unrelated value, everything fromram_baseto that address is mapped with L3 pages. That is slow, it costs heap for page tables, and nothing logs why.ctxr_exec_holds_ro_range()reads CTRR_C/D only when!cpu_features->apple_sysregs_unlocked. Suggested fix: apply the same condition here, or accept the range only when it lies inside[cur_boot_args.phys_base, phys_base + mem_size), and print the chosen top once (for exampleMMU: L3 up to 0x... (CTRR_C)). Boot logs would then show which machines take the new path.
Hardware rows we can run (offered earlier). On M1 Pro (T6000), M2 (T8112), M4 Pro (J616s, T6040) and A18 Pro (Neo, T8140), chainload this head as Stage 2 and boot to the desktop. Pass: all CPUs online, no SError or abort in the aura log, and the L3 top equals _base wherever CTRR_C is not armed. That last check needs the print from point 2.
Assisted-by: LLM (Claude:Opus 5.5)
|
The arithmetic checks out:
A boot row on an M4 Air (T8132) would be useful alongside the rows already offered, since that iBoot generation may also arm CTRR_C. Assisted-by: LLM (Claude:Opus 5.5) |
10ccc1b to
5935898
Compare
|
@RyanTheTide thanks for both reviews. All points are in
On this head:
The rows on your M1 Pro, M2, M4 Pro and A18 Pro would be very welcome. The |
RyanTheTide
left a comment
There was a problem hiding this comment.
No blockers. Re-checked 5935898 against both of our earlier comments; every point is addressed:
- CTRR_D is read alongside CTRR_C (
mmu_ctrr_ranges(),src/memory.c:419-438). - Nothing is read with unlocked Apple system registers, the same condition
ctxr_exec_holds_ro_range()uses.init_cpu()setscpu_featuresin startup beforeaura_main(), so the check sees the real value.ctxr_range()also returns false outside EL2. - The cost no longer depends on where iBoot puts the range: only the L2 blocks whose output range intersects an armed range get L3 pages (
mmu_holds_ctrr()). An odd UPR value can split only the blocks it names. - The test is on the output address, so the
REGION_*aliases of the range are split too. - Each armed range is printed once.
I also checked the interval test ([start, end) against [target, target + 2 MiB), and end <= start is skipped), the interaction with the firmware-RO split (RO first, then CTRR, then a plain L2 block), and the paths that come after it. Unmaps pass to = 0, so they never split and stay correct. Once the MMU is on, the L2 branch is skipped, so no later mapping can create an L2 block over the range.
One small point, not blocking:
src/memory.c:471(the L1 branch inmmu_map()): the L1 path doesn't consult the ranges. It is unreachable on Apple's 16K granule, so nothing breaks today. A one-line comment that the CTRR split assumes no L1 blocks (or the samemmu_holds_ctrr()test there) would keep a 4K build from silently mapping an armed range with a 1 GiB block.
Hardware rows we can run on this head, chainloaded as Stage 2 and booted to the desktop. Pass on every Mac: all CPUs online, and no SError or abort in the aura log.
- M1 Pro (T6000), M2 (T8112): no
MMU: L3 pages over CTRR_line, because their system registers are unlocked. Boot otherwise unchanged. - M4 Pro (J616s, T6040), A18 Pro (Neo, T8140): the boot log shows whether either range is armed. If one is, it is mapped with L3 pages and the desktop boot is unchanged.
- M4 Air (J713, T8132), now in our lab: the same check. This covers the T8132 row you didn't have.
Assisted-by: LLM (Claude:Opus 5.5)
|
Correction to my J873g row above: under main + this commit, HDMI did not come up. Only the two USB-C displays worked. The main DCP's firmware asserted when Linux took it over ( This commit doesn't cause it. Main's T8152 hand-off leaves the endpoints aura started for HDMI running and doesn't report them, so |
iBoot can arm CTRR_C and CTRR_D over physical ranges that L2 blocks
would cover: on T8152 it arms CTRR_C over the 48 KiB below its
top_of_kernel_data, above the boot object. mmu_map() keeps L3 pages
only below aura's base, so on a boot where that range lands above the
next 32 MiB boundary it sits in an L2 block. A secondary that walks such
a block takes an address size fault at level 2 (seen on CPU 0, a
secondary there: the J873g boots on CPU 6, as its first stack access
after mmu_init_secondary_local()), and the payload path's
smp_start_secondaries() then brought the machine down. The boot core
uses the same block without a fault. Whether it hits depends on where
iBoot places the object: 5 of 10 boots of the M6 mini (27.2), each time
CTRR_C was inside an L2 block.
Main hits it on the J873g too: chainloaded with boot= from the ESP, CPU
0 (MPIDR 0x80000000) faulted in fb_console_scroll() while
cpufreq_init() printed, on the framebuffer write at 0x1000fa12010 (ESR
0x96000002) in the L2 block that holds CTRR_C, before the handoff.
Build exactly the L2 blocks whose output range contains an armed CTRR_C
or CTRR_D from L3 pages, as mmu_map() already does for the firmware's
read-only range. Testing the output address covers every virtual alias
of the RAM, and the cost no longer depends on where iBoot puts the
range. The ranges are read once, and only with locked Apple system
registers, as kboot reads them; an absent or unarmed range changes
nothing, and each armed one is logged ("MMU: L3 pages over CTRR_C
[...)"). With this, main boots the J873g desktop kernel from the ESP
with all twelve CPUs.
Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
5935898 to
d1322d6
Compare
|
@RyanTheTide thanks. The L1 point is in Thanks for lining up the M1 Pro, M2, M4 Pro, A18 Pro and J713 rows. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed d1322d6. Approving the code:
- Only L2 blocks whose output range intersects an armed CTRR_C/D get L3 pages (
src/memory.c:498plusmmu_holds_ctrr()), so every RAM alias is covered, and the cost doesn't depend on where iBoot puts the range. - Nothing is read with unlocked Apple system registers (
:428), the same rule kboot uses. ro_start/ro_endare only read undersplit_ro.- Unmaps never split.
- The L1 note covers the 4K case.
This is stage-wide page-table code, so it needs rows on this head (or its merge with main) before merging. Each Mac chainloads it as Stage 2 and boots to the desktop. Pass on every Mac: all CPUs online, no SError or abort in the aura log, and boot otherwise unchanged:
- M1 Pro (T6000) and M2 (T8112): no
MMU: L3 pages over CTRR_line, since their sysregs are unlocked. - M4 Pro (J616s, T6040), A18 Pro (J700, T8140), M4 Air (J713, T8132) and M5 Pro (J714s, T6050): the log shows whether either range is armed. Where one is, it's mapped with L3 pages.
The J873g row (with and without the commit) is in. CI on this head is still queued.
Assisted-by: Claude Opus 5.5
|
Thanks. The L1 note in We'll run d1322d6 as Stage 2 on our M1 Pro, M2, M4 Pro and A18 Pro and post the rows here: all CPUs online, no SError or abort in the log, and on the M4 Pro and A18 Pro whether a CTRR range is armed and mapped with L3 pages. |
|
J713 (13" MacBook Air M4, T8132, 27.2 stub) row on d1322d6 merged with main a4df613 (Stage 2
The boot is otherwise the same as main a4df613 on the same setup, which showed the same CTRR_C reservation without the L3 line. Assisted-by: LLM (Claude:Opus 5.5) |
|
J616s (M4 Pro, T6040) row on d1322d6 merged with main a4df613 (Stage 2
Assisted-by: LLM (Claude:Opus 5.5) |
|
M1 Pro (J316s, T6000) row on d1322d6 merged with main 83d2841 (Stage 2
The J616s row is above. Assisted-by: LLM (Claude:Opus 5.5) |
|
M2 (J413, T8112) row on d1322d6 merged with main 83d2841 (Stage 2
Assisted-by: LLM (Claude:Opus 5.5) |
|
J700 (MacBook Neo, A18 Pro, T8140, macOS 26.6.2 firmware) row on d1322d6 merged with main afc8ec1 (
The one-shot boot added Assisted-by: LLM (Claude:Opus 5.5) |
|
A18 Pro (J700) row after the merge: main 6affb8e as the Stage 2, as an aura-try one-shot on the fleet kernel, booted to the desktop.
Assisted-by: LLM (Claude:Opus 5.5) |
…50 handoff bounds Three merged changes had no test in the tree. Each gets a host test that builds the code unchanged, with the registers, the ADT and the device tree as stand-ins: - test_mmu_ctrr_l3.py (aurora-silicon#411): the page-table builder of memory.c and ctxr_range() run on host memory with 16K pages. An L2 block whose output range holds an armed CTRR_C or CTRR_D is built from L3 pages, in every alias of the RAM, and no other block is. The ranges are read once, and not at all with unlocked Apple system registers, off EL2 or for an unmapping; a register that faults under the guard changes nothing. Seeded layouts are compared with a model of the mapping rule. - test_sptm_virt_cpu_ids.py (aurora-silicon#407): the S2R trace's walk of /cpus, the stop-mode and go-mode core masks and the DCC transport's per-core cookie and errno, each driven with cpu-ids on both sides of 32, up to MAX_CPUS - 1. - test_t6050_handoff_bounds.py (aurora-silicon#408): a panel-less board through dt_set_display_handoff(), and the panel path's ADT checks. A boot framebuffer that starts at or past the end of /vram, and a bandwidth scratch in a PMC metadata block of under 4 bytes, are refused and the device tree is left as it was; the edges on the allowed side are still handed off. Seeded cases are compared with the rule in whole numbers, which cannot wrap. Each test takes another source through an environment variable (AURA_MMU_SOURCE, AURA_SPTM_SOURCE, AURA_T6050_SOURCE), so the same file can be run against a changed copy as a negative control. No production code changes. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
With this, aura main boots the J873g (M6 Mac mini) desktop kernel from the ESP. Without it, main faults in its own console before the handoff.
Problem
iBoot can arm CTRR_C and CTRR_D over physical ranges that L2 blocks would cover. On T8152 it arms CTRR_C over the 48 KiB below its
top_of_kernel_data, above the boot object.mmu_map()uses L3 pages only below aura's base. When the armed range lands above the next 32 MiB boundary, it sits inside an L2 block, and a secondary CPU walking that block takes an address size fault at level 2. The boot core uses the same block without a fault. On the J873g the boot CPU is CPU 6, so CPU 0 (MPIDR0x80000000) is a secondary.Whether it hits depends on where iBoot places the object; on the M6 under macOS 27.2 it hit 5 of 10 boots. On main
3efa4a81, chainloaded on the J873g withboot=from the ESP:fb_console_scroll()→memcpy32whilecpufreq_init()prints.0x1000fa12010(ESR0x96000002), in the 32 MiB block that holds CTRR_C.Change
mmu_map()builds exactly the L2 blocks whose output range contains an armed CTRR_C or CTRR_D from L3 pages, as it already does for the firmware's read-only range:The ranges are read once (
ctxr_range()), and only with locked Apple system registers, as kboot reads them. An absent or unarmed range changes nothing. Each armed range is logged once:MMU: L3 pages over CTRR_C [start, end). The rule that maps everything below aura's base with L3 pages is unchanged.Testing
J873g (macOS 27.2 boot policy): main
3efa4a81+ this commit, chainloaded from the installed Stage 1 withboot=<ESP>;aurora/ctxr/Image;aurora/gpu/t8152-j873-dcp-gpu.dtb;aurora/ctxr/initramfs.cpio.gz:MMU: L3 pages over CTRR_C [0x1000ef9c000, 0x1000efa8000), then the handoff. CTRR_D is not armed.7.3.0-aurora-j873-avd-usb4-perf+comes up with CPUs0-11online, the GPU render node, the two USB-C displays and no failed units. HDMI did not come up: the main DCP's firmware asserted when Linux took it over, which this commit does not cause (fixed by kboot, display: T8152: report live AFK endpoints; hand the display controllers over powered off #419). Its EIZO showed simpledrm's boot framebuffer, which I first counted as the third display.Checks:
make format-check(clang-format 20.1.8) is clean.CHAINLOADING=1, with and withoutESP_STAGE2=1,-Wstack-usage=2048 -Os) builds with no warnings inmemory.c.3efa4a81:test_dcp_iboot_wire,test_external_dependency_groupandtest_xnuboot_layout.The same boot also covers #300's post-merge row on the J873g, which is posted there.
cc @DjDeveloperr @RyanTheTide @Acelogic @LiamRay10