From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 332D746982F; Fri, 7 Aug 2026 07:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786089167; cv=none; b=S3viOebPqF7v5Eh6Xd7bOJEV6HHbSOnyyJXsqftY1Jenu+sZX4MRnI6FqZL2oAscQFVJ8tGoEdtTrTRQ7p9HHGTnRl+XwaVy3dwe81Pa+Om9KK2V1t/1ubEDNOz7G5GwU33ChLhsBzda3kQJDdyRFGzxk4ku8slLsC4y/ShrQ6k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786089167; c=relaxed/simple; bh=WVTLT0aTEA2e65hAJgZRewaHW7EUiv0iDKGlVdq1Aco=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=GHkagXSiqPGrmUJ6Sa0C9jLbFETQ+LRDvSHRYhHiWgnBhCqfgIOi2Y2KYWb6Lnn0B+JkPrd0wwbLVUcN4eaOWMEVH10snZ4UR/yIGJyoq9mehyJayCK5srFrc+kUJTde+CizIXaxQW6Fm2F8TxC+F9DsSyQ2vzEJx+wXRgiwYLo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HKc2WmEi; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HKc2WmEi" 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.