Repository navigation
arm64: the FP/SIMD registers belong to the thread and to the domain - #381
Merged
Merged
Conversation
On arm64 nothing saved v0-v31, FPSR and FPCR: __switch_to and
__switch_domain_to carry x19-x29, lr and sp, the exception frame x0-x30.
The threads of a process, the guests sharing a CPU and the kernel itself
(built without -mgeneral-regs-only, it used v0/v1 in printk, sprintf,
fork, the hypercall path) all wrote the same registers. A preempted
thread got another context's values back.
The visible failure was a process killed in musl's fmt_fp: the loop which
writes the integer part of a floating-point number goes through v0/v1 at
each step, a corrupted value never reaches zero, and the loop writes
upward until it leaves the stack. Seen twice in SOO-NG campaigns on a
capsule printing "%.2f".
Now:
- struct fpsimd_state (v0-v31, FPSR, FPCR), saved and loaded by
fpsimd_save()/fpsimd_restore();
- the scheduler saves it for the thread it leaves and loads the next
one's; a new thread starts with its creator's, as fork() requires;
- AVZ does the same for the domains, in vcpu_t, which the injector
already copies into the capsule's context: the state travels with a
snapshot (size of that context changes, both ends must be rebuilt);
- the arm64 kernel is built with -mgeneral-regs-only, so the registers
stay those of the context which entered it until a switch. strtod.c
and roxml_xpath.c compute in doubles and are exempted; nothing in the
kernel calls them.
Test, SOO-NG on virt64 under QEMU, 180 s per node, a capsule whose
threads hold a pattern in d0, d1, d8, d31 and read it back in user mode,
or format doubles of known text:
before after
one capsule, one thread 37 / 29742 0 / 27421
one capsule, two threads 8535 / 17923 0 / 14218
two capsules on a node 2975 / 15535 0 / 13392
two threads formatting doubles killed at once 0 / 19.8 M
(wrong reads / reads.) Before, the values found were the other thread's
pattern, the other capsule's, and kernel addresses.
All 17 configurations build; after the change only fpsimd_save and
fpsimd_restore touch an FP/SIMD register in the kernel image.
Limits: tested on SOO-NG's copy of these sources, not on a standalone
SO3 nor on a board; migration of a capsule with the new context not
exercised; a signal handler still runs on the interrupted thread's
registers; arm32 is unchanged (vfp_save_state()/vfp_restore_state() have
no caller there either).
Contributor
Author
|
Rebased on main after #380 (x86_64). Two conflicts, both in Makefiles next to the x86 additions: the arm64 flags in |
daniel-rossier
force-pushed
the
fix/arm64-fpsimd-context
branch
from
November 15, 2026 09:07
daaf4f2 to
775f37d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On arm64 nothing saved v0–v31, FPSR and FPCR:
__switch_toand__switch_domain_tocarry x19–x29, lr and sp, the exception frame x0–x30. The threads of a process, the guests sharing a CPU and the kernel itself (built without-mgeneral-regs-only, it used v0/v1 inprintk,sprintf, fork, the hypercall path) all wrote the same registers. A preempted thread got another context's values back.The visible failure was a process killed in musl's
fmt_fp: the loop which writes the integer part of a floating-point number goes through v0/v1 at each step, a corrupted value never reaches zero, and the loop writes upward until it leaves the stack.Change
struct fpsimd_state(v0–v31, FPSR, FPCR), saved and loaded byfpsimd_save()/fpsimd_restore().fork()requires.vcpu_t. The injector already copiesvcpu_tinto a capsule's context, so the state travels with a snapshot; the size of that context changes, both ends must be rebuilt.-mgeneral-regs-only, so the registers stay those of the context which entered it until a switch.strtod.candroxml_xpath.ccompute in doubles and are exempted; nothing in the kernel calls them.Checks
SOO-NG on virt64 under QEMU, 180 s per node, a capsule whose threads hold a pattern in d0, d1, d8, d31 and read it back in user mode, or format doubles of known text (wrong reads / reads):
Before, the values found were the other thread's pattern, the other capsule's, and kernel addresses.
fpsimd_saveandfpsimd_restoretouch an FP/SIMD register in the kernel image.Limits
vfp_save_state()/vfp_restore_state()have no caller there either.