From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC448606A31C for ; Mon, 30 Nov 2026 16:52:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Fr4BShtz; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gj2iImJK 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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=QB8udzuFY2WUPywsnmZ0ymQFqoFSWuKsD7XWwNeITbg=; b=Fr4BShtzl5VucEODPJD4bpdkoM lP95PPPgYLkVm9HverxXDt3Rj4PrEM4FrrvevoVbb5xJG1kBvcxGBNzO+vE5g6wmmyKsY/bXANVOB a5nLKMmYYuS1WCvXCaP6HAL1GSA8Lb0QiVoITGnG6Cn+on6IYAzJBNYPl7QeaXmHDn9+vYNj8h+Uu TZ6HWIL2oe2glvooamdV6O37BPTF6F/gHVVwEEQCVmWBgQjedYPwWhKYpiVGPGP8rr+zS7HGdGNDa Ay49wyopiIJ0B0Dz0xlJwz2uKx03AHN74ilxq/dtjBqaEYkYTJUO4vxifFqPDz4xIgt4MipO0bRW0 deFRr21w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY4c4-00000005Kqw-2dxb; Mon, 30 Nov 2026 16:52:24 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY4c3-00000005Kqm-43eH for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 16:52:24 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5E5A143E51; Mon, 30 Nov 2026 16:52:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 588491F00896; Mon, 30 Nov 2026 16:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796057543; bh=QB8udzuFY2WUPywsnmZ0ymQFqoFSWuKsD7XWwNeITbg=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=gj2iImJKRx9LikBtv8fpii/FVN9HovytjSICD8YUBv1OxWsGXQaH61OTw49JKE5Y1 m5YMOb0D0499G/fChignVaaezaMqu1ZihZF1bVbpb93DtRsVv63mRAFXqp/L0QU5/u chPhHnqvuKD6Ir2/sWS5hXNT3aWCxFIDv+GRPpxF/MgXH6aSwFZGSlSIO7sFs9BDe0 UrMQLFlxycnHlI29nfTOH60xnK+RGKeRT8yduDPykHkOCQARJVjpnawCAKyotZ+Tvb k9DcORdHnk6f1Rl+FC2PVcvNlU75XFiLsVnCN2VJohQr+SBC+A2X5S6fltrcpxXE86 tsGnuMleHCj/A== Date: Mon, 30 Nov 2026 16:52:14 +0000 From: "Lorenzo Stoakes (ARM)" To: Leonardo Bras Cc: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Christoffer Dall , Jintack Lim , Wei-Lin Chang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Usama Arif , stable@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Top up the mmu memcache on user fault for NV Message-ID: References: <20261126-fix-nv-cache-topup-v1-1-a22c936872fe@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Mon, Nov 30, 2026 at 12:03:25PM +0000, Leonardo Bras wrote: > On Fri, Nov 27, 2026 at 01:09:11PM +0000, Lorenzo Stoakes (ARM) wrote: > > On Fri, Nov 27, 2026 at 11:58:04AM +0000, Leonardo Bras wrote: > > > On Thu, Nov 26, 2026 at 05:28:29PM +0000, Lorenzo Stoakes (ARM) wrote: > > > > The S2 user fault path tops up the MMU memcache (used for page table > > > > pre-allocation as the point at which page tables are installed may not > > > > allocate) except when: > > > > > > > > * It's a permission fault AND > > > > * dirty page logging is disabled AND > > > > * pKVM is disabled > > > > > > > > At which point it is assumed no page table will be allocated. > > > > > > > > However nested virtualisation adds another edge case - the mapping size of > > > > a shadow S2 is clamped to that of the guest's own S2. If the guest > > > > hypervisor replaces a block mapping with a table, a permission fault on the > > > > shadow block has to be mapped at PAGE_SIZE, which requires a page table to > > > > collapse the block into. > > > > > > Can you please expand on how would that happen? > > > > > > IIUC when a guest hypervisor replaces a block mapping with a table, it > > > calls a tlbi in the range, and L0 will trap and remove the Shadow S2 entry, > > > then next access shouldn't be a permission but a translation fault. > > > > > > What am I missing? > > > > That's a great point, actually :) > > > > But nothing really enforces that L1 does that for sure, even a bug could produce > > that, and you really want to avoid the host getting in bother in that case. > > > > (The host kernel has to behave properly no matter what guests do). > > Oh right, there can be malfunctioning guests :) > > > > > I was able to (get claude to) repro this easily. > > > > But actually I think there's another case too, even assuming everything's > > well-behaved: > > > > * vCPU B: Writes to a read-only shadow block -> permission fault, exits > > to the host. > > > > * vCPU A: Concurrently does its break/TLBI/make on the L1 S2, replacing > > the block with writable pages. The TLBI clears the shadow block. > > > > * vCPU B: Now handles the fault. It's still a permission fault as far as > > the ESR is concerned so we skip the top-up, but the L1 S2 now says > > page rather than block, so we go to map a page and have to allocate > > page table(s) for it. > > > > This needs the mapping size to have changed (otherwise we just try to relax > > permissions, which doesn't allocate) which can happen when splitting, > > replacing pages with a THP page, etc. > > > > In general I think just topping up regardless is the better route, but for > > a backport this is the least big change to fix this. > > > > Ok, fair enough. > > FWIW: > Reviewed-by: Leonardo Bras Thanks! I plan to send a v2 with unconditional topup as per the discussion with Usama, would you be OK with me propagating the tag to that? > > Thanks! > Leo -- Cheers, Lorenzo