diff mbox

[2/4] KVM: nVMX: Introduce update_vmcs12_vm_entry_controls

Message ID 20170601221306.86372-3-jmattson@google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jim Mattson June 1, 2017, 10:13 p.m. UTC
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 <jmattson@google.com>
---
 arch/x86/kvm/vmx.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
diff mbox

Patch

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.