Skip to content

Commit 11776aa

Browse files
committed
KVM: VMX: Handle forced exit due to preemption timer in fastpath
Handle VMX preemption timer VM-Exits due to KVM forcing an exit in the exit fastpath, i.e. avoid calling back into handle_preemption_timer() for the same exit. There is no work to be done for forced exits, as the name suggests the goal is purely to get control back in KVM. In addition to shaving a few cycles, this will allow cleanly separating handle_fastpath_preemption_timer() from handle_preemption_timer(), e.g. it's not immediately obvious why _apparently_ calling handle_fastpath_preemption_timer() twice on a "slow" exit is necessary: the "slow" call is necessary to handle exits from L2, which are excluded from the fastpath by vmx_vcpu_run(). Link: https://lore.kernel.org/r/20240110012705.506918-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e6b5d16 commit 11776aa

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6000,12 +6000,15 @@ static fastpath_t handle_fastpath_preemption_timer(struct kvm_vcpu *vcpu)
60006000
if (unlikely(vmx->loaded_vmcs->hv_timer_soft_disabled))
60016001
return EXIT_FASTPATH_REENTER_GUEST;
60026002

6003-
if (!vmx->req_immediate_exit) {
6004-
kvm_lapic_expired_hv_timer(vcpu);
6005-
return EXIT_FASTPATH_REENTER_GUEST;
6006-
}
6003+
/*
6004+
* If the timer expired because KVM used it to force an immediate exit,
6005+
* then mission accomplished.
6006+
*/
6007+
if (vmx->req_immediate_exit)
6008+
return EXIT_FASTPATH_EXIT_HANDLED;
60076009

6008-
return EXIT_FASTPATH_NONE;
6010+
kvm_lapic_expired_hv_timer(vcpu);
6011+
return EXIT_FASTPATH_REENTER_GUEST;
60096012
}
60106013

60116014
static int handle_preemption_timer(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)