diff mbox series

[v2,04/18] KVM: nVMX: reset cache/shadows on nested consistency check VMExit

Message ID 20180828160459.14093-5-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: nVMX: add option to perform early consistency checks via H/W | expand

Commit Message

Sean Christopherson Aug. 28, 2018, 4:04 p.m. UTC
Reset the vm_{entry,exit}_controls_shadow variables as well as the
segment cache on consistency check VMExit.  The shadow values in
particular can lead to missed updates due to stale shadows.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/vmx.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Jim Mattson Sept. 19, 2018, 9:22 p.m. UTC | #1
On Tue, Aug 28, 2018 at 9:04 AM, Sean Christopherson
<sean.j.christopherson@intel.com> wrote:
> Reset the vm_{entry,exit}_controls_shadow variables as well as the
> segment cache on consistency check VMExit.  The shadow values in
> particular can lead to missed updates due to stale shadows.

I feel like this should go into vmx_switch_vmcs() instead. Every time
we switch vmcs, for whatever reason, the shadows are going to be
stale.
Sean Christopherson Sept. 19, 2018, 9:29 p.m. UTC | #2
On Wed, Sep 19, 2018 at 02:22:09PM -0700, Jim Mattson wrote:
> On Tue, Aug 28, 2018 at 9:04 AM, Sean Christopherson
> <sean.j.christopherson@intel.com> wrote:
> > Reset the vm_{entry,exit}_controls_shadow variables as well as the
> > segment cache on consistency check VMExit.  The shadow values in
> > particular can lead to missed updates due to stale shadows.
> 
> I feel like this should go into vmx_switch_vmcs() instead. Every time
> we switch vmcs, for whatever reason, the shadows are going to be
> stale.

That would make a lot more sense.
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b7aca0edeb59..6097d0115056 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -13355,12 +13355,18 @@  static void nested_vmx_entry_failure(struct kvm_vcpu *vcpu,
 			struct vmcs12 *vmcs12,
 			u32 reason, unsigned long qualification)
 {
+	struct vcpu_vmx *vmx = to_vmx(vcpu);
+
+	vm_entry_controls_reset_shadow(vmx);
+	vm_exit_controls_reset_shadow(vmx);
+	vmx_segment_cache_clear(vmx);
+
 	load_vmcs12_host_state(vcpu, vmcs12);
 	vmcs12->vm_exit_reason = reason | VMX_EXIT_REASONS_FAILED_VMENTRY;
 	vmcs12->exit_qualification = qualification;
 	nested_vmx_succeed(vcpu);
 	if (enable_shadow_vmcs)
-		to_vmx(vcpu)->nested.sync_shadow_vmcs = true;
+		vmx->nested.sync_shadow_vmcs = true;
 }
 
 static int vmx_check_intercept(struct kvm_vcpu *vcpu,