Skip to content

smp: keep the SMP_SHARED state in .bss, out of the file (16 KiB on every toolchain) - #611

Merged
RyanTheTide merged 1 commit into
mainfrom
fix/smp-shared-bss
Nov 30, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
fix/smp-shared-bss

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

The SMP state that a core reads with its MMU off or uncached (reset stacks, spin table, S2R mailbox, kernel park slots: SMP_SHARED in smp.c) had a 16 KiB page of its own at the start of .data. All of it is zero except three initial values, but the page was in the file part of every image, before _file_vital_end. That is the part the ESP Stage 2 has to keep below the panel DCP's log buffer.

This puts those pages at the start of .bss (.bss.smp_shared) in aura-raw.ld and aura.ld. They are still 16 KiB pages of their own: memory.c maps exactly [_smp_shared_start, _smp_shared_end) uncached, smp.c cleans that range to PoC for T8152, and S2R cleans [_data_start, _bss_end) as before. _start_c clears .bss and then calls the new smp_shared_init(), which sets the three values that don't start as zero: boot_cpu_idx = -1, spin_table = spin_table_image, and an MPIDR of ~0 in every smp_reset_stacks entry. Nothing reads them earlier. No secondary runs, and no reset comes back into the image, before smp_init(). On T8142 the secondaries already avoid the whole boot object (.bss included), so that path is unchanged.

Why this and not only #609: packed relocations (#609) free about 70 KB, but only with lld or GNU ld 2.43 and later. GNU ld 2.42 (Ubuntu 24.04) ignores -z pack-relative-relocs on AArch64. Every distribution package links with lld (fedora-aurora aura.spec, alarm-aurora PKGBUILD, nixos-aurora pkgs/aura.nix, all USE_CLANG=1). Two shipping builds link with GNU ld 2.42, though: this repo's release.yml (the release assets, ubuntu-latest) and aurora-installer's uefi-only-build.yaml (ESP_STAGE2=1). So a binutils bump on the gcc CI leg alone, or a check that refuses ld < 2.43, wouldn't fix what ships. This change frees 16 KiB with every toolchain. It doesn't depend on #609 and merges with it cleanly in either order.

ESP Stage 2 headroom in bytes (tools/stage1_size.sh, floor 4096, warning below 8192), base main fa05512:

tree gcc + GNU ld 2.42 (ubuntu 24.04) gcc 15 + GNU ld 2.46 (ubuntu 26.04) fedora:44 clang + lld
main 4160 (warning) 10928 5920 (warning)
main + this 27392 27312 27936
main + this + #601 + #604 10424 26728 27328
main + #609 + this + #601 + #604 10424 108648 92864

Stage 1 (dev) headroom, gcc 2.42: main 44056, this 60440, all four 43472. fedora: main 44592, this 60976, all four 125904. All flavours pass in every run. The release workflow's own configuration (make ARCH=aarch64-linux-gnu- RELEASE=1 CHAINLOADING=1 ESP_STAGE2=0/1, GNU ld 2.42) gives the same numbers.

Tested:

  • Full host pytest: 1507 passed, 26 skipped on this branch. On main + Pack the relative relocations (RELR) to free ESP Stage 2 room #609 + this + kboot: T8152: hand the running internal-panel DCP to Linux (successor of #289) #601 + kboot: default the display on the J504, J514C, J514M and J516M, admitted from the ADT #604: 1623 passed, 28 skipped.
  • New tests/python/test_smp_shared_bss.py: no SMP_SHARED declaration has an initializer (re-adding = -1 fails it), smp_shared_init() sets the three values and _start_c calls it right after clearing .bss, and both linker scripts place .bss.smp_shared on its own pages at the start of .bss. test_stage1_room.py's layout check on a real link now also asserts _file_end <= _bss_start == _smp_shared_start < _smp_shared_end.
  • stage1_size.sh with gcc + GNU ld 2.42 (aurora-s1gcc), gcc 15 + GNU ld 2.46 (ubuntu:26.04) and fedora:44 clang (Fedora RUSTFLAGS, BUILDSTD=1) on the trees in the table.
  • Buildbox clang 22 builds of this branch and of the four-PR combination: ESP Stage 2 release, ESP Stage 2 + DEBUGUSB_PROXY=1, SPTM_VIRT=1 SPTM_VIRT_ESP=1 AURACTL=1 -Oz, and default Stage 1. All link. readelf: .bss is still NOBITS, and _smp_shared_start == _bss_start == _file_end, 16 KiB aligned, with the SMP_SHARED symbols inside it.
  • clang-format 22 clean on the changed C files.

Rows needed before merge: this changes SMP init on every Mac.

  1. A one-shot boot of Stage 1 + ESP Stage 2 built at this head (method-T chain, kits/aura/20261123-stage1-signoff/s1so.sh) on J615 (T8122). Check that every CPU in the ADT comes online in Linux (nproc, no SMP: failure lines in the aura log), and do a CPU offline/online cycle (reset stacks).
  2. A second family as the regression row: J473 (T6020).
  3. An s2idle/deep-sleep resume on a Mac that resumes through aura's S2R mailbox and kernel park (Neo, T8140, rtc0). Those structures moved.

They can be combined with #609's J615/J473 rows by building main + #609 + this.

Risk: two-way · all Macs (SMP bring-up, reset and S2R state now zeroed at start and initialized in smp_shared_init())

@DjDeveloperr: code-owner ping. This is the toolchain-independent room for #601/#604, which #609 can't give on GNU ld 2.42.

The state a core reads with its MMU off or uncached (reset stacks, spin
table, S2R mailbox, kernel park slots) had a 16 KiB page of its own in
.data. Every byte of it but three initial values is zero, yet the page
sat in the file part of every image, before _file_vital_end, where the
ESP Stage 2 has to end below the panel DCP's log buffer.

Put it on its own pages at the start of .bss (.bss.smp_shared) in both
linker scripts. memory.c still maps exactly those pages uncached and
smp.c still cleans them to PoC; S2R cleans [_data_start, _bss_end) as
before. _start_c clears .bss and then calls smp_shared_init(), which
sets the three values that do not start as zero: boot_cpu_idx -1,
spin_table at spin_table_image, and an MPIDR of ~0 in every
smp_reset_stacks entry. Nothing reads them earlier: no secondary runs
and no reset can come back to this image before smp_init().

This frees 16 KiB of the file on every toolchain. Packed relocations
(aura#609) free more, but only with lld or GNU ld 2.43 and later; the
release workflow and the installer's UEFI-only build link with Ubuntu
24.04's GNU ld 2.42, which ignores -z pack-relative-relocs on AArch64.
gcc + GNU ld 2.42, ESP Stage 2 headroom: main 4160 B, this 27392 B;
main + this + #601 + #604 (with or without #609) 10424 B.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 30, 2026 09:19
@github-actions github-actions Bot added blast:all 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 e7a148f0: not ready yet

Check Detail
CI at head ok 28 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA e7a148f0, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · all Macs (SMP bring-up, reset and S2R state now zeroed at start and initialized in smpsharedinit()) @DjDeveloperr: code-owner ping. This is the toolchain-independent room for #601/#604, which #609 can't give on GNU ld 2.42.

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 e7a148f0 for hosted checks and the SMP hardware rows.

Checked: The normal entry reaches the BSS clear and restores the three nonzero initial values before secondary bring-up. The linker scripts keep the shared state on its own aligned pages. The non-T8152 uncached mappings and T8152 clean still use the shared bounds, and the S2R full-data clean spans the new BSS placement. The T8142 alternate secondary block remains separate. Seven focused SMP and linker-layout cases passed locally across GNU ld and lld.

Please retain the two-family one-shot boot and CPU reset coverage and a real S2R mailbox resume at the landing head, with the existing owner approval for the Stage 1 trial.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

SMP + S2R row on the MacBook Neo (J700, T8140), built together with #609. PASS.

Tested:

  • Tree: main 7dbbeb1 + Pack the relative relocations (RELR) to free ESP Stage 2 room #609 649298b + smp: keep the SMP_SHARED state in .bss, out of the file (16 KiB on every toolchain) #611 e7a148f, merged locally (9b012556). ESP Stage 2 with the package flags
    (make BUILDSTD=1 RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1 USE_CLANG=1 BUILTIN_LOGO=aurora, buildbox clang 22), 1.0.0b17-g9b012556.
    readelf/nm: _smp_shared_start == _bss_start == _file_end (0x150000), _smp_shared_end 0x160000, .bss NOBITS,
    boot_cpu_idx, spin_table, smp_reset_stacks inside it. tools/stage1_size.sh (clang 22): all five flavours pass,
    esp-stage2 headroom 93472 B.
  • Neo one-shot (aura-try of that image + the Neo's own DTB/U-Boot tail under the installed Stage 1 1.0.0b10, trial guard +
    dead-man), with the same checks on the saved Stage 2 1.0.0b17 first as the A/B baseline:
    • Every ADT CPU online: aura Starting CPU 0/1/2/3/5 ... Started, MPIDR 0x0/0x1/0x2/0x3/0x10101 (boot CPU 4), Linux
      smp: Brought up 1 node, 6 CPUs, 6 DT cpu nodes, online 0-5. Same as the baseline.
    • CPU offline/online (kernel park, spin-table CPUs can park: the boot object brings them back): cpu1-5 off, then on,
      all Booted secondary processor, online 0-5. PASS on the fresh boot, after deep T6041 (J616C, M4 Max 16"): FDT-scoped DAPF init and NVMe split-BAR admission #1 and after deep pmgr: don't refuse the whole table for a parent the ADT does not list #2.
    • s2idle (rtcwake -d rtc0 -m mem, mem_sleep s2idle): success +1, fail 0.
    • deep (mem_sleep deep, rtc0), twice: apple-sleep ...: back from sleep, boot object resumes 0 -> 1, then 1 -> 2,
      Enabling non-boot CPUs with CPU1-5 up, online 0-5 afterwards. Baseline: one deep, 0 -> 1, same lines.
    • Enforcing, 0 failed units, 0 AVC; kernel errors identical to the baseline (one dwc3 genpd_prepare returns -11 per sleep).
  • Restored: saved Stage 2 running, aura-try absent, trial files removed, GRUB boot_success=1, next_entry empty, Enforcing,
    0 failed. Silent. Stage 1, LocalPolicy, NVRAM and the installed Stage 2 were not written.

Evidence: traces/boot/20261130-609-611-neo (README, per-boot logs). Rows 1 (J615) and 2 (J473) of the list in the description
are still separate; the #609 J615 one-shot (traces/boot/20261130-609-rows) predates this PR's code.

@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 e7a148f0 for the remaining CPU boot/reset rows. Hosted CI and the live S2R row are satisfied.

Checked: The Neo combined Stage 2 includes this exact head and #609. It brought all six CPUs online, hotplugged CPU 1–5 before and after sleep, and completed both deep resumes via the boot object. The saved-image control and restoration receipt preserve the baseline. That is the requested Neo S2R coverage.

Keep the outstanding J615 and J473 CPU boot/reset rows, or record the maintainer's disposition for their scope. The Neo trial used the installed Stage 1 and covers the new Stage 2 path.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Row 1 (J615, MacBook Air M3, T8122): method-T chain one-shot of Stage 1 + ESP Stage 2 built with #609 and this PR. PASS.

Tested:

  • Tree: main 7dbbeb1 + Pack the relative relocations (RELR) to free ESP Stage 2 room #609 649298b + smp: keep the SMP_SHARED state in .bss, out of the file (16 KiB on every toolchain) #611 e7a148f, merged locally (43abc435). Buildbox clang 22, shipping flavours:
    Stage 1 make RELEASE=1 CHAINLOADING=1 BUILTIN_LOGO=aurora USE_CLANG=1 BUILDSTD=1, ESP Stage 2 the same + ESP_STAGE2=1,
    both 1.0.0b17-g43abc435. readelf/nm: .rela.dyn empty, .relr.dyn present; _smp_shared_start == _bss_start == _file_end
    (S1 0x140000, S2 0x150000), boot_cpu_idx, spin_table, smp_reset_stacks inside the NOBITS page.
  • Chain: the installed Stage 1 (1.0.0b13) took a one-shot aura-try marker and chainloaded the candidate Stage 1 once; that Stage 1
    loaded the candidate ESP Stage 2 with this Mac's own DTB/U-Boot tail. Installed Stage 1, configured Stage 2, LocalPolicy, NVRAM
    and GRUB were not written. Baseline: the same checks on the saved chain (Stage 2 1.0.0b15) in the same session.
  • Versions: Stage 1 log aura 1.0.0b17-g43abc435, cmdline: aura-trial; /chosen stage2 version 1.0.0b17-g43abc435.
  • Move then relocate: aura moved itself from 0x10006d98000 to 0x10004968000, the run base stage 1 gave it;
    chainload: image staged at 0x10009244000 runs its first 0x3b4000 bytes at 0x10004968000; the next-stage sha matches the candidate.
  • Logo and console: fb: display logo, fb console: max rows 54, max cols 74; simpledrm fb0 + fbcon, gdm up.
  • Linux: running, Enforcing, 0 failed units, 0 AVC.
  • CPUs: ADT has 8 CPUs (cpu0-3 cluster 0, cpu4-7 cluster 1), 8 spin-table DT nodes, smp: Brought up 1 node, 8 CPUs, online 0-7
    (boot CPU smp_id 4). The J615 Stage 2 log ring wraps before Linux reads it (on the baseline as well), so aura's Starting CPU
    lines are not kept on this Mac; the count check is ADT = DT = Linux online.
  • Offline/online of cpu1-7, three cycles (kernel park, spin-table CPUs can park: the boot object brings them back): all back each
    cycle, 21 Booted secondary processor, online 0-7. Same on the baseline.
  • s2idle, rtcwake -m mem on the apple-pmu-rtc (rtc0 on this Mac; rtc1 is macsmc-rtc without a wake alarm): success 0 -> 1,
    fail 0, all CPUs online, network back. Same on the baseline. No deep on the J615 (the G16 GPU refuses it).
  • Kernel errors: identical to the main-only control of the same chain path from the Pack the relative relocations (RELR) to free ESP Stage 2 room #609 rows (main a382495); compared with the
    b15 production boot only the ANE lines that follow any b17 Stage 2 and one brcmfmac ring-pointer line differ, both present in
    that control too.
  • Restored: saved Stage 2 unchanged, no trial marker or try files, next_entry empty, Enforcing, 0 failed units. Silent row.

Second family: the Neo (T8140) combined row above (CPUs, offline/online, s2idle and two deep resumes through the boot object).

Maintainer note: the J473 row is replaced by the Neo row, because the J473 is held by ORCH5.

Risk: low. Boot-path change, now exercised on T8122 through both a chained Stage 1 and the ESP Stage 2, and on T8140 through the
ESP Stage 2 with sleep resume.

@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 e7a148f with the documented second-family disposition.

Checked: Hosted CI passed. The J615 combined method-T trial included the exact #611 head in both candidate stages, brought all eight CPUs online, completed 21 secondary CPU returns and one s2idle resume, and restored the saved boot. The Neo combined Stage 2 row exercised six CPUs, hotplug and two live deep resumes through the boot object. The maintainer accepted it in place of J473. These receipts cover the requested initialization and S2R paths at their tested compositions.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merging at e7a148f0 (merge) under the 6-point rule. (1) The review App's verdict at this head: APPROVED. (2) CI is green at this head (readiness excluded). (3/4) Rows: J615 method-T chain of main+#609+#611 PASS: 8 CPUs, 3 offline/online cycles, s2idle (traces/boot/20261130-611-j615); Neo T8140 combined row PASS incl. 2 deep resumes through S2R (traces/boot/20261130-609-611-neo); J473 row replaced by the Neo row (maintainer decision). (5) No blocking review is open. (6) Dj was pinged with no objection. Revert: git revert -m 1 <commit>.

@RyanTheTide
RyanTheTide merged commit 713ac47 into main Nov 30, 2026
32 checks passed
@RyanTheTide
RyanTheTide deleted the fix/smp-shared-bss branch November 30, 2026 12:24
RyanTheTide added a commit that referenced this pull request Dec 1, 2026
Picks up main's size work (#609 RELR, #611 SMP .bss) so the gcc esp-stage2 build clears the 4 KiB headroom floor; no conflicts.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:all 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant