Skip to content

Commit 582b394

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: riscv: selftests: Fix incorrect rounding in page_align()
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: 3e06cdf ("KVM: selftests: Add initial support for RISC-V 64-bit") Reviewed-by: Andrew Jones <andrew.jones@linux.dev> Signed-off-by: Fuad Tabba <tabba@google.com> Link: https://patch.msgid.link/20260109082218.3236580-4-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent dd0c5d0 commit 582b394

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tools/testing/selftests/kvm/lib/riscv/processor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext)
2828

2929
static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
3030
{
31-
return (v + vm->page_size) & ~(vm->page_size - 1);
31+
return (v + vm->page_size - 1) & ~(vm->page_size - 1);
3232
}
3333

3434
static uint64_t pte_addr(struct kvm_vm *vm, uint64_t entry)

0 commit comments

Comments
 (0)