Skip to content

Commit e6b5d16

Browse files
committed
KVM: VMX: Re-enter guest in fastpath for "spurious" preemption timer exits
Re-enter the guest in the fast path if VMX preeemption timer VM-Exit was "spurious", i.e. if KVM "soft disabled" the timer by writing -1u and by some miracle the timer expired before any other VM-Exit occurred. This is just an intermediate step to cleaning up the preemption timer handling, optimizing these types of spurious VM-Exits is not interesting as they are extremely rare/infrequent. Link: https://lore.kernel.org/r/20240110012705.506918-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 9c9025e commit e6b5d16

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5992,8 +5992,15 @@ static fastpath_t handle_fastpath_preemption_timer(struct kvm_vcpu *vcpu)
59925992
{
59935993
struct vcpu_vmx *vmx = to_vmx(vcpu);
59945994

5995-
if (!vmx->req_immediate_exit &&
5996-
!unlikely(vmx->loaded_vmcs->hv_timer_soft_disabled)) {
5995+
/*
5996+
* In the *extremely* unlikely scenario that this is a spurious VM-Exit
5997+
* due to the timer expiring while it was "soft" disabled, just eat the
5998+
* exit and re-enter the guest.
5999+
*/
6000+
if (unlikely(vmx->loaded_vmcs->hv_timer_soft_disabled))
6001+
return EXIT_FASTPATH_REENTER_GUEST;
6002+
6003+
if (!vmx->req_immediate_exit) {
59976004
kvm_lapic_expired_hv_timer(vcpu);
59986005
return EXIT_FASTPATH_REENTER_GUEST;
59996006
}

0 commit comments

Comments
 (0)