KVM: selftests: Affine threads to random CPUs in hardware disable test

Affine the worker threads to random CPUs in the hardware disable test, and
honor the starting CPU set in the process.  Hardcoding to CPUs 0-3 is both
wrong and less interesting than running on random CPUs.

Opportunistically convert the local 'i' to an int, as the macros it tests
against are signed, and using 'i' as an iterator is conventionally declared
as an int.

Link: https://patch.msgid.link/20260731195612.2697986-7-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
Sean Christopherson 2026-07-31 12:56:06 -07:00
parent d58cc7bbc5
commit 563416ea9a

View File

@ -149,12 +149,17 @@ void wait_for_child_setup(pid_t pid)
int main(int argc, char **argv)
{
u32 i;
int s, r;
cpu_set_t allowed_cpu_set;
int s, r, cpu, i;
pid_t pid;
for (i = 0; i < VCPU_NUM; i++)
CPU_SET(i, &threads_cpu_set);
kvm_sched_getaffinity(0, sizeof(cpu_set_t), &allowed_cpu_set);
for (i = 0; i < VCPU_NUM && CPU_COUNT(&allowed_cpu_set); i++) {
cpu = kvm_pick_random_cpu(&allowed_cpu_set);
CPU_CLR(cpu, &allowed_cpu_set);
CPU_SET(cpu, &threads_cpu_set);
}
sem = sem_open("vm_sem", O_CREAT | O_EXCL, 0644, 0);
sem_unlink("vm_sem");