File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ package ring0
19
19
import (
20
20
"encoding/binary"
21
21
"reflect"
22
+ "sync"
22
23
23
24
"gvisor.dev/gvisor/pkg/hostarch"
24
25
"gvisor.dev/gvisor/pkg/sentry/arch"
@@ -30,6 +31,8 @@ func HaltAndWriteFSBase(regs *arch.Registers)
30
31
31
32
// init initializes architecture-specific state.
32
33
func (k * Kernel ) init (maxCPUs int ) {
34
+ initSentryXCR0 ()
35
+
33
36
entrySize := reflect .TypeOf (kernelEntry {}).Size ()
34
37
var (
35
38
entries []kernelEntry
@@ -257,7 +260,16 @@ func (c *CPU) SwitchToUser(switchOpts SwitchOpts) (vector Vector) {
257
260
return
258
261
}
259
262
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
+ }
261
273
262
274
// startGo is the CPU entrypoint.
263
275
//
You can’t perform that action at this time.
0 commit comments