[PATCH 20/20] KVM: selftests: Add arch hook to force page tables to be naturally aligned
From: Sean Christopherson
Date: Wed Aug 26 2026 - 19:11:54 EST
Add an arch hook to communicate to the core physical page allocator that
page table allocations need to be naturally aligned. The hook will be used
for upcoming PowerPC support, which has MMU tables that are larger than the
guest base page size and need to be naturally aligned.
Bury the hook in the physical page allocator to avoid having to plumb a
rarely used param into the main APIs.
Cc: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
tools/testing/selftests/kvm/include/kvm_util.h | 2 ++
tools/testing/selftests/kvm/lib/kvm_util.c | 9 ++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index 1264cd1a343a..ffd4cf740d7f 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -1050,6 +1050,8 @@ void kvm_gsi_routing_write(struct kvm_vm *vm, struct kvm_irq_routing *routing);
const char *exit_reason_str(unsigned int exit_reason);
+bool kvm_arch_needs_naturally_aligned_page_tables(void);
+
gpa_t ____vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, gpa_t min_gpa,
u32 memslot, bool protected, bool naturally_aligned);
gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages,
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 8b5b330a5889..57b653fbd0b1 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -2085,10 +2085,16 @@ gpa_t ____vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages, gpa_t min_gpa,
__builtin_unreachable();
}
+__weak bool kvm_arch_needs_naturally_aligned_page_tables(void)
+{
+ return false;
+}
+
gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages,
enum kvm_mem_region_type type, bool protected)
{
struct userspace_mem_region *region = vm_get_mem_region(vm, type);
+ bool naturally_aligned = false;
gpa_t min_gpa;
TEST_ASSERT(region, "No region for type '%u', memslot '%u'",
@@ -2110,6 +2116,7 @@ gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages,
break;
case MEM_REGION_PT:
min_gpa = KVM_GUEST_PAGE_TABLE_MIN_PADDR;
+ naturally_aligned = kvm_arch_needs_naturally_aligned_page_tables();
break;
case MEM_REGION_TEST_EXTRA:
min_gpa = region->region.guest_phys_addr;
@@ -2120,7 +2127,7 @@ gpa_t __vm_phy_pages_alloc(struct kvm_vm *vm, size_t nr_pages,
}
return ____vm_phy_pages_alloc(vm, nr_pages, min_gpa, vm->memslots[type],
- protected, false);
+ protected, naturally_aligned);
}
/*
--
2.55.0.887.g758fc8c411-goog