Skip to content

arm64: spin table: close the holding pen behind each released CPU (deep-sleep wake panic) - #2192

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
m0d16l14n1:j815/spin-table-pen-release
Nov 25, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
m0d16l14n1:j815/spin-table-pen-release

Conversation

@m0d16l14n1

@m0d16l14n1 m0d16l14n1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The spin-table holding pen is never closed after a CPU is released. After boot, secondary_holding_pen_release still holds the last CPU's MPIDR, and secondary_data.task still holds its idle task (__cpu_up() only clears it on failure).

With the restartable spin table (aurora,rvbar-spin-table), a CPU comes back through the pen whenever the SoC restarts it at its reset vector: after a sleep's commit, and at the wake. The CPU whose MPIDR is still in the pen goes straight through it, ahead of its own bring-up:

  • It runs secondary_start_kernel() as that CPU, with no STARTING callbacks run, so it has no tick device.
  • It marks itself online, so the real bring-up returns at once.
  • It then faults at the first menu_select() after cpuidle_resume().
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020
CPU: 9 UID: 0 PID: 0 Comm: swapper/9
pc : tick_nohz_get_sleep_length+0x68/0xd4
 menu_select -> cpuidle_select -> do_idle -> cpu_startup_entry -> secondary_start_kernel
Kernel panic - not syncing: Attempted to kill the idle task!

The J815 hit this when every core was started together at the end of the wake, as macOS does (the next PR in this series). The same stale value can let a core through after the commit too, because the pen checks the release before secondary_pen_deep.

Change

  • The released CPU resets the release to INVALID_HWID in cpu_postboot. That runs before complete(&cpu_running), so it can't race with the next bring-up.
  • The release is reset again before a suspend's hold and after the wake, before any CPU is started.
  • secondary_data.task is cleared after a successful bring-up, as before 5.x, so a stray core parks in __secondary_too_slow.

Tested on J815 (MacBook Air 15" M5):

  • Two real deep sleeps (256 s and 172 s) with all nine secondary cores started together at the wake: all back online, no oops.
  • The same kernel without this change panicked on the first wake (trace above).
  • Rebased onto integration/aurora cc14570: W=1 adds no warnings in arch/arm64/kernel/. checkpatch --strict gives one warning, for the quoted oops line in the commit message, which is kept unwrapped.

J813 (sithglan, gig3m): 8 deep sleeps with this as the first commit of #2193, in their comments there.

Still owed (HW rows): the smp.c hunk is generic arm64, so one plain spin-table Mac (M1 or M2) booted on this kernel with all CPUs online; and the regression line for the J815 run (0 failed units, 0 SELinux denials, 0 new kernel errors).

Part of the J815 bring-up; board results are summarised in #135.

@sithglan

Copy link
Copy Markdown
Contributor

Tested on J813 as the first commit of #2193 (head 8e270f6 on integration/aurora 0abc2f3). Details are in #2193 (comment).

  • The J813 boots with maxcpus=1 and onlines the other nine CPUs from userspace. That bring-up works with the pen closed: CPUs 0-9 online.
  • Eight real deep sleeps (8 to 180 s) on one boot, no oops. All ten CPUs were back after every wake.
  • Two of them ran with soc: apple: sleep: T8142: start the cores and write the cluster words as XNU (on #2192) #2193's switches back at the old behaviour (cpu_burst=0 cluster_rmw=0 perf_down=1), which leaves this commit's one-by-one start.
  • The other six ran with the wake burst, so cores waited in the pen until their bring-up released them.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 1.

The ordering is sound. smp_rvbar_spin_table_postboot() resets the release at arch/arm64/kernel/smp_spin_table.c:488. It runs from secondary_start_kernel() (arch/arm64/kernel/smp.c:243-244), before complete(&cpu_running) (smp.c:271), so the boot CPU's next write_pen_release(mpidr) in smp_rvbar_spin_table_cpu_boot() (smp_spin_table.c:355) can't race with it. The resets at smp_spin_table.c:226 (before the hold) and :338 (after the wake, before any start) close the post-commit window. Clearing secondary_data.task at smp.c:148 is safe because the CPU has already read the task in __secondary_switched before it can complete cpu_running. The clean to PoC matches what update_cpu_boot_status() does for the MMU-off reader.

  1. Commit 3cf4478 has a Co-Authored-By: Claude Opus 5.5 <[email protected]> trailer and the same Signed-off-by twice. Keep one human Signed-off-by and drop the co-author trailer. The PR body ends in a "Generated with Claude Code" line with an emoji. Replace it with Assisted-by: LLM (Claude:Opus 5.5).

HW row: J815 (2 deep sleeps, burst start) and J813 (8 deep sleeps) cover the new path. The smp.c hunk is generic arm64, so also boot one plain spin-table Mac (M1 or M2) on this kernel with all CPUs online. Add the regression line for the J815 run: 0 failed units, 0 SELinux denials, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

secondary_holding_pen_release is written with a CPU's MPIDR to let it
out of the pen and never reset, so after boot it still names the last
CPU released. secondary_data.task likewise keeps that CPU's idle task:
__cpu_up() only clears it on failure.

With the restartable spin table (aurora,rvbar-spin-table) a CPU comes
back through the pen whenever the SoC restarts it at its reset vector:
after a system sleep's commit, and at the wake. The CPU whose MPIDR is
still in the pen walks straight through into secondary_startup, ahead of
its own bring-up, and runs secondary_start_kernel() as that CPU with
the stale task. The hotplug state machine has not started it, so no
STARTING callback runs (no arch timer, no tick device), yet it marks
itself online and completes cpu_running, so the real bring-up returns
at once. It idles quietly while cpuidle is paused and faults at the
first menu_select() after cpuidle_resume():

  Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020
  CPU: 9 UID: 0 PID: 0 Comm: swapper/9
  pc : tick_nohz_get_sleep_length+0x68/0xd4
  Call trace:
   tick_nohz_get_sleep_length+0x68/0xd4 (P)
   menu_select+0x414/0x774
   cpuidle_select+0x1c/0x28
   do_idle+0x1e8/0x310
   cpu_startup_entry+0x34/0x38
   secondary_start_kernel+0x198/0x1bc
  Kernel panic - not syncing: Attempted to kill the idle task!

Seen on a J815 (MacBook Air 15" M5) when every core was started at the
end of the wake, as macOS does, instead of one by one at its bring-up.

Reset the release to INVALID_HWID in the released CPU's cpu_postboot,
which runs before complete(&cpu_running), so it can't race with the
next bring-up; and again before a suspend's hold and after the wake,
before any CPU is started. Clear secondary_data.task after a successful
bring-up too, as kernels before 5.x did, so a core that still reaches
__secondary_switched without a bring-up of its own waits in
__secondary_too_slow instead of running as another CPU.

Tested on J815: two real deep sleeps (256 s and 172 s) with all nine
secondary cores started together at the wake, all back online, where
the same kernel without this change panicked on the first wake.

Signed-off-by: Nick <[email protected]>
@m0d16l14n1
m0d16l14n1 force-pushed the j815/spin-table-pen-release branch from 3cf4478 to c5daf57 Compare November 21, 2026 12:51
@m0d16l14n1

m0d16l14n1 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@RyanTheTide fixed: one human Signed-off-by, no co-author line, and the body ends with Assisted-by: LLM (Claude:Opus 5.5).

Rebased onto cc14570, and arch/arm64/kernel/ is W=1-clean. The M1/M2 spin-table boot and the J815 regression line are still owed.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of c5daf57: No blockers.

Earlier point 1 resolved: the commit has one human Signed-off-by and no co-author trailer, and the PR body ends with Assisted-by: LLM (Claude:Opus 5.5). The code is the same patch as before the rebase (arch/arm64/kernel/smp.c:142-152, arch/arm64/kernel/smp_spin_table.c:226, :338, :488), so the ordering analysis from the last review still holds.

HW row (still owed): one plain spin-table Mac (M1 or M2) booted on this kernel with all CPUs online, since the smp.c hunk is generic arm64; and the regression line for the J815 run: 0 failed units, 0 SELinux denials, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The holding-pen change is still needed. Head c5daf572c69c replays cleanly onto integration/aurora 5441428d9033. Both smp.o and smp_spin_table.o build for arm64. The M1/M2 spin-table boot control remains open.

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

Review at c5daf57. Clearing the release word in postboot closes the pen before the secondary publishes cpu_running. Clearing the task after the CPU-online check leaves the failed bring-up path intact. This changes the generic arm64 task publication as well as the Apple reset-vector path. Keep the reported deep-sleep row separate from a plain J413 cold boot that checks all CPUs online and a short resume regression. The host check is green.

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

Formal §1–§6 pre-PR checklist review at c5daf572c69cf596d254050089476e9793f67e53 against integration/aurora (70a00e583b03):

The synchronization and ordering in the patch are sound and still needed on integration/aurora (merges cleanly, CI host-tests green):

  • smp_rvbar_spin_table_postboot() resets secondary_holding_pen_release to INVALID_HWID before set_cpu_online() and complete(&cpu_running) in secondary_start_kernel(), so it cannot race with the boot CPU's next write_pen_release(mpidr).
  • spin_table_hold_parked() and spin_table_stop_finished() close the suspend-commit and wake windows before any secondary is started.
  • Clearing secondary_data.task in __cpu_up() after cpu_online(cpu) is safe because __secondary_switched already consumed secondary_data.task before secondary_start_kernel() could complete cpu_running.

Checklist findings:

  • §1 No model gating: PASS on gating (zero chip/board/firmware gates), but note cross-Mac coverage below because the arch/arm64/kernel/smp.c hunk runs on every Apple Silicon Mac (including plain spin-table M1/M2).
  • §2 Production-ready, no hacks: PASS. Default command line, no sleeps/retries or parameters.
  • §3 Safety: PASS. Prevents a real NULL-deref wake panic.
  • §4 Clean-room & attribution: PASS. Commit c5daf572c69c carries human author/committer (Nick <[email protected]>) and a single human Signed-off-by: with zero AI trailers; PR body ends with Assisted-by:.
  • §5 Evidence: BLOCKER (still owed). J815 (2 deep sleeps) and J813 (8 deep sleeps via #2193) cover the aurora,rvbar-spin-table wake path, but the two hardware items explicitly listed as still owed in the PR body remain open:
    1. One plain spin-table Mac (M1 or M2) cold-booted with this change verifying all CPUs come online cleanly (covering the generic arch/arm64/kernel/smp.c hunk).
    2. The full §5 regression line for the J815 run (0 SELinux denials, 0 failed units, 0 new kernel errors).
  • §6 Naming: PASS.

Non-blocking edge-case note: in smp_rvbar_spin_table_cpu_boot(), write_pen_release(mpidr) runs before spin_table_power->cpu_on(mpidr), and __cpu_up() returns early on a boot_secondary() error without clearing secondary_data.task — if cpu_on() ever fails, both the pen release and secondary_data.task remain set until the next bring-up or sleep hold. Resetting them on the cpu_on() error path would tighten that corner case, though it is not a merge blocker.

Posting the plain spin-table (M1/M2) control boot and the J815 regression line will clear this PR.

@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at c5daf572: ready to merge

Check Detail
CI at head ok 2 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at c5daf572
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: none matched in CODEOWNERS
Merge: gh pr merge 2192 --merge (Owners and Core through the bypass: add --admin).

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

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

Verdict: FINISH, then merge at c5daf572c69c: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: this changes CPU bring-up for every spin-table Mac, so one plain spin-table Mac (M1 or M2) needs a cold boot at this head with all CPUs online and a CPU offline/online cycle. The J815 and J813 deep-sleep runs cover the aurora,rvbar-spin-table wake path. Thanks for tracking down the wake panic.

Checked: no Apple material, no gates: the holding pen closes behind each released CPU. CI green.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 25, 2026 05:34

Superseded by the review at c5daf57

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

J815 (MacBook Air 15" M5) row at 8be9e731e313 (on #2192 c5daf572c69c), in a batched candidate.

Candidate: m0d16l14n1/linux j815/prtest-r6 8ad9358 = main 70381bd with these PR heads merged unchanged: #2384 f9d03e8, #2385 b1c3392, #2192 c5daf57, #2193 8be9e73, #3123 227c89b, #3124 1a272ce, #3125 4ad71b8, #3129 6d5ec4d, #3130 76bf36c, plus the open J815 PRs. Stage 2: aura main 508390223 + aura#391/#165/#363. Command line: default + pcie_aspm=off apple_sleep.deep=1 nvme_apple.sleep_untested=1 appledrm.s2r_untested=1 apple_sep.xart_writes=0 apple_sep.provision_keybag=0.

The earlier J815 rows couldn't reach the commit (refused by DCP/SEP before it). With #2384, #3129 and #3130 in the same tree, one timed deep sleep and wake:

apple-sleep: wake: 9 cores started in one burst; stop/sys/e/p now 0/0/0/0
Timekeeping suspended for 24.464 seconds
sleep 1: rc 0, '9 cores started in one burst' x1, 9 Booted secondary processor, online 0-9, suspend_stats fail 0

No panic on the wake, no core retried.

Regression on the same boot (6aaae3d9, after the wake): 0 SELinux denials (SELinux off), 0 failed units, 0 new kernel errors vs the previous boot, 0 WARN/BUG/Oops.

Not yet: more than one cycle per boot; J813.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 25, 2026
@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

J815 (MacBook Air 15" M5) row at c5daf572c69c unchanged: PASS.

Candidate: m0d16l14n1/linux j815/prtest-r7 d70fd05 = main a60fef7 with these PR heads merged unchanged: #2384 f9d03e8, #2385 b1c3392, #2192 c5daf57, #2193 8be9e73, #3123 822a1dd, #3124 1a272ce, #3125 4ad71b8, #3129 6d5ec4d, #3130 76bf36c, plus the open J815 PRs (r6 + #3123's new head). Stage 2 as on r6. Command line: default + pcie_aspm=off apple_sleep.deep=1 nvme_apple.sleep_untested=1 appledrm.s2r_untested=1 apple_sep.xart_writes=0 apple_sep.provision_keybag=0 apple_sleep.t8142_wake_s=0 (the last one turns off the timed PMU wake, so the sleep lasts until a key).

One deep sleep with no timer, woken by a key on the built-in keyboard after about 10 minutes (boot 9325546c): Timekeeping suspended for 603.654 seconds, 9 cores started in one burst, CPUs 0-9 online, suspend_stats success=1 fail=0; the wake source is the built-in keyboard/trackpad. Panel, NVMe, Wi-Fi (up 5 s after the wake) and Bluetooth (LE mouse still connected, 0 TX/RX errors, exec 2 / IPC 2) back.

Regression on the same boot, after the wake: 0 SELinux denials (SELinux off), 0 failed units, 0 new kernel errors vs the previous boot, 0 WARN/BUG/Oops.

@RyanTheTide

Copy link
Copy Markdown
Contributor

c5daf572c69c J316s (M1 Pro, spin-table SMP peer) PASS: 10/10 CPUs online, 0 failed, 0 AVC, 0 SMP/spin-table errors, s2idle 1/1, GL+Borealis VK ok.

Verification details (exact head c5daf572c69cf596d254050089476e9793f67e53, guarded one-shot, default cmdline)
  • J316s (M1 Pro, T6000) (7.3.0-aurora-pr2899-2192, boot_id=6cc8f2f5):
    • All 10 CPUs (present=0-9, online=0-9, nproc=10, DT enable-method = "spin-table") brought online cleanly (smp: Brought up 1 node, 10 CPUs, SMP: Total of 10 processors activated., smp_err=0).
    • Plain spin-table offline attempts on cpu1 and cpu9 returned expected -EOPNOTSUPP (Operation not supported, no cpu_die), leaving online=0-9.
    • rtc1 s2idle 1/1 (suspend_stats: success=1 fail=0, post-s2idle online=0-9).
    • GL (Apple M1 Pro (G13S C0)) + Borealis VK smoke PASS (cases=1 rc=0), 0 AVC, 0 failed, Enforcing.
    • Restored & verified on saved 7.3.0-aurora-fleet89 (boot_id=f41c88f7, trial kernel removed).

@DjDeveloperr
DjDeveloperr merged commit 89542c5 into aurora-silicon:main Nov 25, 2026
5 checks passed
RyanTheTide added a commit that referenced this pull request Nov 26, 2026
soc: apple: sleep: T8142: start the cores and write the cluster words as XNU (on #2192)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-template PR body lacks Tested or Risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants