Repository navigation
nvme: apple: start a post-M4 ANS the boot loader powered off - #38
DjDeveloperr wants to merge 7 commits into
Conversation
A coprocessor's SART loses its entries with the coprocessor's power. An earlier owner that powered it off can pass the entries on, and sart_set_entry() writes one back at its index and keeps it, as sart_init() keeps the entries it finds. Signed-off-by: Diljit Singh <[email protected]>
e9f8a2d to
09973be
Compare
b276b4e to
a20e374
Compare
…e state After a power cycle, firmware that kept its state in DRAM says HELLO by itself once the run bit is set, and keeps the buffers it was given. apple_rtkit_boot_warm() is the existing boot with a flag: no INIT, the endpoint map answered as macOS does after a wake (bit 1 added to every part but the last, the last masked by the caller), no endpoint started again, then AP power on. Such firmware can report its power state before HELLO or between the endpoint map's parts: the handshake records that, and drops what other endpoints send meanwhile. Firmware that reports its power on and then says no HELLO picked its kept session back up: AP power goes on and the session carries on. Signed-off-by: Diljit Singh <[email protected]>
aura now shuts ANS down after its own use, as on M1-M3, instead of handing its running session on. It powers ANS's PCIe block off and back on before U-Boot, so U-Boot finds ANS powered with its CPU stopped, and the SART entries the firmware's buffers need in the nvme node's apple,sart-entries: per entry (index << 8 | flags), address and size, 64 bits each. With that property, apple_nvme_probe() writes the entries back, enables the mailbox's receive side as macOS does after a sleep, sets the run bit and starts the firmware as after a power loss, then sets the controller up as before. Linux still adopts a running ANS, so U-Boot hands it on running, as before, and drops the property from the OS's tree. A post-M4 session straight from iBoot, which no stage has set up, gets its one-time RTKit handshake on every post-M4 controller, not only on T6040. A running session from an older aura is adopted as before. Pre-M4 controllers boot ANS as before. Signed-off-by: Diljit Singh <[email protected]>
a20e374 to
66b55b3
Compare
The warm start took an IOP power report of "on" followed by no HELLO for a session the firmware had picked back up, and turned AP power on without a handshake. That came from reading a CPU status of 0x6a as "kept its idle state". On the J700 the start that failed (ANS-chain-kit-08) did get HELLO: this branch, built with DEBUG, didn't print, and both mailbox controls read their reset value. The firmware had restarted, and what it never sent was the endpoint map after HELLO. The boot loader stage now disables the controller before it powers ANS off, which leaves no case for this branch. Log HELLO and each endpoint map part as debug lines, so a failed start says how far the handshake got. Signed-off-by: Diljit Singh <[email protected]>
The warm start answers the last part of the endpoint map with that part's bitmap masked by last_mask. For ANS that is bit 0, endpoint 0x20, as macOS answers after a wake. The loop then tested its own reply for APPLE_RTKIT_MGMT_EPMAP_REPLY_MORE, which is bit 0 too, so it went back to wait for a part the firmware never sends. The firmware's IOP power report came in that wait, and the start failed with -110 a second later. On the J700 (ANS-chain-kit-09) U-Boot logged HELLO, map base 0, map base 1 (the last part), then the IOP power report and -110. aura's three starts from off in the same boot passed: they end the map on the message's last bit. The "unexpected message type 7" of kits 05 and 06 was the same report, read where the next map part was expected. End the loop on the reply's LAST bit, which is set exactly when the firmware's part was the last. Signed-off-by: Diljit Singh <[email protected]>
|
An M4 data point for #38 with #40, from one J773g (Mac mini M4, T8132). It's one Mac, but this is the start from off working on an M4. Build. aurora-wip Through the aura proxy, ANS handed over off. Stage 1's proxy chainloaded aura 1.0.0b10. That instance ran Linux was booted with Native, no proxy. iBoot, Stage 1 1.0.0b8 (installer Alpha 19), an ESP Stage 2 with aura 1.0.0b10 plus the companion aura change below, then this U-Boot. U-Boot wrote both markers and loaded Shim, GRUB and Linux followed. Linux logged Companion aura change. Stage 1 1.0.0b8 hands ANS on running, with no SART entries. An ESP Stage 2 from aura main that boots its embedded U-Boot never touches NVMe, so it passes that session on as it is, with no Not covered: U-Boot's own NVMe log lines (no serial console; the record above is what we have), #38 without #40 on an M4, other M4 boards, and M4 Pro and Max. |
|
Three corrections to my comment above:
|
|
A T8140 data point, from one MacBook Neo (J700): this PR starts ANS from off in most boots, but 3 of 116 failed, and a trace of one failure shows the firmware sending nothing after the run bit. Build and chain. aurora-wip Results, 2026-11-12. Of 116 trial boots, 113 started ANS from off and 3 failed. In one more cycle, either the trial or the regular boot after it failed the same way. aura's own start from off in Stage 1 worked in every boot. A failed boot's panel shows only Why the panel shows only One traced failure. A test-only record in Seconds later, at
A timing difference. aura's own start from off ( Next. The test build now holds the screen whenever Separately, one regular boot of the older chain failed with the same panel, right after a trial's watchdog reset. That chain is 1.0.0b9 Stage 1 and Stage 2 with |
… the run bit On a J700, 3 of 116 starts from off failed: no HELLO after the run bit, and none later. The traced one read CPU status 0x62 before the run bit; every working start read 0x6a, the status right after a reset of ANS. Its CPU had been stopped without a reset since it last ran, and such a CPU doesn't start again from the run bit. Reset ANS (its PMGR reset, which takes the SART entries with it) when the status lacks the reset bit, then write the entries and start it. When the firmware still doesn't answer, stop the CPU, reset ANS, write the entries again and start it once more with a new RTKit instance. Print the status before the run bit and any reset, for a Mac without a serial console. Signed-off-by: Diljit Singh <[email protected]>
|
@niteria, thanks for the trace: it points at the CPU's state before the run bit, not at the wait. What 0x62 means.
Why the gap probably doesn't matter in itself.
The change, pushed to this branch as
Testing here. I'll run it on our J700 in two loops of 50 boots, through your chain arrangement:
If you can run 🤖 Generated with Claude Code |
|
Before trusting the reset path: Aurora's Linux tree stopped using this exact reset on post-M4 ANS because it raised an SError on a J700. aurora-silicon/linux@3053678703b4 ("nvme-apple: Restart a stopped resident ANS without a PMGR reset", carried from Satya's change of 2026-09-18) says:
It was tested on T8140 (J700). Since then, Linux restarts a stopped resident post-M4 ANS with the run bit and a fresh handshake, and keeps the reset for older generations. That's the state U-Boot unmasks SError at start ( Your loop B should settle it quickly. We're running |
|
An update from our loop on the J700. We've paused it for now.
What a working start looks like. Our test build passes U-Boot's record to Linux in
The traced A second failure, a different one. It came with A pattern, not proven. All four failures today came on a trial booted right after a regular boot of the older chain (1.0.0b9 Stage 1 and Stage 2, U-Boot adopting the session, then Linux). After we switched to booting each trial right after the previous trial's Linux, about 100 trials in a row worked. A loop alternating regular and trial boots then gave 19 more working trials before we stopped. At about 3% per boot, that doesn't settle it. The Neo is back on its daily chain. The loop and the trace build are ready to run again, with |
|
@niteria, loop A from our J700, with
So, like your 80 starts, natural starts haven't exercised the reset path yet. The timing agrees with your 117 working starts; our measurement points differ slightly. Two things this loop doesn't cover:
On the SError. Loop B is next on the Neo. It's the same U-Boot with a test-only switch that takes the reset path on every boot, so it answers whether One related data point. Today aura reset a stopped, resident ANS on this J700 twice, in its macOS cold handoff, with the gate held active: 🤖 Generated with Claude Code |
A start from off that is retried frees its RTKit instance first. That instance's buffers came from LMB through nvme_handoff_shmem_setup(), but it had no destroy callback, so apple_rtkit_free() passed them to free(): heap corruption once the firmware had asked for any. They also stayed in the handoff list, published to the OS as reserved memory. Take them out of the SART, return them to LMB and drop them from the list instead. Signed-off-by: Diljit Singh <[email protected]>
|
@niteria, loops B and C from our J700, in your chain arrangement. Short version: the PMGR reset raised no SError here, including from a stopped ANS with its firmware resident (20 of 20 boots), and the PR's retry recovered every time. Testing it also turned up a bug in the retry path, now fixed on this branch. Loop B, 10 boots ( Loop C, 20 boots: a second test switch makes each boot reach the state your SError question is about.
Results:
So on this J700, at this point in boot, U-Boot's reset of a cleanly stopped, resident ANS doesn't raise the SError described in Two things this shows about
The bug, fixed in
Still open: what leaves a 🤖 Generated with Claude Code |
|
This series is now carried unchanged, rebased onto current aurora-wip, in #48 (all seven commits, authorship kept). This branch conflicts with aurora-wip and has no CI run on its head. Could we continue review and hardware rows on #48 and close this one when #48 merges? The J700 loops (113/116, 50/50, loop B/C) and the J773g rows here stay the evidence for the carried commits. #40 would then need its base moved from fix/nvme-apple-t8140-ans-restart to #48's branch or aurora-wip. Happy to do that retarget if it helps. |
|
I recommend closing this in favour of #48. #48 carries all seven commits of this branch unchanged, rebased onto current aurora-wip with authorship kept. It merges cleanly, while this branch conflicts with aurora-wip and has no CI run on its head. Review of the retry path ( One point to carry to #48, which doesn't seem to have been raised yet: the failing start in the traced J700 boot read HW row: on #48's head. J700, the chain arrangement, at least 300 boots alternating with regular boots (where all four failures came from), with a count of starts that needed the reset. J773g, three native boots. Both with Linux root on NVMe, 0 failed units and 0 new kernel errors. Assisted-by: LLM (Claude:Opus 5.5) |
Draft: the start from off doesn't work yet. Adoption of an older aura's session passed on the Neo in kit-04. The start from off failed in kits 05 to 08; kit-08 showed ANS's CPU still stopped in its idle loop at U-Boot's run bit, so aura's power-off isn't resetting it on this path. See Tested. Don't merge before aurora-silicon/aura#107, and hold the distribution pins until an M4 Mac has booted the pair. Someone with an M4 Max is working with us and may be able to run it.
aura#107 changes how a post-M4 ANS (M4, M4 Pro and Max, and T8140) gets from aura to U-Boot. aura no longer hands U-Boot its running session. It shuts ANS down after its own use, as it already does on M1-M3, and powers ANS's PCIe block off and back on before U-Boot. U-Boot then finds ANS powered with its CPU stopped, plus the SART entries the firmware's buffers need.
The first version of this PR restarted ANS inside U-Boot: a full power cycle of ANS and APCIe with the PHY tables, read from the DT that aura#112 filled. All of that is gone. U-Boot now only writes the SART entries back, sets the run bit and starts the firmware as after a power loss, then sets the controller up as before. It needs no PHY code, no APCIe tables and no power-domain handling.
The DT property
One property on the ANS
nvmenode, written by aura (aura#107) when ANS will be off at the payload's start:Three 64-bit cells per SART entry. It isn't T8140-specific:
apple_nvme_probe()reads it on every post-M4 controller. U-Boot deletes it from the tree it hands the OS, because U-Boot leaves ANS running for Linux. Nothing else goes in the DT for this.apple_nvme_probe() on a post-M4 controller
apple,sart-entriesapple_rtkit_boot_warm()), then sets the controller up; on a failure,ANS didn't start from off (<err>); it stays down until a rebootU-Boot to Linux stays live: Linux still adopts a running ANS. To take the same path at boot, Linux would need three things: read
apple,sart-entriesat probe and write the entries back, the APCIe and PHY bring-up its wake path already has (t8140-sleep.c), and the warm RTKit start that today only runs on resume.Commits
arm: apple: sart: write an entry back after a power lossaddssart_set_entry().arm: apple: rtkit: start an IOP after a power loss under kept firmware stateaddsapple_rtkit_boot_warm(), the existing boot with a flag: no INIT, the endpoint map answered as macOS does after a wake (bit 1 on every part but the last, the last masked by the caller), no endpoint started again, then AP power on. IOP and AP power reports that come during the handshake are recorded, and other endpoints' messages dropped.nvme: apple: start a post-M4 ANS the boot loader powered offaddsapple_nvme_start_from_off(), the generic handshake check and the fixup that drops the property from the OS's tree.Compatibility
Stage 1 comes from the installer, which bundles one at build time and replaces an installed Stage 1 when they differ. Stage 2 (on the ESP) and U-Boot come from the distro packages, pinned apart. "Old aura" hands its running ANS session on. "New aura" is aura#107. "#38 + removal" is the held follow-up (#40) that drops the adoption.
For a normal boot (Stage 1, then Stage 2 with U-Boot inline, then Linux):
apple,sart-entries, and adopts it as before. Works: kit-04 rowlegacypassed on the Neo.loudpassed on the Neo with this message.nvme.sart=. Stage 2 brings the PCIe block back and writesapple,sart-entries. U-Boot starts ANS from off. Not yet shown: in kit-05 and kit-06 rowchain(Stage 2 in Stage 1's place) aura's half passed and U-Boot's start failed (kits 05 to 07, see Tested); kit-08 reruns it.nvme.sart=. On T8140 itspcie_init()skips the PHY-IP tables on the powered-off PHY; on T8132 it tries a cold handshake. No NVMe.boot=(aura loads Linux itself): new aura starts ANS (from off, or off and on from an older stage's session) and leaves it running for Linux, which adopts it as today. U-Boot doesn't take part.aura#112's tables play no part in booting. Only Linux's deep sleep reads them.
The three "No NVMe" rows are reachable today: an installer with a new Stage 1 on an image with an older U-Boot or Stage 2, or a distro bumping one pin without the other. So none of this ships until the installer and all three distros move together. The distro side is in aurora-silicon/alarm-aurora#174, aurora-silicon/fedora-aurora#213 and aurora-silicon/nixos-aurora#178 (drafts: each package requires the other's version). The installer needs the same gate and has no PR yet.
Pre-M4
Pre-M4 controllers boot ANS through
apple_nvme_boot()as before. #23 restarted a pre-M4 ANS and broke the M2 (T8112,apple_rtkit_bootreturned -110), and #25 reverted it. Nothing here touches that path: every change is behindpost_m4in the match data.Measured
The first version passed row 3 of ANS-chain-kit-03 on the Neo (J700) on 2026-11-08: after a full power cycle, the SART wrote back 6 entries, HELLO came 0 ms after the run bit, the endpoint map was
0x51f/0x3, and ANS was on at 67 ms. U-Boot then read its env and the initramfs (32 MB in 28 ms) and Linux came up with its root on NVMe. That run is where the warm start and SART write-back here come from. It also showed IORVBAR and the I2A mailbox survive the power cycle, so this version doesn't touch them.This version hasn't run.
Tested
apple_m1andapple_j873withWERRORbuild clean with gcc 16.1.1 (0 warnings) in the build guest, which verified clean before and after. checkpatch has nothing on the series.09973be235with-DDEBUGonnvme_apple.oandrtkit.o, aura#107 at7ee13f10plus aura#112, -77 with its root on NVMe:legacypassed: the Neo's installed Stage 1 (an older aura) handed its session on running, and this U-Boot adopted it as before. It read its env and the initramfs from NVMe (32 MB in 27 ms) and handed the session to Linux, which came up with its root on btrfs from NVMe, NVMelive, 64 MiB direct at 1.0 GB/s, and sync.chaindidn't reach U-Boot. aura's Stage 2 failed its cold PHY bring-up after powering ANS off (pcie: PHY clock enable timed out), fixed in aura#107.chain, 2026-11-08 11:46 UTC, the same U-Boot image (09973be235): aura powered ANS off, brought its PCIe block back and passed 6 SART entries inapple,sart-entries. U-Boot wrote them back and set the run bit, then readrtkit_boot: unexpected message type 7(an IOP power-state acknowledgement) where HELLO comes first, and failed withANS didn't start from off (-22); it stays down until a reboot. Loud, no hang. - ANS-chain-kit-06, 12:06 UTC, with a drain of the mailbox before the run bit (b276b4ee3c) and one in aura after its idle: neither found a message, and U-Boot failed the same way. So the report came from the firmware after the run bit. The warm start, as reworked intortkit_boot(), took the next management message as HELLO and the one after as the endpoint map, and failed on anything else. This PR's first version (kit-03) waited for HELLO and dropped what came first; Linux handles power reports in any order. This head (a20e374b2d) has the warm handshake record IOP and AP power reports and drop other endpoints' messages wherever they come, each with a debug line, and prints an unexpected message in full. The drain is gone.a20e374b2dwith kit-05's aura: aura's half passed a third time. U-Boot loggedrtkit: endpoint 0x0 message 0x70000000000020 in the handshake, the IOP reporting its power ON (0x20), and then no HELLO within 1 s:ANS didn't start from off (-110). So after the run bit the firmware went straight to ON, as one that kept running would, instead of restarting. The starts that got HELLO first are macOS after a sleep (it writes the mailbox's I2A control to 0x20001 just before the run bit), this PR's first version in kit-03 (it wrote IORVBAR and enabled I2A before the run bit), and aura's own start, which follows a session with no NVMe shutdown. U-Boot's follows an NVMe sleep shutdown (CC.SHN 3) and wrote neither. This head (66b55b3783) enables I2A receive before the run bit, as macOS does, and logs ANS's CPU and mailbox state just before it. If the firmware still reports power on with no HELLO, it takes that as the kept session picked back up: AP power on, then the controller setup as before, with a debug line saying so. ANS-chain-kit-08, runk08-chain2, 13:05 UTC (the first run lost the chainloaded file on the ESP to an unflushed copy and never reached U-Boot): aura's half passed. U-Boot loggedbefore the run bit: CPU 0x0 status 0x6a, mailbox A2I 0x20001 I2A 0x20001, then the samemessage 0x70000000000020(IOP power ON) andANS didn't start from off (-110). I2A receive was already on, so enabling it changed nothing. CPU status 0x6a has stopped (bit 1) and idle (bit 5) set: ANS's CPU was still stopped in its idle loop after aura's power-off and kboot's power-on, so it kept its state rather than restarting. The resumed-session path didn't run. The likeliest reading is HELLO after the power report, then no endpoint map within 1 s, but the warm path logs no HELLO, so which wait timed out isn't certain. Neither path passed.loudran nvme: apple: drop the post-M4 adoption #40 on09973be235and passed: it refused with its message.Size
First version: +1107/-22. Now: +174/-33, in five files.
Base branch
This targets
aurora-wip, notmain, which is 99 commits behind. #23, its revert #25, and the CTXR window (#32, #36) all landed onaurora-wip, and the distribution packages pin it.🤖 Generated with Claude Code