[PATCH v5 6/9] KVM: selftests: Limit the number of VM creates in hardware_disable_test

From: Ritesh Harjani (IBM)

Date: Tue Sep 22 2026 - 14:37:13 EST


hardware_disable_test forks several VMs (NR_IERATIONS=512). This patch
limits that number to 4 when we know that we are running in constraint
host environment. The number 4 is just a safe minimum when
kvm_arch_vm_create_may_enomem() can be true.

Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>
---
tools/testing/selftests/kvm/hardware_disable_test.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/hardware_disable_test.c b/tools/testing/selftests/kvm/hardware_disable_test.c
index 43a36ef3ead8..e90a17b8160e 100644
--- a/tools/testing/selftests/kvm/hardware_disable_test.c
+++ b/tools/testing/selftests/kvm/hardware_disable_test.c
@@ -20,6 +20,7 @@
#define NR_VCPUS 4
#define NR_SLEEPERS_PER_VCPU 16
#define NR_ITERATIONS 512
+#define NR_ITERATIONS_LIMIT 4
#define DELAY_US_MAX 2000

static cpu_set_t threads_cpu_set;
@@ -127,7 +128,7 @@ void wait_for_child_setup(pid_t pid)
int main(int argc, char **argv)
{
cpu_set_t allowed_cpu_set;
- int s, r, cpu, i;
+ int s, r, cpu, i, nr_iterations;
pid_t pid;

kvm_sched_getaffinity(0, sizeof(cpu_set_t), &allowed_cpu_set);
@@ -141,7 +142,9 @@ int main(int argc, char **argv)
sem = sem_open("vm_sem", O_CREAT | O_EXCL, 0644, 0);
sem_unlink("vm_sem");

- for (i = 0; i < NR_ITERATIONS; ++i) {
+ nr_iterations = kvm_arch_vm_create_may_enomem() ? NR_ITERATIONS_LIMIT :
+ NR_ITERATIONS;
+ for (i = 0; i < nr_iterations; ++i) {
pid = fork();
TEST_ASSERT(pid >= 0, "%s: unable to fork", __func__);
if (pid == 0)
--
2.39.5