From: David Matlack <dmatlack@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
seanjc@google.com, stable@vger.kernel.org
Subject: Re: [PATCH 4/4] KVM: x86: Use a stable condition around all VT-d PI paths
Date: Mon, 29 Nov 2021 23:41:50 +0000 [thread overview]
Message-ID: <YaVlPso5X2dM+kXC@google.com> (raw)
In-Reply-To: <20211123004311.2954158-5-pbonzini@redhat.com>
On Mon, Nov 22, 2021 at 07:43:11PM -0500, Paolo Bonzini wrote:
> Currently, checks for whether VT-d PI can be used refer to the current
> status of the feature in the current vCPU; or they more or less pick
> vCPU 0 in case a specific vCPU is not available.
>
> However, these checks do not attempt to synchronize with changes to
> the IRTE. In particular, there is no path that updates the IRTE when
> APICv is re-activated on vCPU 0; and there is no path to wakeup a CPU
> that has APICv disabled, if the wakeup occurs because of an IRTE
> that points to a posted interrupt.
>
> To fix this, always go through the VT-d PI path as long as there are
> assigned devices and APICv is available on both the host and the VM side.
> Since the relevant condition was copied over three times, take the hint
> and factor it into a separate function.
>
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Cc: stable@vger.kernel.org
> Reviewed-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: David Matlack <dmatlack@google.com>
> ---
> arch/x86/kvm/vmx/posted_intr.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
> index 5f81ef092bd4..1c94783b5a54 100644
> --- a/arch/x86/kvm/vmx/posted_intr.c
> +++ b/arch/x86/kvm/vmx/posted_intr.c
> @@ -5,6 +5,7 @@
> #include <asm/cpu.h>
>
> #include "lapic.h"
> +#include "irq.h"
> #include "posted_intr.h"
> #include "trace.h"
> #include "vmx.h"
> @@ -77,13 +78,18 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
> pi_set_on(pi_desc);
> }
>
> +static bool vmx_can_use_vtd_pi(struct kvm *kvm)
> +{
> + return irqchip_in_kernel(kvm) && enable_apicv &&
> + kvm_arch_has_assigned_device(kvm) &&
> + irq_remapping_cap(IRQ_POSTING_CAP);
> +}
> +
> void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu)
> {
> struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu);
>
> - if (!kvm_arch_has_assigned_device(vcpu->kvm) ||
> - !irq_remapping_cap(IRQ_POSTING_CAP) ||
> - !kvm_vcpu_apicv_active(vcpu))
> + if (!vmx_can_use_vtd_pi(vcpu->kvm))
> return;
>
> /* Set SN when the vCPU is preempted */
> @@ -141,9 +147,7 @@ int pi_pre_block(struct kvm_vcpu *vcpu)
> struct pi_desc old, new;
> struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu);
>
> - if (!kvm_arch_has_assigned_device(vcpu->kvm) ||
> - !irq_remapping_cap(IRQ_POSTING_CAP) ||
> - !kvm_vcpu_apicv_active(vcpu))
> + if (!vmx_can_use_vtd_pi(vcpu->kvm))
> return 0;
>
> WARN_ON(irqs_disabled());
> @@ -270,9 +274,7 @@ int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq,
> struct vcpu_data vcpu_info;
> int idx, ret = 0;
>
> - if (!kvm_arch_has_assigned_device(kvm) ||
> - !irq_remapping_cap(IRQ_POSTING_CAP) ||
> - !kvm_vcpu_apicv_active(kvm->vcpus[0]))
> + if (!vmx_can_use_vtd_pi(kvm))
> return 0;
>
> idx = srcu_read_lock(&kvm->irq_srcu);
> --
> 2.27.0
>
next prev parent reply other threads:[~2021-11-29 23:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20211123004311.2954158-1-pbonzini@redhat.com>
2021-11-23 0:43 ` [PATCH 1/4] KVM: x86: ignore APICv if LAPIC is not enabled Paolo Bonzini
2021-11-25 1:36 ` Sean Christopherson
2021-11-29 23:32 ` David Matlack
2021-11-30 7:50 ` Maxim Levitsky
2021-11-23 0:43 ` [PATCH 2/4] KVM: VMX: prepare sync_pir_to_irr for running with APICv disabled Paolo Bonzini
2021-11-29 22:14 ` Sean Christopherson
2021-11-30 8:31 ` Paolo Bonzini
2021-11-29 23:34 ` David Matlack
2021-11-30 7:57 ` Maxim Levitsky
2021-11-23 0:43 ` [PATCH 3/4] KVM: x86: check PIR even for vCPUs with disabled APICv Paolo Bonzini
2021-11-29 23:39 ` David Matlack
2021-11-30 7:58 ` Maxim Levitsky
2021-11-23 0:43 ` [PATCH 4/4] KVM: x86: Use a stable condition around all VT-d PI paths Paolo Bonzini
2021-11-29 23:41 ` David Matlack [this message]
2021-11-30 8:05 ` Maxim Levitsky
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=YaVlPso5X2dM+kXC@google.com \
--to=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=stable@vger.kernel.org \
/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