Skip to content

Commit

Permalink
KVM: x86: Move handling of is_guest_mode() into fastpath exit handlers
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sean Christopherson committed Feb 23, 2024
1 parent 11776aa commit bf1a494
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions arch/x86/kvm/svm/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4089,6 +4089,9 @@ static int svm_vcpu_pre_run(struct kvm_vcpu *vcpu)

static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
{
if (is_guest_mode(vcpu))
return EXIT_FASTPATH_NONE;

if (to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
to_svm(vcpu)->vmcb->control.exit_info_1)
return handle_fastpath_set_msr_irqoff(vcpu);
Expand Down Expand Up @@ -4235,9 +4238,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);
}

Expand Down
6 changes: 3 additions & 3 deletions arch/x86/kvm/vmx/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -7214,6 +7214,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);
Expand Down Expand Up @@ -7425,9 +7428,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);
}

Expand Down

0 comments on commit bf1a494

Please sign in to comment.