* [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
@ 2025-10-30 18:50 Sean Christopherson
2025-10-31 5:44 ` Yao Yuan
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Sean Christopherson @ 2025-10-30 18:50 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
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.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/svm/svm.c | 7 +------
arch/x86/kvm/vmx/tdx.c | 6 +-----
arch/x86/kvm/vmx/vmx.c | 9 +--------
arch/x86/kvm/x86.c | 12 ++++++++++++
5 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 48598d017d6f..4fbe4b7ce1da 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -2167,6 +2167,7 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
+void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason);
void kvm_enable_efer_bits(u64);
bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index f14709a511aa..83e0d4d5f4c5 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3451,13 +3451,8 @@ static bool svm_check_exit_valid(u64 exit_code)
static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code)
{
- vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code);
dump_vmcb(vcpu);
- vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
- vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
- vcpu->run->internal.ndata = 2;
- vcpu->run->internal.data[0] = exit_code;
- vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
+ kvm_prepare_unexpected_reason_exit(vcpu, exit_code);
return 0;
}
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 326db9b9c567..079d9f13eddb 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -2145,11 +2145,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
}
unhandled_exit:
- vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
- vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
- vcpu->run->internal.ndata = 2;
- vcpu->run->internal.data[0] = vp_enter_ret;
- vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
+ kvm_prepare_unexpected_reason_exit(vcpu, vp_enter_ret);
return 0;
}
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 1021d3b65ea0..08f7957ed4c3 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6642,15 +6642,8 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
return kvm_vmx_exit_handlers[exit_handler_index](vcpu);
unexpected_vmexit:
- vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n",
- exit_reason.full);
dump_vmcs(vcpu);
- vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
- vcpu->run->internal.suberror =
- KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
- vcpu->run->internal.ndata = 2;
- vcpu->run->internal.data[0] = exit_reason.full;
- vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
+ kvm_prepare_unexpected_reason_exit(vcpu, exit_reason.full);
return 0;
}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index b4b5d2d09634..c826cd05228a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9110,6 +9110,18 @@ void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa)
}
EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_event_vectoring_exit);
+void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason)
+{
+ vcpu_unimpl(vcpu, "unexpected exit reason 0x%llx\n", exit_reason);
+
+ vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+ vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
+ vcpu->run->internal.ndata = 2;
+ vcpu->run->internal.data[0] = exit_reason;
+ vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
+}
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_unexpected_reason_exit);
+
static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
{
struct kvm *kvm = vcpu->kvm;
base-commit: 4cc167c50eb19d44ac7e204938724e685e3d8057
--
2.51.1.930.gacf6e81ea2-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-30 18:50 [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits Sean Christopherson
@ 2025-10-31 5:44 ` Yao Yuan
2025-10-31 17:01 ` Sean Christopherson
2025-10-31 10:10 ` Huang, Kai
` (5 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Yao Yuan @ 2025-10-31 5:44 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel
On Thu, Oct 30, 2025 at 11:50:03AM +0800, Sean Christopherson wrote:
> 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.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/svm/svm.c | 7 +------
> arch/x86/kvm/vmx/tdx.c | 6 +-----
> arch/x86/kvm/vmx/vmx.c | 9 +--------
> arch/x86/kvm/x86.c | 12 ++++++++++++
> 5 files changed, 16 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 48598d017d6f..4fbe4b7ce1da 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -2167,6 +2167,7 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
> void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
>
> void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
> +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason);
>
> void kvm_enable_efer_bits(u64);
> bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index f14709a511aa..83e0d4d5f4c5 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3451,13 +3451,8 @@ static bool svm_check_exit_valid(u64 exit_code)
>
> static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code)
> {
> - vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code);
> dump_vmcb(vcpu);
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = exit_code;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, exit_code);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index 326db9b9c567..079d9f13eddb 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -2145,11 +2145,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
> }
>
> unhandled_exit:
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = vp_enter_ret;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, vp_enter_ret);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 1021d3b65ea0..08f7957ed4c3 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6642,15 +6642,8 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
> return kvm_vmx_exit_handlers[exit_handler_index](vcpu);
>
> unexpected_vmexit:
> - vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n",
> - exit_reason.full);
> dump_vmcs(vcpu);
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror =
> - KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = exit_reason.full;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, exit_reason.full);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index b4b5d2d09634..c826cd05228a 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9110,6 +9110,18 @@ void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa)
> }
> EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_event_vectoring_exit);
>
> +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason)
> +{
> + vcpu_unimpl(vcpu, "unexpected exit reason 0x%llx\n", exit_reason);
I like the dedup, and this brings above for tdx which not
before. Just one small thing: Will it be better if keep the
"vmx"/"svm" hint as before and plus the "tdx" hint yet ?
Reviewed-by: Yao Yuan <yaoyuan@linux.alibaba.com>
> +
> + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> + vcpu->run->internal.ndata = 2;
> + vcpu->run->internal.data[0] = exit_reason;
> + vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> +}
> +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_unexpected_reason_exit);
> +
> static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
> {
> struct kvm *kvm = vcpu->kvm;
>
> base-commit: 4cc167c50eb19d44ac7e204938724e685e3d8057
> --
> 2.51.1.930.gacf6e81ea2-goog
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-30 18:50 [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits Sean Christopherson
2025-10-31 5:44 ` Yao Yuan
@ 2025-10-31 10:10 ` Huang, Kai
2025-10-31 11:18 ` Gupta, Pankaj
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Huang, Kai @ 2025-10-31 10:10 UTC (permalink / raw)
To: pbonzini@redhat.com, seanjc@google.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
On Thu, 2025-10-30 at 11:50 -0700, Sean Christopherson wrote:
> 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.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
>
Acked-by: Kai Huang <kai.huang@intel.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-30 18:50 [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits Sean Christopherson
2025-10-31 5:44 ` Yao Yuan
2025-10-31 10:10 ` Huang, Kai
@ 2025-10-31 11:18 ` Gupta, Pankaj
2025-11-03 17:37 ` Yosry Ahmed
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Gupta, Pankaj @ 2025-10-31 11:18 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
> 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.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
> ---
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/svm/svm.c | 7 +------
> arch/x86/kvm/vmx/tdx.c | 6 +-----
> arch/x86/kvm/vmx/vmx.c | 9 +--------
> arch/x86/kvm/x86.c | 12 ++++++++++++
> 5 files changed, 16 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 48598d017d6f..4fbe4b7ce1da 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -2167,6 +2167,7 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
> void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
>
> void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
> +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason);
>
> void kvm_enable_efer_bits(u64);
> bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index f14709a511aa..83e0d4d5f4c5 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3451,13 +3451,8 @@ static bool svm_check_exit_valid(u64 exit_code)
>
> static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code)
> {
> - vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code);
> dump_vmcb(vcpu);
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = exit_code;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, exit_code);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index 326db9b9c567..079d9f13eddb 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -2145,11 +2145,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
> }
>
> unhandled_exit:
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = vp_enter_ret;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, vp_enter_ret);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 1021d3b65ea0..08f7957ed4c3 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6642,15 +6642,8 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
> return kvm_vmx_exit_handlers[exit_handler_index](vcpu);
>
> unexpected_vmexit:
> - vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n",
> - exit_reason.full);
> dump_vmcs(vcpu);
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror =
> - KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = exit_reason.full;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, exit_reason.full);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index b4b5d2d09634..c826cd05228a 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9110,6 +9110,18 @@ void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa)
> }
> EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_event_vectoring_exit);
>
> +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason)
> +{
> + vcpu_unimpl(vcpu, "unexpected exit reason 0x%llx\n", exit_reason);
> +
> + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> + vcpu->run->internal.ndata = 2;
> + vcpu->run->internal.data[0] = exit_reason;
> + vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> +}
> +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_unexpected_reason_exit);
> +
> static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
> {
> struct kvm *kvm = vcpu->kvm;
>
> base-commit: 4cc167c50eb19d44ac7e204938724e685e3d8057
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-31 5:44 ` Yao Yuan
@ 2025-10-31 17:01 ` Sean Christopherson
2025-11-01 1:49 ` Yao Yuan
0 siblings, 1 reply; 11+ messages in thread
From: Sean Christopherson @ 2025-10-31 17:01 UTC (permalink / raw)
To: Yao Yuan; +Cc: Paolo Bonzini, kvm, linux-kernel
On Fri, Oct 31, 2025, Yao Yuan wrote:
> On Thu, Oct 30, 2025 at 11:50:03AM +0800, Sean Christopherson wrote:
> I like the dedup, and this brings above for tdx which not
> before. Just one small thing: Will it be better if keep the
> "vmx"/"svm" hint as before and plus the "tdx" hint yet ?
It'd be nice to have, but I honestly don't think it's worth going out of our
way to capture that information. If someone can't disambiguate "kvm" to mean
"vmx/tdx" vs. "svm" based on the host, they've got bigger problems.
And as for "vmx" vs. "tdx", I really hope that's not meaningful information for
users, e.g. the printks are ratelimited, and users should really be gleaning
information from the VMM instance, not from dmesg.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-31 17:01 ` Sean Christopherson
@ 2025-11-01 1:49 ` Yao Yuan
0 siblings, 0 replies; 11+ messages in thread
From: Yao Yuan @ 2025-11-01 1:49 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel
On Fri, Oct 31, 2025 at 10:01:38AM +0800, Sean Christopherson wrote:
> On Fri, Oct 31, 2025, Yao Yuan wrote:
> > On Thu, Oct 30, 2025 at 11:50:03AM +0800, Sean Christopherson wrote:
> > I like the dedup, and this brings above for tdx which not
> > before. Just one small thing: Will it be better if keep the
> > "vmx"/"svm" hint as before and plus the "tdx" hint yet ?
>
> It'd be nice to have, but I honestly don't think it's worth going out of our
> way to capture that information. If someone can't disambiguate "kvm" to mean
> "vmx/tdx" vs. "svm" based on the host, they've got bigger problems.
>
> And as for "vmx" vs. "tdx", I really hope that's not meaningful information for
> users, e.g. the printks are ratelimited, and users should really be gleaning
> information from the VMM instance, not from dmesg.
thanks for your reply, Good point on printks are ratelimited!
Reviewed-by: yaoyuan@linux.alibaba.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-30 18:50 [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits Sean Christopherson
` (2 preceding siblings ...)
2025-10-31 11:18 ` Gupta, Pankaj
@ 2025-11-03 17:37 ` Yosry Ahmed
2025-11-04 17:16 ` Sean Christopherson
2025-11-04 2:00 ` Xiaoyao Li
` (2 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Yosry Ahmed @ 2025-11-03 17:37 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel
On Thu, Oct 30, 2025 at 11:50:03AM -0700, Sean Christopherson wrote:
> 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.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/svm/svm.c | 7 +------
> arch/x86/kvm/vmx/tdx.c | 6 +-----
> arch/x86/kvm/vmx/vmx.c | 9 +--------
> arch/x86/kvm/x86.c | 12 ++++++++++++
> 5 files changed, 16 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 48598d017d6f..4fbe4b7ce1da 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -2167,6 +2167,7 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
> void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
>
> void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
> +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason);
>
> void kvm_enable_efer_bits(u64);
> bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index f14709a511aa..83e0d4d5f4c5 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3451,13 +3451,8 @@ static bool svm_check_exit_valid(u64 exit_code)
>
> static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code)
> {
> - vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code);
> dump_vmcb(vcpu);
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = exit_code;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, exit_code);
> return 0;
> }
We can probably drop svm_handle_invalid_exit() entirely now, but looks
good either way:
Reviewed-by: Yosry Ahmed <yosry.ahmed@linux.dev>
>
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index 326db9b9c567..079d9f13eddb 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -2145,11 +2145,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
> }
>
> unhandled_exit:
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = vp_enter_ret;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, vp_enter_ret);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 1021d3b65ea0..08f7957ed4c3 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6642,15 +6642,8 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
> return kvm_vmx_exit_handlers[exit_handler_index](vcpu);
>
> unexpected_vmexit:
> - vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n",
> - exit_reason.full);
> dump_vmcs(vcpu);
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror =
> - KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = exit_reason.full;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, exit_reason.full);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index b4b5d2d09634..c826cd05228a 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9110,6 +9110,18 @@ void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa)
> }
> EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_event_vectoring_exit);
>
> +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason)
> +{
> + vcpu_unimpl(vcpu, "unexpected exit reason 0x%llx\n", exit_reason);
> +
> + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> + vcpu->run->internal.ndata = 2;
> + vcpu->run->internal.data[0] = exit_reason;
> + vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> +}
> +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_unexpected_reason_exit);
> +
> static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
> {
> struct kvm *kvm = vcpu->kvm;
>
> base-commit: 4cc167c50eb19d44ac7e204938724e685e3d8057
> --
> 2.51.1.930.gacf6e81ea2-goog
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-30 18:50 [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits Sean Christopherson
` (3 preceding siblings ...)
2025-11-03 17:37 ` Yosry Ahmed
@ 2025-11-04 2:00 ` Xiaoyao Li
2025-11-04 3:03 ` Binbin Wu
2025-11-04 17:45 ` Sean Christopherson
6 siblings, 0 replies; 11+ messages in thread
From: Xiaoyao Li @ 2025-11-04 2:00 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
On 10/31/2025 2:50 AM, Sean Christopherson wrote:
> 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.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/svm/svm.c | 7 +------
> arch/x86/kvm/vmx/tdx.c | 6 +-----
> arch/x86/kvm/vmx/vmx.c | 9 +--------
> arch/x86/kvm/x86.c | 12 ++++++++++++
> 5 files changed, 16 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 48598d017d6f..4fbe4b7ce1da 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -2167,6 +2167,7 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
> void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
>
> void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
> +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason);
>
> void kvm_enable_efer_bits(u64);
> bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index f14709a511aa..83e0d4d5f4c5 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3451,13 +3451,8 @@ static bool svm_check_exit_valid(u64 exit_code)
>
> static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code)
> {
> - vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code);
> dump_vmcb(vcpu);
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = exit_code;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, exit_code);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> index 326db9b9c567..079d9f13eddb 100644
> --- a/arch/x86/kvm/vmx/tdx.c
> +++ b/arch/x86/kvm/vmx/tdx.c
> @@ -2145,11 +2145,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath)
> }
>
> unhandled_exit:
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = vp_enter_ret;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, vp_enter_ret);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 1021d3b65ea0..08f7957ed4c3 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6642,15 +6642,8 @@ static int __vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
> return kvm_vmx_exit_handlers[exit_handler_index](vcpu);
>
> unexpected_vmexit:
> - vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n",
> - exit_reason.full);
> dump_vmcs(vcpu);
> - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> - vcpu->run->internal.suberror =
> - KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> - vcpu->run->internal.ndata = 2;
> - vcpu->run->internal.data[0] = exit_reason.full;
> - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> + kvm_prepare_unexpected_reason_exit(vcpu, exit_reason.full);
> return 0;
> }
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index b4b5d2d09634..c826cd05228a 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9110,6 +9110,18 @@ void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa)
> }
> EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_event_vectoring_exit);
>
> +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason)
> +{
> + vcpu_unimpl(vcpu, "unexpected exit reason 0x%llx\n", exit_reason);
> +
> + vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> + vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> + vcpu->run->internal.ndata = 2;
> + vcpu->run->internal.data[0] = exit_reason;
> + vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> +}
> +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_prepare_unexpected_reason_exit);
> +
> static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
> {
> struct kvm *kvm = vcpu->kvm;
>
> base-commit: 4cc167c50eb19d44ac7e204938724e685e3d8057
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-30 18:50 [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits Sean Christopherson
` (4 preceding siblings ...)
2025-11-04 2:00 ` Xiaoyao Li
@ 2025-11-04 3:03 ` Binbin Wu
2025-11-04 17:45 ` Sean Christopherson
6 siblings, 0 replies; 11+ messages in thread
From: Binbin Wu @ 2025-11-04 3:03 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel
On 10/31/2025 2:50 AM, Sean Christopherson wrote:
> 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.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-11-03 17:37 ` Yosry Ahmed
@ 2025-11-04 17:16 ` Sean Christopherson
0 siblings, 0 replies; 11+ messages in thread
From: Sean Christopherson @ 2025-11-04 17:16 UTC (permalink / raw)
To: Yosry Ahmed; +Cc: Paolo Bonzini, kvm, linux-kernel
On Mon, Nov 03, 2025, Yosry Ahmed wrote:
> On Thu, Oct 30, 2025 at 11:50:03AM -0700, Sean Christopherson wrote:
> > 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.
> >
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > ---
> > arch/x86/include/asm/kvm_host.h | 1 +
> > arch/x86/kvm/svm/svm.c | 7 +------
> > arch/x86/kvm/vmx/tdx.c | 6 +-----
> > arch/x86/kvm/vmx/vmx.c | 9 +--------
> > arch/x86/kvm/x86.c | 12 ++++++++++++
> > 5 files changed, 16 insertions(+), 19 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> > index 48598d017d6f..4fbe4b7ce1da 100644
> > --- a/arch/x86/include/asm/kvm_host.h
> > +++ b/arch/x86/include/asm/kvm_host.h
> > @@ -2167,6 +2167,7 @@ void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu,
> > void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu);
> >
> > void kvm_prepare_event_vectoring_exit(struct kvm_vcpu *vcpu, gpa_t gpa);
> > +void kvm_prepare_unexpected_reason_exit(struct kvm_vcpu *vcpu, u64 exit_reason);
> >
> > void kvm_enable_efer_bits(u64);
> > bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
> > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> > index f14709a511aa..83e0d4d5f4c5 100644
> > --- a/arch/x86/kvm/svm/svm.c
> > +++ b/arch/x86/kvm/svm/svm.c
> > @@ -3451,13 +3451,8 @@ static bool svm_check_exit_valid(u64 exit_code)
> >
> > static int svm_handle_invalid_exit(struct kvm_vcpu *vcpu, u64 exit_code)
> > {
> > - vcpu_unimpl(vcpu, "svm: unexpected exit reason 0x%llx\n", exit_code);
> > dump_vmcb(vcpu);
> > - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
> > - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON;
> > - vcpu->run->internal.ndata = 2;
> > - vcpu->run->internal.data[0] = exit_code;
> > - vcpu->run->internal.data[1] = vcpu->arch.last_vmentry_cpu;
> > + kvm_prepare_unexpected_reason_exit(vcpu, exit_code);
> > return 0;
> > }
>
> We can probably drop svm_handle_invalid_exit() entirely now
Hmm, yeah. I'll do so in a separate follow-up, as I want to do more than just
fold svm_handle_invalid_exit() into svm_invoke_exit_handler().
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
2025-10-30 18:50 [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits Sean Christopherson
` (5 preceding siblings ...)
2025-11-04 3:03 ` Binbin Wu
@ 2025-11-04 17:45 ` Sean Christopherson
6 siblings, 0 replies; 11+ messages in thread
From: Sean Christopherson @ 2025-11-04 17:45 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel
On Thu, 30 Oct 2025 11:50:03 -0700, Sean Christopherson wrote:
> 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.
>
>
Applied to kvm-x86 misc, thanks!
[1/1] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits
https://github.com/kvm-x86/linux/commit/65a70164aba7
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-11-04 17:47 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30 18:50 [PATCH] KVM: x86: Add a helper to dedup reporting of unhandled VM-Exits Sean Christopherson
2025-10-31 5:44 ` Yao Yuan
2025-10-31 17:01 ` Sean Christopherson
2025-11-01 1:49 ` Yao Yuan
2025-10-31 10:10 ` Huang, Kai
2025-10-31 11:18 ` Gupta, Pankaj
2025-11-03 17:37 ` Yosry Ahmed
2025-11-04 17:16 ` Sean Christopherson
2025-11-04 2:00 ` Xiaoyao Li
2025-11-04 3:03 ` Binbin Wu
2025-11-04 17:45 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox