Skip to content

Commit 7ced03b

Browse files
avagingvisor-bot
authored andcommitted
ring0: Initialize sentryXCR0 from Kernel.init()
Fixes google#6300 PiperOrigin-RevId: 385840917
1 parent 5ad30ca commit 7ced03b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/ring0/kernel_amd64.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ring0
1919
import (
2020
"encoding/binary"
2121
"reflect"
22+
"sync"
2223

2324
"gvisor.dev/gvisor/pkg/hostarch"
2425
"gvisor.dev/gvisor/pkg/sentry/arch"
@@ -30,6 +31,8 @@ func HaltAndWriteFSBase(regs *arch.Registers)
3031

3132
// init initializes architecture-specific state.
3233
func (k *Kernel) init(maxCPUs int) {
34+
initSentryXCR0()
35+
3336
entrySize := reflect.TypeOf(kernelEntry{}).Size()
3437
var (
3538
entries []kernelEntry
@@ -257,7 +260,16 @@ func (c *CPU) SwitchToUser(switchOpts SwitchOpts) (vector Vector) {
257260
return
258261
}
259262

260-
var sentryXCR0 = xgetbv(0)
263+
var (
264+
sentryXCR0 uintptr
265+
sentryXCR0Once sync.Once
266+
)
267+
268+
// initSentryXCR0 saves a value of XCR0 in the host mode. It is used to
269+
// initialize XCR0 of guest vCPU-s.
270+
func initSentryXCR0() {
271+
sentryXCR0Once.Do(func() { sentryXCR0 = xgetbv(0) })
272+
}
261273

262274
// startGo is the CPU entrypoint.
263275
//

0 commit comments

Comments
 (0)