Skip to content

Commit c42dec1

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: VMX: synthesize invalid VM exit when emulating invalid guest state
Since no actual VM entry happened, the VM exit information is stale. To avoid this, synthesize an invalid VM guest state VM exit. Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Maxim Levitsky <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 136a55c commit c42dec1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6622,10 +6622,21 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
66226622
vmx->loaded_vmcs->soft_vnmi_blocked))
66236623
vmx->loaded_vmcs->entry_time = ktime_get();
66246624

6625-
/* Don't enter VMX if guest state is invalid, let the exit handler
6626-
start emulation until we arrive back to a valid state */
6627-
if (vmx->emulation_required)
6625+
/*
6626+
* Don't enter VMX if guest state is invalid, let the exit handler
6627+
* start emulation until we arrive back to a valid state. Synthesize a
6628+
* consistency check VM-Exit due to invalid guest state and bail.
6629+
*/
6630+
if (unlikely(vmx->emulation_required)) {
6631+
vmx->fail = 0;
6632+
vmx->exit_reason.full = EXIT_REASON_INVALID_STATE;
6633+
vmx->exit_reason.failed_vmentry = 1;
6634+
kvm_register_mark_available(vcpu, VCPU_EXREG_EXIT_INFO_1);
6635+
vmx->exit_qualification = ENTRY_FAIL_DEFAULT;
6636+
kvm_register_mark_available(vcpu, VCPU_EXREG_EXIT_INFO_2);
6637+
vmx->exit_intr_info = 0;
66286638
return EXIT_FASTPATH_NONE;
6639+
}
66296640

66306641
trace_kvm_entry(vcpu);
66316642

0 commit comments

Comments
 (0)