[PATCH v3 3/4] KVM: selftests: Use allowed memory nodes in test_numa_allocation()

From: Shivank Garg

Date: Mon Sep 07 2026 - 03:32:44 EST


test_numa_allocation() assumes that nodes 0 and 1 exist and are usable.
That is not guaranteed on systems with sparse or memoryless nodes, or
when a cpuset restricts the task.

Pick two nodes from MPOL_F_MEMS_ALLOWED and use MAXNODE_FOR_MASK() when
passing the masks to mbind(). Keep the two-node requirement because the
test verifies that pages are allocated on different nodes.

Signed-off-by: Shivank Garg <shivankg@xxxxxxx>
---
tools/testing/selftests/kvm/guest_memfd_test.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c
index ea8e38064e83..cc5abca1adae 100644
--- a/tools/testing/selftests/kvm/guest_memfd_test.c
+++ b/tools/testing/selftests/kvm/guest_memfd_test.c
@@ -127,18 +127,19 @@ static void test_mbind(int fd, size_t total_size)
static void test_numa_allocation(int fd, size_t total_size)
{
unsigned long node0_mask, node1_mask;
- unsigned long maxnode = 8;
+ unsigned long maxnode = MAXNODE_FOR_MASK(node0_mask);
+ unsigned long mems_allowed;
int nid0, nid1;
void *pages[4];
int status[4];
char *mem;
int i;

- if (!is_multi_numa_node_system())
+ if (kvm_get_numa_memory_nodes(&mems_allowed) < 2)
return;

- nid0 = 0;
- nid1 = 1;
+ nid0 = kvm_get_next_numa_node(mems_allowed, -1);
+ nid1 = kvm_get_next_numa_node(mems_allowed, nid0);
node0_mask = BIT(nid0);
node1_mask = BIT(nid1);


--
2.43.0