Re: [PATCH v3 09/20] KVM: nVMX: assimilate nested_vmx_entry_failure() into nested_vmx_enter_non_root_mode()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 26, 2018 at 9:23 AM, Sean Christopherson
<sean.j.christopherson@xxxxxxxxx> wrote:
> Handling all VMExits due to failed consistency checks on VMEnter in
> nested_vmx_enter_non_root_mode() consolidates all relevant code into
> a single location, and removing nested_vmx_entry_failure() eliminates
> a confusing function name and label.  For a VMEntry, "fail" and its
> derivatives has a very specific meaning due to the different behavior
> of a VMEnter VMFail versus VMExit, i.e. it wasn't obvious that
> nested_vmx_entry_failure() handled VMExit scenarios.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
> ---
>  arch/x86/kvm/vmx.c | 75 +++++++++++++++++++++-------------------------
>  1 file changed, 34 insertions(+), 41 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 9fac37294f02..4188720758f8 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -2056,9 +2056,6 @@ static inline bool is_nmi(u32 intr_info)
>  static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
>                               u32 exit_intr_info,
>                               unsigned long exit_qualification);
> -static void nested_vmx_entry_failure(struct kvm_vcpu *vcpu,
> -                       struct vmcs12 *vmcs12,
> -                       u32 reason, unsigned long qualification);
>
>  static int __find_msr_index(struct vcpu_vmx *vmx, u32 msr)
>  {
> @@ -12550,20 +12547,22 @@ static int check_vmentry_postreqs(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
>         return 0;
>  }
>
> +static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
> +                                  struct vmcs12 *vmcs12);
>  /*
>   * If exit_qual is NULL, this is being called from state restore (either RSM
>   * or KVM_SET_NESTED_STATE).  Otherwise it's called from vmlaunch/vmresume.
>   */
> -static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, u32 *exit_qual)
> +static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu,
> +                                         bool from_vmentry)
>  {
>         struct vcpu_vmx *vmx = to_vmx(vcpu);
>         struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
> -       bool from_vmentry = !!exit_qual;
> -       u32 dummy_exit_qual;
> -       int r = 0;
> +       u32 exit_reason = EXIT_REASON_INVALID_STATE;
> +       u32 exit_qual;
>
> -       if (from_vmentry && check_vmentry_postreqs(vcpu, vmcs12, exit_qual))
> -               return EXIT_REASON_INVALID_STATE;
> +       if (from_vmentry && check_vmentry_postreqs(vcpu, vmcs12, &exit_qual))
> +               goto vmentry_fail_vmexit;
>
>         enter_guest_mode(vcpu);
>
> @@ -12575,18 +12574,17 @@ static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, u32 *exit_qual)
>         if (vmcs12->cpu_based_vm_exec_control & CPU_BASED_USE_TSC_OFFSETING)
>                 vcpu->arch.tsc_offset += vmcs12->tsc_offset;
> -       r = EXIT_REASON_INVALID_STATE;
> -       if (prepare_vmcs02(vcpu, vmcs12, from_vmentry ? exit_qual : &dummy_exit_qual))
> +       if (prepare_vmcs02(vcpu, vmcs12, &exit_qual))
>                 goto fail;
>
>         if (from_vmentry) {
>                 nested_get_vmcs12_pages(vcpu);
>
> -               r = EXIT_REASON_MSR_LOAD_FAIL;
> -               *exit_qual = nested_vmx_load_msr(vcpu,
> -                                                vmcs12->vm_entry_msr_load_addr,
> -                                                vmcs12->vm_entry_msr_load_count);
> -               if (*exit_qual)
> +               exit_reason = EXIT_REASON_MSR_LOAD_FAIL;
> +               exit_qual = nested_vmx_load_msr(vcpu,
> +                                               vmcs12->vm_entry_msr_load_addr,
> +                                               vmcs12->vm_entry_msr_load_count);
> +               if (exit_qual)
>                         goto fail;
>         } else {
>                 /*
> @@ -12607,12 +12605,28 @@ static int nested_vmx_enter_non_root_mode(struct kvm_vcpu *vcpu, u32 *exit_qual)
>          */
>         return 0;
>
> +       /*
> +        * A failed consistency check that leads to a VMExit during L1's
> +        * VMEnter to L2 is a variation of a normal VMexit, as explained in
> +        * 23.7 "VM-entry failures during or after loading guest state".
> +        */

I know that you just moved this comment, but as of revision
325384-067US, this is section 26.7. I try to avoid referencing SDM
section numbers, because they change quite frequently.

Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx>



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux