Only the exit reason and exit qualification fields are written on a failed VM-entry. Sequester the other exit-information field updates in a separate function, and call it from the appropriate conditional block. Fixes: 4704d0befb072 ("KVM: nVMX: Exiting from L2 to L1") Signed-off-by: Jim Mattson <jmattson@xxxxxxxxxx> --- arch/x86/kvm/vmx.c | 54 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 5059c6b45914..4cddd6fab1c5 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -10531,6 +10531,7 @@ static void vmcs12_save_pending_event(struct kvm_vcpu *vcpu, u32 idt_vectoring; unsigned int nr; + vmcs12->idt_vectoring_info_field = 0; if (vcpu->arch.exception.pending && vcpu->arch.exception.reinject) { nr = vcpu->arch.exception.nr; idt_vectoring = nr | VECTORING_INFO_VALID_MASK; @@ -10749,6 +10750,34 @@ static void update_vmcs12_vm_entry_controls(struct kvm_vcpu *vcpu, } /* + * Record information about the nature of the VM-exit in the VM-exit + * information fields of vmcs12. Note that this function assumes that + * all of the extra VM-exit information aside from the "VM-exit + * interruption information" is live in vmcs02. + */ +static void record_extra_vmcs12_exit_information(struct kvm_vcpu *vcpu, + struct vmcs12 *vmcs12, + u32 exit_intr_info) +{ + vmcs12->vm_exit_intr_info = exit_intr_info; + if ((vmcs12->vm_exit_intr_info & + (INTR_INFO_VALID_MASK | INTR_INFO_DELIVER_CODE_MASK)) == + (INTR_INFO_VALID_MASK | INTR_INFO_DELIVER_CODE_MASK)) + vmcs12->vm_exit_intr_error_code = + vmcs_read32(VM_EXIT_INTR_ERROR_CODE); + vmcs12->vm_exit_instruction_len = vmcs_read32(VM_EXIT_INSTRUCTION_LEN); + vmcs12->vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); + vmcs12->guest_linear_address = vmcs_readl(GUEST_LINEAR_ADDRESS); + /* + * Transfer the event that L0 or L1 may want to inject into L2 + * to "IDT-vectoring information" and associated fields. Note + * that this function may overwrite "VM-exit instruction + * length." + */ + vmcs12_save_pending_event(vcpu, vmcs12); +} + +/* * 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 @@ -10763,31 +10792,18 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, u32 exit_reason, u32 exit_intr_info, unsigned long exit_qualification) { - /* update exit information fields: */ - + /* + * The exit reason and exit qualification are saved for failed + * VM-entry as well as VM-exit. + */ vmcs12->vm_exit_reason = exit_reason; vmcs12->exit_qualification = exit_qualification; - vmcs12->vm_exit_intr_info = exit_intr_info; - if ((vmcs12->vm_exit_intr_info & - (INTR_INFO_VALID_MASK | INTR_INFO_DELIVER_CODE_MASK)) == - (INTR_INFO_VALID_MASK | INTR_INFO_DELIVER_CODE_MASK)) - vmcs12->vm_exit_intr_error_code = - vmcs_read32(VM_EXIT_INTR_ERROR_CODE); - vmcs12->idt_vectoring_info_field = 0; - vmcs12->vm_exit_instruction_len = vmcs_read32(VM_EXIT_INSTRUCTION_LEN); - vmcs12->vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - - vmcs12->guest_linear_address = vmcs_readl(GUEST_LINEAR_ADDRESS); - if (!(vmcs12->vm_exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY)) { update_vmcs12_vm_entry_controls(vcpu, vmcs12); save_vmcs12_guest_state(vcpu, vmcs12); - /* - * Transfer the event that L0 or L1 may wanted to inject into - * L2 to IDT_VECTORING_INFO_FIELD. - */ - vmcs12_save_pending_event(vcpu, vmcs12); + record_extra_vmcs12_exit_information(vcpu, vmcs12, + exit_intr_info); } /* -- 2.13.0.219.gdb65acc882-goog