Re: [PATCH v2] KVM: arm64: Unconditionally top up the mmu memcache on user fault
From: Leonardo Bras
Date: Fri Dec 04 2026 - 08:40:23 EST
On Thu, Dec 03, 2026 at 06:45:24PM +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 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.
Cool!
I wonder how that will impact with Usama's patch prepended.
Thanks!
Leo