* [PATCH v3 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup
@ 2026-01-06 9:24 Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 1/5] KVM: arm64: selftests: Disable unused TTBR1_EL1 translations Fuad Tabba
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Fuad Tabba @ 2026-01-06 9:24 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, will,
pbonzini, shuah, anup, itaru.kitayama, andrew.jones, tabba
Changes from v2 [1]:
- Collected Reviewed-by tags from the previous version (thanks!)
- Rebased on 6.19-rc4
- No code changes
This series tidies up a few things in the KVM selftests. It addresses an
error in memory alignment, hardens the arm64 MMU configuration for
selftests, and fixes minor documentation issues.
First, for arm64, the series explicitly disables translation table walks
for the unused upper virtual address range (TTBR1). Since selftests run
entirely in the lower range (TTBR0), leaving TTBR1 uninitialized but
active could lead to unpredictable behavior if guest code accesses high
addresses. We set EPD1 (and TBI1) to ensure such accesses
deterministically generate translation faults.
Second, the series fixes the `page_align()` implementation in both arm64
and riscv. The previous version incorrectly rounded up already-aligned
addresses to the *next* page, potentially wasting memory or causing
unexpected gaps. After fixing the logic in the arch-specific files, the
function is moved to the common `kvm_util.h` header to eliminate code
duplication.
Finally, a few comments and argument descriptions in `kvm_util` are
updated to match the actual code implementation.
Based on Linux 6.19-rc4.
Cheers,
/fuad
[1] https://lore.kernel.org/all/20251215165155.3451819-1-tabba@google.com/
Fuad Tabba (5):
KVM: arm64: selftests: Disable unused TTBR1_EL1 translations
KVM: arm64: selftests: Fix incorrect rounding in page_align()
KVM: riscv: selftests: Fix incorrect rounding in page_align()
KVM: selftests: Move page_align() to shared header
KVM: selftests: Fix typos and stale comments in kvm_util
tools/testing/selftests/kvm/include/arm64/processor.h | 4 ++++
tools/testing/selftests/kvm/include/kvm_util.h | 9 +++++++--
tools/testing/selftests/kvm/lib/arm64/processor.c | 7 ++-----
tools/testing/selftests/kvm/lib/kvm_util.c | 2 +-
tools/testing/selftests/kvm/lib/riscv/processor.c | 5 -----
5 files changed, 14 insertions(+), 13 deletions(-)
base-commit: 9ace4753a5202b02191d54e9fdf7f9e3d02b85eb
--
2.52.0.351.gbe84eed79e-goog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 1/5] KVM: arm64: selftests: Disable unused TTBR1_EL1 translations
2026-01-06 9:24 [PATCH v3 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup Fuad Tabba
@ 2026-01-06 9:24 ` Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 2/5] KVM: arm64: selftests: Fix incorrect rounding in page_align() Fuad Tabba
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Fuad Tabba @ 2026-01-06 9:24 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, will,
pbonzini, shuah, anup, itaru.kitayama, andrew.jones, tabba
KVM selftests map all guest code and data into the lower virtual address
range (0x0000...) managed by TTBR0_EL1. The upper range (0xFFFF...)
managed by TTBR1_EL1 is unused and uninitialized.
If a guest accesses the upper range, the MMU attempts a translation
table walk using uninitialized registers, leading to unpredictable
behavior.
Set `TCR_EL1.EPD1` to disable translation table walks for TTBR1_EL1,
ensuring that any access to the upper range generates an immediate
Translation Fault. Additionally, set `TCR_EL1.TBI1` (Top Byte Ignore) to
ensure that tagged pointers in the upper range also deterministically
trigger a Translation Fault via EPD1.
Define `TCR_EPD1_MASK`, `TCR_EPD1_SHIFT`, and `TCR_TBI1` in
`processor.h` to support this configuration. These are based on their
definitions in `arch/arm64/include/asm/pgtable-hwdef.h`.
Suggested-by: Will Deacon <will@kernel.org>
Reviewed-by: Itaru Kitayama <itaru.kitayama@fujitsu.com>
Signed-off-by: Fuad Tabba <tabba@google.com>
---
tools/testing/selftests/kvm/include/arm64/processor.h | 4 ++++
tools/testing/selftests/kvm/lib/arm64/processor.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/tools/testing/selftests/kvm/include/arm64/processor.h b/tools/testing/selftests/kvm/include/arm64/processor.h
index ff928716574d..ac97a1c436fc 100644
--- a/tools/testing/selftests/kvm/include/arm64/processor.h
+++ b/tools/testing/selftests/kvm/include/arm64/processor.h
@@ -90,6 +90,9 @@
#define TCR_TG0_64K (UL(1) << TCR_TG0_SHIFT)
#define TCR_TG0_16K (UL(2) << TCR_TG0_SHIFT)
+#define TCR_EPD1_SHIFT 23
+#define TCR_EPD1_MASK (UL(1) << TCR_EPD1_SHIFT)
+
#define TCR_IPS_SHIFT 32
#define TCR_IPS_MASK (UL(7) << TCR_IPS_SHIFT)
#define TCR_IPS_52_BITS (UL(6) << TCR_IPS_SHIFT)
@@ -97,6 +100,7 @@
#define TCR_IPS_40_BITS (UL(2) << TCR_IPS_SHIFT)
#define TCR_IPS_36_BITS (UL(1) << TCR_IPS_SHIFT)
+#define TCR_TBI1 (UL(1) << 38)
#define TCR_HA (UL(1) << 39)
#define TCR_DS (UL(1) << 59)
diff --git a/tools/testing/selftests/kvm/lib/arm64/processor.c b/tools/testing/selftests/kvm/lib/arm64/processor.c
index d46e4b13b92c..5b379da8cb90 100644
--- a/tools/testing/selftests/kvm/lib/arm64/processor.c
+++ b/tools/testing/selftests/kvm/lib/arm64/processor.c
@@ -384,6 +384,8 @@ void aarch64_vcpu_setup(struct kvm_vcpu *vcpu, struct kvm_vcpu_init *init)
tcr_el1 |= TCR_IRGN0_WBWA | TCR_ORGN0_WBWA | TCR_SH0_INNER;
tcr_el1 |= TCR_T0SZ(vm->va_bits);
+ tcr_el1 |= TCR_TBI1;
+ tcr_el1 |= TCR_EPD1_MASK;
if (use_lpa2_pte_format(vm))
tcr_el1 |= TCR_DS;
--
2.52.0.351.gbe84eed79e-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 2/5] KVM: arm64: selftests: Fix incorrect rounding in page_align()
2026-01-06 9:24 [PATCH v3 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 1/5] KVM: arm64: selftests: Disable unused TTBR1_EL1 translations Fuad Tabba
@ 2026-01-06 9:24 ` Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 3/5] KVM: riscv: " Fuad Tabba
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Fuad Tabba @ 2026-01-06 9:24 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, will,
pbonzini, shuah, anup, itaru.kitayama, andrew.jones, tabba
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>
---
tools/testing/selftests/kvm/lib/arm64/processor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/lib/arm64/processor.c b/tools/testing/selftests/kvm/lib/arm64/processor.c
index 5b379da8cb90..607a4e462984 100644
--- a/tools/testing/selftests/kvm/lib/arm64/processor.c
+++ b/tools/testing/selftests/kvm/lib/arm64/processor.c
@@ -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)
--
2.52.0.351.gbe84eed79e-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 3/5] KVM: riscv: selftests: Fix incorrect rounding in page_align()
2026-01-06 9:24 [PATCH v3 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 1/5] KVM: arm64: selftests: Disable unused TTBR1_EL1 translations Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 2/5] KVM: arm64: selftests: Fix incorrect rounding in page_align() Fuad Tabba
@ 2026-01-06 9:24 ` Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 4/5] KVM: selftests: Move page_align() to shared header Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 5/5] KVM: selftests: Fix typos and stale comments in kvm_util Fuad Tabba
4 siblings, 0 replies; 8+ messages in thread
From: Fuad Tabba @ 2026-01-06 9:24 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, will,
pbonzini, shuah, anup, itaru.kitayama, andrew.jones, tabba
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")
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
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.351.gbe84eed79e-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 4/5] KVM: selftests: Move page_align() to shared header
2026-01-06 9:24 [PATCH v3 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup Fuad Tabba
` (2 preceding siblings ...)
2026-01-06 9:24 ` [PATCH v3 3/5] KVM: riscv: " Fuad Tabba
@ 2026-01-06 9:24 ` Fuad Tabba
2026-01-06 19:46 ` Sean Christopherson
2026-01-06 9:24 ` [PATCH v3 5/5] KVM: selftests: Fix typos and stale comments in kvm_util Fuad Tabba
4 siblings, 1 reply; 8+ messages in thread
From: Fuad Tabba @ 2026-01-06 9:24 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, will,
pbonzini, shuah, anup, itaru.kitayama, andrew.jones, tabba
To avoid code duplication, move page_align() to the shared `kvm_util.h`
header file.
No functional change intended.
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Fuad Tabba <tabba@google.com>
---
tools/testing/selftests/kvm/include/kvm_util.h | 5 +++++
tools/testing/selftests/kvm/lib/arm64/processor.c | 5 -----
tools/testing/selftests/kvm/lib/riscv/processor.c | 5 -----
3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index 81f4355ff28a..dabbe4c3b93f 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -1258,6 +1258,11 @@ static inline int __vm_disable_nx_huge_pages(struct kvm_vm *vm)
return __vm_enable_cap(vm, KVM_CAP_VM_DISABLE_NX_HUGE_PAGES, 0);
}
+static inline uint64_t page_align(struct kvm_vm *vm, uint64_t v)
+{
+ return (v + vm->page_size - 1) & ~(vm->page_size - 1);
+}
+
/*
* Arch hook that is invoked via a constructor, i.e. before exeucting main(),
* to allow for arch-specific setup that is common to all tests, e.g. computing
diff --git a/tools/testing/selftests/kvm/lib/arm64/processor.c b/tools/testing/selftests/kvm/lib/arm64/processor.c
index 607a4e462984..143632917766 100644
--- a/tools/testing/selftests/kvm/lib/arm64/processor.c
+++ b/tools/testing/selftests/kvm/lib/arm64/processor.c
@@ -21,11 +21,6 @@
static vm_vaddr_t exception_handlers;
-static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
-{
- return (v + vm->page_size - 1) & ~(vm->page_size - 1);
-}
-
static uint64_t pgd_index(struct kvm_vm *vm, vm_vaddr_t gva)
{
unsigned int shift = (vm->pgtable_levels - 1) * (vm->page_shift - 3) + vm->page_shift;
diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c
index d5e8747b5e69..f8ff4bf938d9 100644
--- a/tools/testing/selftests/kvm/lib/riscv/processor.c
+++ b/tools/testing/selftests/kvm/lib/riscv/processor.c
@@ -26,11 +26,6 @@ bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext)
return !ret && !!value;
}
-static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
-{
- return (v + vm->page_size - 1) & ~(vm->page_size - 1);
-}
-
static uint64_t pte_addr(struct kvm_vm *vm, uint64_t entry)
{
return ((entry & PGTBL_PTE_ADDR_MASK) >> PGTBL_PTE_ADDR_SHIFT) <<
--
2.52.0.351.gbe84eed79e-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 5/5] KVM: selftests: Fix typos and stale comments in kvm_util
2026-01-06 9:24 [PATCH v3 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup Fuad Tabba
` (3 preceding siblings ...)
2026-01-06 9:24 ` [PATCH v3 4/5] KVM: selftests: Move page_align() to shared header Fuad Tabba
@ 2026-01-06 9:24 ` Fuad Tabba
4 siblings, 0 replies; 8+ messages in thread
From: Fuad Tabba @ 2026-01-06 9:24 UTC (permalink / raw)
To: kvm, kvm-riscv, kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, joey.gouly, suzuki.poulose, yuzenghui, will,
pbonzini, shuah, anup, itaru.kitayama, andrew.jones, tabba
Fix minor documentation errors in `kvm_util.h` and `kvm_util.c`.
- Correct the argument description for `vcpu_args_set` in `kvm_util.h`,
which incorrectly listed `vm` instead of `vcpu`.
- Fix a typo in the comment for `kvm_selftest_arch_init` ("exeucting" ->
"executing").
- Correct the return value description for `vm_vaddr_unused_gap` in
`kvm_util.c` to match the implementation, which returns an address "at
or above" `vaddr_min`, not "at or below".
No functional change intended.
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Fuad Tabba <tabba@google.com>
---
tools/testing/selftests/kvm/include/kvm_util.h | 4 ++--
tools/testing/selftests/kvm/lib/kvm_util.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index dabbe4c3b93f..e29b2cbcb82b 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -939,7 +939,7 @@ void *vcpu_map_dirty_ring(struct kvm_vcpu *vcpu);
* VM VCPU Args Set
*
* Input Args:
- * vm - Virtual Machine
+ * vcpu - vCPU
* num - number of arguments
* ... - arguments, each of type uint64_t
*
@@ -1264,7 +1264,7 @@ static inline uint64_t page_align(struct kvm_vm *vm, uint64_t v)
}
/*
- * Arch hook that is invoked via a constructor, i.e. before exeucting main(),
+ * Arch hook that is invoked via a constructor, i.e. before executing main(),
* to allow for arch-specific setup that is common to all tests, e.g. computing
* the default guest "mode".
*/
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 8279b6ced8d2..fab6b62d7810 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -1351,7 +1351,7 @@ struct kvm_vcpu *__vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id)
* Output Args: None
*
* Return:
- * Lowest virtual address at or below vaddr_min, with at least
+ * Lowest virtual address at or above vaddr_min, with at least
* sz unused bytes. TEST_ASSERT failure if no area of at least
* size sz is available.
*
--
2.52.0.351.gbe84eed79e-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3 4/5] KVM: selftests: Move page_align() to shared header
2026-01-06 9:24 ` [PATCH v3 4/5] KVM: selftests: Move page_align() to shared header Fuad Tabba
@ 2026-01-06 19:46 ` Sean Christopherson
2026-01-06 19:48 ` Fuad Tabba
0 siblings, 1 reply; 8+ messages in thread
From: Sean Christopherson @ 2026-01-06 19:46 UTC (permalink / raw)
To: Fuad Tabba
Cc: kvm, kvm-riscv, kvmarm, linux-arm-kernel, maz, oliver.upton,
joey.gouly, suzuki.poulose, yuzenghui, will, pbonzini, shuah,
anup, itaru.kitayama, andrew.jones
On Tue, Jan 06, 2026, Fuad Tabba wrote:
> To avoid code duplication, move page_align() to the shared `kvm_util.h`
> header file.
>
> No functional change intended.
>
> Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
> tools/testing/selftests/kvm/include/kvm_util.h | 5 +++++
> tools/testing/selftests/kvm/lib/arm64/processor.c | 5 -----
> tools/testing/selftests/kvm/lib/riscv/processor.c | 5 -----
> 3 files changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> index 81f4355ff28a..dabbe4c3b93f 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> @@ -1258,6 +1258,11 @@ static inline int __vm_disable_nx_huge_pages(struct kvm_vm *vm)
> return __vm_enable_cap(vm, KVM_CAP_VM_DISABLE_NX_HUGE_PAGES, 0);
> }
>
> +static inline uint64_t page_align(struct kvm_vm *vm, uint64_t v)
Maybe vm_page_align()? So that it's a bit more obvious when reading call sites
that the alignment is done with respect to the guest's "base" page size, not the
host's page size.
> +{
> + return (v + vm->page_size - 1) & ~(vm->page_size - 1);
> +}
> +
> /*
> * Arch hook that is invoked via a constructor, i.e. before exeucting main(),
> * to allow for arch-specific setup that is common to all tests, e.g. computing
> diff --git a/tools/testing/selftests/kvm/lib/arm64/processor.c b/tools/testing/selftests/kvm/lib/arm64/processor.c
> index 607a4e462984..143632917766 100644
> --- a/tools/testing/selftests/kvm/lib/arm64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/arm64/processor.c
> @@ -21,11 +21,6 @@
>
> static vm_vaddr_t exception_handlers;
>
> -static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
> -{
> - return (v + vm->page_size - 1) & ~(vm->page_size - 1);
> -}
> -
> static uint64_t pgd_index(struct kvm_vm *vm, vm_vaddr_t gva)
> {
> unsigned int shift = (vm->pgtable_levels - 1) * (vm->page_shift - 3) + vm->page_shift;
> diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c
> index d5e8747b5e69..f8ff4bf938d9 100644
> --- a/tools/testing/selftests/kvm/lib/riscv/processor.c
> +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c
> @@ -26,11 +26,6 @@ bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext)
> return !ret && !!value;
> }
>
> -static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
> -{
> - return (v + vm->page_size - 1) & ~(vm->page_size - 1);
> -}
> -
> static uint64_t pte_addr(struct kvm_vm *vm, uint64_t entry)
> {
> return ((entry & PGTBL_PTE_ADDR_MASK) >> PGTBL_PTE_ADDR_SHIFT) <<
> --
> 2.52.0.351.gbe84eed79e-goog
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 4/5] KVM: selftests: Move page_align() to shared header
2026-01-06 19:46 ` Sean Christopherson
@ 2026-01-06 19:48 ` Fuad Tabba
0 siblings, 0 replies; 8+ messages in thread
From: Fuad Tabba @ 2026-01-06 19:48 UTC (permalink / raw)
To: Sean Christopherson
Cc: kvm, kvm-riscv, kvmarm, linux-arm-kernel, maz, oliver.upton,
joey.gouly, suzuki.poulose, yuzenghui, will, pbonzini, shuah,
anup, itaru.kitayama, andrew.jones
On Tue, 6 Jan 2026 at 19:46, Sean Christopherson <seanjc@google.com> wrote:
>
> On Tue, Jan 06, 2026, Fuad Tabba wrote:
> > To avoid code duplication, move page_align() to the shared `kvm_util.h`
> > header file.
> >
> > No functional change intended.
> >
> > Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> > Signed-off-by: Fuad Tabba <tabba@google.com>
> > ---
> > tools/testing/selftests/kvm/include/kvm_util.h | 5 +++++
> > tools/testing/selftests/kvm/lib/arm64/processor.c | 5 -----
> > tools/testing/selftests/kvm/lib/riscv/processor.c | 5 -----
> > 3 files changed, 5 insertions(+), 10 deletions(-)
> >
> > diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> > index 81f4355ff28a..dabbe4c3b93f 100644
> > --- a/tools/testing/selftests/kvm/include/kvm_util.h
> > +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> > @@ -1258,6 +1258,11 @@ static inline int __vm_disable_nx_huge_pages(struct kvm_vm *vm)
> > return __vm_enable_cap(vm, KVM_CAP_VM_DISABLE_NX_HUGE_PAGES, 0);
> > }
> >
> > +static inline uint64_t page_align(struct kvm_vm *vm, uint64_t v)
>
> Maybe vm_page_align()? So that it's a bit more obvious when reading call sites
> that the alignment is done with respect to the guest's "base" page size, not the
> host's page size.
Yes, that's clearer. I'll fix this.
Thanks,
/fuad
> > +{
> > + return (v + vm->page_size - 1) & ~(vm->page_size - 1);
> > +}
> > +
> > /*
> > * Arch hook that is invoked via a constructor, i.e. before exeucting main(),
> > * to allow for arch-specific setup that is common to all tests, e.g. computing
> > diff --git a/tools/testing/selftests/kvm/lib/arm64/processor.c b/tools/testing/selftests/kvm/lib/arm64/processor.c
> > index 607a4e462984..143632917766 100644
> > --- a/tools/testing/selftests/kvm/lib/arm64/processor.c
> > +++ b/tools/testing/selftests/kvm/lib/arm64/processor.c
> > @@ -21,11 +21,6 @@
> >
> > static vm_vaddr_t exception_handlers;
> >
> > -static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
> > -{
> > - return (v + vm->page_size - 1) & ~(vm->page_size - 1);
> > -}
> > -
> > static uint64_t pgd_index(struct kvm_vm *vm, vm_vaddr_t gva)
> > {
> > unsigned int shift = (vm->pgtable_levels - 1) * (vm->page_shift - 3) + vm->page_shift;
> > diff --git a/tools/testing/selftests/kvm/lib/riscv/processor.c b/tools/testing/selftests/kvm/lib/riscv/processor.c
> > index d5e8747b5e69..f8ff4bf938d9 100644
> > --- a/tools/testing/selftests/kvm/lib/riscv/processor.c
> > +++ b/tools/testing/selftests/kvm/lib/riscv/processor.c
> > @@ -26,11 +26,6 @@ bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext)
> > return !ret && !!value;
> > }
> >
> > -static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
> > -{
> > - return (v + vm->page_size - 1) & ~(vm->page_size - 1);
> > -}
> > -
> > static uint64_t pte_addr(struct kvm_vm *vm, uint64_t entry)
> > {
> > return ((entry & PGTBL_PTE_ADDR_MASK) >> PGTBL_PTE_ADDR_SHIFT) <<
> > --
> > 2.52.0.351.gbe84eed79e-goog
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-01-06 19:49 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-06 9:24 [PATCH v3 0/5] KVM: selftests: Alignment fixes and arm64 MMU cleanup Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 1/5] KVM: arm64: selftests: Disable unused TTBR1_EL1 translations Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 2/5] KVM: arm64: selftests: Fix incorrect rounding in page_align() Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 3/5] KVM: riscv: " Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 4/5] KVM: selftests: Move page_align() to shared header Fuad Tabba
2026-01-06 19:46 ` Sean Christopherson
2026-01-06 19:48 ` Fuad Tabba
2026-01-06 9:24 ` [PATCH v3 5/5] KVM: selftests: Fix typos and stale comments in kvm_util Fuad Tabba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox