Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/6] KVM: arm64: nv: Grow the shadow S2 MMU pool on demand
@ 2026-11-24 21:12 Nathan Chen
  2026-11-24 21:12 ` [RFC PATCH 1/6] KVM: arm64: nv: Allocate shadow S2 MMUs in blocks Nathan Chen
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Nathan Chen @ 2026-11-24 21:12 UTC (permalink / raw)
  To: linux-arm-kernel, kvmarm, linux-kernel
  Cc: Mark Rutland, Will Deacon, Catalin Marinas, Zenghui Yu,
	Suzuki K Poulose, Steffen Eiden, Joey Gouly, Fuad Tabba,
	Oliver Upton, Marc Zyngier, Tom Matthias, Shameer Kolothum Thodi,
	Jason Gunthorpe, Julian Miller

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.

Testing on a 16-bit VMID, 4K pages host with 64-vCPU L1 and idle
2-vCPU Firecracker L2s:

- Ramping to 300 L2s grew the pool 128 -> 192 -> 256 -> 320, with no
  host CPU usage spike observed and no VMID TLB flushes.

- Dropping to 20 L2s and forcing an ALLE1 (an L1 VMID rollover from
  churning ~66K VMs) parked all grown MMUs and returned the budget.
  Ramping back to 300 reactivated them without allocating, with no
  host CPU usage spike observed.

- VM teardown returned the budget, with no warnings in dmesg.

Testing with 14 L2s on a 4-vCPU L1 with 6 L2 guests powered off or
rebooted:

- Firecracker unmaps guest memory before exiting, and L1 issues a TLBI
  RIPAS2E1IS over all of the L2's memory, leaving its shadow MMU empty.
  Patch 6 parked 5 of the 6 MMUs, and the remaining L2 had an MMU from
  the initial pool which should never be parked. This is reclaim on
  range invalidation, not on L2 shutdown, as a range invalidation
  doesn't necessarily mean the nested VM is gone.

Known limitations:

- ALLE1 parking can't tell live idle nested VMs from dead ones. After
  an ALLE1, the remaining L2s found their MMUs parked, and each of
  their vcpus recycled an initial MMU that was empty but still valid,
  doing a whole-IPA unmap. Serialised on mmu_lock, these made L1 spike
  host CPU usage for a brief period. Skipping the unmap of an
  already empty victim would avoid this, but changes the recycle path
  and is left out of this RFC.

- On SIGTERM or SIGKILL, L1 issues no TLBI naming the L2's VMID, while
  it runs or as it is torn down. The leftover MMUs are then only parked
  on an ALLE1, which a Linux guest hypervisor only issues on its own
  VMID rollover.

For SIGTERM and SIGKILL, an alternative I prototyped is a periodic scan
that parks grown MMUs no vcpu used since the previous scan. With a 10s
period, it returned a dead nested VM's budget without taking
MMUs from live idle ones.
However, the scan has to unmap what it parks: after dropping from 300 to
20 L2s, MMU mapping took some time and could delay the vcpus of a busy
L1.

Is parking on ALLE1 and range invalidation good enough to start with,
or would you prefer a periodic scan or another signal for nested VMs
whose VMM is killed?

This series was developed with AI assistance (Anthropic Claude, through
Cursor). It was used for design trade-offs, testing, and adversarial
review of feedback received. I ran the tests on hardware, have reviewed
every change, and take full DCO responsibility for the series.

A branch can be found here with the series applied: 
https://github.com/NathanChenNVIDIA/linux/tree/rfc_alle1_nested_s2_mmu_pool_dynamic_budgeted_kvmarmnext

Nathan Chen (6):
  KVM: arm64: nv: Allocate shadow S2 MMUs in blocks
  KVM: arm64: nv: Pick the shadow S2 MMU to recycle with a clock
  KVM: arm64: Add kvm_arm_vmid_nr_usable()
  KVM: arm64: nv: Grow the shadow S2 MMU pool on demand
  KVM: arm64: nv: Park grown MMUs on ALLE1 and reactivate them on demand
  KVM: arm64: nv: Park shadow S2 MMUs emptied by a guest range
    invalidation

 arch/arm64/include/asm/kvm_host.h   |  25 +-
 arch/arm64/include/asm/kvm_nested.h |   2 +
 arch/arm64/kvm/nested.c             | 350 ++++++++++++++++++++++++----
 arch/arm64/kvm/sys_regs.c           |   9 +
 arch/arm64/kvm/vmid.c               |  12 +
 5 files changed, 356 insertions(+), 42 deletions(-)


base-commit: 263a8db21f7321d74a9258d17151b295290b5dea
-- 
2.43.0



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-24 22:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 21:12 [RFC PATCH 0/6] KVM: arm64: nv: Grow the shadow S2 MMU pool on demand Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 1/6] KVM: arm64: nv: Allocate shadow S2 MMUs in blocks Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 2/6] KVM: arm64: nv: Pick the shadow S2 MMU to recycle with a clock Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 3/6] KVM: arm64: Add kvm_arm_vmid_nr_usable() Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 4/6] KVM: arm64: nv: Grow the shadow S2 MMU pool on demand Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 5/6] KVM: arm64: nv: Park grown MMUs on ALLE1 and reactivate them " Nathan Chen
2026-11-24 21:12 ` [RFC PATCH 6/6] KVM: arm64: nv: Park shadow S2 MMUs emptied by a guest range invalidation Nathan Chen
2026-11-24 22:29 ` [RFC PATCH 0/6] KVM: arm64: nv: Grow the shadow S2 MMU pool on demand Oliver Upton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox