summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/include
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2026-09-02 17:16:22 -0700
committerSean Christopherson <seanjc@google.com>2026-09-11 09:35:49 -0700
commit3a2a37d2d48e6844dde61032faf130400fad5312 (patch)
tree12097c2b8f31022aa99b0dda1e91c77bcb61436a /tools/testing/selftests/kvm/include
parentd2dde5c387fc9ae1b9364c1bc096bac5d419756f (diff)
KVM: selftests: Compute node masks on-demand in xAPIC IPI test
Compute the node masks for the source (from) and destination (to) NUMA nodes in the xAPIC IPI test instead of pre-filling an array of masks with node per mask. Computing the mask on-demand is technically slower, but doesn't require a large-ish on-stack array, and more importantly allows the test to use a generic "get next NUMA node" API without having to commit all of KVM selftests to using a large array of single-bit nodemasks. Implement said API as a common KVM NUMA API so that it can be used by other tests, e.g. in guest_memfd tests. Deliberately make @from "exclusive" as the anticipated usage in KVM selftests is to select the next, *different* node, i.e. so that users don't have to copy+paste code to assert that the found node is different than the starting node. The obvious downside is that implementing the exclusive logic forces callers to pass -1 instead of 0 when the goal is to find the first node in the mask, but that arguably yields more intuitive code anyways. From an overall test functionality/coverage perspective, no functional change intended (the walking pattern of node migration should be unchanged). Reviewed-by: Shivank Garg <shivankg@amd.com> Link: https://patch.msgid.link/20260903001625.2792367-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm/include')
-rw-r--r--tools/testing/selftests/kvm/include/numaif.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/testing/selftests/kvm/include/numaif.h b/tools/testing/selftests/kvm/include/numaif.h
index 71f261eafc90..299dddff2729 100644
--- a/tools/testing/selftests/kvm/include/numaif.h
+++ b/tools/testing/selftests/kvm/include/numaif.h
@@ -6,7 +6,7 @@
#include <dirent.h>
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
#include <linux/mempolicy.h>
#include "kvm_syscalls.h"
@@ -41,6 +41,25 @@ KVM_SYSCALL_DEFINE(mbind, 6, void *, addr, unsigned long, size, int, mode,
*/
#define MAXNODE_FOR_MASK(mask) (BITS_PER_TYPE(mask) + 1)
+/*
+ * Return the node ID of the next NUMA node in the mask, starting at @from+1.
+ * Guarantees a node is found, and that the found node is not @from. Pass -1
+ * to find the first node in the mask.
+ */
+static inline int kvm_get_next_numa_node(unsigned long nodemask, int from)
+{
+ const unsigned long nr_bits = BITS_PER_TYPE(nodemask);
+ int to;
+
+ to = find_next_bit(&nodemask, nr_bits, from + 1);
+ if (to == nr_bits)
+ to = find_next_bit(&nodemask, nr_bits, 0);
+
+ TEST_ASSERT(to != nr_bits && to != from,
+ "Unabled to find second NUMA node (from = %d, to = %d)", from, to);
+ return to;
+}
+
static inline int get_max_numa_node(void)
{
struct dirent *de;