From: sashiko-bot@kernel.org
To: "Josh Hilke" <jrhilke@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 19/21] KVM: selftests: Print vCPU affinity on timeout during IRQ test
Date: Thu, 04 Jun 2026 02:21:25 +0000 [thread overview]
Message-ID: <20260604022125.A29011F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604020143.748245-20-jrhilke@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] kvm_print_vcpu_affinity() uses get_nprocs() as the loop boundary, which silently truncates CPUs with indices >= get_nprocs() on sparse topologies.
--
commit 9e2355f47489ee5cf4674888f5c4b7d1058bc869
Author: Josh Hilke <jrhilke@google.com>
KVM: selftests: Print vCPU affinity on timeout during IRQ test
Adds a helper function to print the physical CPU affinity of a vCPU thread
in a human-readable format. Uses this new helper in the irq_test to provide
context when a vCPU times out waiting for an interrupt during migration.
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index e538e6147ec3f..7fc3aaf763797 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
[ ... ]
> @@ -662,6 +663,54 @@ void kvm_print_vcpu_pinning_help(void)
> " (default: no pinning)\n", name, name);
> }
>
> +void kvm_print_vcpu_affinity(struct kvm_vcpu *vcpu, pid_t tid)
> +{
> + int nprocs = get_nprocs();
> + bool first_range = true;
> + int i, start = -1;
> + cpu_set_t cpus;
> +
> + kvm_sched_getaffinity(tid, sizeof(cpus), &cpus);
> +
> + /*
> + * Output format examples:
> + * - Single CPU: "vCPU 0 (TID 1234) affined to pCPU(s): 2"
> + * - List: "vCPU 0 (TID 1234) affined to pCPU(s): 0,2,4"
> + * - Range: "vCPU 0 (TID 1234) affined to pCPU(s): 0-7"
> + * - Mixed: "vCPU 0 (TID 1234) affined to pCPU(s): 0-3,8,10-12"
> + */
> + printf("vCPU %u (TID %d) affined to pCPU(s): ", vcpu->id, tid);
> +
> + for (i = 0; i <= nprocs; i++) {
> + /*
> + * Iterate to nprocs (inclusive) to ensure that if the last pCPU
> + * is part of a range, the 'else' block triggers one final time
> + * to flush that range to stdout.
> + */
> + if (i < nprocs && CPU_ISSET(i, &cpus)) {
[Severity: Medium]
Does using get_nprocs() as the loop boundary risk silently truncating CPUs
on sparse topologies?
get_nprocs() returns the count of currently online CPUs, not the maximum
CPU ID. If a system has 4 online CPUs but their IDs are 0, 1, 2, and 7,
get_nprocs() will return 4.
This would cause the loop to terminate prematurely, completely ignoring
valid but higher-numbered CPU indices (like CPU 7) in the cpu_set_t mask.
Should this iterate up to CPU_SETSIZE instead to encompass the entire mask
capacity, similar to other helper functions like pin_task_to_random_cpu()?
> + if (start == -1)
> + start = i;
> + continue;
> + }
> +
> + if (start != -1) {
> + int end = i - 1;
> +
> + if (!first_range)
> + printf(",");
> +
> + if (start == end)
> + printf("%d", start);
> + else
> + printf("%d-%d", start, end);
> +
> + start = -1;
> + first_range = false;
> + }
> + }
> + printf("\n");
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604020143.748245-1-jrhilke@google.com?part=19
next prev parent reply other threads:[~2026-06-04 2:21 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 2:01 [PATCH v5 00/21] KVM: selftests: Link with VFIO selftests lib and test device interrupts Josh Hilke
2026-06-04 2:01 ` [PATCH v5 01/21] KVM: selftests: Build and link selftests/vfio/lib into KVM selftests Josh Hilke
2026-06-04 2:01 ` [PATCH v5 02/21] KVM: selftests: Add guest read/write macros Josh Hilke
2026-06-04 2:01 ` [PATCH v5 03/21] KVM: selftests: Rename guest_rng to kvm_rng Josh Hilke
2026-06-04 2:01 ` [PATCH v5 04/21] KVM: selftests: Add helper to generate random u64 in range [min,max] Josh Hilke
2026-06-04 2:12 ` sashiko-bot
2026-06-04 16:12 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 05/21] KVM: selftests: Add IRQ injection test Josh Hilke
2026-06-04 16:19 ` Sean Christopherson
2026-06-04 16:26 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 06/21] KVM: selftests: Add helper to get host IRQ from device MSIX for IRQ bypass test Josh Hilke
2026-06-04 2:09 ` sashiko-bot
2026-06-04 20:01 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 07/21] KVM: selftests: Verify IRQ bypass works in IRQ test Josh Hilke
2026-06-04 16:22 ` Sean Christopherson
2026-06-04 17:56 ` Sean Christopherson
2026-06-04 19:25 ` Sean Christopherson
2026-06-04 19:52 ` Sean Christopherson
2026-06-04 23:14 ` Sean Christopherson
2026-06-04 23:35 ` David Matlack
2026-06-04 2:01 ` [PATCH v5 08/21] KVM: selftests: Add helpers to write proc IRQ affinity for " Josh Hilke
2026-06-04 2:09 ` sashiko-bot
2026-06-04 19:35 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 09/21] KVM: selftests: Add helpers to print " Josh Hilke
2026-06-04 2:09 ` sashiko-bot
2026-06-04 17:17 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 10/21] KVM: selftests: Verify interrupts are received when IRQ affinity changes in " Josh Hilke
2026-06-04 2:13 ` sashiko-bot
2026-06-04 2:01 ` [PATCH v5 11/21] KVM: selftests: Verify IRQs wake up halted vCPUs " Josh Hilke
2026-06-04 2:15 ` sashiko-bot
2026-06-04 16:11 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 12/21] KVM: selftests: Verify interrupts are received after modifying IRQ routes " Josh Hilke
2026-06-04 17:22 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 13/21] KVM: selftests: Make number of IRQs configurable " Josh Hilke
2026-06-04 17:35 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 14/21] KVM: selftests: Verify non-postable IRQ remapping " Josh Hilke
2026-06-04 17:22 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 15/21] KVM: selftests: Add kvm_gettid() wrapper and convert users Josh Hilke
2026-06-04 2:01 ` [PATCH v5 16/21] KVM: selftests: Add kvm_sched_getaffinity() " Josh Hilke
2026-06-04 17:23 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 17/21] KVM: selftests: Add pin_task_to_random_cpu() helper function for IRQ test Josh Hilke
2026-06-04 2:01 ` [PATCH v5 18/21] KVM: selftests: Verify vCPU migration during IRQ delivery in " Josh Hilke
2026-06-04 17:27 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 19/21] KVM: selftests: Print vCPU affinity on timeout during " Josh Hilke
2026-06-04 2:21 ` sashiko-bot [this message]
2026-06-04 17:28 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 20/21] KVM: selftests: Make number of vCPUs configurable in " Josh Hilke
2026-06-04 2:20 ` sashiko-bot
2026-06-04 17:29 ` Sean Christopherson
2026-06-04 17:41 ` Sean Christopherson
2026-06-04 2:01 ` [PATCH v5 21/21] KVM: selftests: Add xAPIC support " Josh Hilke
2026-06-04 2:22 ` sashiko-bot
2026-06-04 17:34 ` Sean Christopherson
2026-06-04 20:22 ` [PATCH v5 00/21] KVM: selftests: Link with VFIO selftests lib and test device interrupts Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260604022125.A29011F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jrhilke@google.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.