archive mirror
 help / color / mirror / Atom feed
From: Joao Martins <>
Cc: "Joao Martins" <>,,
	"Paolo Bonzini" <>,
	"Radim Krčmář" <>,
	"Sean Christopherson" <>,
	"Vitaly Kuznetsov" <>,
	"Wanpeng Li" <>,
	"Jim Mattson" <>,
	"Joerg Roedel" <>,
	"Liran Alon" <>,
	"Jag Raman" <>
Subject: [PATCH v2 1/3] KVM: VMX: Consider PID.PIR to determine if vCPU has pending interrupts
Date: Mon, 11 Nov 2019 17:20:10 +0000	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Commit 17e433b54393 ("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: 17e433b54393 ("KVM: Fix leak vCPU's VMCS value into other pCPU")
Reviewed-by: Jagannathan Raman <>
Co-developed-by: Liran Alon <>
Signed-off-by: Liran Alon <>
Signed-off-by: Joao Martins <>
* Fixed broken Sob Chain;
* Add missing tags;
* Only test PID.PIR if PID.SN=1 and reflect that in commit message last
 arch/x86/kvm/vmx/vmx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 31ce6bc2c371..4c7d2935f7ec 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6141,7 +6141,11 @@ static int vmx_sync_pir_to_irr(struct kvm_vcpu *vcpu)
 static bool vmx_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu)
-	return pi_test_on(vcpu_to_pi_desc(vcpu));
+	struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu);
+	return pi_test_on(pi_desc) ||
+		(pi_test_sn(pi_desc) &&
+		!bitmap_empty((unsigned long *)pi_desc->pir, NR_VECTORS));
 static void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)

  reply	other threads:[~2019-11-11 17:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-11 17:20 [PATCH v2 0/3] KVM: VMX: Posted Interrupts fixes Joao Martins
2019-11-11 17:20 ` Joao Martins [this message]
2019-11-11 17:20 ` [PATCH v2 2/3] KVM: VMX: Do not change PID.NDST when loading a blocked vCPU Joao Martins
2019-11-19 11:36   ` Wanpeng Li
2019-11-19 14:44     ` Joao Martins
2019-11-11 17:20 ` [PATCH v2 3/3] KVM: VMX: Introduce pi_is_pir_empty() helper Joao Martins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).