From: sashiko-bot@kernel.org
To: "Jing Zhang" <jingzhangos@google.com>
Cc: kvm@vger.kernel.org, "Marc Zyngier" <maz@kernel.org>,
kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH] KVM: arm64: vgic-its: Fix O(C*I) loop in vgic_its_free_collection_list
Date: Tue, 18 Aug 2026 22:47:52 +0000 [thread overview]
Message-ID: <20260818224752.9FB341F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260818223422.367803-1-jingzhangos@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Unconditional dereference of `ite->collection` during ITS table save leads to host kernel panic.
- [High] Unmitigated O(Total ITEs) loops during ITS command processing lead to guest-triggered soft lockups and RCU stalls.
--
--- Patch [1]: [PATCH] KVM: arm64: vgic-its: Fix O(C*I) loop in vgic_its_free_collection_list ---
commit 57034db6ba413048ab15ade32e11d1ba6a290388
Author: Jing Zhang <jingzhangos@google.com>
KVM: arm64: vgic-its: Fix O(C*I) loop in vgic_its_free_collection_list
When destroying the vgic-its collection list,
vgic_its_free_collection_list() iterates over every collection and for
each, calls vgic_its_free_collection(). This function walks every
Interrupt Translation Entry (ITE) across all devices via
for_each_lpi_its() to nullify the collection pointer.
[ ... ]
> diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
> index 4477f870c7b36..5e907a34226e3 100644
> --- a/arch/arm64/kvm/vgic/vgic-its.c
> +++ b/arch/arm64/kvm/vgic/vgic-its.c
> @@ -1122,9 +1122,21 @@ static void vgic_its_free_device_list(struct kvm *kvm, struct vgic_its *its)
> static void vgic_its_free_collection_list(struct kvm *kvm, struct vgic_its *its)
> {
> struct its_collection *cur, *temp;
> + struct its_device *device;
> + struct its_ite *ite;
>
> - list_for_each_entry_safe(cur, temp, &its->collection_list, coll_list)
> - vgic_its_free_collection(its, cur->collection_id);
> + /*
> + * Bulk-clear the collection pointers for all ITEs.
> + * This transforms the teardown complexity from O(Collections * ITEs)
> + * to O(Collections + ITEs), avoiding guest-triggered host RCU stalls.
> + */
[Severity: High]
This isn't a bug introduced by this patch, but does this fix cover the same RCU
stall vulnerability in the ITS command ring processing?
A guest can queue up to 32,768 MAPC commands to remap an existing collection,
which vgic_its_process_commands() processes sequentially under cmd_lock
without yielding. For each command, update_affinity_collection() loops over
all ITEs:
arch/arm64/kvm/vgic/vgic-its.c:update_affinity_collection() {
for_each_lpi_its(device, ite, its) {
if (ite->collection != coll)
continue;
update_affinity_ite(kvm, ite);
}
}
With a large number of ITEs, can this unmitigated loop still cause soft lockups
and RCU stalls on the host?
> + for_each_lpi_its(device, ite, its)
> + ite->collection = NULL;
[Severity: Critical]
This is a pre-existing issue, but can setting ite->collection to NULL here
cause a kernel panic during state saving?
If a guest clears GITS_BASER1 (triggering this teardown) or unmaps a collection
via MAPC with valid=0, the ITEs are left in the device list with a NULL
collection pointer.
Later, if host userspace triggers VM state saving, vgic_its_save_ite() blindly
dereferences ite->collection:
arch/arm64/kvm/vgic/vgic-its.c:vgic_its_save_ite() {
val = ((u64)next_offset << KVM_ITS_ITE_NEXT_SHIFT) |
((u64)ite->irq->intid << KVM_ITS_ITE_PINTID_SHIFT) |
ite->collection->collection_id;
}
Does vgic_its_save_ite() need to verify ite->collection is non-NULL before
attempting to access its collection_id?
> +
> + list_for_each_entry_safe(cur, temp, &its->collection_list, coll_list) {
> + list_del(&cur->coll_list);
> + kfree(cur);
> + }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260818223422.367803-1-jingzhangos@google.com?part=1
prev parent reply other threads:[~2026-08-18 22:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 22:34 [PATCH] KVM: arm64: vgic-its: Fix O(C*I) loop in vgic_its_free_collection_list Jing Zhang
2026-08-18 22:47 ` sashiko-bot [this message]
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=20260818224752.9FB341F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jingzhangos@google.com \
--cc=kvm@vger.kernel.org \
--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