Skip to content

arm64: apple: handle M4+ WFI/WFIT state loss by MIDR alone - #2286

Closed
RyanTheTide wants to merge 1 commit into
integration/aurorafrom
sweep-kcmd/wfx
Closed

RyanTheTide wants to merge 1 commit into
integration/aurorafrom
sweep-kcmd/wfx

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Apple M4 and later cores (MIDR part 0x052 and up) can lose their general-purpose and FP/SIMD registers in WFI and WFIT. This kernel already handles that on every such part through midr_is_apple_m4_or_later(): cpu_do_idle() saves the registers around WFI, and cpuinfo records WFxT as absent, so ARM64_HAS_WFXT and HWCAP2_WFXT stay off. This PR removes the per-chip leftovers from before that predicate, plus the J700 device-tree boot argument.

What changes

Before After
has_wfxt() with a T8142/T6050/T8152 MIDR list has_cpuid_feature() / HWCAP_CAP(), as upstream. The sanitised ID_AA64ISAR2_EL1.WFxT already reads 0 on every M4+ part, so the list never changed the result.
__delay() busy-waits on T8142/T6050 only Every M4+ part takes the WFE event-stream loop. arm64.nowfxt selected that path on T8152 (0 bad SHA-256 runs in 288 under schedutil on J873), and T8140 and T6040 run it today. smp_cond_load_*() and the spinlocks already run WFE on these cores all the time.
A loader's idle=nop is ignored on T8142/T6050 only Ignored on every part that takes the register-saving WFI. apple_keep_idle_nop still keeps it for comparisons.
t8140-j700.dts /chosen bootargs = "arm64.nowfxt" ("Temporary") Removed. T8140 (0x060/0x061) has been matched by the predicate since the M4+ wait-state change.
midr_is_apple_m4_or_later() with a one-line comment The comment now gives the evidence per part and explains why parts nobody measured (T8132, T6041, the other T605x variants, later parts) are matched.

Who this affects

On EFI boots (U-Boot -> GRUB -> EFI stub), drivers/firmware/efi/libstub/fdt.c replaces /chosen/bootargs with the loader's command line. Neither the DT arm64.nowfxt nor the idle=nop arm64.nowfxt aura appends ever reached those kernels, and they already ran WFI with the register save and no WFxT. For them the only change is that __delay() on T8142/T6050 uses WFE instead of spinning.

Direct (non-EFI) boots from aura or m1n1 no longer depend on loader arguments. The companion aura change stops appending them: aurora-silicon/aura#333.

Testing

  • Built with the fleet74 configuration (7.3.0-aurora-fleet74, LLVM=1): arch/arm64/kernel/{idle,cpufeature,cpuinfo,setup,smp}.o and arch/arm64/lib/delay.o, using the new asm/cputype.h, with 0 warnings. has_wfxt and its MIDR table are gone from cpufeature.o.
  • t8140-j700.dtb: dtc shows 0 warnings. Its decompiled tree differs from the fleet74 DTB only in the removed bootargs line.
  • checkpatch: 0 errors. Its 2 warnings are about the Co-Authored-By trailer.
  • No full Image was linked. The comment change in asm/cputype.h would rebuild most of the tree.

Hardware row still needed (MacBook Neo, T8140), on a direct boot with no arm64.nowfxt or idle=nop: /proc/cmdline without either, wfxt absent from /proc/cpuinfo Features, cpuidle usage counters increasing on every CPU, a SHA-256 correctness loop under schedutil, and s2idle. The idle and WFxT paths have no other per-chip logic left to test on J616s (T6040), M1 Pro or M2.

Assisted-by: LLM (Claude:Opus 5.5)

Apple M4 and later cores (MIDR part 0x052 and up) can come back from WFI
and WFIT with their general-purpose and FP/SIMD registers cleared. The
kernel already handles this on every such part through
midr_is_apple_m4_or_later(): cpu_do_idle() saves the registers around
WFI (d58647b, 34649b4) and cpuinfo records WFxT as absent
(5186d2e), so ARM64_HAS_WFXT and HWCAP2_WFXT stay off. Several
per-chip leftovers from before that predicate remained:

- has_wfxt() (848cb14, Thomas Glanzmann) kept a T8142/T6050/T8152
  MIDR list. The sanitised ID_AA64ISAR2_EL1 already reads WFxT as 0 on
  those parts and on every other M4+ part, so the list never changes the
  result. Go back to has_cpuid_feature() and HWCAP_CAP() for WFxT. Its
  comment also pointed at apple_m5_needs_wait_save(), which no longer
  exists.

- __delay() busy-waited on T8142 and T6050 only (dbb5e44), to stay
  off WFIT. WFIT cannot be reached there any more, and the WFE
  event-stream loop that remains is the same path arm64.nowfxt selected
  on T8152 (0 bad SHA-256 runs in 288 under schedutil on J873) and the
  path T8140 and T6040 run today. WFE is also what smp_cond_load_*()
  and the spinlocks run on these cores all the time. Drop the list.

- An idle=nop from the boot loader was ignored on T8142 and T6050 only
  (5c9cbb2, 72f8eec). Ignore it on every part that takes the
  register-saving WFI. Older aura and m1n1 append it on every M4+ chip,
  after the user's arguments; spinning idle costs 85-92 C against 43 C
  on T8140, about 90 C on T8142 and about 10 W on T6050.
  apple_keep_idle_nop still keeps it for comparisons.

- t8140-j700.dts set bootargs = "arm64.nowfxt" in /chosen, marked
  temporary until the kernel stopped using WFxT on T8140. The kernel
  already did (part 0x060/0x061 is matched). Remove it.

Document the per-part evidence at midr_is_apple_m4_or_later(), and why
parts nobody measured are matched (the same core generations, and later
parts by default).

On EFI boots (U-Boot -> GRUB -> EFI stub) the stub replaces
/chosen/bootargs with the loader's command line, so neither the DT
bootargs nor the arguments aura appends reached the kernel there. For
those users the only change is __delay() on T8142/T6050 using WFE instead
of spinning. Direct (non-EFI) boots stop depending on loader arguments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Hardware rows, 2026-11-20: one-shot boots of 7.3.0-aurora-sweepk2. The source is sweep-kcmd/sweepk2-kit cc59ea1, which is integration/aurora 0abc2f3 plus #2292 (make aurora_defconfig), #2286 and #2272. Each boot ran with no machine-specific kernel arguments. The test entries dropped user4k=on, plymouth.ignore-serial-consoles and the apple_sep trace/guard arguments; only root/rootflags/quiet plus the lab watchdog arguments remained.

Mac SoC boot /proc/config.gz == built config tipd command nodes 4K userspace (no user4k=on) WFI register save wfxt hwcap SHA-256 loop (schedutil) failed units / AVC / kernel errors / oops / DART faults
MacBook Neo J700 T8140 32 s yes 2 yes yes hidden 216 runs, 0 wrong 0 / 0 / 0 / 0 / 0
MacBook Pro J616s T6040 62 s yes 4 yes yes hidden 504 runs, 0 wrong 0 / 0 / 0 / 0 / 0
MacBook Pro J316s T6000 45 s yes 4 yes n/a (M1) absent 360 runs, 0 wrong 0 / 0 / 0 / 0 / 0
MacBook Air J413 T8112 27 s yes 3 yes n/a (M2) absent 288 runs, 0 wrong 0 / 0 / 0 / 0 / 0

All four Macs:

  • Boot state: SELinux enforcing, KASLR active (non-zero _text), iommu: DMA domain TLB invalidation policy: strict mode, PREEMPT_LAZY, renderD128 + apple-drm bound.
  • Idle: cpuidle states are entered on every CPU.
  • T8140: booted without arm64.nowfxt or idle=nop; the MIDR-based WFI save and WFxT hiding cover it.

Each Mac went back to its normal kernel afterwards.

Not covered by these rows: suspend/resume, GPU/NVMe throughput against the current kernel, and audio.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 1.

  1. Commit 3fb56e0 has no Signed-off-by and ends with Co-Authored-By: Claude Opus 5.5 <[email protected]>; checkpatch flagged it too. Add the human sign-off and drop the trailer.

The code is sound:

  • __cpuinfo_store_cpu() records WFxT as absent on every M4+ CPU (cpuinfo.c:560). ARM64_HAS_WFXT and the WFXT hwcap are system-scope, so has_cpuid_feature() reads the sanitised value and gives the same answer the MIDR list did. A late CPU being checked at local scope cannot turn on a system cap that was never set.
  • In __delay() (delay.c:45-60), T8142/T6050 now take the WFE event-stream loop. That is the same instruction __cmpwait runs in every spinlock wait on these cores, so it adds no new kind of wait state.
  • Ignoring idle=nop (idle.c:82) now follows apple_wfi_loses_regs, which is exactly the set that saves registers around WFI.
  • delay.c has no other cputype.h user.

The rows above were run on this exact commit (the kit merges 3fb56e0 unchanged): J700, J616s, J316s and J413 boot cleanly without the loader arguments.

  1. The one behaviour change for EFI-booted users is __delay() on T8142/T6050, and no M5 ran it. That needs a row. The PR's own row list also had s2idle on the J700, which the comment says was not covered. s2idle goes through the cpuidle WFI path this PR now relies on without arm64.nowfxt.

HW row:

  • J700 on this head, direct boot without arm64.nowfxt/idle=nop: 3x s2idle, then the SHA-256 loop under schedutil with 0 wrong.
  • J813 or J714s (T8142/T6050) on this head: SHA-256 loop under schedutil plus a cpufreq-transition stress, 0 wrong.
  • Both: 0 AVC, 0 failed units, no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@satchlj

satchlj commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Claude Opus 5.5 on @satchlj's behalf. T6050 (J775c, Mac Studio M5 Max) row for head 3fb56e02460a: the __delay() WFE path, WFxT off, and s2idle.

What was booted: not an exact-head tree.

  • It is lobata's cand-15 (integration/aurora plus our open PRs, 2ed7977aa07c) merged with this head, as merge 7d7f803243dc.
  • Identical to the head: arch/arm64/lib/delay.c, kernel/cpufeature.c and kernel/cpuinfo.c.
  • Different from the head:
    • asm/cputype.h adds the candidate's T6050 0x068/0x069 part IDs.
    • kernel/idle.c conflicted with arm64: idle: defer the idle=nop override until built-in drivers probe #2190's T6050 WFI deferral, which the candidate carries. I resolved it by hand to keep that deferral for its listed models, with this PR's "ignore idle=nop" for every other M4+ part. So the idle=nop branch in this tree is not this PR's code for T6050.
  • The cmdline has no idle=nop and no arm64.nowfxt, so that branch is never reached here.
  • So this row covers __delay(), WFxT and s2idle only. Default cmdline, one one-shot boot (1a5259e5).

Results

  • Boot log: Apple: preserving registers across WFI. wfxt is absent from /proc/cpuinfo Features. cpuidle is apple_idle (WFI, WFI). schedutil on all three policies.
  • SHA-256 loop: 18 workers, one pinned to each CPU, each hashing a 64 MiB tmpfs buffer and checking against the reference, with 10–90 ms sleeps between runs so the cores keep entering WFI.
    • 300 s under schedutil: 70,768 runs, 0 wrong.
    • 300 s plus a cpufreq-transition stress (scaling_max_freq cycled min/mid/max on every policy every 50 ms, 2,650 cycles; total_trans 52,185 / 85,053 / 50,995): 37,539 runs, 0 wrong.
    • After 3 × 12 s rtcwake -m freeze (rc 0 each): 60 s, 14,115 runs, 0 wrong.
  • __delay() actually ran: a kprobe (p:apsdelay __delay, kprobe_profile) counted 15,646 calls in the first 300 s and 82,285 under the stress. I did not trace which callers made those calls.
  • No new errors: 0 AVC, 0 failed units. No SError, Oops, BUG, WARNING, "undefined instruction" or DVFS lines. The 11 kernel error lines are the known DCP lane-count/clock and speakers-off lines. scaling_max_freq was restored on every policy.

The J700 rows from your list aren't ours: lobata is only the T6050.

Assisted-by: LLM (Anthropic:Claude Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Replaced by #2796: the same changes with the commit trailers fixed, on the current integration/aurora.The hardware rows from this PR are linked from the new description.

@RyanTheTide
RyanTheTide deleted the sweep-kcmd/wfx branch November 27, 2026 13:22
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.

2 participants