summaryrefslogtreecommitdiffhomepage
path: root/pkg/ring0/kernel_amd64.go
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2021-07-20 12:04:47 -0700
committergVisor bot <gvisor-bot@google.com>2021-07-20 12:07:23 -0700
commit7ced03b3831983e35cb25ad0a9d5632ea322f9a4 (patch)
tree4bd0c003ec35ca4d9aa5791d7ecd6b870e21aa5f /pkg/ring0/kernel_amd64.go
parent5ad30cac2ede4eda318c78264e3b9810035ef27d (diff)
ring0: Initialize sentryXCR0 from Kernel.init()
Fixes #6300 PiperOrigin-RevId: 385840917
Diffstat (limited to 'pkg/ring0/kernel_amd64.go')
-rw-r--r--pkg/ring0/kernel_amd64.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/pkg/ring0/kernel_amd64.go b/pkg/ring0/kernel_amd64.go
index b5c4a39e3..a04b60b08 100644
--- a/pkg/ring0/kernel_amd64.go
+++ b/pkg/ring0/kernel_amd64.go
@@ -19,6 +19,7 @@ package ring0
import (
"encoding/binary"
"reflect"
+ "sync"
"gvisor.dev/gvisor/pkg/hostarch"
"gvisor.dev/gvisor/pkg/sentry/arch"
@@ -30,6 +31,8 @@ func HaltAndWriteFSBase(regs *arch.Registers)
// init initializes architecture-specific state.
func (k *Kernel) init(maxCPUs int) {
+ initSentryXCR0()
+
entrySize := reflect.TypeOf(kernelEntry{}).Size()
var (
entries []kernelEntry
@@ -257,7 +260,16 @@ func (c *CPU) SwitchToUser(switchOpts SwitchOpts) (vector Vector) {
return
}
-var sentryXCR0 = xgetbv(0)
+var (
+ sentryXCR0 uintptr
+ sentryXCR0Once sync.Once
+)
+
+// initSentryXCR0 saves a value of XCR0 in the host mode. It is used to
+// initialize XCR0 of guest vCPU-s.
+func initSentryXCR0() {
+ sentryXCR0Once.Do(func() { sentryXCR0 = xgetbv(0) })
+}
// startGo is the CPU entrypoint.
//