Skip to content

Commit e9093fd

Browse files
tlendackybonzini
authored andcommitted
KVM: SVM: Prepare for SEV-ES exit handling in the sev.c file
This is a pre-patch to consolidate some exit handling code into callable functions. Follow-on patches for SEV-ES exit handling will then be able to use them from the sev.c file. Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Message-Id: <5b8b0ffca8137f3e1e257f83df9f5c881c8a96a3.1607620209.git.thomas.lendacky@amd.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 8164a5f commit e9093fd

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,6 +3097,43 @@ static void dump_vmcb(struct kvm_vcpu *vcpu)
30973097
"excp_to:", save->last_excp_to);
30983098
}
30993099

3100+
static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code)
3101+
{
3102+
if (exit_code < ARRAY_SIZE(svm_exit_handlers) &&
3103+
svm_exit_handlers[exit_code])
3104+
return 0;
3105+
3106+
vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code);
3107+
dump_vmcb(vcpu);
3108+
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
3109+
vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
3110+
vcpu->run->internal.ndata = 2;
3111+
vcpu->run->internal.data[0] = exit_code;
3112+
vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
3113+
3114+
return -EINVAL;
3115+
}
3116+
3117+
static int svm_invoke_exit_handler(struct vcpu_svm *svm, u64 exit_code)
3118+
{
3119+
if (svm_handle_invalid_exit(&svm->vcpu, exit_code))
3120+
return 0;
3121+
3122+
#ifdef CONFIG_RETPOLINE
3123+
if (exit_code == SVM_EXIT_MSR)
3124+
return msr_interception(svm);
3125+
else if (exit_code == SVM_EXIT_VINTR)
3126+
return interrupt_window_interception(svm);
3127+
else if (exit_code == SVM_EXIT_INTR)
3128+
return intr_interception(svm);
3129+
else if (exit_code == SVM_EXIT_HLT)
3130+
return halt_interception(svm);
3131+
else if (exit_code == SVM_EXIT_NPF)
3132+
return npf_interception(svm);
3133+
#endif
3134+
return svm_exit_handlers[exit_code](svm);
3135+
}
3136+
31003137
static void svm_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2,
31013138
u32 *intr_info, u32 *error_code)
31023139
{
@@ -3163,32 +3200,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
31633200
if (exit_fastpath != EXIT_FASTPATH_NONE)
31643201
return 1;
31653202

3166-
if (exit_code >= ARRAY_SIZE(svm_exit_handlers)
3167-
|| !svm_exit_handlers[exit_code]) {
3168-
vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%x\n", exit_code);
3169-
dump_vmcb(vcpu);
3170-
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
3171-
vcpu->run->internal.suberror =
3172-
KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
3173-
vcpu->run->internal.ndata = 2;
3174-
vcpu->run->internal.data[0] = exit_code;
3175-
vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
3176-
return 0;
3177-
}
3178-
3179-
#ifdef CONFIG_RETPOLINE
3180-
if (exit_code == SVM_EXIT_MSR)
3181-
return msr_interception(svm);
3182-
else if (exit_code == SVM_EXIT_VINTR)
3183-
return interrupt_window_interception(svm);
3184-
else if (exit_code == SVM_EXIT_INTR)
3185-
return intr_interception(svm);
3186-
else if (exit_code == SVM_EXIT_HLT)
3187-
return halt_interception(svm);
3188-
else if (exit_code == SVM_EXIT_NPF)
3189-
return npf_interception(svm);
3190-
#endif
3191-
return svm_exit_handlers[exit_code](svm);
3203+
return svm_invoke_exit_handler(svm, exit_code);
31923204
}
31933205

31943206
static void reload_tss(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)