KVM: arm64: Add KUnit tests for stage 2 walker memcache consumption
RFC PATCH 1/1 KVM: arm64: Add KUnit tests for stage 2 walker memcache consumption
The stage 2 walker in hyp/pgtable.c takes every dependency through struct kvm_pgtable_mm_ops, so it can be exercised against a mock allocator with a bounded page budget: the same shape as the memcache a fault handler stages before calling kvm_pgtable_stage2_map().
Granularity changes that dirty logging forces at fault time (collapse of pages into a block when logging stops, block splits when it starts) consume that budget in ways that today only surface under a running guest on arm64 hardware. Pin the walker allocation contract down at unit level instead: a fresh page mapping must succeed with a stocked cache and fail cleanly with ENOMEM on an empty one, and coalescing pages back into a block must consume no cache pages at all.
All map calls pass KVM_PGTABLE_WALK_SKIP_BBM_TLBI and SKIP_CMO since no hardware walker can ever observe the tables under test.
Run with:
tools/testing/kunit/kunit.py run --arch=arm64 'kvm-stage2-pgtable.*'
---
Hey, I tested these tests, they work, Feel free to review in your own time! This series was inspired by Fuads selftests [1]
[1] https://lore.kernel.org/all/[email protected]/
arch/arm64/kvm/Kconfig | 11 ++ arch/arm64/kvm/Makefile | 2 + arch/arm64/kvm/pgtable_test.c | 252 ++++++++++++++++++++++++++++++++++ 3 files changed, 265 insertions(+) create mode 100644 arch/arm64/kvm/pgtable_test.c
arch/arm64/kvm/Kconfig +11 -0
@@ -44,6 +44,17 @@ menuconfig KVM if KVM +config KVM_PGTABLE_KUNIT_TEST + bool "KUnit tests for the stage 2 page table walker" if !KUNIT_ALL_TESTS + depends on KUNIT=y + default KUNIT_ALL_TESTS + help + Say Y here to run unit tests for the stage 2 page table walker + in hyp/pgtable.c against a mock allocator, covering how map and + collapse operations consume the fault handler memcache. + + If unsure, say N. + config PTDUMP_STAGE2_DEBUGFS bool "Present the stage-2 pagetables to debugfs" depends on DEBUG_KERNEL
arch/arm64/kvm/Makefile +2 -0
@@ -32,6 +32,8 @@ kvm-$(CONFIG_PTDUMP_STAGE2_DEBUGFS) += ptdump.o kvm-$(CONFIG_NVHE_EL2_TRACING) += hyp_trace.o +kvm-$(CONFIG_KVM_PGTABLE_KUNIT_TEST) += pgtable_test.o + always-y := hyp_constants.h hyp-constants.s define rule_gen_hyp_constants
arch/arm64/kvm/pgtable_test.c new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
2.47.3