summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/platform
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-04-21 16:27:27 -0700
committergVisor bot <gvisor-bot@google.com>2021-04-21 16:27:27 -0700
commit6f9db949d89000d920da5c97adad470cf97b1c6c (patch)
tree2009e78af867ce8347b2c750ae96f18724ae93b2 /pkg/sentry/platform
parente3a5da8ce62826f56c0b531590bb472ea717eeac (diff)
parent58843520b5eb64924d295ca2e03eeaecbf8d65a1 (diff)
Merge pull request #5737 from dqminh:tsc-scaling
PiperOrigin-RevId: 369758655
Diffstat (limited to 'pkg/sentry/platform')
-rw-r--r--pkg/sentry/platform/kvm/kvm_const.go1
-rw-r--r--pkg/sentry/platform/kvm/machine.go8
-rw-r--r--pkg/sentry/platform/kvm/machine_amd64.go5
3 files changed, 14 insertions, 0 deletions
diff --git a/pkg/sentry/platform/kvm/kvm_const.go b/pkg/sentry/platform/kvm/kvm_const.go
index 2492d57be..eb2dcccac 100644
--- a/pkg/sentry/platform/kvm/kvm_const.go
+++ b/pkg/sentry/platform/kvm/kvm_const.go
@@ -66,6 +66,7 @@ const (
_KVM_CAP_ARM_VM_IPA_SIZE = 0xa5
_KVM_CAP_VCPU_EVENTS = 0x29
_KVM_CAP_ARM_INJECT_SERROR_ESR = 0x9e
+ _KVM_CAP_TSC_CONTROL = 0x3c
)
// KVM limits.
diff --git a/pkg/sentry/platform/kvm/machine.go b/pkg/sentry/platform/kvm/machine.go
index b3d4188a3..99f036bba 100644
--- a/pkg/sentry/platform/kvm/machine.go
+++ b/pkg/sentry/platform/kvm/machine.go
@@ -67,6 +67,9 @@ type machine struct {
// maxSlots is the maximum number of memory slots supported by the machine.
maxSlots int
+ // tscControl checks whether cpu supports TSC scaling
+ tscControl bool
+
// usedSlots is the set of used physical addresses (sorted).
usedSlots []uintptr
@@ -214,6 +217,11 @@ func newMachine(vm int) (*machine, error) {
log.Debugf("The maximum number of slots is %d.", m.maxSlots)
m.usedSlots = make([]uintptr, m.maxSlots)
+ // Check TSC Scaling
+ hasTSCControl, _, errno := unix.RawSyscall(unix.SYS_IOCTL, uintptr(m.fd), _KVM_CHECK_EXTENSION, _KVM_CAP_TSC_CONTROL)
+ m.tscControl = errno == 0 && hasTSCControl == 1
+ log.Debugf("TSC scaling support: %t.", m.tscControl)
+
// Create the upper shared pagetables and kernel(sentry) pagetables.
m.upperSharedPageTables = pagetables.New(newAllocator())
m.mapUpperHalf(m.upperSharedPageTables)
diff --git a/pkg/sentry/platform/kvm/machine_amd64.go b/pkg/sentry/platform/kvm/machine_amd64.go
index e8e209249..d7abfefb4 100644
--- a/pkg/sentry/platform/kvm/machine_amd64.go
+++ b/pkg/sentry/platform/kvm/machine_amd64.go
@@ -213,6 +213,11 @@ func (c *vCPU) setSystemTime() error {
// capabilities as it is emulated in KVM. We don't actually use this
// capability, but it means that this method should be robust to
// different hardware configurations.
+
+ // if tsc scaling is not supported, fallback to legacy mode
+ if !c.machine.tscControl {
+ return c.setSystemTimeLegacy()
+ }
rawFreq, err := c.getTSCFreq()
if err != nil {
return c.setSystemTimeLegacy()