Commit Graph

20 Commits

Author SHA1 Message Date
Jamie Liu 3f1642e4bc Remove ring0 floating point save/load functions on amd64.
ring0.Save/LoadFloatingPoint() are only usable if the caller can ensure that Go
will not clobber floating point registers before/after calling them
respectively. Due to regabig in Go 1.17, this is no longer the case; regabig
(among other things) maintains a zeroed XMM15 during ABIInternal execution,
including by zeroing it after ABI0-to-ABIInternal transitions. In
ring0.sysenter/exception, this happens in
ring0.kernelSyscall/kernelException.abi0 respectively; in
ring0.CPU.SwitchToUser, this happens after returning from
ring0.sysret/iret.abi0. Delete these functions and do floating point save/load
in assembly.

While arm64 doesn't appear to be immediately affected (so this CL permits us to
resume usage of Go 1.17), its use of Save/LoadFloatingPoint() still seems to be
incorrect for the same fundamental reason (Go code can't sanely assume what
registers the Go compiler will or won't use) and should be fixed eventually.

PiperOrigin-RevId: 401895658
2021-10-08 18:03:23 -07:00
Andrei Vagin 0bdd79ccd4 kvm: trap mmap syscalls to map new regions to the guest
We install seccomp rules so that the SIGSYS signal is generated for
each mmap system call. Then our signal handler executes the real mmap
syscall and if a new regions is created, it maps it to the guest.

Signed-off-by: Andrei Vagin <avagin@google.com>
2021-09-22 14:39:36 -07:00
Andrei Vagin 0690c25e06 kvm: set CR0.NE = 1
CR0.NE enables internal x87 floating point error reporting when set, else
enables PC style x87 error detection.

On AMD, the #MF exception isn't generated if CR0.NE isn't set.

PiperOrigin-RevId: 386340269
2021-07-22 15:55:31 -07:00
Jamie Liu 1ad3822200 Add go:build directives as required by Go 1.17's gofmt.
PiperOrigin-RevId: 385894869
2021-07-20 16:28:45 -07:00
Andrei Vagin 7ced03b383 ring0: Initialize sentryXCR0 from Kernel.init()
Fixes #6300

PiperOrigin-RevId: 385840917
2021-07-20 12:07:23 -07:00
Michael Pratt 36a17a814b Go 1.17 support for the KVM platform
Go 1.17 adds a new register-based calling convention. While transparent for
most applications, the KVM platform needs special work in a few cases.

First of all, we need the actual address of some assembly functions, rather
than the address of a wrapper. See http://gvisor.dev/pr/5832 for complete
discussion of this.

More relevant to this CL is that ABI0-to-ABIInternal wrappers (i.e., calls from
assembly to Go) access the G via FS_BASE. The KVM quite fast-and-loose about
the Go environment, often calling into (nosplit) Go functions with
uninitialized FS_BASE.

That will no longer work in Go 1.17, so this CL changes the platform to
consistently restore FS_BASE before calling into Go code.

This CL does not affect arm64 code. Go 1.17 does not support the register-based
calling convention for arm64 (it will come in 1.18), but arm64 also does not
use a non-standard register like FS_BASE for TLS, so it may not require any
changes.

PiperOrigin-RevId: 384234305
2021-07-12 08:01:53 -07:00
Andrei Vagin ec6a7ebc75 Rework the workaround of the XCR0 issue
XCR0 has to be synchronized with the host. We can call xsave from the host
context and then call xrstor from the guest context and vise versa. This means
we need to support the same set of FPU features in both contexts.

PiperOrigin-RevId: 378988281
2021-06-11 18:43:26 -07:00
Andrei Vagin cde8e8b7a9 kvm: prefault a root table page before switching into a user address space
The root table physical page has to be mapped to not fault in iret or sysret
after switching into a user address space.  sysret and iret are in the upper
half that is global and so page tables of lower levels are already mapped.

Fixes #5742

PiperOrigin-RevId: 371458644
2021-04-30 23:07:15 -07:00
gVisor bot e2b5de65ce Merge pull request #5749 from zhlhahaha:2126
PiperOrigin-RevId: 369686298
2021-04-21 10:45:44 -07:00
gVisor bot 7420821a7b Merge pull request #5767 from avagin:mxcsr
PiperOrigin-RevId: 367730917
2021-04-09 17:15:06 -07:00
gVisor bot ae019e39b0 Merge pull request #5736 from lubinszARM:pr_bblu_tlb_asid
PiperOrigin-RevId: 367523491
2021-04-08 15:53:37 -07:00
Andrei Vagin eb9b8e53a3 platform/kvm/x86: restore mxcsr when switching from guest to sentry
Goruntime sets mxcsr once and never changes it.

Reported-by: syzbot+ec55cea6e57ec083b7a6@syzkaller.appspotmail.com
Fixes: #5754
2021-04-01 13:28:15 -07:00
Howard Zhang a8584ab67f apply hostarch on pagetables_arm64_test.go
Signed-off-by: Howard Zhang <howard.zhang@arm.com>
2021-03-30 17:29:47 +08:00
Zach Koopmans 8a2f7e716d [syserror] Split usermem package
Split usermem package to help remove syserror dependency in go_marshal.
New hostarch package contains code not dependent on syserror.

PiperOrigin-RevId: 365651233
2021-03-29 13:30:21 -07:00
Robin Luk 72cd22163f arm64 ring0: don't use inner-sharable to invalidate tlb
It is enough to invalidate the tlb of local vcpu in switch().
TLBI with inner-sharable will invalidate the tlb in other vcpu.

Arm64 hardware supports at least 256 pcid, so I think it's ok
to set the length of pcid pool to 128.

Signed-off-by: Robin Luk <lubin.lu@antgroup.com>
2021-03-26 16:10:21 +08:00
Howard Zhang a01fc7108f Fix nogo test error
Signed-off-by: Howard Zhang <howard.zhang@arm.com>
2021-03-25 17:39:28 +08:00
Andrei Vagin 56a9a13976 Move the code that manages floating-point state to a separate package
This change is inspired by Adin's cl/355256448.

PiperOrigin-RevId: 364695931
2021-03-23 18:46:37 -07:00
Robin Luk 6eb80b2e2d arm64 kvm:implement basic lazy save and restore for FPSIMD registers
Implement basic lazy save and restore for FPSIMD registers, which only
  restore FPSIMD state on el0_fpsimd_acc and save FPSIMD state in switch().

Signed-off-by: Robin Luk <lubin.lu@antgroup.com>
2021-02-03 11:50:36 +00:00
Robin Luk 25130d6183 arm64: clean code
In order to improve the performance and stability, I reorg 2 modules slightly.
  arch: no red zone on Arm64.
  ring0: use stp instead of movd, and set RSV_REG_APP=R19.
Signed-off-by: Robin Luk <lubin.lu@antgroup.com>
2021-02-03 11:50:35 +00:00
Adin Scannell f884ea13b7 Move ring0 package.
This allows the package to serve as a general purpose ring0 support package, as
opposed to being bound to specific sentry platforms.

Updates #5039

PiperOrigin-RevId: 355220044
2021-02-02 12:03:26 -08:00