From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796394151; b=UvWk5NJ4ufgpJ6ncb/DyAs1LW0XBXOFR396Sv9A0aIk6MG+mQw4+1+G6/pIsMvE3OeIl buGPeNix1VQ7lkOs1zf5Zr/Ghd2o8vLMv8fOrsxn10gl8ANra2rhVzE2SQmOJ5Gh+YEMw Ov+bTuhgP2ER9ObJJkizrQjYU9W/F0qa9q4NTOaTE0P8VZqL/NWO2PDwBTDAfBdL+fwiy xmcFqd4rbiqQtJEys//UzFyGvC1AMuY0KYaqgHwD3uFLAj2POVGzohBBsTDCtpg65Nka8 cEJ/XzN72fZEPgVxL9pel1rRliGEWwrPSxf1BPgSWvIG6TsTG2bWdOzNdXwEwHUZ1Bw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796394151; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=j83ZGRoy6iPo/AZUhvOjdubpa6DbQ2Yolbow0/Z3Xlk=; b=FUCVDiqLUT4eu/TA6zKAmk95DMYLBqtbDJJ3B7AS8IQ3vghhKLETaTVbSJwv3b9njOIi 64ph9JgM28duM6rkkATvmuz8ypFA0Iv3AxIwBsfRhLQ/C2XYrqMByy7IU+c49bh7i05L5 pQTOam/knhQ+/kVlAS7phL7CkgD8MsvLkC2P4ogOJYzIjwG910GGXkgzK88xVb/oqhSP5 N9XJGKAhO5nh0or4l6YWXu2hoSzrbYxvnWwRvF2yevgder1BgA2UTPZghfUFvoVFJ2BUI TSc1q9pFjPkRKmNK+6te4MlzNsmthwh7nUFkhmgKGd63f3sUpnt9Gr309Gm1KyesBNg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=l4T+9LdB; arc=none smtp.remote-ip=91.218.175.199 Received: from mta0.migadu.com (out-199.mta0.migadu.com [91.218.175.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC6FF606A32D for ; Fri, 4 Dec 2026 14:22:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC6FF606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=l4T+9LdB X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=GdI3nz+eBJ9DBw3y9zOS+Rr9vMMPnVU07iAbOplCsZ0=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796394147; v=1; x=1796998947; b=l4T+9LdBkLimz6/n81DjbIorJ2dvjQnbDD0rOIpEFaur7ciDtCP64GxmYUYnyoSG70xLax8d bHqpzJCmdP5tyh84KfiS+mcJD+3XJvhHeCGIeqnJS0XWnS0v05drtZjqtYJ/HUUgoal06ih6Ipi qMoly/u5O2kt9V4yJzPHxseE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id f4488cb974964e83; Fri, 04 Dec 2026 14:22:27 +0000 X-Mizu-Trace-ID: f4488cb974964e83 X-Migadu-Flow: FLOW_OUT Message-ID: <0220d594-041c-41f7-b8ba-84cfaffda1af@linux.dev> Date: Fri, 4 Dec 2026 14:22:26 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] KVM: arm64: Unconditionally top up the mmu memcache on user fault To: "Lorenzo Stoakes (ARM)" , 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 , Yanan Wang Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261203-fix-nv-cache-topup-v2-1-afc8fc1f87a2@kernel.org> Content-Language: en-US From: Usama Arif In-Reply-To: <20261203-fix-nv-cache-topup-v2-1-afc8fc1f87a2@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 03/12/2026 10:45, 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 this is not safe - if the mapping size differs from that at which > the permission fault was taken, we must install a new mapping, which may > require a page table. This can happen when: > > * A guest hypervisor replaces a block in its own S2 with a table without > issuing a TLBI (likely due to a bug) - the shadow S2 mapping size is > clamped to that of the guest's S2, so the shadow block has to be > collapsed. > > * A guest hypervisor does issue the TLBI, but races with another vCPU > which has already taken a permission fault on the shadow block. > > * Nested virtualisation isn't in use at all, but the VMM replaces a THP > with 64K hugetlb pages while a permission fault on it is in flight. > > 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, top up the memcache unconditionally. This is cheap, as the top > up does nothing if the cache already holds enough objects. > > Note that dirty logging had a similar issue, addressed in > commit 56fd1fc526e6 ("KVM: arm64: Top up stage-2 memcache for dirty > logging faults"). > > Local testing with dirty logging disabled indicated no performance > impact. > > kvm_page_table_test was modified to take 65,536 permission faults with > dirty logging disabled, and run on an Apple M2 with the kernel under test > running as an NV guest. The median time across ~70 runs was 1.059s without > this patch and 1.062s with it. > > A control stage in the same runs, whose code this patch does not touch, > showed a similar level of variation so this is clearly within noise levels. > > Fixes: 7d894834a305 ("KVM: arm64: Add usage of stage 2 fault lookup level in user_mem_abort()") > Fixes: fd276e71d1e7 ("KVM: arm64: nv: Handle shadow stage 2 page faults") > Cc: stable@vger.kernel.org > Signed-off-by: Lorenzo Stoakes (ARM) > Reviewed-by: Leonardo Bras > --- > v2: > * Switched to always topping up as per Usama. > * Got performance numbers as per Leo. > * Tweaked commit message to be more succinct. > * Retitled the patch as it is no longer NV-specific. > * Added a Fixes tag for the non-NV case, which predates NV support. > > v1: > https://lore.kernel.org/r/20261126-fix-nv-cache-topup-v1-1-a22c936872fe@kernel.org > --- > arch/arm64/kvm/mmu.c | 19 +++---------------- > 1 file changed, 3 insertions(+), 16 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index a0d4981ebb99..4ef32bedb327 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -2248,28 +2248,15 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault_desc *s2fd, > static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd, > struct kvm_s2_fault_result *result) > { > - bool perm_fault = kvm_s2_fault_is_perm(s2fd); > struct kvm_s2_fault_vma_info s2vi = {}; > enum kvm_pgtable_prot prot; > void *memcache; > int ret; > > - /* > - * 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 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. > - */ > memcache = get_mmu_memcache(s2fd->vcpu); > - if (!perm_fault || memslot_is_logging(s2fd->memslot) || > - is_protected_kvm_enabled()) { > - ret = topup_mmu_memcache(s2fd->mmu, memcache); > - if (ret) > - return ret; > - } > + ret = topup_mmu_memcache(s2fd->mmu, memcache); > + if (ret) > + return ret; > LGTM! Thanks for the fix! Acked-by: Usama Arif > ret = kvm_s2_fault_pin_pfn(s2fd, &s2vi); > if (ret == -EHWPOISON) { > > --- > base-commit: 012e4bc01e339a65dc7c59181b5efb33b171d12c > change-id: 20261126-fix-nv-cache-topup-9ab1fd829014 > > Cheers,