[PATCH v2 12/14] KVM: selftests: Support testing with multiple vCPUs

Josh Hilke
2026-03-31T19:41:48Z

From: David Matlack <dmatlack@google.com>

Add the '-v' flag to vfio_pci_irq_test to support testing with multiple
vCPUs. The test will round-robin the device's interrupt across all
active vCPUs, ensuring that multi-processor interrupt routing and load
balancing are working correctly within the guest.

Signed-off-by: David Matlack <dmatlack@google.com>
Signed-off-by: Josh Hilke <jrhilke@google.com>
Co-developed-by: Josh Hilke <jrhilke@google.com>
---
tools/testing/selftests/kvm/vfio_pci_irq_test.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/vfio_pci_irq_test.c b/tools/testing/selftests/kvm/vfio_pci_irq_test.c
index c2f48c6710dd..8c6c7c424b92 100644
--- a/tools/testing/selftests/kvm/vfio_pci_irq_test.c
+++ b/tools/testing/selftests/kvm/vfio_pci_irq_test.c
@@ -186,7 +186,7 @@ static void send_msi(struct vfio_pci_device *device, bool use_device_msi, int ms

static void help(const char *name)
{
- printf("Usage: %s [-a] [-b] [-d] [-e] [-h] [-i nr_irqs] [-n] [-p] segment:bus:device.function\n",
+ printf("Usage: %s [-a] [-b] [-d] [-e] [-h] [-i nr_irqs] [-n] [-p] [-v nr_vcpus] segment:bus:device.function\n",
name);
printf("\n");
printf(" -a: Randomly affinitize the device IRQ to different CPUs\n"
@@ -200,6 +200,8 @@ static void help(const char *name)
printf(" -n: Route some of the device interrupts to be delivered as\n"
" an NMI into the guest.\n");
printf(" -p: Pin vCPU threads to random pCPUs throughout the test.\n");
+ printf(" -v: Set the number of vCPUs that the test should create.\n"
+ " Interrupts will be round-robined among vCPUs.\n");
printf("\n");
exit(KSFT_FAIL);
}
@@ -242,7 +244,7 @@ int main(int argc, char **argv)

device_bdf = vfio_selftests_get_bdf(&argc, argv);

- while ((c = getopt(argc, argv, "abdehi:np")) != -1) {
+ while ((c = getopt(argc, argv, "abdehi:npv:")) != -1) {
switch (c) {
case 'a':
irq_affinity = true;
@@ -265,6 +267,9 @@ int main(int argc, char **argv)
case 'p':
pin_vcpus = true;
break;
+ case 'v':
+ nr_vcpus = atoi_positive("nr_vcpus", optarg);
+ break;
case 'h':
default:
help(argv[0]);
--
2.53.0.1118.gaef5881109-goog