Skip to content

Commit 7b3d1bb

Browse files
committed
KVM: VMX: Handle KVM-induced preemption timer exits in fastpath for L2
Eat VMX treemption timer exits in the fastpath regardless of whether L1 or L2 is active. The VM-Exit is 100% KVM-induced, i.e. there is nothing directly related to the exit that KVM needs to do on behalf of the guest, thus there is no reason to wait until the slow path to do nothing. Opportunistically add comments explaining why preemption timer exits for emulating the guest's APIC timer need to go down the slow path. Link: https://lore.kernel.org/r/20240110012705.506918-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent bf1a494 commit 7b3d1bb

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6007,13 +6007,26 @@ static fastpath_t handle_fastpath_preemption_timer(struct kvm_vcpu *vcpu)
60076007
if (vmx->req_immediate_exit)
60086008
return EXIT_FASTPATH_EXIT_HANDLED;
60096009

6010+
/*
6011+
* If L2 is active, go down the slow path as emulating the guest timer
6012+
* expiration likely requires synthesizing a nested VM-Exit.
6013+
*/
6014+
if (is_guest_mode(vcpu))
6015+
return EXIT_FASTPATH_NONE;
6016+
60106017
kvm_lapic_expired_hv_timer(vcpu);
60116018
return EXIT_FASTPATH_REENTER_GUEST;
60126019
}
60136020

60146021
static int handle_preemption_timer(struct kvm_vcpu *vcpu)
60156022
{
6016-
handle_fastpath_preemption_timer(vcpu);
6023+
/*
6024+
* This non-fastpath handler is reached if and only if the preemption
6025+
* timer was being used to emulate a guest timer while L2 is active.
6026+
* All other scenarios are supposed to be handled in the fastpath.
6027+
*/
6028+
WARN_ON_ONCE(!is_guest_mode(vcpu));
6029+
kvm_lapic_expired_hv_timer(vcpu);
60176030
return 1;
60186031
}
60196032

@@ -7214,7 +7227,12 @@ void noinstr vmx_spec_ctrl_restore_host(struct vcpu_vmx *vmx,
72147227

72157228
static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
72167229
{
7217-
if (is_guest_mode(vcpu))
7230+
/*
7231+
* If L2 is active, some VMX preemption timer exits can be handled in
7232+
* the fastpath even, all other exits must use the slow path.
7233+
*/
7234+
if (is_guest_mode(vcpu) &&
7235+
to_vmx(vcpu)->exit_reason.basic != EXIT_REASON_PREEMPTION_TIMER)
72187236
return EXIT_FASTPATH_NONE;
72197237

72207238
switch (to_vmx(vcpu)->exit_reason.basic) {

0 commit comments

Comments
 (0)