linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Joao Martins <joao.m.martins@oracle.com>, kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, "Radim Krčmář" <rkrcmar@redhat.com>,
	"Sean Christopherson" <sean.j.christopherson@intel.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>,
	"Wanpeng Li" <wanpengli@tencent.com>,
	"Jim Mattson" <jmattson@google.com>,
	"Joerg Roedel" <joro@8bytes.org>,
	"Liran Alon" <liran.alon@oracle.com>,
	"Jag Raman" <jag.raman@oracle.com>
Subject: Re: [PATCH v1 1/3] KVM: VMX: Consider PID.PIR to determine if vCPU has pending interrupts
Date: Mon, 11 Nov 2019 15:46:55 +0100	[thread overview]
Message-ID: <67bca655-fea3-4b57-be3c-7dc58026b5d9@redhat.com> (raw)
In-Reply-To: <20191106175602.4515-2-joao.m.martins@oracle.com>

On 06/11/19 18:56, Joao Martins wrote:
> 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.
> 
> Fixes: 17e433b54393 ("KVM: Fix leak vCPU's VMCS value into other pCPU")
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> Signed-off-by: Liran Alon <liran.alon@oracle.com>
> ---
>  arch/x86/kvm/vmx/vmx.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 31ce6bc2c371..18b0bee662a5 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6141,7 +6141,10 @@ 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) ||
> +		!bitmap_empty((unsigned long *)pi_desc->pir, NR_VECTORS);
>  }
>  
>  static void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)

Should we check the bitmap only if SN is false?  We have a precondition
that if SN is clear then non-empty PIR implies ON=1 (modulo the small
window in vmx_vcpu_pi_load of course), so that'd be a bit faster.

Paolo


  parent reply	other threads:[~2019-11-11 14:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-06 17:55 [PATCH v1 0/3] KVM: VMX: Posted Interrupts fixes Joao Martins
2019-11-06 17:56 ` [PATCH v1 1/3] KVM: VMX: Consider PID.PIR to determine if vCPU has pending interrupts Joao Martins
2019-11-07 16:00   ` Jag Raman
2019-11-11 14:46   ` Paolo Bonzini [this message]
2019-11-11 14:59     ` Joao Martins
2019-11-11 15:58       ` Paolo Bonzini
2019-11-06 17:56 ` [PATCH v1 2/3] KVM: VMX: Do not change PID.NDST when loading a blocked vCPU Joao Martins
2019-11-06 21:54   ` Joao Martins
2019-11-11 14:39   ` Paolo Bonzini
2019-11-11 14:48     ` Joao Martins
2019-11-11 14:50       ` Paolo Bonzini
2019-11-11 14:56         ` Joao Martins
2019-11-11 14:59           ` Liran Alon
2019-11-11 15:53             ` Sean Christopherson
2019-11-11 17:27               ` Joao Martins
2019-11-06 17:56 ` [PATCH v1 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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=67bca655-fea3-4b57-be3c-7dc58026b5d9@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jag.raman@oracle.com \
    --cc=jmattson@google.com \
    --cc=joao.m.martins@oracle.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liran.alon@oracle.com \
    --cc=rkrcmar@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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).