Skip to content

KVM: selftests: Link with VFIO selftests lib and test device interrupts

Josh Hilke kvm lkml sashiko-reviews 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest21 patches 23 repliesIn review
  2. v419 patches 5 repliesSuperseded
  3. v316 patches 15 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v214 patches27 repliesSuperseded

Changes in v5 from the cover letter

- Rename get_proc_vfio_irq_number() to vfio_msix_to_host_irq()
- Rename open_proc_irq_affinity() and write_proc_irq_affinity() to include "_smp_affinity_list"
- Print /proc/irq/<irq>/smp_affinity and effective_affinity on timeout failures
- Convert IRQ type from 'int' to 'unsigned int' across helpers and the test
- Fix compiler warnings for uninitialized variables in irq_test.c
- Remove rate-limiting on affinity changes

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/21KVM: selftests: Build and link selftests/vfio/lib into KVM selfteststools/testing/selftests/kvm/Makefile.kvm+4 -10 replies
2/21KVM: selftests: Add guest read/write macrostools/testing/selftests/kvm/dirty_log_test.c tools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/mmu_stress_test.c +1 more+24 -260 replies
3/21KVM: selftests: Rename guest_rng to kvm_rngtools/testing/selftests/kvm/dirty_log_perf_test.c tools/testing/selftests/kvm/dirty_log_test.c tools/testing/selftests/kvm/include/test_util.h +4 more+33 -330 replies
4/21KVM: selftests: Add helper to generate random u64 in range [min,max]tools/testing/selftests/kvm/include/test_util.h tools/testing/selftests/kvm/lib/test_util.c+21 -01 reply
5/21KVM: selftests: Add IRQ injection testtools/testing/selftests/kvm/Makefile.kvm tools/testing/selftests/kvm/irq_test.c+176 -02 replies
6/21KVM: selftests: Add helper to get host IRQ from device MSIX for IRQ bypass testtools/testing/selftests/kvm/Makefile.kvm tools/testing/selftests/kvm/include/proc_util.h tools/testing/selftests/kvm/lib/proc_util.c+50 -01 reply
7/21KVM: selftests: Verify IRQ bypass works in IRQ testtools/testing/selftests/kvm/irq_test.c+57 -76 replies
8/21KVM: selftests: Add helpers to write proc IRQ affinity for IRQ testtools/testing/selftests/kvm/include/proc_util.h tools/testing/selftests/kvm/lib/proc_util.c+22 -01 reply
9/21KVM: selftests: Add helpers to print proc IRQ affinity for IRQ testtools/testing/selftests/kvm/include/proc_util.h tools/testing/selftests/kvm/lib/proc_util.c+34 -01 reply
10/21KVM: selftests: Verify interrupts are received when IRQ affinity changes in IRQ testtools/testing/selftests/kvm/irq_test.c+38 -30 replies
11/21KVM: selftests: Verify IRQs wake up halted vCPUs in IRQ testtools/testing/selftests/kvm/irq_test.c+27 -51 reply
12/21KVM: selftests: Verify interrupts are received after modifying IRQ routes in IRQ testtools/testing/selftests/kvm/irq_test.c+18 -21 reply
13/21KVM: selftests: Make number of IRQs configurable in IRQ testtools/testing/selftests/kvm/irq_test.c+6 -21 reply
14/21KVM: selftests: Verify non-postable IRQ remapping in IRQ testtools/testing/selftests/kvm/irq_test.c+35 -91 reply
15/21KVM: selftests: Add kvm_gettid() wrapper and convert userstools/testing/selftests/kvm/demand_paging_test.c tools/testing/selftests/kvm/include/kvm_syscalls.h tools/testing/selftests/kvm/lib/assert.c +2 more+11 -90 replies
16/21KVM: selftests: Add kvm_sched_getaffinity() wrapper and convert userstools/testing/selftests/kvm/arch_timer.c tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c tools/testing/selftests/kvm/include/kvm_syscalls.h +3 more+8 -131 reply
17/21KVM: selftests: Add pin_task_to_random_cpu() helper function for IRQ testtools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/lib/kvm_util.c+23 -00 replies
18/21KVM: selftests: Verify vCPU migration during IRQ delivery in IRQ testtools/testing/selftests/kvm/irq_test.c+31 -21 reply
19/21KVM: selftests: Print vCPU affinity on timeout during IRQ testtools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/irq_test.c tools/testing/selftests/kvm/lib/kvm_util.c+52 -01 reply
20/21KVM: selftests: Make number of vCPUs configurable in IRQ testtools/testing/selftests/kvm/irq_test.c+6 -22 replies
21/21KVM: selftests: Add xAPIC support in IRQ testtools/testing/selftests/kvm/irq_test.c+23 -51 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 00/21] KVM: selftests: Link with VFIO selftests lib and test device interrupts

This is v5 of a series which introduces tools/testing/selftests/kvm/irq_test.c in KVM selftests. This test exercises the delivery of interrupts (both emulated via eventfd and real from a VFIO device) to guest vCPUs. Beyond basic injection, the series adds coverage for several complex scenarios, including:
- Dynamic updates to KVM's GSI routing table while interrupts are active.
- Waking up halted vCPUs via interrupts.
- Stressing interrupt delivery during random host IRQ affinity changes.
- Stressing interrupt delivery during random vCPU thread migration across physical CPUs.
- Testing non-postable interrupt remapping (using NMIs to force transitions).
- Supporting both xAPIC and x2APIC modes in the guest.

The series also links the VFIO selftests library into KVM selftests to enable testing of VFIO-KVM interactions.

The test can optionally use a PCI device bound to vfio-pci to test physical device interrupts. If using a device, it can be invoked by passing the BDF to the VFIO selftests setup script, and then running the test with the device BDF passed via the -d option:

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

This test only supports x86. Testing physical device interrupts (-d argument) requires a device with a supported VFIO selftest driver. Currently supported devices include:
- Intel DSA (Data Streaming Accelerator), 8086:0b25
- Intel IOAT (I/O Acceleration Technology), 8086:2021

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.
-c: Clear GSI Routes. Periodically destroys/recreates KVM's GSI routing table to
verify handling of dynamic IRQ updates.
-d: Device MSI Triggers. Uses the physical device to trigger MSIs instead of
eventfd emulation (requires a supported device driver).
-i: IRQ Count. Sets the number of interrupts to generate (default 1000). -m: vCPU Migration. Migrates vCPUs to random physical CPUs to verify that
posted interrupts follow the vCPU across host cores.
-n: NMI Delivery. Routes interrupts as NMIs into the guest to verify the
VFIO-NMI delivery path.
-v: vCPU Count. Distributes interrupts across multiple vCPUs via round-robin
routing.
-x: xAPIC Mode. Forces legacy xAPIC mode to verify compatibility.

---
Changelog

v4 -> v5
- Rename get_proc_vfio_irq_number() to vfio_msix_to_host_irq()
- Rename open_proc_irq_affinity() and write_proc_irq_affinity() to include "_smp_affinity_list"
- Print /proc/irq/<irq>/smp_affinity and effective_affinity on timeout failures
- Convert IRQ type from 'int' to 'unsigned int' across helpers and the test
- Fix compiler warnings for uninitialized variables in irq_test.c
- Remove rate-limiting on affinity changes

v4: https://lore.kernel.org/kvm/[email protected]/

David Matlack (13):
KVM: selftests: Build and link selftests/vfio/lib into KVM selftests
KVM: selftests: Add guest read/write macros
KVM: selftests: Add IRQ injection test
KVM: selftests: Add helper to get host IRQ from device MSIX for IRQ
bypass test
KVM: selftests: Verify IRQ bypass works in IRQ test
KVM: selftests: Verify interrupts are received when IRQ affinity
changes in IRQ test
KVM: selftests: Verify IRQs wake up halted vCPUs in IRQ test
KVM: selftests: Verify interrupts are received after modifying IRQ
routes in IRQ test
KVM: selftests: Make number of IRQs configurable in IRQ test
KVM: selftests: Verify non-postable IRQ remapping in IRQ test
KVM: selftests: Verify vCPU migration during IRQ delivery in IRQ test
KVM: selftests: Make number of vCPUs configurable in IRQ test
KVM: selftests: Add xAPIC support in IRQ test

Josh Hilke (8):
KVM: selftests: Rename guest_rng to kvm_rng
KVM: selftests: Add helper to generate random u64 in range [min,max]
KVM: selftests: Add helpers to write proc IRQ affinity for IRQ test
KVM: selftests: Add helpers to print proc IRQ affinity for IRQ test
KVM: selftests: Add kvm_gettid() wrapper and convert users
KVM: selftests: Add kvm_sched_getaffinity() wrapper and convert users
KVM: selftests: Add pin_task_to_random_cpu() helper function for IRQ
test
KVM: selftests: Print vCPU affinity on timeout during IRQ test

 tools/testing/selftests/kvm/Makefile.kvm      |   8 +-
 tools/testing/selftests/kvm/arch_timer.c      |   2 +-
 .../kvm/arm64/arch_timer_edge_cases.c         |   2 +-
 .../selftests/kvm/demand_paging_test.c        |   2 +-
 .../selftests/kvm/dirty_log_perf_test.c       |   4 +-
 tools/testing/selftests/kvm/dirty_log_test.c  |  11 +-
 .../selftests/kvm/include/kvm_syscalls.h      |   7 +
 .../testing/selftests/kvm/include/kvm_util.h  |  13 +
 .../testing/selftests/kvm/include/proc_util.h |  15 +
 .../testing/selftests/kvm/include/test_util.h |  25 +-
 .../selftests/kvm/include/x86/kvm_util_arch.h |   4 +-
 tools/testing/selftests/kvm/irq_test.c        | 380 ++++++++++++++++++
 tools/testing/selftests/kvm/lib/assert.c      |   8 +-
 tools/testing/selftests/kvm/lib/kvm_util.c    |  95 ++++-
 tools/testing/selftests/kvm/lib/memstress.c   |   8 +-
 tools/testing/selftests/kvm/lib/proc_util.c   |  90 +++++
 tools/testing/selftests/kvm/lib/test_util.c   |  27 +-
 tools/testing/selftests/kvm/mmu_stress_test.c |  15 +-
 tools/testing/selftests/kvm/rseq_test.c       |   6 +-
 tools/testing/selftests/kvm/steal_time.c      |  22 +-
 20 files changed, 662 insertions(+), 82 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/include/proc_util.h
 create mode 100644 tools/testing/selftests/kvm/irq_test.c
 create mode 100644 tools/testing/selftests/kvm/lib/proc_util.c
Signature · 1 line
2.54.0.1032.g2f8565e1d1-goog