- Use the correct instruction in safecopy.checkXstate(). Before this CL:
```
TEXT pkg/sentry/arch/fpu/fpu.initX86FPState.abi0(SB)
...
fpu_amd64.s:78 0x7661b2 480fae2f XRSTOR64 0(DI)
TEXT pkg/safecopy/safecopy.checkXstate.abi0(SB)
...
xrstor_amd64.s:54 0x7648a0 0fae2f XRSTOR 0(DI)
```
I'm not sure what the actual difference between XRSTOR and XRSTOR64 is, but
Linux is careful to use XRSTOR64 (arch/x86/kernel/fpu/xstate.h:XRSTOR,
REX_PREFIX) so it probably matters.
- When an AfterLoad callback fails, log the error message before the failing
object, since the latter can be huge and prevent the error message from being
logged.
- Include additional information in the error message emitted by
fpu.State.AfterLoad().
PiperOrigin-RevId: 605534648
SETREGSET/GETREGSET expect AMX portions of fpstate to always be used.
For this reason we need to allocate enough memory for this to happen,
even if we never populate the AMX portions within initX86FPState.
PiperOrigin-RevId: 599702181
For now we are going to completely disable using AMX, so we will
always subtract extended state size reserved from AMX from the rest
of the extended state size, and hardcode the AMX XCR0 bits to be
always off.
Fixes#9750.
PiperOrigin-RevId: 599302059
Since everything fits inside an int64, we avoid using crypto/rand.Int, which
can allocate and uses the much more complex big.Int.
PiperOrigin-RevId: 580050587
It is an idea of running codespell as part of our presubmit checks.
Before enabling it for new changes, let's fix what it has found.
Signed-off-by: Andrei Vagin <avagin@gmail.com>
Starting with Go 1.21, build tags select the language version. We currently
have several `go:build go1.1` tags, which were intended to act as "true" tags.
But that will break with 1.21. So replace them with "!false".
Fixes#9568.
PiperOrigin-RevId: 576020779
When we reserve space for an FPU state in a signal frame, we need to use
the size of the current fpu state. The kernel cpuid can report a smaller size.
On restore, we need to read the size of an fpu state from a signal frame.
After S/R, it can't be different from the current fpu size.
PiperOrigin-RevId: 546972243
We don't care about corrupting the current state, because sigreturn
syscalls never report errors and they queue SIGSEGV in case of any
problems.
Here are results fro the signal_benchmark on the kvm platform:
Before:
BM_FaultSignalFixup/real_time 6127 ns 6087 ns 111708
After:
BM_FaultSignalFixup/real_time 3661 ns 3654 ns 199755
PiperOrigin-RevId: 462021118
Since `arch.Context64` is the only concrete implementation of
`arch.Context`, this does not functionally change anything.
While `arch.Context64` *can* mean multiple things in the codebase, since
the `arch` module uses conditional compilation to create different builds
for AMD64 vs ARM64, the `Context64` type is still singular within each
possible version this can compile to.
This avoids the overhead involved in calling interface
functions in Go:
https://github.com/teh-cmc/go-internals/blob/master/chapter2_interfaces/README.md#dynamic-dispatch
This overhead is particularly painful for functions like `SyscallSaveOrig`
which is a no-op on AMD64.
On KVM, this reduces syscall latency by 4~5%:
```
name old wall_ns/op new wall_ns/op delta
Getpid 602 ± 4% 579 ± 3% -3.94% (p=0.000 n=66+195)
GetpidOpt 604 ± 3% 573 ± 3% -5.10% (p=0.000 n=71+194)
name old cpu_ns/op new cpu_ns/op delta
Getpid 604 ± 5% 581 ± 0% -3.81% (p=0.000 n=75+130)
GetpidOpt 604 ± 2% 574 ± 3% -4.95% (p=0.000 n=71+196)
```
PiperOrigin-RevId: 461742893
reflect.ValueOf takes an interface{}, so when passed a slice the compiler emits
a call to runtime.convTslice to heap-allocate a copy of the slice header.
PiperOrigin-RevId: 394310052