Skip to content

Commit 9482ae4

Browse files
jpemartinsbonzini
authored andcommitted
KVM: VMX: Consider PID.PIR to determine if vCPU has pending interrupts
Commit 17e433b ("KVM: Fix leak vCPU's VMCS value into other pCPU") introduced vmx_dy_apicv_has_pending_interrupt() in order to determine if a vCPU have a pending posted interrupt. This routine is used by kvm_vcpu_on_spin() when searching for a a new runnable vCPU to schedule on pCPU instead of a vCPU doing busy loop. vmx_dy_apicv_has_pending_interrupt() determines if a vCPU has a pending posted interrupt solely based on PID.ON. However, when a vCPU is preempted, vmx_vcpu_pi_put() sets PID.SN which cause raised posted interrupts to only set bit in PID.PIR without setting PID.ON (and without sending notification vector), as depicted in VT-d manual section 5.2.3 "Interrupt-Posting Hardware Operation". Therefore, checking PID.ON is insufficient to determine if a vCPU has pending posted interrupts and instead we should also check if there is some bit set on PID.PIR if PID.SN=1. Fixes: 17e433b ("KVM: Fix leak vCPU's VMCS value into other pCPU") Reviewed-by: Jagannathan Raman <[email protected]> Co-developed-by: Liran Alon <[email protected]> Signed-off-by: Liran Alon <[email protected]> Signed-off-by: Joao Martins <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent d9ff274 commit 9482ae4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6167,7 +6167,11 @@ static int vmx_sync_pir_to_irr(struct kvm_vcpu *vcpu)
61676167

61686168
static bool vmx_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu)
61696169
{
6170-
return pi_test_on(vcpu_to_pi_desc(vcpu));
6170+
struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu);
6171+
6172+
return pi_test_on(pi_desc) ||
6173+
(pi_test_sn(pi_desc) &&
6174+
!bitmap_empty((unsigned long *)pi_desc->pir, NR_VECTORS));
61716175
}
61726176

61736177
static void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)

0 commit comments

Comments
 (0)