[PATCH 2/2] KVM: VMX: Dedup VM-Enter error handling for VM-Fail and VM-Exit

From: Sean Christopherson

Date: Thu Oct 22 2026 - 15:12:36 EST


Dedup the error handling code for failed VM-Entry as the only difference
between the VM-Fail and VM-Exit cases is the source of the failure reason.

Other than clearing vmx->fail on a VM-Exit failure, which should be a nop
absent other bugs, no functional change intended.

Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/vmx/vmx.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 29aa93cea963..a15cdad5c06a 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6741,21 +6741,13 @@ int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
if (vmx->vt.emulation_required)
return handle_invalid_guest_state(vcpu);

- if (exit_reason.failed_vmentry) {
+ if (exit_reason.failed_vmentry || unlikely(vmx->fail)) {
dump_vmcs(vcpu);
vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
- vcpu->run->fail_entry.hardware_entry_failure_reason
- = exit_reason.full;
+ vcpu->run->fail_entry.hardware_entry_failure_reason =
+ vmx->fail ? vmcs_read32(VM_INSTRUCTION_ERROR) : exit_reason.full;
vcpu->run->fail_entry.cpu = vcpu->arch.last_vmentry_cpu;
- return 0;
- }

- if (unlikely(vmx->fail)) {
- dump_vmcs(vcpu);
- vcpu->run->exit_reason = KVM_EXIT_FAIL_ENTRY;
- vcpu->run->fail_entry.hardware_entry_failure_reason
- = vmcs_read32(VM_INSTRUCTION_ERROR);
- vcpu->run->fail_entry.cpu = vcpu->arch.last_vmentry_cpu;
vmx->fail = 0;
return 0;
}
--
2.56.0.257.gf7497c7d27-goog