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 210E64AEEF; Sun, 23 Aug 2026 07:51:02 +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=1787471464; cv=none; b=LY2XHZSQOu4U4DILHqWBvEbgszh5hUvmTPftstrI0ZtkRwKwPxP5vpQtmcktHYeMPiM9iuN4PQou+BrFtEnZWSCU3aBl0IXJabSXvv949scWjoGO7gQZxP9u+EgSCcaMN6TSmy0CGXTySfGyn3eNW4wSuDA97jnOFN/l5wB8V3M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787471464; c=relaxed/simple; bh=ZLORkb6qqgyCDskvJMYpim/9TqST1rT4BNtTNgmSe3s=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=AHunlPpu51IagEuR3BvOZRPBushEUlbu0gphgh94IhIsHPTYq3mMyWFEsL74SVWk69GNzJfCyJLA16BkpZg+HZIZ1BwnoCZ7hgIsOkRxUnDYUpdCB5AoDAAKym0dMHGwem5cTCM4WUFT+o5vFQ7QkwOm3EQWBVNEhe7eB9eHrfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jQcpZfEi; 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="jQcpZfEi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B04B1F000E9; Sun, 23 Aug 2026 07:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787471462; bh=3DIEEbwz6PHcPkpp1UT7HF1ofN3OEvJ90bHzV9iEJXw=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=jQcpZfEiS6+cwHQ6IbXiCpOmUF3Ik2OYTaiKQ0E4XMoV4J+s9mi7uN/D21utY1vyC B2LeV/550wDICtyUannmRKF8t7WiUqQY3Oui81RhPsxSmfC8au+lfTWPQBSShj/PQS 01YrLJeXjXHDzIQ8/BR5yyG3am75louqHIn7rpBDPmxWLM9uZ2nMWfGKkrIsHWZcMD SYgfvb4PKgWs2wIUEVVhI6kfChs94ZruzET9M3x4r0qOR3zoq44uVfkOsXVKv3Vgzn PqG1yrDF4+INochMXIqLCktuDFH4hhD0lRkAVHfHedPtsFH2SdMJd1X4JonrXUW1rq xJVTuqhKKY26A== 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 1wy2yp-00000000NkD-3aq5; Sun, 23 Aug 2026 07:50:59 +0000 Date: Sun, 23 Aug 2026 08:53:31 +0100 Message-ID: <87tsolnuh0.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: <20260822-kvm-arm-nested-virt-fix-v2-0-ac4059a0eaa6@kernel.org> References: <20260822-kvm-arm-nested-virt-fix-v2-0-ac4059a0eaa6@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 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 ;-) : Reviewed-by: Marc Zyngier M. -- Jazz isn't dead. It just smells funny.