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 B074CC5DF81 for ; Sun, 23 Aug 2026 07:51:10 +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=3DIEEbwz6PHcPkpp1UT7HF1ofN3OEvJ90bHzV9iEJXw=; b=SiqvCYfNU6AhTpz9mLcitvoZJt oCp1xhqgFQs/VGhMfSPsqAPRWc5W5LuogQQOwXiSGaWG1E6pCRa+oaBnkcVxVMoxO6gCzhET0aXGt k6gOl79UpqtLhC2O94D9mPFym3XRVCs/OPlgPnIEPyh8cWKcZS1alRPCDkUNeXwsfSCg5icB7Ak3J umzwCqKYCt/7JD3lhxqtqd5WaVNw96pqmS6f7FSwKNgmsjK7DH+/U8T9kLcqN0mKiZHSIJNWDEzbX hZH6vTsk4CnPWtK6HtTMadE9RrYw5JQ0aIbBU8WKgIDGkV50zjKZ+6i5GDGcQ/iECMxZfBiS4FT55 SNkIXiwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wy2yu-0000000FA46-1Z2V; Sun, 23 Aug 2026 07:51:04 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wy2yt-0000000FA40-1iOt for linux-arm-kernel@lists.infradead.org; Sun, 23 Aug 2026 07:51:03 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 7B7F740C2B; Sun, 23 Aug 2026 07:51:02 +0000 (UTC) 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) 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 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 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.