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 C9BF0C5DF9C for ; Mon, 24 Aug 2026 15:54:29 +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=Q/YK2XBpqlieY7KJvqGJYsHNS+SMvy1GkrZAPQ1gJ5k=; b=VAOgWdT9fIaBZvn7+KrVKwINNS kRtk8JoD2CyTLqmk0SZ2EckkO+ANYWUO2FS/5l7pHtFlpsiaW69pw8sqTUHuELta6JAMmhfcGjmIn SrfObZBFQDWNMlxmIq8HDGWM9D+v77GaJ1Fihc2Vol4fL6EUfklM1oSMr1Y4gIp/4TN/dY9a+VEkQ JqWqVMgZPiM2W7616T47H+xJ4edEfcWHxj6uyrWySOV8WzEgtWY9fNtEGvvMFPPaAl7DV9d6BHxCU +EZEY0z8UAGqzlaymiDCdyKK36h1c1l5AIGjniCJjdgfp4oqSJwZtVVscOwFeGz9Mup0HgJig+8dS lWND03Ow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wyX07-0000000GyY5-0fEI; Mon, 24 Aug 2026 15:54:19 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wyX05-0000000GyXv-2ZFl for linux-arm-kernel@lists.infradead.org; Mon, 24 Aug 2026 15:54:17 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5EB444020F; Mon, 24 Aug 2026 15:54:17 +0000 (UTC) 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) 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 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.