Skip to content

spi: apple-qspi: cover the J813's NOR status in KUnit - #2772

Draft
sithglan wants to merge 2 commits into
aurora-silicon:mainfrom
sithglan:thomas/j813-qspi-nvram
Draft

sithglan wants to merge 2 commits into
aurora-silicon:mainfrom
sithglan:thomas/j813-qspi-nvram

Conversation

@sithglan

@sithglan sithglan commented Nov 22, 2026 •

Copy link
Copy Markdown

Stacked on #2817 (its commit is the first one here until it lands). Since #2817, the J813 (MacBook Air 13-inch, M5) is admitted for NVRAM writes through its device tree's nvram partition (0x700000, 1 MiB, the ADT anvram) and its probed part. It needs no board entry any more, so this PR now only adds a KUnit case for the J813's NOR status registers:

flash_status: jedec=ef6517 sr1=00 sr2=02 sr3=60

That is a W25Q64 with QE set, the SR3 drive strength at its default, and no block protection. These registers must pass the write policy for a part that tolerates no block-protect bits.

Testing

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Read at 41aed6c. The row is right for the J813 (window, controller and part match its ADT and the probe), and the KUnit case for its status registers is a good addition.

The table it extends is the problem, though. apple_qspi_boards[] is a per-board list (board compatible, controller address, NVRAM window, JEDEC id), and every entry so far carries the same window and the same part. The NVRAM window is already in the device tree (t8142-j813-peripherals.dtsi describes anvram at 0x700000 for 1 MiB, from the ADT), the controller is the node itself, and the part is read back from the chip at probe. So the write-candidate decision could be: the controller's node has an NVRAM partition described in the tree, and the flash's JEDEC id and status registers pass the existing policy. A new board would then need its DT node and nothing in the driver, and a board with an unexpected part would still be refused, by the part rather than by its name. Several rows are already marked "assumed" (J715, J604, iMacs), which is exactly the guessing this would remove.

I wouldn't hold this one-line J813 addition hostage to that rework, since the write path is safety-relevant and conservative as it is. But please open the follow-up (or say in the commit message why the board key is needed beyond the DT window and the JEDEC check), so the list stops growing.

Assisted-by: LLM (Claude:Opus 5.5)

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

Adversarial review at 41aed6cb3155 against the pre-PR checklist.

What checks out

  • Code & hardware values (§3): The J813 table row (apple,t8142-qspi, apple,j813, 0x3a5118000, 0x700000, 0x100000, W25Q64, bp_ok = 0) matches t8142-j813-peripherals.dtsi and t8142-j813.dts. The KUnit case for sr1=00 sr2=02 sr3=60 (bp_ok = 0) and the 240-combination matrix update in tools/asahi/qspi-nvram-tests.py are accurate.
  • Clean-room & attribution (§4): Clean. Human author/committer + Signed-off-by: only, no AI trailers in the commit, Assisted-by: present in the PR body.
  • Naming (§6) & CI: Clean; host-tests passed on 41aed6cb3155.

Blocker — §1 (No model gating / per-board table)

apple_qspi_boards[] is a per-board allowlist keyed on of_machine_is_compatible("apple,j813") with hardcoded controller base, NVRAM window, and JEDEC ID — all values the machine already provides via DT (qspi node + nvram fixed-partition already parsed by apple_qspi_nvram_window()) and runtime NOR probing (0x9f JEDEC ID + status registers already checked on every write in apple_qspi_nvram_modify()). As the PR body itself notes, this leaves J815 (which shares t8142-j813-peripherals.dtsi) and future Macs excluded until manually listed.

Per pre-PR checklist §1 (hard rule), please resolve this via one of two paths before merge:

  1. (Preferred) Replace the per-board table with generic DT nvram-partition + known-safe probed JEDEC/status qualification (keeping any board-specific bp_ok exception minimal/DT-driven), so every Mac with a valid NVRAM DT node and verified flash part works without per-board code; or
  2. If boot-NOR defense-in-depth makes a board-keyed allowlist genuinely unavoidable for now, explicitly explain why in the commit message (as §1 requires whenever a gate is unavoidable) and file/link the follow-up issue to retire apple_qspi_boards[] (echoing @RyanTheTide's request).

§5 Evidence note (non-blocking once §1 is settled)

The J813 boot run used a tree carrying out-of-tree S2R/USB4 patches rather than clean integration/aurora + this PR, and omitted the explicit §5 regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors). Please include those counts when updating.

Assisted-by: LLM (Gemini 4 Neon)

@sithglan

Copy link
Copy Markdown
Author

Thanks to you both. I took Dj's second path:

  • Follow-up: spi: apple-qspi: admit NVRAM writes by DT window and probed part; retire apple_qspi_boards[] #2815 retires apple_qspi_boards[]. Writes would then be admitted from the DT nvram window and the probed part. The part's block-protect range is decoded against the window, so bp_ok and the second-part IDs stop being per-board, and the window has to hold an NVRAM bank before writes are admitted. Every board the table admits today has to stay admitted with the same window.
  • Commit message (36e75f7, message only, the code is unchanged): it now says why the board key stays for now. A row pins the window and the part that the board's ADT and probe were checked against, so a device tree with a wrong nvram partition cannot open other boot NOR ranges, and bp_ok records the protection that board's firmware leaves set. It links spi: apple-qspi: admit NVRAM writes by DT window and probed part; retire apple_qspi_boards[] #2815.
  • §5 row: still owed. The J813 is being reinstalled right now. Once it is back, I'll boot clean integration/aurora plus this PR alone, without the S2R or USB4 patches, run aurora-bless, and post the counts: AVC denials, failed units and new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Thanks. The follow-up is the right destination, and #2815 is where the board key goes away. Since this PR still adds a board row, I'd rather land #2815 first and rebase this onto it, so the J813 is admitted by its nvram window and probed part with no new table entry. If #2815 needs more time and the J813 write path is wanted now, landing this first is acceptable only with #2815 queued straight after. The §5 row (clean integration plus this PR alone, aurora-bless, counts) applies either way.

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan

Copy link
Copy Markdown
Author

Agreed, #2815 first. It is #2817 (draft until the J813 row runs): no table, writes admitted by the node's nvram partition and the probed part. The J813 is admitted through its DT, so I'll rebase this PR onto #2817 and keep only the KUnit case for the J813's status registers. The aurora-bless row on clean integration/aurora plus #2817 covers both PRs.

Assisted-by: LLM (Claude:Opus 5.5)

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

Re-review against the pre-PR checklist (§1–§6) at verified live head 36e75f779bc135d725e0393274082cdc0b742c74 (diff 41aed6cb..36e75f77): holding CHANGES_REQUESTED — not ready for MERGETRAIN-LINUX4 yet.

Diff 41aed6cb..36e75f77

  • Code: 0 lines changed (code, KUnit case, and tools/asahi/qspi-nvram-tests.py matrix are identical to 41aed6cb).
  • Commit message: Updated to document the boot-NOR defense-in-depth rationale for keeping the board key temporarily and links follow-up issue aurora-silicon/linux#2815 (now implemented as Draft PR #2817).

Checklist Status (§1–§6 & CI)

  • §1 (No model gating): You satisfied Path 2 of my prior review in the commit message and opened #2815 / Draft #2817. However, as you and @RyanTheTide agreed in the comments above, the right landing order is #2817 first, then rebasing this PR onto #2817 to drop the new apple_qspi_boards[] entry and retain only the J813 status-register KUnit test. Keeping CHANGES_REQUESTED active so this table-adding head is not merged ahead of #2817.
  • §2 / §3 / §4 / §6: Clean. Hardware parameters (apple,t8142-qspi, apple,j813, 0x3a5118000, 0x700000, 0x100000, W25Q64, bp_ok = 0) match the J813 DT/ADT; commit 36e75f77 carries human identity (Thomas Glanzmann) + human Signed-off-by: with zero AI trailers; PR body includes Assisted-by:.
  • CI: host-tests PASS on 36e75f779bc135d725e0393274082cdc0b742c74.
  • §5 (Hardware evidence — still owed): The clean integration/aurora + PR J813 boot/test run (aurora-bless set/readback/clear without out-of-tree S2R/USB4 patches) and explicit regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors) are still pending once the J813 reinstall finishes (or via the combined clean integration/aurora + #2817 + rebased #2772 row you proposed).

Next Steps to APPROVE

  1. Land #2817 (#2815) and rebase #2772 onto it (keeping the J813 status-register KUnit case, with no new apple_qspi_boards[] row) — or mark #2772 Draft in the meantime.
  2. Post the clean integration/aurora J813 aurora-bless verification run with explicit §5 regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors).

Assisted-by: LLM (Gemini 4 Neon)

@sithglan
sithglan marked this pull request as draft November 22, 2026 15:13
@sithglan

Copy link
Copy Markdown
Author

Marked as draft until #2817 lands. I'll then rebase this onto it (the J813 status-register KUnit case only, no table row) and post the clean integration/aurora J813 aurora-bless run with the AVC, failed-unit and new-kernel-error counts.

Assisted-by: LLM (Claude:Opus 5.5)

@sithglan
sithglan force-pushed the thomas/j813-qspi-nvram branch from 36e75f7 to f14ad50 Compare November 22, 2026 18:16
@sithglan sithglan changed the title spi: apple-qspi: admit the J813's NVRAM spi: apple-qspi: cover the J813's NOR status in KUnit Nov 22, 2026
@sithglan

Copy link
Copy Markdown
Author

Rebased onto #2817 as agreed: the table row is gone, and only the J813 status-register KUnit case remains (f14ad50). The J813 aurora-bless row ran on clean integration/aurora + #2817: set, read back and clear passed, and the NOR outside the window was unchanged. Counts: 0 AVC denials (no SELinux), 0 failed units, 0 new kernel errors. Full row in #2817. This stays a draft until #2817 lands.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Thanks. f14ad50 is now just the J813 status-register KUnit case on top of #2817, with no table row. The J813 bless row (set, read back and clear, NOR outside the window unchanged, 0 failed units, 0 new kernel errors) covers it. Fine from my side once #2817 lands. The two open safety items there gate both.

Assisted-by: LLM (Claude:Opus 5.5)

A controller became a write candidate only through a row of
apple_qspi_boards[]: controller and machine compatible, controller
base, the nvram window the device tree had to describe exactly, the
JEDEC IDs and the block-protect bits the firmware leaves set. Each new
Mac needed a row, and five of the ten rows were assumed rather than
checked against an ADT and a probe.

Take those facts from the machine instead, and check the device tree's
partition against the flash before anything is written to it:

- The window is the node's one "nvram" partition, if it is not marked
  read-only, is a whole number of 64 KiB NVRAM banks from a 4 KiB
  boundary and lies within three-byte addressing
  (apple_qspi_window_valid()).
- The part is read back before every program or erase and must be in a
  short part table (W25Q64, Macronix 2B27, W25Q16, GD25UF16E), which
  gives its size and the block-protect bits its firmware leaves set.
  The window must end within the part: a three-byte address past it
  wraps around into the start of the flash.
- Before the first program or erase, and latched for the controller:
  the part's SFDP density must be the size the table bounds the window
  with, and every bank of the window must start with a v3 NVRAM store
  header ("3VVN", version 1, a store size within the bank) or be blank
  throughout, with at least one store. A partition over firmware, a
  stale one, or one running into padding or an image partway through a
  bank, admits nothing.
- Also at that point, the block-protect bits are decoded, and a bank
  they reach even in part is dropped from the writable banks. A program
  or erase there is refused before WREN, so a bank erase cannot stop
  halfway with the bank's header already gone. On the J700, BP0 covers
  the top 64 KiB, so the window's last bank [0x1e4000, 0x1f4000) is
  never written. The bits are decoded against each request as well:
  one in the protected range is refused before WREN instead of failing
  its readback and latching read-only.

The read-only default and the root opt-in, the opcode, range, page and
erase checks, the readback verify and the fault latch are unchanged.
Refusals for the part, its size, SFDP, the window and protection are
logged, rate limited, with the reason.

The boards the table admitted keep their window and part. Any other
board whose device tree describes a usable nvram partition is admitted
by these checks alone.

The rules live in spi-apple-qspi-policy.h, where KUnit covers the window
rule, the bank header, the part table, the protected ranges, the banks
they leave writable and SFDP parsing. tools/asahi/qspi-nvram-tests.py
runs the driver's write path against a flash model with SFDP and NVRAM
banks, with changed-guard controls for each new check.

Closes: aurora-silicon#2815
Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
The J813 (MacBook Air 13-inch, M5) reads a Winbond W25Q64 (ef6517) with
QE set and the SR3 drive strength at its default, and no block
protection:

  flash_status: jedec=ef6517 sr1=00 sr2=02 sr3=60

Since aurora-silicon#2817 the J813 is a write candidate through its device tree's
nvram partition (0x700000, 1 MiB, the ADT anvram) and its probed part,
with no board entry. Check in KUnit that these status registers pass
the write policy for a part that tolerates no block-protect bits.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@sithglan
sithglan force-pushed the thomas/j813-qspi-nvram branch from f14ad50 to 87650bc Compare November 22, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants