Re: [RFC PATCH 0/6] KVM: arm64: nv: Grow the shadow S2 MMU pool on demand

From: Nathan Chen

Date: Wed Nov 25 2026 - 17:37:01 EST


Hi Oliver,

On 11/24/2026 2:29 PM, Oliver Upton wrote:
On Tue, Nov 24, 2026 at 01:12:12PM -0800, Nathan Chen wrote:
A nested-capable VM gets 2 shadow stage-2 MMUs per vcpu. Once the guest
hypervisor runs more nested VMs than that, nearly every nested context
switch recycles a live MMU and spikes host CPU usage.

This series lets KVM grow the shadow MMU pool on demand when the pool
is too small, up to a host-wide VMID budget. It also parks grown MMUs
on a guest TLBI ALLE1 and when a guest range invalidation leaves them
empty, in order to return unused capacity.
Thanks for taking a look at the problem. There's no argument that we
need to do something, the existing MMU allocation policy was good enough
for doing nested development and would get replaced eventually.

With that said, I feel rather strongly that we should not invest further
in the MMU array because it is quite inflexible. On top of that we need
an actual eviction policy that selects cold MMUs as victims instead of
the current round robin approach. I don't think you need to do anything
special on the invalidation side with a good eviction policy.

I think this is what we need:

- A VM-wide hashtable for storing stage-2 MMUs, keyed off of
{VTCR_EL2, VTTBR_EL2, HCR_EL2.VM} to align with how we handle TLB
match at stage-2. The hashtable can be dimensioned based on a
configurable VM limit for shadow stage-2 MMUs.

- A state tracking mechanism for victim selection. An LRU list seems
like a reasonable starting point.

- RCU replacement of the evicted MMU. I need to think about it a bit
more but you should be able to reuse the PGD in the new MMU context
as well since we know that no vCPU holds a reference on the victim.
That ought to be the goal anyway.

That should allow us to dynamically allocate MMUs while also improving
upon the current behavior for constrained MMU allocations.

Thanks for the detailed direction, that makes sense. I'll drop the
array-based approach, including the invalidation-side parking, and
rework the series around the approach you mentioned above.

For the per-VM limit, should we keep it capped at
S2_MMU_PER_VCPU * nr_vcpus by default? And should it be overridable
via a module parameter or per-VM capability, or would you prefer no
per-VM cap at all, with the pool growing on demand and only evicting
when allocation fails?

Thanks,
Nathan