Skip to content

Commit 0f65a9d

Browse files
sean-jcbonzini
authored andcommitted
KVM: VMX: Don't do full kick when triggering posted interrupt "fails"
Replace the full "kick" with just the "wake" in the fallback path when triggering a virtual interrupt via a posted interrupt fails because the guest is not IN_GUEST_MODE. If the guest transitions into guest mode between the check and the kick, then it's guaranteed to see the pending interrupt as KVM syncs the PIR to IRR (and onto GUEST_RVI) after setting IN_GUEST_MODE. Kicking the guest in this case is nothing more than an unnecessary VM-Exit (and host IRQ). Opportunistically update comments to explain the various ordering rules and barriers at play. Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 782f645 commit 0f65a9d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3998,7 +3998,7 @@ static int vmx_deliver_nested_posted_interrupt(struct kvm_vcpu *vcpu,
39983998

39993999
/* the PIR and ON have been set by L1. */
40004000
if (!kvm_vcpu_trigger_posted_interrupt(vcpu, true))
4001-
kvm_vcpu_kick(vcpu);
4001+
kvm_vcpu_wake_up(vcpu);
40024002
return 0;
40034003
}
40044004
return -1;
@@ -4036,7 +4036,7 @@ static int vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu, int vector)
40364036
* posted interrupt "fails" because vcpu->mode != IN_GUEST_MODE.
40374037
*/
40384038
if (!kvm_vcpu_trigger_posted_interrupt(vcpu, false))
4039-
kvm_vcpu_kick(vcpu);
4039+
kvm_vcpu_wake_up(vcpu);
40404040

40414041
return 0;
40424042
}

arch/x86/kvm/x86.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9978,10 +9978,11 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
99789978
smp_mb__after_srcu_read_unlock();
99799979

99809980
/*
9981-
* This handles the case where a posted interrupt was
9982-
* notified with kvm_vcpu_kick. Assigned devices can
9983-
* use the POSTED_INTR_VECTOR even if APICv is disabled,
9984-
* so do it even if APICv is disabled on this vCPU.
9981+
* Process pending posted interrupts to handle the case where the
9982+
* notification IRQ arrived in the host, or was never sent (because the
9983+
* target vCPU wasn't running). Do this regardless of the vCPU's APICv
9984+
* status, KVM doesn't update assigned devices when APICv is inhibited,
9985+
* i.e. they can post interrupts even if APICv is temporarily disabled.
99859986
*/
99869987
if (kvm_lapic_enabled(vcpu))
99879988
static_call_cond(kvm_x86_sync_pir_to_irr)(vcpu);

0 commit comments

Comments
 (0)