Skip to content

Commit bf1a494

Browse files
committed
KVM: x86: Move handling of is_guest_mode() into fastpath exit handlers
Let the fastpath code decide which exits can/can't be handled in the fastpath when L2 is active, e.g. when KVM generates a VMX preemption timer exit to forcefully regain control, there is no "work" to be done and so such exits can be handled in the fastpath regardless of whether L1 or L2 is active. Moving the is_guest_mode() check into the fastpath code also makes it easier to see that L2 isn't allowed to use the fastpath in most cases, e.g. it's not immediately obvious why handle_fastpath_preemption_timer() is called from the fastpath and the normal path. Link: https://lore.kernel.org/r/20240110012705.506918-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 11776aa commit bf1a494

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4089,6 +4089,9 @@ static int svm_vcpu_pre_run(struct kvm_vcpu *vcpu)
40894089

40904090
static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
40914091
{
4092+
if (is_guest_mode(vcpu))
4093+
return EXIT_FASTPATH_NONE;
4094+
40924095
if (to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
40934096
to_svm(vcpu)->vmcb->control.exit_info_1)
40944097
return handle_fastpath_set_msr_irqoff(vcpu);
@@ -4235,9 +4238,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu,
42354238

42364239
svm_complete_interrupts(vcpu);
42374240

4238-
if (is_guest_mode(vcpu))
4239-
return EXIT_FASTPATH_NONE;
4240-
42414241
return svm_exit_handlers_fastpath(vcpu);
42424242
}
42434243

arch/x86/kvm/vmx/vmx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7214,6 +7214,9 @@ void noinstr vmx_spec_ctrl_restore_host(struct vcpu_vmx *vmx,
72147214

72157215
static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
72167216
{
7217+
if (is_guest_mode(vcpu))
7218+
return EXIT_FASTPATH_NONE;
7219+
72177220
switch (to_vmx(vcpu)->exit_reason.basic) {
72187221
case EXIT_REASON_MSR_WRITE:
72197222
return handle_fastpath_set_msr_irqoff(vcpu);
@@ -7425,9 +7428,6 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
74257428
vmx_recover_nmi_blocking(vmx);
74267429
vmx_complete_interrupts(vmx);
74277430

7428-
if (is_guest_mode(vcpu))
7429-
return EXIT_FASTPATH_NONE;
7430-
74317431
return vmx_exit_handlers_fastpath(vcpu);
74327432
}
74337433

0 commit comments

Comments
 (0)