ref: 4f310b8f515e28f44f06554684b349dadcc5b0dd
parent: c7dcc82b0be805717efbe77c98eaadf3ee1e31af
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Sep 13 18:54:05 EDT 2021
devvmx: skip tsc offset writing if CPU doesn't support it
--- a/sys/src/9/pc/devvmx.c
+++ b/sys/src/9/pc/devvmx.c
@@ -267,6 +267,7 @@
char errstr[ERRMAX];
Ureg ureg;
uvlong tscoffset;
+ u32int procbctls;
uintptr cr2;
uintptr xcr0;
uintptr dr[8]; /* DR7 is also kept in VMCS */
@@ -962,6 +963,7 @@
x |= PROCB_USECTLS2;
x &= msr >> 32;
vmcswrite(PROCB_CTLS, x);
+ vmx->procbctls = x;
if(rdmsr(VMX_PROCB_CTLS2_MSR, &msr) < 0) error("rdmsr(VMX_PROCB_CTLS2_MSR failed");
x = PROCB_EPT | PROCB_VPID | PROCB_UNRESTR;
@@ -1062,10 +1064,12 @@
vmcswrite(VMEXIT_MSRSTADDR, PADDR(vmx->msrguest));
vmcswrite(VMEXIT_MSRLDADDR, PADDR(vmx->msrhost));
vmcswrite(MSR_BITMAP, PADDR(vmx->msrbits));
-
- cycles(&vmx->tscoffset);
- vmcswrite(VMCS_TSC_OFFSET, vmx->tscoffset);
+ if(vmx->procbctls & PROCB_TSCOFFSET){
+ cycles(&vmx->tscoffset);
+ vmcswrite(VMCS_TSC_OFFSET, vmx->tscoffset);
+ }
+
if(sizeof(uintptr) == 8){
vmxaddmsr(vmx, Star, 0);
vmxaddmsr(vmx, Lstar, 0);
@@ -1682,7 +1686,7 @@
}
rc = vmlaunch(&vmx->ureg, vmx->launched);
cycles(&end);
- useend = 1;
+ useend = vmx->procbctls & PROCB_TSCOFFSET;
vmx->cr2 = getcr2();
if(m->xcr0 != 0 && vmx->xcr0 != m->xcr0)
putxcr0(m->xcr0);