All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fuad Tabba <tabba@google.com>
To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org
Cc: maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com,
	 suzuki.poulose@arm.com, yuzenghui@huawei.com, will@kernel.org,
	 pbonzini@redhat.com, shuah@kernel.org, anup@brainfault.org,
	tabba@google.com
Subject: [PATCH v1 3/5] KVM: riscv: selftests: Fix incorrect rounding in page_align()
Date: Mon, 15 Dec 2025 15:45:31 +0000	[thread overview]
Message-ID: <20251215154533.3154405-4-tabba@google.com> (raw)
In-Reply-To: <20251215154533.3154405-1-tabba@google.com>

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: 3e06cdf10520 ("KVM: selftests: Add initial support for RISC-V 64-bit")
Signed-off-by: Fuad Tabba <tabba@google.com>
---
 tools/testing/selftests/kvm/lib/riscv/processor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c
index 2eac7d4b59e9..d5e8747b5e69 100644
--- a/tools/testing/selftests/kvm/lib/riscv/processor.c
+++ b/tools/testing/selftests/kvm/lib/riscv/processor.c
@@ -28,7 +28,7 @@ bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext)
 
 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 pte_addr(struct kvm_vm *vm, uint64_t entry)
-- 
2.52.0.239.gd5f0c6e74e-goog


  parent reply	other threads:[~2025-12-15 15:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15 15:45 [PATCH v1 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup Fuad Tabba
2025-12-15 15:45 ` [PATCH v1 1/5] KVM: arm64: selftests: Disable unused TTBR1_EL1 translations Fuad Tabba
2025-12-15 15:45 ` [PATCH v1 2/5] KVM: arm64: selftests: Fix incorrect rounding in page_align() Fuad Tabba
2025-12-15 15:45 ` Fuad Tabba [this message]
2025-12-15 15:45 ` [PATCH v1 4/5] KVM: selftests: Move page_align() to shared header Fuad Tabba
2025-12-15 15:45 ` [PATCH v1 5/5] KVM: selftests: Fix typos and stale comments in kvm_util Fuad Tabba
  -- strict thread matches above, loose matches on Subject: below --
2025-12-15 15:55 [PATCH v1 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup Fuad Tabba
2025-12-15 15:55 ` [PATCH v1 3/5] KVM: riscv: selftests: Fix incorrect rounding in page_align() Fuad Tabba
2025-12-15 15:55   ` Fuad Tabba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251215154533.3154405-4-tabba@google.com \
    --to=tabba@google.com \
    --cc=anup@brainfault.org \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=shuah@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.