]> Git Repo - linux.git/commitdiff
KVM: nVMX: Reset register cache (available and dirty masks) on VMCS switch
authorSean Christopherson <[email protected]>
Wed, 15 Apr 2020 20:34:51 +0000 (13:34 -0700)
committerPaolo Bonzini <[email protected]>
Tue, 21 Apr 2020 13:13:06 +0000 (09:13 -0400)
Reset the per-vCPU available and dirty register masks when switching
between vmcs01 and vmcs02, as the masks track state relative to the
current VMCS.  The stale masks don't cause problems in the current code
base because the registers are either unconditionally written on nested
transitions or, in the case of segment registers, have an additional
tracker that is manually reset.

Note, by dropping (previously implicitly, now explicitly) the dirty mask
when switching the active VMCS, KVM is technically losing writes to the
associated fields.  But, the only regs that can be dirtied (RIP, RSP and
PDPTRs) are unconditionally written on nested transitions, e.g. explicit
writeback is a waste of cycles, and a WARN_ON would be rather pointless.

Signed-off-by: Sean Christopherson <[email protected]>
Message-Id: <20200415203454[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/vmx/vmx.h

index 5a214cbf243c0524aea1708a401fa295df97db38..c01005ec445f2fc2bcdcfb136460d93f3290e6e3 100644 (file)
@@ -307,6 +307,7 @@ static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
        vmx_sync_vmcs_host_state(vmx, prev);
        put_cpu();
 
+       vmx_register_cache_reset(vcpu);
        vmx_segment_cache_clear(vmx);
 }
 
index f9bee922f1e6c92bd76a8a85496df962bfb3ad3c..629c89314d4437ae61af92da981fe81a86788a13 100644 (file)
@@ -6711,12 +6711,7 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
        loadsegment(es, __USER_DS);
 #endif
 
-       vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
-                                 | (1 << VCPU_EXREG_RFLAGS)
-                                 | (1 << VCPU_EXREG_PDPTR)
-                                 | (1 << VCPU_EXREG_SEGMENTS)
-                                 | (1 << VCPU_EXREG_CR3));
-       vcpu->arch.regs_dirty = 0;
+       vmx_register_cache_reset(vcpu);
 
        pt_guest_exit(vmx);
 
index 31d7252df16353f8b099d1479b605c3125ff3166..6b668b6048984a8abe05611472052e9b1e595fe7 100644 (file)
@@ -8,6 +8,7 @@
 #include <asm/intel_pt.h>
 
 #include "capabilities.h"
+#include "kvm_cache_regs.h"
 #include "ops.h"
 #include "vmcs.h"
 
@@ -447,6 +448,16 @@ static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx)
        vmx->segment_cache.bitmask = 0;
 }
 
+static inline void vmx_register_cache_reset(struct kvm_vcpu *vcpu)
+{
+       vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
+                                 | (1 << VCPU_EXREG_RFLAGS)
+                                 | (1 << VCPU_EXREG_PDPTR)
+                                 | (1 << VCPU_EXREG_SEGMENTS)
+                                 | (1 << VCPU_EXREG_CR3));
+       vcpu->arch.regs_dirty = 0;
+}
+
 static inline u32 vmx_vmentry_ctrl(void)
 {
        u32 vmentry_ctrl = vmcs_config.vmentry_ctrl;
This page took 0.092128 seconds and 4 git commands to generate.