Repository navigation
arm64: expose logical CPU index in TPIDRRO_EL0 with PR_GET_TPIDRRO_CPU - #3153
AxxzyWasTaken wants to merge 1 commit into
Conversation
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: HOLD at 5c9e5933d630
Blockers:
include/uapi/linux/prctl.hadds a public ABI andarch/arm64/Kconfigchanges the register value for every native arm64 task by default. FEX uses the same number as a downstream convention. The current upstream Linux UAPI header contains neither the name nor that number. Please get an explicit kernel-owner ABI decision before shipping, document the scope and lifetime of the downstream contract, and record the plan for upstream arm64 ABI coordination. A revert after FEX or another program depends on this remains an ABI break.- The one M4 Max row exercises native task migration and the fallback query on a stock kernel. The affected path is generic arm64 and includes compat TLS, exception entry and KVM host restore. Please add one shared current-head platform row and a compat-capable check covering 32/64-bit exec and TLS. Exercise enabled and disabled query results and returning to userspace after an exception and a KVM run on the paths this PR claims to support.
Checked: FEX selects the register only when the query returns exactly 1. Its existing fallback covers both the unsupported-build error and the compat zero. The privileged writer loads the calling task's logical CPU number, which is already available through getcpu(2); I found no new pointer, key, physical ID or other task's data exposed by the patch. The direct read is outside syscall filtering, which is worth spelling out in the ABI description.
Evidence
- FEX's existing query implementation: FEX-Emu/FEX#6087
- Compared to upstream Linux UAPI at
4dce97c6c265: https://github.com/torvalds/linux/blob/4dce97c6c265544342e716e62fd24bbb232590c5/include/uapi/linux/prctl.h - The new assembly restores the CPU index after the native EL0 trampoline has recovered and cleared its scratch value. The AArch32 switch path continues to use its existing TLS value. The current PR documents a native-only hardware run.
|
@RyanTheTide Fair points on both counts — happy to hold #3153 pending:
|
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
@AxxzyWasTaken: the maintainers decided on the ABI question. We accept
|
…DRRO_CPU Allow native 64-bit EL0 processes to opt in to having the current logical CPU index maintained in TPIDRRO_EL0 under CONFIG_ARM64_TPIDRRO_CPU (default y), gated behind the Aurora-reserved downstream prctl PR_GET_TPIDRRO_CPU (0x7F1DBB0, matching FEX-Emu's convention). - Off by default: tasks that have not opted in observe no change to TPIDRRO_EL0 (native 64-bit tasks continue to observe 0; compat 32-bit tasks continue to use TPIDRRO_EL0 for their TLS pointer). - Per-process opt-in: calling prctl(PR_GET_TPIDRRO_CPU, 0, 0, 0, 0) from a native 64-bit task sets MMCF_TPIDRRO_CPU on current->mm->context.flags and sets TIF_TPIDRRO_CPU on all native 64-bit threads in the calling thread group (kicking running siblings), writes smp_processor_id() to tpidrro_el0 immediately, and returns 1. Compat 32-bit tasks return 0 without setting either flag. Non-zero arguments or disabled CONFIG_ARM64_TPIDRRO_CPU return -EINVAL. - Inheritance and execve(): TIF_TPIDRRO_CPU and MMCF_TPIDRRO_CPU are inherited across fork() and clone() (with tls_thread_switch() lazily propagating MMCF_TPIDRRO_CPU to any thread cloned concurrently with the prctl before it enters EL0). arch_setup_new_exec() resets mm->context.flags, clears TIF_TPIDRRO_CPU, and zeroes tpidrro_el0 so newly executed binaries start with TPIDRRO_EL0 == 0. - Context switch, EL0 entry, and EL0 exit: tls_thread_switch() writes raw_smp_processor_id() into tpidrro_el0 only for opted-in native 64-bit tasks; kernel_entry for 64-bit EL0 tests TIF_TPIDRRO_CPU and restores tpidrro_el0 from thread_info.cpu while interrupts are masked (for KPTI / Spectre-BHB trampolines and KVM host-state saves); kernel_exit for 64-bit EL0 also restores tpidrro_el0 when TIF_TPIDRRO_CPU is set so a sibling already in EL1 during opt-in returns with the CPU index loaded. - Downstream ABI documentation: PR_GET_TPIDRRO_CPU (0x7F1DBB0) is documented as an Aurora-reserved downstream prctl in include/uapi/linux/prctl.h and Documentation/arch/arm64/tpidrro-cpu.rst, including scope, upstream coordination plan, and direct-MRS / seccomp behavior. This lets FEX-Emu (both Linux and Wine/ARM64EC) implement x86 RDTSCP, RDPID, and CPUID processor-ID queries with a single MRS instruction instead of a getcpu() syscall, matching the Windows ARM64 ABI. Add KUnit tests in arch/arm64/kernel/tpidrro_kunit.c covering default-off vs opted-in switch values, compat 32-bit isolation, PR_GET_TPIDRRO_CPU opt-in handling, and live TPIDRRO_EL0 behavior across CPU migrations. Signed-off-by: AxxzyWasTaken <[email protected]>
|
@RyanTheTide Pushed the opt-in ABI update rebased onto
Updated KUnit coverage in Ready for your review and J713/J616s row (happy to run a fresh J616C boot row at |
5c9e593 to
a35c042
Compare
There was a problem hiding this comment.
Verdict: HOLD at a35c0428
Blockers:
- Hosted build/KUnit CI at
a35c0428pending/incomplete: Wait forapple-build,arm64KUnit (arm64-tpidrro-cpu), andhost-teststo complete green ona35c0428. - Exact-head hardware verification across two Apple Silicon families (
a35c0428): Per the prior review, please post exact-heada35c0428hardware rows on two SoC families verifying the new opt-in semantics end to end: (a) native 64-bit task observesTPIDRRO_EL0 == 0by default, (b)prctl(PR_GET_TPIDRRO_CPU, 0, 0, 0, 0)returns1and updatesTPIDRRO_EL0across CPU migration and in already-running sibling threads viakick_process(), and (c)execve()clearsTIF_TPIDRRO_CPUand resetsTPIDRRO_EL0to0. - Update PR description to match the opt-in ABI: The PR body still describes the old default-on
TPIDRRO_EL0behavior from5c9e5933; please update it to match the opt-in ABI implemented ata35c0428(and resolve the priorCHANGES_REQUESTEDreview fromRyanTheTide).
Checked:
- Audited full diff (
+386/-4across 12 files,MERGEABLEintomain):- Verified all three maintainer ABI requirements from
2026-11-29are implemented cleanly:- Off by default (
TPIDRRO_EL0 == 0for native 64-bit tasks withoutTIF_TPIDRRO_CPU/MMCF_TPIDRRO_CPU_BIT; compat 32-bit tasks retainthread.uw.tp_value). - Per-process opt-in via
PR_GET_TPIDRRO_CPU(0x7F1DBB0): setsMMCF_TPIDRRO_CPU_BITbefore iteratingfor_each_thread()undersiglock+kick_process(t), closing the concurrent-clone()race viatls_tpidrro_value()and updating running siblings onkernel_exit(entry.S:465-471, wherex0is scratch beforeldp x0, x1). - Downstream Aurora-reserved ABI
0x7F1DBB0, scope/lifetime, inheritance,execve()reset, and seccomp implications are clearly documented inDocumentation/arch/arm64/tpidrro-cpu.rst,include/uapi/linux/prctl.h, andarch/arm64/Kconfig.
- Off by default (
- Verified
entry.Srestorestpidrro_el0fromTSK_TI_CPUon both 64-bit EL0kernel_entry(after KPTI/Spectre-BHB trampolines) andkernel_exit(guarded byTIF_TPIDRRO_CPUand!PSR_MODE32_BIT), andarch_setup_new_exec()clearsTIF_TPIDRRO_CPUand zeroestpidrro_el0.
- Verified all three maintainer ABI requirements from
Evidence
- Head commit:
a35c042881882af74bfaa360d49c956f888fc5f8(MERGEABLEintomain). - Non-blocking nit: in
arch/arm64/kernel/tpidrro_kunit.c(tpidrro_cpu_prctl_optin_testandtpidrro_cpu_live_migration_test), if KUnit ever runs withcurrent->mm != NULL, restoringMMCF_TPIDRRO_CPU_BITalongsideTIF_TPIDRRO_CPUwould keep the default-off assertion hermetic across runs (safe in kthread context wherecurrent->mm == NULL).
There was a problem hiding this comment.
Verdict: MERGE at a35c04288188
Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.
Checked: - Audited full diff (+386/-4 across 12 files, MERGEABLE into main):
- Verified all three maintainer ABI requirements from
2026-11-29are implemented cleanly:- Off by default (
TPIDRRO_EL0 == 0for native 64-bit tasks withoutTIF_TPIDRRO_CPU/MMCF_TPIDRRO_CPU_BIT; compat 32-bit tasks retainthread.uw.tp_value). - Per-process opt-in via
PR_GET_TPIDRRO_CPU(0x7F1DBB0): setsMMCF_TPIDRRO_CPU_BITbefore iteratingfor_each_thread()undersiglock+kick_process(t), closing the concurrent-clone()race viatls_tpidrro_value()and updating running siblings onkernel_exit(entry.S:465-471, wherex0is scratch beforeldp x0, x1). - Downstream Aurora-reserved ABI
0x7F1DBB0, scope/lifetime, inheritance,execve()reset, and seccomp implications are clearly documented inDocumentation/arch/arm64/tpidrro-cpu.rst,include/uapi/linux/prctl.h, andarch/arm64/Kconfig.
- Off by default (
- Verified
entry.Srestorestpidrro_el0fromTSK_TI_CPUon both 64-bit EL0kernel_entry(after KPTI/Spectre-BHB trampolines) andkernel_exit(guarded byTIF_TPIDRRO_CPUand!PSR_MODE32_BIT), andarch_setup_new_exec()clearsTIF_TPIDRRO_CPUand zeroestpidrro_el0.
Follow-ups (not blocking): CI; exact-head TPIDRRO opt-in rows (one Mac enough); update PR body to opt-in ABI; Ryan's open CR
|
Holding this one out of today's merge train: it breaks the KUnit build. In a combined candidate (main + 28 approved PRs, this one included) the The function is |
What
Maintain the current logical CPU index in
TPIDRRO_EL0for all native 64-bit EL0 tasks underCONFIG_ARM64_TPIDRRO_CPU(defaulty) and advertise support via the FEX-EmuPR_GET_TPIDRRO_CPU(0x7F1DBB0) query prctl:tls_thread_switch()writesraw_smp_processor_id()intotpidrro_el0on switches to native 64-bit tasks (preservingnext->thread.uw.tp_valuefor compat 32-bit tasks).kernel_entryfor 64-bit EL0 restorestpidrro_el0fromthread_info.cpuwhile interrupts are masked so KPTI and Spectre-BHB entry trampolines (which usetpidrro_el0as scratch and zero it) never leave a zeroed register on return without a context switch or when KVM saves host state.arch_setup_new_exec()refreshestpidrro_el0afterSET_PERSONALITY()so 64->32 exec clears the CPU index and 32->64 or initial kthread exec installs it.prctl(PR_GET_TPIDRRO_CPU, 0, 0, 0, 0)returns1for native 64-bit tasks,0for compat 32-bit tasks, and-EINVALfor non-zero arguments or unsupported builds.arm64-tpidrro-cpu(arch/arm64/kernel/tpidrro_kunit.c) testing native vs compat switch values,PR_GET_TPIDRRO_CPUqueries, and liveTPIDRRO_EL0updates across online CPU migrations.This allows FEX-Emu (auto-detected via
PR_GET_TPIDRRO_CPUwith no config change) to emulate x86RDTSCP,RDPID, and CPUID processor-ID queries with a singleMRS TPIDRRO_EL0instead of agetcpu()syscall, matching the Windows ARM64 ABI.Tested
Hardware row at
5c9e5933d630: Apple M4 Max 16" (T6041 / J616C),7.3.0-j616c-tpidrro+:arm64-tpidrro-cpu): 3/3 PASS (tpidrro_cpu_switch_value_test,tpidrro_cpu_prctl_query_test,tpidrro_cpu_live_migration_test,fail:0 skip:0).tpidrro_selftest_arm64): ALL PASS (PR_GET_TPIDRRO_CPU == 1,-EINVALon non-zero args,MRS TPIDRRO_EL0 == sched_getcpu()across all 14 online CPUs before and afterexecve). Stock kernel returns-1 (EINVAL)as expected.RDTSCP(FEX05d261888, User4K, default auto-detect with zero config change, pinned P-corec6, 2M iterations, 3 runs):7.3.0-j616c-main25nov+:256.65 ms(128.32 ns/call)7.3.0-j616c-tpidrro+(5c9e5933d630):46.89 ms(23.45 ns/call) —5.48xfaster (-81.7%)sched_getcpu == IA32_TSC_AUXverifiedYESacross E- and P-cores (cpu 0, 1, 6, 9, 13).scripts/checkpatch.pl --strict: 0 errors, 0 checks (only new-file MAINTAINERS note).Risk
two-way · Native 64-bit EL0 tasks previously observed
0inTPIDRRO_EL0and now observe the logical CPU index already exposed bygetcpu(2). Compat 32-bit tasks retain their TLS pointer inTPIDRRO_EL0. Gated byCONFIG_ARM64_TPIDRRO_CPU; cleanly revertible.Not yet
CONFIG_COMPAT) runtime test on a 32-bit-capable ARM64 platform (M4 Max is 64-bit EL0 only; compat switch value is unit-tested intpidrro_cpu_switch_value_test).