From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BFE71C5AC7C for ; Fri, 7 Aug 2026 07:52:54 +0000 (UTC) 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-Owner; bh=yXFQ17/5vxQYbI6hCw4WkGerRL2hME9nwzyNjht/Jxw=; b=amw3sVhgmOn5siNThf5IXI1mfA jIGsRYAUAX/1pwnEu3Bk7g7HQezEhZaNHyjqexeahV7STgv0J3FdgULAK9zZjl4vyGVGa++TxFHrn 4k9lkoSgYi/kFgCXyR8Kj8Ph3Be0pLWCHqGmcDI7FUEfROwAuppxmz+sw1AYLfL7qlUXMdqQ5kFKs jfA00WjNjKEMP7+vaoKqEveeFHYOElfWy2hi0JSCuivLAEGf8Gm2MEtFCGiV3yvbX+x3mFitEaHlK ZNYApmishEp0Mm2EoJRGB++zlgUvx++MDv3r7Q5jCrfic5nb9DvEiEmfiUwqPX/pZ4b/ek7qmdaRD ZhC/fESQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wsFNk-00000007J6E-0wDs; Fri, 07 Aug 2026 07:52:44 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wsFNi-00000007J66-3bxF for linux-arm-kernel@lists.infradead.org; Fri, 07 Aug 2026 07:52:42 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 00FB660DC3; Fri, 7 Aug 2026 07:52:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACE901F000E9; Fri, 7 Aug 2026 07:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786089160; bh=yXFQ17/5vxQYbI6hCw4WkGerRL2hME9nwzyNjht/Jxw=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=HKc2WmEiJRYPt+f8hjvNGAH2udR3CX41BRB79GhPArfMarWI3wVnexY8Fo4gppf7Z otjNi2Ik7/q9U1X4hVYz4ldmJFkesN8Lo0MpUzDE3zPNWmSVrpO3vl3nPdDqNjWquo HiTkHRUTJYnrXlxAEKan9C7aC9XGFX8H4VHQYZDMNuB+3NkWypA9azVFvItl2zrCzB bEwTogzIXBGYVrzbls39fnDHqWOxoH/JO4BYkzNjcaTapZKLXZznX4Gb1a3rcazUdt m1lp4WaVNR1DMdnvM8453xLD2Am3fT5nTbp5NhD/7v3whhpFP0rO6+WFKLkVof3czV vVvkORkFvNHPw== 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 1wsFNe-0000000DFws-2Fsb; Fri, 07 Aug 2026 07:52:38 +0000 Date: Fri, 07 Aug 2026 08:52:37 +0100 Message-ID: <864ih6bc56.wl-maz@kernel.org> From: Marc Zyngier To: Qihang Cc: oupton@kernel.org, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] KVM: arm64: vgic-v3: take an LPI reference in vgic_v3_save_pending_tables In-Reply-To: <20260807025534.34125-1-q.h.hack.winter@gmail.com> References: <20260807025534.34125-1-q.h.hack.winter@gmail.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) 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: q.h.hack.winter@gmail.com, oupton@kernel.org, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.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-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 07 Aug 2026 03:55:34 +0100, Qihang wrote: > > 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 M. -- Without deviation from the norm, progress is not possible.