From: Marc Zyngier <maz@kernel.org>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: kvmarm@lists.linux.dev, Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Sweet Tea Dorminy <sweettea@google.com>
Subject: Re: [PATCH 3/5] KVM: arm64: Resolve vLPI by host IRQ in vgic_v4_unset_forwarding()
Date: Fri, 23 May 2025 18:25:50 +0100 [thread overview]
Message-ID: <87v7prdysh.wl-maz@kernel.org> (raw)
In-Reply-To: <20250523160810.4049313-4-oliver.upton@linux.dev>
On Fri, 23 May 2025 17:08:08 +0100,
Oliver Upton <oliver.upton@linux.dev> wrote:
>
> The virtual mapping and "GSI" routing of a particular vLPI is subject to
> change in response to the guest / userspace. This can be pretty annoying
> to deal with when KVM needs to track the physical state that's managed
> for vLPI direct injection.
>
> Make vgic_v4_unset_forwarding() resilient by using the host IRQ to
> resolve the vgic IRQ.
>
> Tested-by: Sweet Tea Dorminy <sweettea@google.com>
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
> arch/arm64/kvm/arm.c | 3 +--
> arch/arm64/kvm/vgic/vgic-v4.c | 45 +++++++++++++++++++----------------
> include/kvm/arm_vgic.h | 3 +--
> 3 files changed, 27 insertions(+), 24 deletions(-)
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 36cfcffb40d8..1de49b48e35e 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -2800,8 +2800,7 @@ void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,
> if (irq_entry->type != KVM_IRQ_ROUTING_MSI)
> return;
>
> - kvm_vgic_v4_unset_forwarding(irqfd->kvm, prod->irq,
> - &irqfd->irq_entry);
> + kvm_vgic_v4_unset_forwarding(irqfd->kvm, prod->irq);
> }
>
> void kvm_arch_irq_bypass_stop(struct irq_bypass_consumer *cons)
> diff --git a/arch/arm64/kvm/vgic/vgic-v4.c b/arch/arm64/kvm/vgic/vgic-v4.c
> index 01a5de8e9e94..193946108192 100644
> --- a/arch/arm64/kvm/vgic/vgic-v4.c
> +++ b/arch/arm64/kvm/vgic/vgic-v4.c
> @@ -508,10 +508,27 @@ int kvm_vgic_v4_set_forwarding(struct kvm *kvm, int virq,
> return ret;
> }
>
> -int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int virq,
> - struct kvm_kernel_irq_routing_entry *irq_entry)
> +static struct vgic_irq *__vgic_host_irq_get_vlpi(struct kvm *kvm, int host_irq)
> +{
> + struct vgic_irq *irq;
> + unsigned long idx;
> +
> + guard(rcu)();
> + xa_for_each(&kvm->arch.vgic.lpi_xa, idx, irq) {
> + if (!irq->hw || irq->host_irq != host_irq)
> + continue;
> +
> + if (!vgic_try_get_irq_kref(irq))
> + return NULL;
> +
> + return irq;
> + }
> +
> + return NULL;
> +}
> +
> +int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int host_irq)
> {
> - struct vgic_its *its;
> struct vgic_irq *irq;
> unsigned long flags;
> int ret = 0;
> @@ -519,31 +536,19 @@ int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int virq,
> if (!vgic_supports_direct_msis(kvm))
> return 0;
>
> - /*
> - * Get the ITS, and escape early on error (not a valid
> - * doorbell for any of our vITSs).
> - */
> - its = vgic_get_its(kvm, irq_entry);
> - if (IS_ERR(its))
> + irq = __vgic_host_irq_get_vlpi(kvm, host_irq);
> + if (!irq)
> return 0;
>
> - mutex_lock(&its->its_lock);
> -
> - ret = vgic_its_resolve_lpi(kvm, its, irq_entry->msi.devid,
> - irq_entry->msi.data, &irq);
> - if (ret)
> - goto out;
> -
Removing the reliance on the ITS locking is another thing that could
be mentioned in the commit message, as it is slightly surprising to
see it here, given that the previous patch is all about that.
My other gripe is that we lose the doorbell validation. I'm not sure
it is a big deal, but I'd rather we keep verifying we're not being fed
rubbish data, in case we need to rely on that in the future.
Thanks,
M.
--
Jazz isn't dead. It just smells funny.
next prev parent reply other threads:[~2025-05-23 17:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-23 16:08 [PATCH 0/5] KVM: arm64: Some VGIC-related fixes Oliver Upton
2025-05-23 16:08 ` [PATCH 1/5] KVM: arm64: Use lock guard in vgic_v4_set_forwarding() Oliver Upton
2025-05-23 16:08 ` [PATCH 2/5] KVM: arm64: Protect vLPI translation with vgic_irq::irq_lock Oliver Upton
2025-05-23 16:08 ` [PATCH 3/5] KVM: arm64: Resolve vLPI by host IRQ in vgic_v4_unset_forwarding() Oliver Upton
2025-05-23 17:25 ` Marc Zyngier [this message]
2025-05-23 18:22 ` Oliver Upton
2025-05-23 16:08 ` [PATCH 4/5] KVM: arm64: Unmap vLPIs affected by changes to GSI routing information Oliver Upton
2025-05-23 17:26 ` Marc Zyngier
2025-05-23 17:48 ` Sean Christopherson
2025-05-23 18:14 ` Marc Zyngier
2025-05-23 20:54 ` Sean Christopherson
2025-05-23 20:58 ` Oliver Upton
2025-05-23 16:08 ` [PATCH 5/5] KVM: arm64: vgic-init: Plug vCPU vs. VGIC creation race Oliver Upton
2025-05-23 17:35 ` [PATCH 0/5] KVM: arm64: Some VGIC-related fixes Marc Zyngier
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=87v7prdysh.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=sweettea@google.com \
--cc=yuzenghui@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.