]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: x86: Move handling of is_guest_mode() into fastpath exit handlers
authorSean Christopherson <seanjc@google.com>
Fri, 15 Aug 2025 00:11:56 +0000 (17:11 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:25:50 +0000 (16:25 +0200)
[ Upstream commit bf1a49436ea37b98dd2f37c57608951d0e28eecc ]

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>
[sean: resolve syntactic conflict in svm_exit_handlers_fastpath()]
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/kvm/svm/svm.c
arch/x86/kvm/vmx/vmx.c

index b4283c2358a6a569508d7f80bcdea1ebcc3a4b8a..337a304d211b33a70dc8bd86faa5608872c6d622 100644 (file)
@@ -3964,6 +3964,9 @@ static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
 {
        struct vmcb_control_area *control = &to_svm(vcpu)->vmcb->control;
 
+       if (is_guest_mode(vcpu))
+               return EXIT_FASTPATH_NONE;
+
        /*
         * Note, the next RIP must be provided as SRCU isn't held, i.e. KVM
         * can't read guest memory (dereference memslots) to decode the WRMSR.
@@ -4127,9 +4130,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu,
 
        svm_complete_interrupts(vcpu);
 
-       if (is_guest_mode(vcpu))
-               return EXIT_FASTPATH_NONE;
-
        return svm_exit_handlers_fastpath(vcpu);
 }
 
index c804ad001a79d936fb3a16e4d70137c8a244219e..18ceed9046a9c1c9a9537d3fbe64232ac68373f0 100644 (file)
@@ -7138,6 +7138,9 @@ void noinstr vmx_spec_ctrl_restore_host(struct vcpu_vmx *vmx,
 
 static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
 {
+       if (is_guest_mode(vcpu))
+               return EXIT_FASTPATH_NONE;
+
        switch (to_vmx(vcpu)->exit_reason.basic) {
        case EXIT_REASON_MSR_WRITE:
                return handle_fastpath_set_msr_irqoff(vcpu);
@@ -7337,9 +7340,6 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
        vmx_recover_nmi_blocking(vmx);
        vmx_complete_interrupts(vmx);
 
-       if (is_guest_mode(vcpu))
-               return EXIT_FASTPATH_NONE;
-
        return vmx_exit_handlers_fastpath(vcpu);
 }