Skip to content

kboot: T6050: hand the PMP's sleep SRAM range over from the ADT - #582

Merged
DjDeveloperr merged 2 commits into
mainfrom
feat/t6050-pmp-sram-keep
Dec 1, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
feat/t6050-pmp-sram-keep

Conversation

@erikwb

@erikwb erikwb commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What: Before a deep sleep Linux stops the PMP and keeps part of its SRAM for the restart: the range in apple,sram-keep, the firmware's __DATA segment. On T6050, kboot_pmp.c (#506) already copies the per-unit PMP settings from the ADT, but not this range, so a DT without a compiled-in range keeps nothing, and the segment moves between firmware versions, so a compiled-in range is only right for one. The loader now sets apple,sram-keep from the ADT PMP node's __DATA segment (by segment-names, from segment-ranges), as an offset into the PMP's SRAM window and a length. Needed by aurora-silicon/linux#3651 (J716c PMP) for deep sleep.

Tested: host test tests/run-pmp-boot-data.sh at 78343765: PASS, with new cases for the range, a firmware layout replacing a DT's value, thirteen missing, malformed, misaligned or out-of-window segment tables that leave the DT's value, and a DT with room for every value but this one, which comes back byte for byte. J716c (16-inch M5 Max, 27.2) with this commit on the J716c daily loader: apple,sram-keep reaches Linux as <0x56000 0x9b000>, the PMP starts, the PMP report runs and the PMC's static agents are 0xb.

Risk: two-way door · T6050 Macs whose DT enables the PMP without the pmp alias: J716c (#3651), J714c, J714s and K116s. On J714s and K116s the ADT's range, when it validates, replaces the DT's compiled-in one.

Not yet:

  • A deep sleep and resume with the PMP running: on the J716c a deep sleep currently resets the Mac a few seconds in, with the PMP on and with it off, on the same kernel and loader, so the restart this range is for cannot be checked yet.
  • J714c, J714s and K116s rows (no such Macs here).
Details
  • Selection: segment-names must give one non-empty name per segment-ranges entry (;-separated, with at most one NUL, as its last byte) and exactly one __DATA. That entry must be non-empty, whole 32-bit words at both ends (Linux keeps it a word at a time) and inside both the ADT register window the pairing matched and the DT's pmp window; the offset is relative to that window, as the kernel's PMP driver expects.
  • Without such a segment, or with a malformed table, the DT's apple,sram-keep (if any) stays and the other values are still copied. A failed write restores the whole DT, as for the other values.
  • On the J716c 27.2 ADT, pmp0's __DATA is 0x9b000 bytes at offset 0x56000, the same as the value the K116s DT carries for 27.2.
Evidence
  • Host test: sh tests/run-pmp-boot-data.sh (ASan and UBSan) at 78343765.
  • J716c trial: a one-shot Stage 2 (aura-try, under a watchdog dead-man) built from the J716c daily loader 00976384 plus this commit (3804504a, the same patch), make USE_CLANG=1 RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1, with the default Stage 2's boot variables; kernel 7.3.0-ewb391+ = aurora-silicon/linux main de965eb5b26b + #3650 + #3651, DTB without t6050-media.dtsi (J716c (M5 Max) hangs at boot since #2278: ave0 encoder with pmgr4 enabled linux#3618). /proc/device-tree/soc@200000000/pmp@284e00000/apple,sram-keep = 00056000 0009b000; PMP started; apple-pmp-report ...: PMP running (status 0x1), requests 0x1000047000.
  • Deep sleep (rtcwake -d rtc1 -m mem -s 30) on that boot, and on the same kernel and loader with main's J716c DT (PMP off): both reset the Mac a few seconds into the sleep and came back on the default kernel. The default J716c daily kernel resets the same way.

Before a deep sleep Linux stops the PMP and keeps part of its SRAM for
the restart: the range in apple,sram-keep, the firmware's __DATA
segment. Without it the T6050 PMP keeps nothing, and its restart after
the wake has no data segment. The segment moves between firmware
versions, so a board DT cannot carry it for every Mac.

When kboot_pmp.c pairs a T6050 PMP with its ADT node, take the segment
that the node's segment-names calls __DATA from its segment-ranges, and
set apple,sram-keep to its offset into the PMP's SRAM window and its
length. segment-names must give one non-empty name per segment and
exactly one __DATA; the segment must be whole 32-bit words, which is how
Linux keeps it, and lie inside both the ADT register window the pairing
matched and the DT's pmp window. Otherwise the DT's apple,sram-keep, if
any, stays; a full DT restores every byte, as for the other values.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb marked this pull request as ready for review November 30, 2026 22:08
@erikwb
erikwb requested review from a team as code owners November 30, 2026 22:08
@erikwb
erikwb requested review from Acelogic and malik-na November 30, 2026 22:08
Reflow two comments and two call lines to the column limit so
format-check passes. No code change.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@github-actions github-actions Bot added blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Merge readiness at 944ed93c: not ready yet

Check Detail
CI at head ok 28 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head no no line with the head SHA 944ed93c, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · T6050 Macs whose DT enables the PMP without the pmp alias: J716c (#3651), J714c, J714s and K116s. On J714s and K116s the ADT's range, when it validates, replaces the DT's compiled-in one.

Areas: none matched in CODEOWNERS

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

@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: HOLD at 944ed93c

Blockers:

  • Queued hosted CI at 944ed93c: build, gcc, selftest, clang-macos, Pytest, fedora/alarm/nix, pr-text, and readiness are still running/queued. Wait for all hosted checks to finish green.
  • Additional T6050 board confirmation (optional/noted under Not yet:): Since apple,sram-keep replaces the compiled-in DT value on J714s and K116s when valid, confirm whether J716c (<0x56000 0x9b000>, matching K116s's DT value) is the intended final row until deep sleep is unblocked on J716c and other T6050 boards can test.

Checked:

  • Audited full diff (+216/-13 across src/kboot_pmp.c and tests/pmp_boot_data.c):
    • adt_pmp_sram_keep() strictly validates segment-names (non-empty ;-separated names, at most one NUL at names_len - 1, no inner NULs, exactly one __DATA, entry count matching segment-ranges), bounds-checks data.size > 0, data.phys >= base, data.phys - base <= min(window, dt_window), data.size <= size - (data.phys - base), 32-bit offset fit, and 4-byte word alignment on both offset and size.
    • Confirmed missing/malformed __DATA preserves the DT's existing apple,sram-keep while still copying other PMP properties, and any fdt_setprop() failure restores the entire DT atomically from saved.
    • Confirmed tests/pmp_boot_data.c exercises 13 malformed/out-of-window negative controls, DT-replacement, FDT-full rollback, and unterminated segment-names, passing under ASan/UBSan.
    • Confirmed live J716c one-shot Stage 2 boot delivered /proc/device-tree/soc@200000000/pmp@284e00000/apple,sram-keep = <0x56000 0x9b000> with PMP started and apple-pmp-report running.
Evidence
  • Head commit: 944ed93c2734a69a38a0ce529debd3507c02b0c5 (MERGEABLE into main).
  • CI snapshot: policy, ESP stage 2 vital size, format-check, and Pytest (ubuntu-24.04-arm) passed; remaining jobs queued/in-progress.

@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 944ed93c

Blockers: None.

Checked:

  • Hosted CI at 944ed93c is now completely green (19P/0F/0Q: all builds, selftest, Pytest matrices, ESP stage 2 vital size, format-check, policy, pr-text, readiness, and distro builds passed).
  • Full audit of src/kboot_pmp.c and tests/pmp_boot_data.c (+216/-13) confirmed strict validation of ADT segment-names/segment-ranges __DATA, word-alignment and window-bounds checks, fallback preservation of compiled-in apple,sram-keep, atomic DT rollback on fdt_setprop failure, 13 negative-control + FDT-full ASan/UBSan tests, and live J716c (T6050, 27.2) Stage 2 boot delivering <0x56000 0x9b000> (matching K116s's DT value) with PMP started and apple-pmp-report running.
Evidence
  • Head commit: 944ed93c2734a69a38a0ce529debd3507c02b0c5 (MERGEABLE into main).
  • CI snapshot: 19P/0F/0Q (0 non-passing checks).

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

Approved. adt_pmp_sram_keep() accepts only one __DATA entry among well-formed segment-names, word-aligned and inside both the matched ADT window and the DT's pmp window, and the offset arithmetic can't underflow. Without a usable range the DT's own value stays, and a failed write restores the whole DT. Rows: J716c on the same patch (this head adds only clang-format), and a J714s (M5 Pro) Stage 2 boot at this head: the loader kept 0x9b000 bytes at 0x58000 from ADT pmp0's __DATA (J716c's ADT gives 0x56000, so the per-machine value is doing its job), the PMP ran with status 0x1 and restarted after each wake, with no PMP errors.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 1, 2026
@DjDeveloperr
DjDeveloperr merged commit 46ff889 into main Dec 1, 2026
32 checks passed
@DjDeveloperr
DjDeveloperr deleted the feat/t6050-pmp-sram-keep branch December 1, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants