[PATCH v2 00/14] KVM: selftests: Link with VFIO selftests lib and test device interrupts

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

I am taking over development of this series from David Matlack.
v1: https://lore.kernel.org/kvm/20250912222525.2515416-1-dmatlack@google.com/

This series is based on the kvm-upstream/queue branch.

This series introduces vfio_pci_irq_test, which exercises the delivery
of VFIO device interrupts (MSI/MSI-X) to guest vCPUs, and links the
VFIO selftests library into KVM selftests to enable testing of VFIO-KVM
interactions.

The test requires a PCI device bound to vfio-pci. It can be invoked by
passing the BDF the VFIO selftests setup script, and then running the
test with the device BDF:

$ ./tools/testing/selftests/vfio/scripts/setup.sh 0000:6a:01.0
$ tools/testing/selftests/kvm/vfio_pci_irq_test 0000:6a:01.0

This test only supports x86. Testing physical device interrupts (-d argument) is
only supported for Intel because there are no VFIO selftest drivers for AMD
devices.

The test can be run with following command-line arguments allow for broad
coverage of the interrupt delivery path:

-a: Random IRQ Affinity. Randomly affinitizes the device IRQ to different
host CPUs to verify stable delivery during interrupt steering changes.
-b: Block vCPUs. Causes vCPUs to HLT instead of spinning, verifying that
Posted-interrupt wakeup (PIW) correctly kicks blocked vCPUs.
-d: Device MSI Triggers. Uses the physical device to trigger MSIs instead
of eventfd emulation (requires a supported device driver).
-e: Clear GSI Routes. Periodically destroys/recreates KVM's GSI routing
table to verify handling of dynamic IRQ updates.
-i: IRQ Count. Sets the number of interrupts to generate (default 1000).
-n: NMI Delivery. Routes interrupts as NMIs into the guest to verify the
VFIO-NMI delivery path.
-p: vCPU Pinning. Migrates vCPUs to random physical CPUs to verify that
posted interrupts follow the vCPU across host cores.
-t: Timeout. Configurable timeout in seconds to wait for an interrupt.
-v: vCPU Count. Distributes interrupts across multiple vCPUs via
round-robin routing.
-x: xAPIC Mode. Forces legacy xAPIC mode to verify compatibility.

Changelog
---------
v2:
- Split the monolithic test into a series of logical patches (Sean)
- Move READ_FROM_GUEST and WRITE_TO_GUEST macros to kvm_util.h (Sean)
- Add gettid, sched_setaffinity, and sched_getaffinity to kvm_syscalls.h (Sean)
- Extract /proc/interrupts parsing logic into lib/irq_util.c (Sean)
- Add -t command-line option for configurable interrupt timeout (Sean)
- Improve assertion messages with specific vCPU failure context (Sean)
- Update guest loop to use cpu_relax() when not blocking (Sean)
- Add KVM_RANDOM_SEED support to kvm_selftest_init for reproducibility (Sean)
- Randomize the default IRQ vector and GSI (Sean)
- Ensure blocked vCPUs are cleaned up correctly after HLT (Sean)
- Use kvm_mmap() instead of mmap() (Sean)

v1: https://lore.kernel.org/kvm/20250912222525.2515416-1-dmatlack@google.com/

David Matlack (11):
KVM: selftests: Build and link sefltests/vfio/lib into KVM selftests
KVM: selftests: Add vfio_pci_irq_test
KVM: selftests: Add support for random host IRQ affinity
KVM: selftests: Allow blocking vCPUs via HLT
KVM: selftests: Add support for physical device MSI triggers
KVM: selftests: Add option to clear GSI routes
KVM: selftests: Make test IRQ count configurable
KVM: selftests: Add support for NMI delivery
KVM: selftests: Add support for vCPU pinning
KVM: selftests: Support testing with multiple vCPUs
KVM: selftests: Add xAPIC mode support

Josh Hilke (3):
KVM: selftests: Add helper functions for IRQ testing
KVM: selftests: Reproduce tests that rely on randomization
KVM: selftests: Make vfio_pci_irq_test timeout configurable

tools/testing/selftests/kvm/Makefile.kvm | 7 +-
.../testing/selftests/kvm/include/irq_util.h | 11 +
.../selftests/kvm/include/kvm_syscalls.h | 7 +
.../testing/selftests/kvm/include/kvm_util.h | 11 +
tools/testing/selftests/kvm/lib/irq_util.c | 84 ++++
tools/testing/selftests/kvm/lib/kvm_util.c | 11 +-
.../testing/selftests/kvm/vfio_pci_irq_test.c | 439 ++++++++++++++++++
7 files changed, 568 insertions(+), 2 deletions(-)
create mode 100644 tools/testing/selftests/kvm/include/irq_util.h
create mode 100644 tools/testing/selftests/kvm/lib/irq_util.c
create mode 100644 tools/testing/selftests/kvm/vfio_pci_irq_test.c

--
2.53.0.1118.gaef5881109-goog