From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796408462; b=ldjv2dQ6fnpUISxL5nNAohQ5x071Vpdp1nyDBEPp7Ji0Nlagohwl3wgdyFgNbfHi1DMG 2J1enopvM9YkwXE5fLjPyplgWP+SsN3HbEaWf4BAtTSkl3njDy+wFmemK/RzBO1aAzi3G IjurQE4a7YEjvQDuqkFqVCvYKH+1gzn/bXIfjzvZIgmSBfCA5zeRiWGKjK9eWaEV2YzHk w6aPPB+HpQyIRHTHDfM3ROD6LtOTc/lO7obgtc6SzRsfqzD6e9akqF9X6QoQw3l1/CvGv ANqZ18VrVInCTvY7hR/Vc6Do8WQ8nKswkgkk8lvLTO/CNYbkIB9cb60oIiEdiQS9h6Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796408462; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Uh8XfIKKoYq5hbxPPFW6ylHxt/R1pld5Md8Et11PGSE=; b=yZaUUvVlkvjlEPK9+I589nh3EASVd9nA+dFMClxhtTotwtLyeubME4mhcyxCzdk/8AaR j5vQXVyvYBwxR6+w9ZfivHgdePyBlG2W2U4IlCRDzzWjYfJOKBU4J9/uSifWt1FDDqtW9 7LlB2dQspUyg7mHNqlMcAvXdwsg8s6yewhmrD2S688InDUw72ZO59IdNJgC3wh7QbDe6s KGr987oibicgKQMIkvIWHjY2kPR7FpdjBG7D5EoLtZTwxK3yvkrJyXk53lcxUAqivC1iY Rz+sZYNegRmafcmhz9LR9SHZI1QY3rWMOOAwIEM406mH3Y4KpQ6ghyQnELXspAyUfTQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cgbGMSHa; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EB9B606A32C; Fri, 4 Dec 2026 18:21:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cgbGMSHa Received: by smtp.kernel.org (Postfix) with ESMTPSA id E90161F00936; Fri, 4 Dec 2026 18:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796408462; bh=Uh8XfIKKoYq5hbxPPFW6ylHxt/R1pld5Md8Et11PGSE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cgbGMSHa+fhw3Q20RhUzlQEaVtvW6sLOT0OZkN0+BOyZ0EmwClxRK8c43EwDH/hjN LIc2ZvjQu+gnp9tKMShNbAWf5+h9aJ6al18qdy+ECx/DBCHR5jwFjdVAN8y3zVERqc ipZtEMimXvaGA1foVwY207vnSWZW+3VP8EaP0uZafDo3Whu3gP7ERN7VA/JKrw9Slb 0Hi33Tqkj3Zg74VHmyFPhIMrW9riVi0/IDiOFlnl7qv8iiC7be6cGSSEf+hF1TmMxO C0cIKpB+DWn+HfdS2K856rmy6ZJ6+YNr1pyUFsk0/GlyRrZEgFUQyLxYAwuwx/6yjE UwqHJXpBINTQQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 4/4] KVM: arm64: vgic: Linearise AP list pruning process Reply-To: sashiko-reviews@lists.linux.dev To: "Paolo Bonzini" , kvm@vger.kernel.org Cc: kvmarm@lists.linux.dev, "Oliver Upton" , "Marc Zyngier" In-Reply-To: <20261204175740.2153746-5-pbonzini@redhat.com> References: <20261204175740.2153746-1-pbonzini@redhat.com> <20261204175740.2153746-5-pbonzini@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 18:21:01 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] KVM: arm64: vgic: O(N * V) culling_list scan in vgic_prune_ap_list() - [High] KVM: arm64: vgic: unbounded retry livelock in vgic_prune_ap_list() - [Medium] KVM: arm64: vgic: unconditional bitmap scans per exit in vgic_prune_ap_list() - [Medium] KVM: arm64: vgic: O(N) kvm_get_vcpu_by_id() lookup in vgic_prune_ap_list() - [Low] KVM: arm64: vgic: missing Fixes trailer for vgic_prune_ap_list() DoS fix -- commit b2eeef66270a88825d1c1ca4b6594220f852f430 Author: Marc Zyngier > KVM: arm64: vgic: Linearise AP list pruning process > > The algorithm used to prune IRQs sitting in the AP list has a quadratic > complexity, as any concurrent change in the list results in a restart of > the processing. The locking is also rather complicated, as we have to > take the locks for both source and target vcpus, plus the per-irq lock. > > While this has served us well so far, people are finding new and amusing > ways to abuse the locking and perform a DoS on the host. Not fun. > > Instead, switch to a linear approach where potentially moved IRQs are > taken off the AP list and then dispatched onto their new targets. This > simplifies the locking (only one vcpu lock at any given time), and only > the interrupts that have been changed during that process are evaluated > again. This allows the pruning process to converge much quicker. > > Signed-off-by: Marc Zyngier > Reviewed-by: Oliver Upton > Cc: stable@vger.kernel.org [Severity: Low] This fixes a host DoS in vgic_prune_ap_list() and is tagged for stable. Should this include: Fixes: 0919e84c0fc1 ("KVM: arm/arm64: vgic-new: Add IRQ sync/flush framew= ork") > diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c > index bea848c93a990..a7e3e1a8a64f1 100644 > --- a/arch/arm64/kvm/vgic/vgic.c > +++ b/arch/arm64/kvm/vgic/vgic.c [ ... ] > @@ -765,109 +788,83 @@ int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsi= gned int intid, void *owner) > static void vgic_prune_ap_list(struct kvm_vcpu *vcpu) > { > struct vgic_cpu *vgic_cpu =3D &vcpu->arch.vgic_cpu; > + DECLARE_BITMAP(pend_map, VGIC_V3_MAX_CPUS) =3D {}; > + DECLARE_BITMAP(kick_map, VGIC_V3_MAX_CPUS) =3D {}; [Severity: Medium] Does this add unnecessary work to every VM exit when no IRQs migrate? kvm_vgic_sync_hwstate() calls vgic_prune_ap_list() on every non-nested GICv2/GICv3 VM exit with IRQs disabled. Zeroing both 512-bit bitmaps on the stack and unconditionally running bitmap_empty() and both for_each_set_bit() loops executes 128 bytes of stack zeroing and three out-of-line 512-bit scans on every exit even when culling_list is empty. Guarding the bitmap initialization and dispatch/kick loops with !list_empty(&culling_list) would keep this off the common exit path. [ ... ] > + for_each_set_bit(i, pend_map, VGIC_V3_MAX_CPUS) { > + struct kvm_vcpu *target =3D kvm_get_vcpu_by_id(vcpu->kvm, i); [Severity: Medium] Can kvm_get_vcpu_by_id() fall back to a linear O(N) xarray walk here (and again in the kick_map loop) with IRQs disabled when userspace creates vCPUs with sparse or out-of-order vcpu_ids? Since pend_map and kick_map are local to vgic_prune_ap_list(), indexing them by dense vcpu->vcpu_idx would allow O(1) kvm_get_vcpu() lookups and bounding the bitmap scans by atomic_read(&vcpu->kvm->online_vcpus) instead of VGIC_V3_MAX_CPUS. [ ... ] > + guard(raw_spinlock)(&target->arch.vgic_cpu.ap_list_lock); > =20 > - raw_spin_lock(&irq->irq_lock); > - raw_spin_unlock(&vcpuB->arch.vgic_cpu.ap_list_lock); > - raw_spin_unlock(&vcpuA->arch.vgic_cpu.ap_list_lock); > + list_for_each_entry_safe(irq, tmp, &culling_list, ap_list) { > + guard(raw_spinlock)(&irq->irq_lock); [Severity: High] Can scanning the entire remaining culling_list for each set bit in pend_map still perform O(N * V) work with hard IRQs disabled and stall remote vCPUs on ap_list_lock? An unprivileged guest with vITS can queue up to 57,344 pending LPIs (INTERRUPT_ID_BITS_ITS is 16) on one vCPU, then retarget one IRQ to each of vCPUs 0..V-2 and the rest to vCPU V-1 (up to 512 vCPUs). Nearly all N IRQs stay on culling_list across every lower-ID iteration, causing ~29M raw spinlock acquisitions with hard IRQs disabled and risking host hard lockups or RCU stalls while holding each target's ap_list_lock across unrelated IRQs. Even with M evenly distributed migrating IRQs, this regresses baseline's O(M) migration cost to O(M * V). In addition, the outer loop has no early list_empty(&culling_list) break, so if earlier iterations cull the remaining IRQs it still looks up and locks ap_list_lock for every remaining stale bit in pend_map. [ ... ] > + /* Catch a potential affinity change */ > + if (irq_target !=3D target) { > + __set_bit(irq_target->vcpu_id, pend_map); > + continue; > + } [ ... ] > + __clear_bit(i, pend_map); > } > =20 > + /* Leftovers? Same player shoot again! */ > + if (unlikely(!list_empty(&culling_list))) > + goto retry; [Severity: High] Can a multi-vCPU guest livelock the host CPU here indefinitely with hard IRQs disabled? Because irq->irq_lock is dropped between target passes and vgic_mmio_write_irouter() only takes irq->irq_lock to update irq->target_vcpu, another vCPU can keep flipping an IRQ's target ahead of the current pass: CPU0 CPU1 kvm_vgic_sync_hwstate() vgic_prune_ap_list() target =3D vcpu0 (pend_map: 0) vgic_mmio_write_irouter() lock(&irq->irq_lock) irq->target_vcpu =3D vcpu1 unlock(&irq->irq_lock) lock(&irq->irq_lock) irq_target !=3D vcpu0 __set_bit(1, pend_map) unlock(&irq->irq_lock) __clear_bit(0, pend_map) target =3D vcpu1 (pend_map: 1) vgic_mmio_write_irouter() lock(&irq->irq_lock) irq->target_vcpu =3D vcpu0 unlock(&irq->irq_lock) lock(&irq->irq_lock) irq_target !=3D vcpu1 __set_bit(0, pend_map) unlock(&irq->irq_lock) __clear_bit(1, pend_map) goto retry; <-- livelocks with IRQs disabled Since kvm_arch_vcpu_ioctl_run() calls kvm_vgic_sync_hwstate() with hard IRQs disabled and vcpu->mode still IN_GUEST_MODE, this blocks host interrupts and cross-CPU IPIs (such as kvm_flush_remote_tlbs()) and can trigger hard lockups or RCU stalls. Bounding the retries and falling back (for example, returning stubborn IRQs to the source vCPU's ap_list) would prevent the livelock. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204175740.2153= 746-1-pbonzini@redhat.com?part=3D4