From: sashiko-bot@kernel.org
To: "Brad Fitzpatrick" <bradfitz@tailscale.com>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH] KVM: arm64: GICv3: Keep active LPIs in the LRs
Date: Thu, 26 Nov 2026 02:05:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-234602@kernel.org> (raw)
In-Reply-To: <20261126-bradfitz-kvm_lpi_active-v1-1-9ff28176bf66@tailscale.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] KVM: arm64: vgic: stale ap_list_summary and sort order in
vgic_flush_lr_state()
- [Medium] KVM: arm64: vgic: active LPIs left stuck active by
vgic_flush_pending_lpis()
--
commit c554f5d3ddcbf7ba9d43ffa052060d79ec852b3b
Author: Brad Fitzpatrick <bradfitz@tailscale.com>
KVM: arm64: GICv3: Keep active LPIs in the LRs
This commit keeps the active state of virtual LPIs when folding list
registers on guest exit, and drops the active state in
vgic_flush_lr_state() only for LPIs that do not fit into the list
registers.
> diff --git a/arch/arm64/kvm/vgic/vgic-v3.c b/arch/arm64/kvm/vgic/vgic-v3.c
> index 65b77fb35be37..ba50809f66928 100644
> --- a/arch/arm64/kvm/vgic/vgic-v3.c
> +++ b/arch/arm64/kvm/vgic/vgic-v3.c
> @@ -90,9 +90,7 @@ static void vgic_v3_fold_lr(struct kvm_vcpu *vcpu, u64 val)
> return;
>
> scoped_guard(raw_spinlock, &irq->irq_lock) {
> - /* Always preserve the active bit for !LPIs, note deactivation */
> - if (irq->intid >= VGIC_MIN_LPI)
> - val &= ~ICH_LR_ACTIVE_BIT;
> + /* Always preserve the active bit, note deactivation */
> deactivated = irq->active && !(val & ICH_LR_ACTIVE_BIT);
> irq->active = !!(val & ICH_LR_ACTIVE_BIT);
>
[Severity: Medium]
Now that vgic_v3_fold_lr() preserves irq->active on LPIs across exits, can
vgic_flush_pending_lpis() unqueue an active LPI while leaving
irq->active == true?
When the guest clears GICR_CTLR_ENABLE_LPIS while an LPI is active,
vgic_mmio_write_v3r_ctlr() pauses the vCPU (folding the active bit into
irq->active) and calls vgic_flush_pending_lpis():
arch/arm64/kvm/vgic/vgic.c:vgic_flush_pending_lpis() {
...
list_for_each_entry_safe(irq, tmp, &vgic_cpu->ap_list_head, ap_list) {
if (irq_is_lpi(vcpu->kvm, irq->intid)) {
raw_spin_lock(&irq->irq_lock);
irq->pending_latch = false;
list_del(&irq->ap_list);
irq->vcpu = NULL;
raw_spin_unlock(&irq->irq_lock);
deleted |= vgic_put_irq_norelease(vcpu->kvm, irq);
}
}
...
}
Because irq->active is still true with irq->vcpu == NULL,
vgic_target_oracle() hits its first check (if (irq->active) return
irq->vcpu ? : irq->target_vcpu;) and bypasses the enabled, pending and
vgic_lpis_enabled() checks. When the vCPU resumes, the LPI is not in any
LR for the guest's EOI, and any later vgic_queue_irq_unlock() (such as
its_sync_lpi_pending_table() when LPIs are re-enabled or update_lpi_config()
on an ITS invalidation) re-queues the LPI onto ap_list_head and loads it
into an LR as active, permanently wedging that LPI and its LR slot because
the guest has already EOI'd the earlier activation.
> diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c
> index fe09ada322625..05459d662965c 100644
> --- a/arch/arm64/kvm/vgic/vgic.c
> +++ b/arch/arm64/kvm/vgic/vgic.c
[ ... ]
> @@ -1059,6 +1061,20 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu)
> break;
> }
>
> + /*
> + * Active LPIs left out of the LRs can't be deactivated by EOIcount, so
> + * drop their active state. See the LPI rules above.
> + */
> + irq = *host_data_ptr(last_lr_irq);
> + if (irq) {
> + list_for_each_entry_continue(irq, &vgic_cpu->ap_list_head, ap_list) {
> + if (irq->intid >= VGIC_MIN_LPI) {
> + guard(raw_spinlock)(&irq->irq_lock);
> + irq->active = false;
> + }
> + }
> + }
> +
> /* Nuke remaining LRs */
> for (int i = count ; i < kvm_vgic_global_state.nr_lr; i++)
> vgic_clear_lr(vcpu, i);
[Severity: Medium]
Does clearing irq->active here leave struct ap_list_summary stale when
vgic_v3_configure_hcr() runs below?
summarize_ap_list() and vgic_sort_ap_list() run at the start of
vgic_flush_lr_state() while overflowing LPIs still have irq->active == true,
counting them in als.nr_act instead of als.nr_pend and sorting
active+pending LPIs as active rather than pending.
When an overflowing LPI was active+pending, clearing irq->active turns it
into a pending interrupt outside the LRs without incrementing als.nr_pend,
so irqs_pending_outside_lrs(&als) can be false and vgic_v3_configure_hcr()
will not set ICH_HCR_EL2_NPIE to deliver it once in-LR pending interrupts
are acknowledged. When an overflowing LPI was active-only, als.nr_act
remains inflated after irq->active is dropped, causing
vgic_v3_configure_hcr() to spuriously enable ICH_HCR_EL2_UIE,
ICH_HCR_EL2_LRENPIE and ICH_HCR_EL2_TDIR.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-bradfitz-kvm_lpi_active-v1-1-9ff28176bf66@tailscale.com?part=1
next prev parent reply other threads:[~2026-11-26 2:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 1:42 [PATCH] KVM: arm64: GICv3: Keep active LPIs in the LRs Brad Fitzpatrick
2026-11-26 1:42 ` Brad Fitzpatrick via B4 Relay
2026-11-26 2:05 ` sashiko-bot [this message]
2026-11-26 8:45 ` Marc Zyngier
2026-11-26 23:15 ` Brad Fitzpatrick
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=sashiko-outbox-234602@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bradfitz@tailscale.com \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.