Re: [PATCH v3 13/16] KVM: selftests: Verify vCPU migration during IRQ delivery
From: Josh Hilke
Date: Thu May 28 2026 - 19:06:08 EST
On Tue, May 26, 2026 at 7:23 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> On Tue, Apr 21, 2026, Josh Hilke wrote:
> > +static inline int gettid(void)
>
> gettid() already exists in at least some of my environments:
Should we just use syscall(__NR_gettid) to avoid any compatibility
issues? It's only used once in the test.
> > +void pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus)
> > +{
> > + int i = 0, nr_cpus = CPU_COUNT(possible_cpus);
> > + int cpu, target_idx;
> > +
> > + target_idx = kvm_random_u64(&kvm_rng) % nr_cpus;
> > +
> > + for (cpu = 0; i < nr_cpus; cpu++) {
>
> Shouldn't this be bounded on "cpu < nr_cpus"? If 'i' gets to nr_cpus, it means
> "i == target_idx" was never taken. And at that point, the loop will hang
> indefinitely because cpu will likely be waaaay out of bounds of possible_cpus,
> i.e. the loop will always continue.
>
> > + if (!CPU_ISSET(cpu, possible_cpus))
> > + continue;
> > +
> > + if (i == target_idx) {
> > + pin_task_to_cpu(task, cpu);
> > + return;
> > + }
> > + i++;
> > + }
Ahh, true. I think it actually needs to be bounded on "cpu <
CPU_SETSIZE" so that we iterate through all of the CPUs.
> This should TEST_FAIL(). Or maybe "break" on the match, and the assert that
> i == target_idx?
Will do