Skip to content

Commit 65a7016

Browse files
committed
KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
Add and use a helper, kvm_prepare_unexpected_reason_exit(), to dedup the code that fills the exit reason and CPU when KVM encounters a VM-Exit that KVM doesn't know how to handle. Reviewed-by: yaoyuan@linux.alibaba.com Reviewed-by: Yao Yuan <yaoyuan@linux.alibaba.com> Reviewed-by: Yosry Ahmed <yosry.ahmed@linux.dev> Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Acked-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20251030185004.3372256-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 211ddde commit 65a7016

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,7 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
21672167
void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
21682168

21692169
void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
2170+
void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason);
21702171

21712172
void kvm_enable_efer_bits(u64);
21722173
bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,13 +3446,8 @@ static bool svm_check_exit_valid(u64 exit_code)
34463446

34473447
static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code)
34483448
{
3449-
vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code);
34503449
dump_vmcb(vcpu);
3451-
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
3452-
vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
3453-
vcpu->run->internal.ndata = 2;
3454-
vcpu->run->internal.data[0] = exit_code;
3455-
vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
3450+
kvm_prepare_unexpected_reason_exit(vcpu, exit_code);
34563451
return 0;
34573452
}
34583453

arch/x86/kvm/vmx/tdx.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,11 +2145,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
21452145
}
21462146

21472147
unhandled_exit:
2148-
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
2149-
vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
2150-
vcpu->run->internal.ndata = 2;
2151-
vcpu->run->internal.data[0] = vp_enter_ret;
2152-
vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
2148+
kvm_prepare_unexpected_reason_exit(vcpu, vp_enter_ret);
21532149
return 0;
21542150
}
21552151

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6623,15 +6623,8 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
66236623
return kvm_vmx_exit_handlers[exit_handler_index](vcpu);
66246624

66256625
unexpected_vmexit:
6626-
vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n",
6627-
exit_reason.full);
66286626
dump_vmcs(vcpu);
6629-
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
6630-
vcpu->run->internal.suberror =
6631-
KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
6632-
vcpu->run->internal.ndata = 2;
6633-
vcpu->run->internal.data[0] = exit_reason.full;
6634-
vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
6627+
kvm_prepare_unexpected_reason_exit(vcpu, exit_reason.full);
66356628
return 0;
66366629
}
66376630

arch/x86/kvm/x86.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9110,6 +9110,18 @@ void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa)
91109110
}
91119111
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_event_vectoring_exit);
91129112

9113+
void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason)
9114+
{
9115+
vcpu_unimpl(vcpu, "unexpected exit reason 0x%llx\n", exit_reason);
9116+
9117+
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
9118+
vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
9119+
vcpu->run->internal.ndata = 2;
9120+
vcpu->run->internal.data[0] = exit_reason;
9121+
vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
9122+
}
9123+
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_unexpected_reason_exit);
9124+
91139125
static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
91149126
{
91159127
struct kvm *kvm = vcpu->kvm;

0 commit comments

Comments
 (0)