Re: [PATCH v3 0/5] KVM: arm64: nv: Implement nested stage-2 reverse map
From: Itaru Kitayama
Date: Tue Jun 23 2026 - 03:49:42 EST
Hi Wei-Lin,
On Sun, May 10, 2026 at 03:53:33PM +0100, Wei-Lin Chang wrote:
> Hi,
>
> This is v3 of optimizing the shadow s2 mmu unmapping during MMU
> notifiers.
>
> Two new preparatory patches are added, one reduces a hole in kvm_s2_mmu
> and another refactors the code a bit during s2 faults. Other changes are
> listed below.
>
> * Changes from v2 [1]:
>
> - Removed "polluted" teminology.
>
> - Use xa_{mk, to}_value() when storing and retriving values from maple
> trees.
>
> - Avoid using the 63rd bit in maple tree values so that xa_{mk, to}_value()
> does not lose us a bit.
>
> - Added reverse map removal during TLBI handling.
>
> - Other suggested refactorings.
>
> Thanks!
>
> [1]: https://lore.kernel.org/kvmarm/20260411125024.3735989-1-weilin.chang@xxxxxxx/
>
> Wei-Lin Chang (5):
> KVM: arm64: Use a variable for the canonical GPA in kvm_s2_fault_map()
> KVM: arm64: Move shadow_pt_debugfs_dentry to reduce holes in
> kvm_s2_mmu
> KVM: arm64: nv: Avoid full shadow s2 unmap
> KVM: arm64: nv: Remove reverse map entries during TLBI handling
> KVM: arm64: nv: Create nested IPA direct map to speed up reverse map
> removal
>
> arch/arm64/include/asm/kvm_host.h | 17 +-
> arch/arm64/include/asm/kvm_nested.h | 6 +
> arch/arm64/kvm/mmu.c | 43 +++--
> arch/arm64/kvm/nested.c | 238 +++++++++++++++++++++++++++-
> arch/arm64/kvm/sys_regs.c | 3 +
> 5 files changed, 290 insertions(+), 17 deletions(-)
While investigating the long VM teardown time on QEMU in the nested shadow
stage 2 selftest, I instrumented a few functions with bpftrace.
The same kselftest workload produced the following counts:
Without this series (today's kvmarm/fixes):
kvm_nested_s2_unmap: 12
kvm_pgtable_stage2_unmap: 8,388,623
kvm_tlb_flush_vmid_range: 8,388,623
exit_vmid_context: 8,388,639
With this series:
kvm_nested_s2_unmap: 12
kvm_pgtable_stage2_unmap: 18
kvm_tlb_flush_vmid_range: 18
exit_vmid_context: 34
The bpftrace script used was:
#!/usr/bin/env bpftrace
fentry:kvm_nested_s2_unmap
{
@nested = count();
}
fentry:kvm_pgtable_stage2_unmap
{
@pgunmap = count();
}
fentry:kvm_tlb_flush_vmid_range
{
@flush = count();
}
fentry:exit_vmid_context
{
@exit = count();
}
END
{
print(@nested);
print(@pgunmap);
print(@flush);
print(@exit);
}
Is this consistent with what you evaluated during the development?
I wonder if this is good for nested guest boot paths too.
Thanks,
Itaru.
>
> --
> 2.43.0
>