Commit 3a87c7e0 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: nSVM: Add helper to synthesize nested VM-Exit without collateral

Add a helper to consolidate boilerplate for nested VM-Exits that don't
provide any data in exit_info_*.

No functional change intended.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20210302174515.2812275-3-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent cb6a32c2
...@@ -787,12 +787,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) ...@@ -787,12 +787,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
static void nested_svm_triple_fault(struct kvm_vcpu *vcpu) static void nested_svm_triple_fault(struct kvm_vcpu *vcpu)
{ {
struct vcpu_svm *svm = to_svm(vcpu); nested_svm_simple_vmexit(to_svm(vcpu), SVM_EXIT_SHUTDOWN);
svm->vmcb->control.exit_code = SVM_EXIT_SHUTDOWN;
svm->vmcb->control.exit_info_1 = 0;
svm->vmcb->control.exit_info_2 = 0;
nested_svm_vmexit(svm);
} }
int svm_allocate_nested(struct vcpu_svm *svm) int svm_allocate_nested(struct vcpu_svm *svm)
...@@ -1017,50 +1012,11 @@ static void nested_svm_inject_exception_vmexit(struct vcpu_svm *svm) ...@@ -1017,50 +1012,11 @@ static void nested_svm_inject_exception_vmexit(struct vcpu_svm *svm)
nested_svm_vmexit(svm); nested_svm_vmexit(svm);
} }
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)
{
svm->vmcb->control.exit_code = SVM_EXIT_NMI;
svm->vmcb->control.exit_info_1 = 0;
svm->vmcb->control.exit_info_2 = 0;
nested_svm_vmexit(svm);
}
static void nested_svm_intr(struct vcpu_svm *svm)
{
trace_kvm_nested_intr_vmexit(svm->vmcb->save.rip);
svm->vmcb->control.exit_code = SVM_EXIT_INTR;
svm->vmcb->control.exit_info_1 = 0;
svm->vmcb->control.exit_info_2 = 0;
nested_svm_vmexit(svm);
}
static inline bool nested_exit_on_init(struct vcpu_svm *svm) static inline bool nested_exit_on_init(struct vcpu_svm *svm)
{ {
return vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_INIT); return vmcb_is_intercept(&svm->nested.ctl, INTERCEPT_INIT);
} }
static void nested_svm_init(struct vcpu_svm *svm)
{
svm->vmcb->control.exit_code = SVM_EXIT_INIT;
svm->vmcb->control.exit_info_1 = 0;
svm->vmcb->control.exit_info_2 = 0;
nested_svm_vmexit(svm);
}
static int svm_check_nested_events(struct kvm_vcpu *vcpu) static int svm_check_nested_events(struct kvm_vcpu *vcpu)
{ {
struct vcpu_svm *svm = to_svm(vcpu); struct vcpu_svm *svm = to_svm(vcpu);
...@@ -1074,7 +1030,7 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu) ...@@ -1074,7 +1030,7 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu)
return -EBUSY; return -EBUSY;
if (!nested_exit_on_init(svm)) if (!nested_exit_on_init(svm))
return 0; return 0;
nested_svm_init(svm); nested_svm_simple_vmexit(svm, SVM_EXIT_INIT);
return 0; return 0;
} }
...@@ -1092,7 +1048,7 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu) ...@@ -1092,7 +1048,7 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu)
return -EBUSY; return -EBUSY;
if (!nested_exit_on_smi(svm)) if (!nested_exit_on_smi(svm))
return 0; return 0;
nested_svm_smi(svm); nested_svm_simple_vmexit(svm, SVM_EXIT_SMI);
return 0; return 0;
} }
...@@ -1101,7 +1057,7 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu) ...@@ -1101,7 +1057,7 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu)
return -EBUSY; return -EBUSY;
if (!nested_exit_on_nmi(svm)) if (!nested_exit_on_nmi(svm))
return 0; return 0;
nested_svm_nmi(svm); nested_svm_simple_vmexit(svm, SVM_EXIT_NMI);
return 0; return 0;
} }
...@@ -1110,7 +1066,8 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu) ...@@ -1110,7 +1066,8 @@ static int svm_check_nested_events(struct kvm_vcpu *vcpu)
return -EBUSY; return -EBUSY;
if (!nested_exit_on_intr(svm)) if (!nested_exit_on_intr(svm))
return 0; return 0;
nested_svm_intr(svm); trace_kvm_nested_intr_vmexit(svm->vmcb->save.rip);
nested_svm_simple_vmexit(svm, SVM_EXIT_INTR);
return 0; return 0;
} }
......
...@@ -2225,12 +2225,8 @@ static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode) ...@@ -2225,12 +2225,8 @@ static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode)
int ret; int ret;
if (is_guest_mode(vcpu)) { if (is_guest_mode(vcpu)) {
svm->vmcb->control.exit_code = guest_mode_exit_codes[opcode];
svm->vmcb->control.exit_info_1 = 0;
svm->vmcb->control.exit_info_2 = 0;
/* Returns '1' or -errno on failure, '0' on success. */ /* Returns '1' or -errno on failure, '0' on success. */
ret = nested_svm_vmexit(svm); ret = nested_svm_simple_vmexit(svm, guest_mode_exit_codes[opcode]);
if (ret) if (ret)
return ret; return ret;
return 1; return 1;
......
...@@ -444,6 +444,15 @@ int svm_allocate_nested(struct vcpu_svm *svm); ...@@ -444,6 +444,15 @@ int svm_allocate_nested(struct vcpu_svm *svm);
int nested_svm_vmrun(struct kvm_vcpu *vcpu); int nested_svm_vmrun(struct kvm_vcpu *vcpu);
void nested_svm_vmloadsave(struct vmcb *from_vmcb, struct vmcb *to_vmcb); void nested_svm_vmloadsave(struct vmcb *from_vmcb, struct vmcb *to_vmcb);
int nested_svm_vmexit(struct vcpu_svm *svm); int nested_svm_vmexit(struct vcpu_svm *svm);
static inline int nested_svm_simple_vmexit(struct vcpu_svm *svm, u32 exit_code)
{
svm->vmcb->control.exit_code = exit_code;
svm->vmcb->control.exit_info_1 = 0;
svm->vmcb->control.exit_info_2 = 0;
return nested_svm_vmexit(svm);
}
int nested_svm_exit_handled(struct vcpu_svm *svm); int nested_svm_exit_handled(struct vcpu_svm *svm);
int nested_svm_check_permissions(struct kvm_vcpu *vcpu); int nested_svm_check_permissions(struct kvm_vcpu *vcpu);
int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr, int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
......
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