]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: selftests: Fix incorrect rounding in page_align()
authorFuad Tabba <tabba@google.com>
Fri, 9 Jan 2026 08:22:15 +0000 (08:22 +0000)
committerMarc Zyngier <maz@kernel.org>
Thu, 15 Jan 2026 13:39:53 +0000 (13:39 +0000)
The implementation of `page_align()` in `processor.c` calculates
alignment incorrectly for values that are already aligned. Specifically,
`(v + vm->page_size) & ~(vm->page_size - 1)` aligns to the *next* page
boundary even if `v` is already page-aligned, potentially wasting a page
of memory.

Fix the calculation to use standard alignment logic: `(v + vm->page_size
- 1) & ~(vm->page_size - 1)`.

Fixes: 7a6629ef746d ("kvm: selftests: add virt mem support for aarch64")
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Fuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20260109082218.3236580-3-tabba@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
tools/testing/selftests/kvm/lib/arm64/processor.c

index 5b379da8cb902b707262b9c51a4ecf0cd409be7f..607a4e46298435a51341b612350fb5f622136eec 100644 (file)
@@ -23,7 +23,7 @@ static vm_vaddr_t exception_handlers;
 
 static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
 {
-       return (v + vm->page_size) & ~(vm->page_size - 1);
+       return (v + vm->page_size - 1) & ~(vm->page_size - 1);
 }
 
 static uint64_t pgd_index(struct kvm_vm *vm, vm_vaddr_t gva)