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 B50AA450411; Mon, 24 Aug 2026 15:54:17 +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=1787586859; cv=none; b=dYCl+iPQCPYloKn89/lks4iteZr4u3IzVG05hHhofpN+NlH5zSBqV9aHsPvbSHQ/qrETWX80Z+rmEt65P2aOgpFmt3EJg5EknFQolJVKwh++3NoVyL/3Di96bnNI+z8RRcN8p23RzTL6zSwAxBkLPWxsbPB5bLjPspHIi4eY9aI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787586859; c=relaxed/simple; bh=yj+CLjCd6ZN8YVITVo1ajAqsXT5194fFlbwNjWhjLcM=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=gaiutvhroZOqfhoYolsZSAaiAayb24QERVoN/q0fwQVz11lTg1kSBMPabCJ6VENj1ISF4dt9eLVJDcM3JM3h6vPSK+p6cnV3TjHAHvFx9N4NF+tc5Uu+oYzyt5kkiWZGILfgmppeESnQJGI7gXhsW0RF5LfiAhkL3fZCp0YP5tA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XBDmeh7t; 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="XBDmeh7t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FD5F1F000E9; Mon, 24 Aug 2026 15:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787586857; bh=Q/YK2XBpqlieY7KJvqGJYsHNS+SMvy1GkrZAPQ1gJ5k=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=XBDmeh7tkQdYARPGjPdNBK5kC6zjthQwiRE3A8fSloO/zwyEpGoDL5WZfn1vWgPyJ 3HsYSxOzVN3azk/1bfhQRhwCqOoZBTWxKVMRY78nX/TTx2SsywelssenqSr4Lghtd/ rY3vZehxVuRS0sdmO69AYs04PDwv+E9ZmrruC4AWhnZG/7ythH2wsv0h26DNnTr7a/ qjimLt1MYiq6LJifz+Y8v9Krph0vn7Ek5q5RjJNyxZ30c2H78UjDpLoKj1iSrcoDE+ XE92ftUKKLS65/jS0wX554/1eL4RwAlvVvYzfESciWGxiKAG+b8EHcA9nYW/+nh8EV +0LvQQUQ9fSTQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=lobster-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 1wyX02-00000000l0h-3eHA; Mon, 24 Aug 2026 15:54:15 +0000 Date: Mon, 24 Aug 2026 16:56:46 +0100 Message-ID: <87ecfno6kh.wl-maz@kernel.org> From: Marc Zyngier To: "Lorenzo Stoakes (ARM)" Cc: Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Christoffer Dall , Wei-Lin Chang , Yao Yuan , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 0/2] KVM: arm64: Fix spurious warn, null ptr deref on S2 teardown race In-Reply-To: References: <20260822-kvm-arm-nested-virt-fix-v2-0-ac4059a0eaa6@kernel.org> <87tsolnuh0.wl-maz@kernel.org> 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: ljs@kernel.org, oupton@kernel.org, tabba@google.com, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, christoffer.dall@arm.com, weilin.chang@arm.com, yaoyuan@linux.alibaba.com, 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 Mon, 24 Aug 2026 14:15:29 +0100, "Lorenzo Stoakes (ARM)" wrote: > > On Sun, Aug 23, 2026 at 08:53:31AM +0100, Marc Zyngier wrote: > > On Sat, 22 Aug 2026 18:46:52 +0100, > > "Lorenzo Stoakes (ARM)" wrote: > > > > > > When GFNs are invalidated in L0 an MMU notifier triggers > > > kvm_unmap_gfn_range() which tears down all of the stage 2 shadow page > > > tables for nested guests via kvm_nested_s2_unmap(). > > > > > > To avoid lockup, the kvm->mmu_lock is dropped while doing this and the task > > > rescheduled once for each block of physical address space (32 MiB for 16 > > > KiB page size), with the lock being reacquired once the task is scheduled > > > again. > > > > > > This results in a potential race between this L0 tear down and tear down of > > > the guest itself in kvm_flush_shadow_all(), a race which has been observed > > > on real hardware. > > > > > > When this race occurs it causes an invalid kernel warning when the PGT of a > > > nested MMU is cleared by kvm_flush_shadow_all() -> > > > kvm_arch_flush_shadow_all() -> kvm_free_stage2_pgd(). > > > > > > Patch 1 fixes this by having stage2_apply_range() no longer return an error > > > when it has experienced a benign race with pgt teardown when it drops the > > > lock. > > > > > > Patch 2 addresses something more serious - bad timing can turn this spurious > > > warning into a NULL pointer dereference. > > > > > > kvm_arch_flush_shadow_all() calls kvm_uninit_stage2_mmu() which calls > > > kvm_free_stage2_pgd() on the canonical kvm->arch.mmu for that guest's S2 > > > mappings, making it NULL. > > > > > > This is problematic if it happens before stage2_apply_range() reacquires > > > the kvm->mmu_lock, as it ultimately returns to kvm_nested_s2_unmap() which > > > dereferences kvm->arch.mmu.pgt with the mmu lock held under the incorrect > > > assumption that it means it's valid, resulting in a NULL pointer > > > dereference. > > > > > > Fix that by checking if kvm->arch.mmu.pgt is NULL before dereferencing it > > > in kvm_nested_s2_unmap() and kvm_nested_s2_wp(). > > > > With the commit message for patch #1 trimmed to something that fits on > > a couple of standard terminal screens ;-) : > > Haha sure will put it on a diet and respin :) Oliver can probably do so when applying the series. Thanks, M. -- Jazz isn't dead. It just smells funny.