RFC KVM: arm64: nv: Grow the shadow S2 MMU pool on demand
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest6 patches 1 replyIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | KVM: arm64: nv: Allocate shadow S2 MMUs in blocksarch/ arch/ | +57 | 0 replies | |
| 2/6 | KVM: arm64: nv: Pick the shadow S2 MMU to recycle with a clockarch/ arch/ | +28 | 0 replies | |
| 3/6 | KVM: arm64: Add kvm_arm_vmid_nr_usable()arch/ arch/ | +13 | 0 replies | |
| 4/6 | KVM: arm64: nv: Grow the shadow S2 MMU pool on demandarch/ arch/ | +148 | 0 replies | |
| 5/6 | KVM: arm64: nv: Park grown MMUs on ALLE1 and reactivate them on demandarch/ arch/ arch/ +1 more | +118 | 0 replies | |
| 6/6 | KVM: arm64: nv: Park shadow S2 MMUs emptied by a guest range invalidationarch/ arch/ arch/ | +10 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC PATCH 0/6] KVM: arm64: nv: Grow the shadow S2 MMU pool on demand
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
Signature · 1 line
2.43.0