From: sashiko-bot@kernel.org
To: "Carlos López" <clopez@suse.de>
Cc: "Marc Zyngier" <maz@kernel.org>,
"Oliver Upton" <oupton@kernel.org>,
kvmarm@lists.linux.dev
Subject: Re: [PATCH v5 1/2] KVM: arm64: vgic: Fix race between LPI release and re-registration
Date: Thu, 09 Jul 2026 14:59:57 +0000 [thread overview]
Message-ID: <20260709145958.3D7F31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709144225.3433646-3-clopez@suse.de>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Race condition between deferred LPI release and concurrent LPI registration leaks memory and triggers a host warning.
--
--- Patch [1]: [PATCH v5 1/2] KVM: arm64: vgic: Fix race between LPI release and re-registration ---
commit 0e3a1226f09c3d09f5b82c5882f2fe2063ffdca4
Author: Carlos López <clopez@suse.de>
Subject: KVM: arm64: vgic: Fix race between LPI release and re-registration
This commit addresses a race condition where an LPI can be deleted or
leaked during concurrent release and re-registration. It moves the refcount
decrement inside the xarray lock for direct releases, and makes
vgic_add_lpi() responsible for freeing 0-refcount LPIs evicted from the
xarray.
> diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
> index 67d107e9a77d1..4685332457270 100644
> --- a/arch/arm64/kvm/vgic/vgic-its.c
> +++ b/arch/arm64/kvm/vgic/vgic-its.c
[ ... ]
> @@ -116,7 +116,20 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid,
> kfree(irq);
> irq = oldirq;
> } else {
> - ret = xa_err(__xa_store(&dist->lpi_xa, intid, irq, 0));
> + /*
> + * The entry is either empty or contains a dead LPI (refcount=0)
> + * from the deferred release path, pending cleanup by
> + * vgic_release_deleted_lpis(). Evict and free it if present.
> + * Make sure that the assumption that the IRQ is pending release
> + * holds before freeing it, as otherwise someone else could still
> + * hold a pointer to the evicted struct.
> + */
> + oldirq = __xa_store(&dist->lpi_xa, intid, irq, 0);
> + ret = xa_err(oldirq);
> + if (!ret && oldirq &&
> + !WARN_ON_ONCE(refcount_read(&oldirq->refcount) ||
> + !oldirq->pending_release))
[Severity: High]
Can this race with vgic_put_irq_norelease() and leak the oldirq structure
while incorrectly triggering the WARN_ON_ONCE()?
Looking at vgic_put_irq_norelease(), the refcount is decremented to 0 before
pending_release is set to true:
vgic_put_irq_norelease()
if (!__vgic_put_irq(kvm, irq))
return false;
// At this point refcount is 0, but pending_release is still false
irq->pending_release = true;
If CPU1 executes vgic_add_lpi() during this window, wouldn't it see
oldirq->pending_release as false, trigger the WARN_ON_ONCE, and then skip
kfree_rcu(oldirq, rcu)?
When CPU0 later resumes and sets pending_release to true, the LPI is
already evicted from the xarray. Because it is no longer in the xarray,
vgic_release_deleted_lpis() would not find it, resulting in a permanent
leak of the old LPI.
> + kfree_rcu(oldirq, rcu);
> }
>
> xa_unlock_irqrestore(&dist->lpi_xa, flags);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260709144225.3433646-2-clopez@suse.de?part=1
next prev parent reply other threads:[~2026-07-09 14:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 14:42 [PATCH v5 0/2] KVM: arm64: vgic: Fix racy LPI release and re-registration handling Carlos López
2026-07-09 14:42 ` [PATCH v5 1/2] KVM: arm64: vgic: Fix race between LPI release and re-registration Carlos López
2026-07-09 14:59 ` sashiko-bot [this message]
2026-07-09 14:42 ` [PATCH v5 2/2] KVM: arm64: vgic: Mitigate potential LPI registration failure Carlos López
2026-07-09 15:09 ` sashiko-bot
2026-07-09 15:52 ` Carlos López
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=20260709145958.3D7F31F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=clopez@suse.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox