[PATCH v4] KVM: arm64: Resume stage-2 range walks where they stopped
Vincent Donnefort
vdonnefort at google.com
Wed Dec 2 08:59:47 PST 2026
On Wed, Nov 18, 2026 at 10:16:48AM +0500, Haseeb Ashraf wrote:
> From: Haseeb Ashraf <haseeb.ashraf at siemens.com>
>
> stage2_apply_range() walks a range one block-sized chunk at a time.
> The walker steps over an invalid entry in one go, but the next walk
> starts at the following chunk, so an invalid entry larger than a chunk
> is visited once for every chunk it covers. Unmapping the whole IPA
> space of a shadow stage-2, as emulating TLBI VMALLS12E1IS and TLBI
> ALLE1IS does, takes 2^18 walks with 4K pages and a 48-bit IPA space,
> however little it maps. Each walk also ends with a range TLBI when
> FEAT_TLBIRANGE and FWB are available.
>
> On an AmpereOne A192-32X (192 CPUs, Xen on KVM, 4K pages, 48-bit IPA),
> a full-range unmap of one shadow stage-2 took 0.84-0.94 s (mean 0.91 s
> over 226 unmaps) on 6.18.29. With v3 of this change and the mainline
> commits it builds on backported, it took 2.1-45 ms (mean 4.1 ms over 672
> unmaps), with 512 to 1023 walks instead of 262144. The slowest TLBI
> VMALLS12E1IS trap took 0.94 s before and 46 ms after.
>
> Have the walk report the address it reached, and have
> stage2_apply_range() resume from there. Unmap, write-protect and flush
> all go through it, so all three get this. kvm_pgtable_stage2_unmap(),
> kvm_pgtable_stage2_wrprotect() and kvm_pgtable_stage2_flush() now
> return the address, or a negative error code, and so do their pKVM
> counterparts, which do not walk page tables and return the end of the
> range. The other callers, in nested.c and at EL2, only looked for an
> error: they now check for a negative value, and those that pass the
> result on turn it back into 0. The walk handles every entry it steps
> over, including invalid entries that carry state, so nothing has to be
> looked up beforehand.
>
> The unmap of a shadow stage-2 also drops the guest stage-2 records of
> the whole span the walk covered: nothing is mapped in the part it
> stepped over, so any record there is stale. Each walk that remains
> ends with the same deferred TLB invalidation as before. The spans that
> were skipped have no valid entry, so there is nothing to invalidate.
>
> Suggested-by: Oliver Upton <oupton at kernel.org>
> Signed-off-by: Haseeb Ashraf <haseeb.ashraf at siemens.com>
Reviewed-by: Vincent Donnefort <vdonnefort at google.com>
> ---
> arch/arm64/include/asm/kvm_pgtable.h | 25 ++++++++----
> arch/arm64/include/asm/kvm_pkvm.h | 6 +--
> arch/arm64/kvm/hyp/nvhe/mem_protect.c | 22 +++++++----
> arch/arm64/kvm/hyp/pgtable.c | 55 +++++++++++++++++----------
> arch/arm64/kvm/mmu.c | 32 ++++++++++------
> arch/arm64/kvm/nested.c | 2 +-
> arch/arm64/kvm/pkvm.c | 14 +++----
> 7 files changed, 97 insertions(+), 59 deletions(-)
>
[...]
More information about the linux-arm-kernel
mailing list