platform/kvm: dont' set MPX bits in the XCR register

We don't expect that runsc uses MPX . MPX was deprecated and its support
has been removed from the Linux Kernel.

We have seen when the host XCR has these bits, but a KVM VM doesn't
support MPX and xsetbv generates #GP.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/7366 from avagin:gvisor-vs-mpx 9cd6a27048cbcd0c01dbecd7697e2c4619b29f28
PiperOrigin-RevId: 438922868
This commit is contained in:
Andrei Vagin
2022-04-01 15:21:49 -07:00
committed by gVisor bot
parent 5b538f75e4
commit 37d5dc5877
+5 -1
View File
@@ -21,6 +21,7 @@ import (
"encoding/binary"
"reflect"
"gvisor.dev/gvisor/pkg/cpuid"
"gvisor.dev/gvisor/pkg/hostarch"
"gvisor.dev/gvisor/pkg/sentry/arch"
)
@@ -293,7 +294,10 @@ func startGo(c *CPU) {
// Need to sync XCR0 with the host, because xsave and xrstor can be
// called from different contexts.
if hasXSAVE {
xsetbv(0, localXCR0)
// Exclude MPX bits. MPX has been deprecated and we have seen
// cases when it isn't supported in VM.
xcr0 := localXCR0 &^ (cpuid.XSAVEFeatureBNDCSR | cpuid.XSAVEFeatureBNDREGS)
xsetbv(0, xcr0)
}
// Set the syscall target.