Commit 55714cdd authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: nSVM: Move SMI vmexit handling to svm_check_nested_events()

Unlike VMX, SVM allows a hypervisor to take a SMI vmexit without having
any special SMM-monitor enablement sequence.  Therefore, it has to be
handled like interrupts and NMIs.  Check for an unblocked SMI in
svm_check_nested_events() so that pending SMIs are correctly prioritized
over IRQs and NMIs when the latter events will trigger VM-Exit.

Note that there is no need to test explicitly for SMI vmexits, because
guests always runs outside SMM and therefore can never get an SMI while
they are blocked.
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent bbdad0b5
...@@ -799,6 +799,15 @@ int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, ...@@ -799,6 +799,15 @@ int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
return vmexit; return vmexit;
} }
static void nested_svm_smi(struct vcpu_svm *svm)
{
svm->vmcb->control.exit_code = SVM_EXIT_SMI;
svm->vmcb->control.exit_info_1 = 0;
svm->vmcb->control.exit_info_2 = 0;
nested_svm_vmexit(svm);
}
static void nested_svm_nmi(struct vcpu_svm *svm) static void nested_svm_nmi(struct vcpu_svm *svm)
{ {
svm->vmcb->control.exit_code = SVM_EXIT_NMI; svm->vmcb->control.exit_code = SVM_EXIT_NMI;
...@@ -831,6 +840,13 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu) ...@@ -831,6 +840,13 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu)
kvm_event_needs_reinjection(vcpu) || svm->nested.exit_required || kvm_event_needs_reinjection(vcpu) || svm->nested.exit_required ||
svm->nested.nested_run_pending; svm->nested.nested_run_pending;
if (vcpu->arch.smi_pending && nested_exit_on_smi(svm)) {
if (block_nested_events)
return -EBUSY;
nested_svm_smi(svm);
return 0;
}
if (vcpu->arch.nmi_pending && nested_exit_on_nmi(svm)) { if (vcpu->arch.nmi_pending && nested_exit_on_nmi(svm)) {
if (block_nested_events) if (block_nested_events)
return -EBUSY; return -EBUSY;
......
...@@ -3778,14 +3778,6 @@ static bool svm_smi_allowed(struct kvm_vcpu *vcpu) ...@@ -3778,14 +3778,6 @@ static bool svm_smi_allowed(struct kvm_vcpu *vcpu)
if (!gif_set(svm)) if (!gif_set(svm))
return false; return false;
if (is_guest_mode(&svm->vcpu) &&
svm->nested.intercept & (1ULL << INTERCEPT_SMI)) {
/* TODO: Might need to set exit_info_1 and exit_info_2 here */
svm->vmcb->control.exit_code = SVM_EXIT_SMI;
svm->nested.exit_required = true;
return false;
}
return !is_smm(vcpu); return !is_smm(vcpu);
} }
......
...@@ -378,6 +378,11 @@ static inline bool svm_nested_virtualize_tpr(struct kvm_vcpu *vcpu) ...@@ -378,6 +378,11 @@ static inline bool svm_nested_virtualize_tpr(struct kvm_vcpu *vcpu)
return is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK); return is_guest_mode(vcpu) && (vcpu->arch.hflags & HF_VINTR_MASK);
} }
static inline bool nested_exit_on_smi(struct vcpu_svm *svm)
{
return (svm->nested.intercept & (1ULL << INTERCEPT_SMI));
}
static inline bool nested_exit_on_nmi(struct vcpu_svm *svm) static inline bool nested_exit_on_nmi(struct vcpu_svm *svm)
{ {
return (svm->nested.intercept & (1ULL << INTERCEPT_NMI)); return (svm->nested.intercept & (1ULL << INTERCEPT_NMI));
......
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