summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2026-09-02 09:41:23 -0700
committerSean Christopherson <seanjc@google.com>2026-09-11 09:08:07 -0700
commit1e59e5a3bdbed560bb2acec3a117f193a646332a (patch)
tree06a9c2daf8523e36b964b9b896f15f2d2835eeef /tools/testing/selftests/kvm
parent6c28a0d7cf1254d0916fba5c387b4b56ed49e124 (diff)
KVM: selftests: Add arch hook to force page tables to be naturally aligned
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@gmail.com> Tested-by: Itaru Kitayama <itaru.kitayama@fujitsu.com> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Tested-by: Itaru Kitayam <itaru.kitayama@fujitsu.com> Link: https://patch.msgid.link/20260902164123.2546762-21-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm')
-rw-r--r--tools/testing/selftests/kvm/include/kvm_util.h2
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util.c9
2 files changed, 10 insertions, 1 deletions
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index e77842311919..8fff5b40a592 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -1052,6 +1052,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 ae17642ebf7f..cb2e7a98820a 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -2085,10 +2085,16 @@ enomem:
__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);
}
/*