Commit 11f0cbf0 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: nSVM: Trace VM-Enter consistency check failures

Use trace_kvm_nested_vmenter_failed() and its macro magic to trace
consistency check failures on nested VMRUN.  Tracing such failures by
running the buggy VMM as a KVM guest is often the only way to get a
precise explanation of why VMRUN failed.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20210204000117.3303214-13-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 648fc8ae
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "lapic.h" #include "lapic.h"
#include "svm.h" #include "svm.h"
#define CC KVM_NESTED_VMENTER_CONSISTENCY_CHECK
static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu,
struct x86_exception *fault) struct x86_exception *fault)
{ {
...@@ -233,14 +235,13 @@ static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu) ...@@ -233,14 +235,13 @@ static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu)
static bool nested_vmcb_check_controls(struct vmcb_control_area *control) static bool nested_vmcb_check_controls(struct vmcb_control_area *control)
{ {
if ((vmcb_is_intercept(control, INTERCEPT_VMRUN)) == 0) if (CC(!vmcb_is_intercept(control, INTERCEPT_VMRUN)))
return false; return false;
if (control->asid == 0) if (CC(control->asid == 0))
return false; return false;
if ((control->nested_ctl & SVM_NESTED_CTL_NP_ENABLE) && if (CC((control->nested_ctl & SVM_NESTED_CTL_NP_ENABLE) && !npt_enabled))
!npt_enabled)
return false; return false;
return true; return true;
...@@ -257,32 +258,36 @@ static bool nested_vmcb_check_cr3_cr4(struct vcpu_svm *svm, ...@@ -257,32 +258,36 @@ static bool nested_vmcb_check_cr3_cr4(struct vcpu_svm *svm,
* CR0.PG && EFER.LME. * CR0.PG && EFER.LME.
*/ */
if ((save->efer & EFER_LME) && (save->cr0 & X86_CR0_PG)) { if ((save->efer & EFER_LME) && (save->cr0 & X86_CR0_PG)) {
if (!(save->cr4 & X86_CR4_PAE) || !(save->cr0 & X86_CR0_PE) || if (CC(!(save->cr4 & X86_CR4_PAE)) ||
kvm_vcpu_is_illegal_gpa(vcpu, save->cr3)) CC(!(save->cr0 & X86_CR0_PE)) ||
CC(kvm_vcpu_is_illegal_gpa(vcpu, save->cr3)))
return false; return false;
} }
return kvm_is_valid_cr4(&svm->vcpu, save->cr4); if (CC(!kvm_is_valid_cr4(vcpu, save->cr4)))
return false;
return true;
} }
/* Common checks that apply to both L1 and L2 state. */ /* Common checks that apply to both L1 and L2 state. */
static bool nested_vmcb_valid_sregs(struct vcpu_svm *svm, static bool nested_vmcb_valid_sregs(struct vcpu_svm *svm,
struct vmcb_save_area *save) struct vmcb_save_area *save)
{ {
if (!(save->efer & EFER_SVME)) if (CC(!(save->efer & EFER_SVME)))
return false; return false;
if (((save->cr0 & X86_CR0_CD) == 0 && (save->cr0 & X86_CR0_NW)) || if (CC((save->cr0 & X86_CR0_CD) == 0 && (save->cr0 & X86_CR0_NW)) ||
(save->cr0 & ~0xffffffffULL)) CC(save->cr0 & ~0xffffffffULL))
return false; return false;
if (!kvm_dr6_valid(save->dr6) || !kvm_dr7_valid(save->dr7)) if (CC(!kvm_dr6_valid(save->dr6)) || CC(!kvm_dr7_valid(save->dr7)))
return false; return false;
if (!nested_vmcb_check_cr3_cr4(svm, save)) if (!nested_vmcb_check_cr3_cr4(svm, save))
return false; return false;
if (!kvm_valid_efer(&svm->vcpu, save->efer)) if (CC(!kvm_valid_efer(&svm->vcpu, save->efer)))
return false; return false;
return true; return true;
...@@ -384,12 +389,12 @@ static inline bool nested_npt_enabled(struct vcpu_svm *svm) ...@@ -384,12 +389,12 @@ static inline bool nested_npt_enabled(struct vcpu_svm *svm)
static int nested_svm_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3, static int nested_svm_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3,
bool nested_npt) bool nested_npt)
{ {
if (kvm_vcpu_is_illegal_gpa(vcpu, cr3)) if (CC(kvm_vcpu_is_illegal_gpa(vcpu, cr3)))
return -EINVAL; return -EINVAL;
if (!nested_npt && is_pae_paging(vcpu) && if (!nested_npt && is_pae_paging(vcpu) &&
(cr3 != kvm_read_cr3(vcpu) || pdptrs_changed(vcpu))) { (cr3 != kvm_read_cr3(vcpu) || pdptrs_changed(vcpu))) {
if (!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) if (CC(!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)))
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment