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 81F58606A31C for ; Fri, 27 Nov 2026 17:27:14 +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=DhwrPM1I; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hAeX8wcz 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=0XmBI/vsqTPBFjciFZ00jSFFbSfcYJDZA86bCCNbmx4=; b=DhwrPM1IdcOI63d7kmarLLRWhA R5CbgUddbFg+KI244J26Hgb5emmeTbdIVBY7QmKhh5ES+jmIpQ2Y7kSavMLFLaa0+0NTwghidmT0P 4wYwEiUAbgxgvuzxz3AA7UzHDgqoJZo03Zx7Ha7UaP8gHUJivCwDPQXhgn3deLoKxL3PucsTOsIeX Mto4JuyA9drjXDNTg1ftlHIJK3CKuD4RPAYE89x5YCzxsYCjG6On7bC+KQDTC6jG8rG/mAlh1Oh92 CQtHpqu/fWinWOHLFJ9O+D9ruG5nUsuNY1lLX3JZDxwkTzc2ZH9X8zOxByjRB656xWfUn4iR/A4DJ 5iUp4MXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xWziv-0000000HGP0-0Taf; Fri, 27 Nov 2026 17:27:01 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xWziq-0000000HGOJ-0esX for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2026 17:26:56 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8E28643D52; Fri, 27 Nov 2026 17:26:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 996B61F00899; Fri, 27 Nov 2026 17:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795800415; bh=0XmBI/vsqTPBFjciFZ00jSFFbSfcYJDZA86bCCNbmx4=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=hAeX8wczzScMlEi3kseFTivVf002FWoibXkMKuLG6apA2bRnJyiRirF5XbENTHJDp 0x6ugFO3kD0HQzi3PtEw7kD20tOU2MDWYPDxSjhTAD2gZ8EqsSR2g9EAk+FsL2kiDy TZ1heB+nrzY+3cwOvy0TCS0afFYTdANPqm7LIu//Z1TZaK5oUXQ+ippkqyqynlQKRO PGQXOjOCEE1GkIQEiIyfpBvA5w4PolyCkmXNCsTfNj6edRzylITYCv5tBdxU5EYxOn B8bP4MOti4xv6qTcxcx/QnFGAKuL1NkuxFnkgsFMWDdRss1C4TXJnY+oCJ0T+I2Mt5 J6lEthLHAmaGA== Date: Fri, 27 Nov 2026 17:26:47 +0000 From: "Lorenzo Stoakes (ARM)" To: Usama Arif 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 , Leonardo Bras , Wei-Lin Chang , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, 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> <20261127152237.108363-1-usama.arif@linux.dev> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261127152237.108363-1-usama.arif@linux.dev> 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=-15.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,INCLUDES_PATCH, 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 Fri, Nov 27, 2026 at 07:22:36AM -0800, Usama Arif wrote: > On Thu, 26 Nov 2026 17:28:29 +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. > > > > With the memcache empty, kvm_mmu_memory_cache_alloc() hits its > > guest-triggerable WARN_ON(!nobjs) and falls back to a GFP_ATOMIC allocation > > under mmu_lock, with a BUG_ON() if that fails. > > > > Therefore, also top up the memcache for permission faults taken on a > > shadow S2. > > > > Note that dirty logging had a similar issue, addressed in commit > > 56fd1fc526e6 ("KVM: arm64: Top up stage-2 memcache for dirty logging > > faults"). > > > > Fixes: fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page faults") > > Cc: stable@vger.kernel.org > > Signed-off-by: Lorenzo Stoakes (ARM) > > --- > > arch/arm64/kvm/mmu.c | 8 +++++--- > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > index a0d4981ebb99..e09a8f2c0482 100644 > > --- a/arch/arm64/kvm/mmu.c > > +++ b/arch/arm64/kvm/mmu.c > > @@ -2256,16 +2256,18 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd, > > > > /* > > * Permission faults just need to update the existing leaf entry, > > - * and so normally don't require allocations from the memcache. The > > - * only exception to this is when dirty logging is enabled at runtime > > + * and so normally don't require allocations from the memcache. One > > + * exception to this is when dirty logging is enabled at runtime > > * and a fault needs to collapse a block entry into a table. > > * Under pKVM a permission fault can also collapse pages into a block, > > * which needs a fresh mapping object, and the hypervisor requires the > > * min-pages memcache even when the install allocates nothing. > > + * With nested, a shadow stage-2 block may also need to be collapsed > > + * into a table if the guest's own stage-2 mapping has become smaller. > > */ > > memcache = get_mmu_memcache(s2fd->vcpu); > > if (!perm_fault || memslot_is_logging(s2fd->memslot) || > > - is_protected_kvm_enabled()) { > > + is_protected_kvm_enabled() || s2fd->nested) { > > ret = topup_mmu_memcache(s2fd->mmu, memcache); > > if (ret) > > return ret; > > > > Thanks for the fix! > > On the narrow condition being the smaller backport: I don't think it > is. The hunk already conflicts on 7.3, where topup_mmu_memcache() still > takes the vCPU, and the condition looks different on 7.2 and older, so > every stable tree needs a small manual backport either way. > > A permission fault can also allocate outside NV. For example, take an > exec permission fault on a THP block, where the VMM replaces that > memory with 64K hugetlb pages before the fault looks up the VMA: > > - the MMU notifier unmaps the block, and mmu_seq is read afterwards > - kvm_s2_resolve_vma_size() forces PAGE_SIZE for the CONT_PTE hugetlb > - PAGE_SIZE != perm_fault_granule, so kvm_pgtable_stage2_map() runs > and allocates a table, with no top-up > > That one is narrow and VMM-driven, but topping up for every fault would > cover it too, and it costs a single comparison when the cache already > holds enough pages. > Reads a little schloppy ;) But I think you're right yeah. Good bloody lord @ 64 KiB hugetlb pages being a thing... obscene :) Anyway, I'll send an unconditional v2, it's really not that much delta in general. -- Cheers, Lorenzo