From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF34C606A32C for ; Mon, 30 Nov 2026 17:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=pVKEf5SC; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bURoyp32 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=yMojGCG3VbnlxP7y2e0Dc4a2QaVMxbTOEBv1SLt8sIY=; b=pVKEf5SChNgBXu9y24uBL74QDm 6ip4r2kJYul3DjXHk0JJpWgX7+980YkVa/hY5js5+wac1KfCr7ahpk9XQwi0w/4MAOPM/Z7uEO8JK SUE0R/xoLeF82YSWyfklDVYD1kfNVzv7AbBzhVY32r/YI4qj2KeoMrDRM40Jb84D3Gl4J6WAa5xT+ jl2xnpd2EvRpTybklXz3Z/XCNs/6KUIJwVlNXJxJa8i5P60+e3X2xC+Pt/kbvv73VeBIZShB//g2d ++nnTHkhbPa4JmR1qddTkbTfwiM3pAYFIRncxv/vANzlAFh+Qp1ovzO6KORES+GeRxQt4WYSjTp2P Zo0bfoGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY5Cb-00000005T30-2z9W; Mon, 30 Nov 2026 17:30:09 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY5CY-00000005T2H-2882 for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 17:30:08 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id B3CE96118F; Mon, 30 Nov 2026 17:30:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B2751F00896; Mon, 30 Nov 2026 17:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796059805; bh=yMojGCG3VbnlxP7y2e0Dc4a2QaVMxbTOEBv1SLt8sIY=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=bURoyp32gpDYZjxailRiPKkni1Z6AdJqgSeVtECKfS1OusOihCbyvx9RQkogVSL7m eqWeTUfpYeif7MlmhsIeZfi6nVw8rW8F3j3SX2+IHTGFn666QCd1pQJ60Krvj9nfSh gTzWZ0SznIODe8LGmJcjcq3O09RMEGRayWfJGKZwDWJcq+A9KJFeOP4a3GDKGEFnXI qv7ebgtFz3VcQIB0ohlhQJIdwJJbcjWvejQ1EQPI2fCGQrXq/m/mGfJv2Tim6wpPGz /j4RyaFPiqAirH9XtsO3kGcnmDjwNyh1J0D76WvPBEK9j44Ze6f71N823UrNKMBjIS Ir7IzrHdXl3HQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xY5CU-00000005B4T-4BIF; Mon, 30 Nov 2026 17:30:03 +0000 Date: Mon, 30 Nov 2026 17:30:02 +0000 Message-ID: <86ik1exm5h.wl-maz@kernel.org> From: Marc Zyngier To: dickson.wu@certik.com Cc: stable@vger.kernel.org, Qihang , Oliver Upton , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 6.6.y] KVM: arm64: vgic-v3: take an LPI reference in vgic_v3_save_pending_tables In-Reply-To: <20261128-vgic-66-v1-1-42c9b298dd47@certik.com> References: <20261128-vgic-66-v1-1-42c9b298dd47@certik.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) X-Archived-By: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: dickson.wu@certik.com, stable@vger.kernel.org, q.h.hack.winter@gmail.com, oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Sat, 28 Nov 2026 18:28:30 +0000, Dickson Wu via B4 Relay wrote: > > From: Qihang > > commit f5b8f203bfc07a5a257dff859e66d2c500f9f509 upstream. > > vgic_v3_save_pending_tables() iterates dist->lpi_xa using xa_for_each() > and dereferences the returned struct vgic_irq in the loop body without > holding a reference on the LPI. > > The xarray iterator only provides temporary RCU coverage while looking up > the current entry. That is not sufficient for this loop body, which reads > fields from struct vgic_irq and performs guest memory accesses before the > iteration completes. > > A concurrent path can trigger this race: the irqfd cached injection path > (vgic_its_inject_cached_translation) obtains a transient LPI reference > via vgic_its_check_cache() without holding kvm->lock, vcpu->mutex, > config_lock, or its_lock. If guest ITS DISCARD then drops the cache and > ITE references under its_lock, the transient inject reference may become > the final one. When vgic_put_irq() drops it, the LPI is erased from > lpi_xa and freed via kfree_rcu(). Meanwhile, vgic_v3_save_pending_tables() > may still hold a stale pointer obtained from the xarray iterator and > dereference it after the RCU grace period completes. > > Fix this by re-fetching each iterated LPI via vgic_get_irq(), which takes > a stable reference, and dropping it with vgic_put_irq() on all paths. > This matches the pattern already used by other lpi_xa iterators in the > vgic ITS code. > > Cc: stable@vger.kernel.org > Signed-off-by: Qihang > Reviewed-by: Marc Zyngier > Link: https://patch.msgid.link/20260807025534.34125-1-q.h.hack.winter@gmail.com > Signed-off-by: Oliver Upton > [ adapted to 6.6.y: pin each LPI under the list lock before use ] > Signed-off-by: Dickson Wu You need to add a lot more about the way you have massaged the original patch and why it actually workds, because there isn't any of this commit message that holds anymore. > --- > This one never made it to 6.6.y. 6.12.y got it as 4000462866bc, but > 6.6 still keeps LPIs on lpi_list_head rather than the lpi_xa xarray, > so the upstream patch doesn't apply. The backport takes a reference on > each LPI under lpi_list_lock, drops the lock for the guest memory > accesses, then retakes it to step to the next entry and drop the > reference with __vgic_put_lpi_locked(). That's the same idea as > upstream's vgic_get_irq()/vgic_put_irq() pairing. > > Tested on 6.6 (e2bb30811e06): arm64 W=1 build of vgic-v3.o, base vs > patched, no new warnings. Both kernels booted under QEMU TCG with KVM > initialized. The KVM vgic_init selftest fails the same way on both at > memslot deletion, so it doesn't cover this path, and I didn't hit the > race itself. Build and boot only. Then this code was never exercised. Unfortunately, merging untested code in this area is probably just as bad than leaving the bug unpatched. You really want to at the very least perform a live migration of a guest and verify that it works. Thanks, M. -- Without deviation from the norm, progress is not possible.