From: Jim Mattson Subject: [PATCH 2/4] KVM: nVMX: Introduce update_vmcs12_vm_entry_controls Date: Thu, 1 Jun 2017 15:13:04 -0700 Message-ID: <20170601221306.86372-3-jmattson@google.com> References: <20170601221306.86372-1-jmattson@google.com> Cc: Jim Mattson To: kvm@vger.kernel.org, nyh@il.ibm.com Return-path: Received: from mail-pf0-f181.google.com ([209.85.192.181]:34308 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751078AbdFAWNx (ORCPT ); Thu, 1 Jun 2017 18:13:53 -0400 Received: by mail-pf0-f181.google.com with SMTP id 9so38751343pfj.1 for ; Thu, 01 Jun 2017 15:13:53 -0700 (PDT) In-Reply-To: <20170601221306.86372-1-jmattson@google.com> Sender: kvm-owner@vger.kernel.org List-ID: VM-entry controls are updated on a VM-exit, but not on a failed VM-entry. Collect these updates in a new function, and call that function from the appropriate conditional block. Fixes: 4704d0befb072 ("KVM: nVMX: Exiting from L2 to L1") Signed-off-by: Jim Mattson --- arch/x86/kvm/vmx.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a01dd8bd712c..5059c6b45914 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -10727,6 +10727,28 @@ static void save_vmcs12_guest_state(struct kvm_vcpu *vcpu, } /* + * Update the VM-entry control fields in vmcs12 after an emulated + * VM-exit (but not after a failed VM-entry). + */ +static void update_vmcs12_vm_entry_controls(struct kvm_vcpu *vcpu, + struct vmcs12 *vmcs12) +{ + /* + * The valid bit (bit 31) is cleared in the "VM-entry + * interruption-information field" on VM-exit. + */ + vmcs12->vm_entry_intr_info_field &= ~INTR_INFO_VALID_MASK; + + /* + * The value of IA32_EFER.LMA is stored in the "IA-32e mode guest" + * VM-entry control. + */ + vmcs12->vm_entry_controls = + (vmcs12->vm_entry_controls & ~VM_ENTRY_IA32E_MODE) | + (vm_entry_controls_get(to_vmx(vcpu)) & VM_ENTRY_IA32E_MODE); +} + +/* * prepare_vmcs12 is part of what we need to do when the nested L2 guest exits * and we want to prepare to run its L1 parent. L1 keeps a vmcs for L2 (vmcs12), * and this function updates it to reflect the changes to the guest state while @@ -10758,16 +10780,9 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, vmcs12->guest_linear_address = vmcs_readl(GUEST_LINEAR_ADDRESS); - vmcs12->vm_entry_controls = - (vmcs12->vm_entry_controls & ~VM_ENTRY_IA32E_MODE) | - (vm_entry_controls_get(to_vmx(vcpu)) & VM_ENTRY_IA32E_MODE); - if (!(vmcs12->vm_exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY)) { + update_vmcs12_vm_entry_controls(vcpu, vmcs12); save_vmcs12_guest_state(vcpu, vmcs12); - /* vm_entry_intr_info_field is cleared on exit. Emulate this - * instead of reading the real value. */ - vmcs12->vm_entry_intr_info_field &= ~INTR_INFO_VALID_MASK; - /* * Transfer the event that L0 or L1 may wanted to inject into * L2 to IDT_VECTORING_INFO_FIELD. -- 2.13.0.219.gdb65acc882-goog