mirror of
https://github.com/torvalds/linux.git
synced 2026-09-25 09:41:03 +02:00
KVM: selftests: Verify interrupts are received when IRQ affinity changes in IRQ test
Extent the eventfd IRQ test with a '-a' flag to randomly affinitize the
device's host IRQ to different physical CPUs throughout the test. This
stresses the kernel's ability to maintain correct interrupt routing and
delivery even as the underlying hardware IRQ affinity is changed
dynamically via /proc/<irq>/smp_affinity{,_list}.
Signed-off-by: David Matlack <dmatlack@google.com>
Co-developed-by: Josh Hilke <jrhilke@google.com>
Signed-off-by: Josh Hilke <jrhilke@google.com>
[sean: massage changelog]
Link: https://patch.msgid.link/20260626213534.3866178-12-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
380b0e5e0e
commit
197b0cd9ac
|
|
@ -12,10 +12,12 @@
|
|||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
static u64 timeout_ns = 2ULL * 1000 * 1000 * 1000;
|
||||
static bool guest_ready_for_irqs[KVM_MAX_VCPUS];
|
||||
static bool guest_received_irq[KVM_MAX_VCPUS];
|
||||
static bool irq_affinity;
|
||||
static bool done;
|
||||
|
||||
#define GUEST_RECEIVED_IRQ(__vcpu) \
|
||||
|
|
@ -137,9 +139,10 @@ static const char *probe_iommu_type(void)
|
|||
|
||||
static void help(const char *name)
|
||||
{
|
||||
printf("Usage: %s [-d <segment:bus:device.function>] [-h] [-t iommu_type]\n", name);
|
||||
printf("Usage: %s [-a] [-d <segment:bus:device.function>] [-h] [-t iommu_type]\n", name);
|
||||
printf("\n");
|
||||
printf("Tests KVM interrupt routing and delivery via irqfd.\n");
|
||||
printf("-a Affine the device's host IRQ to a random physical CPU\n");
|
||||
printf("-d Use a VFIO device to send MSI-X interrupts instead of manually signaling the eventfd\n");
|
||||
printf("-t Override the IOMMU type to use (vfio_type1_iommu or iommufd)\n");
|
||||
printf("\n");
|
||||
|
|
@ -172,10 +175,13 @@ int main(int argc, char **argv)
|
|||
int i, j, c, msix, eventfd;
|
||||
struct iommu *iommu;
|
||||
struct kvm_vm *vm;
|
||||
int irq;
|
||||
int irq, irq_cpu;
|
||||
|
||||
while ((c = getopt(argc, argv, "d:ht:")) != -1) {
|
||||
while ((c = getopt(argc, argv, "ad:ht:")) != -1) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
irq_affinity = true;
|
||||
break;
|
||||
case 'd':
|
||||
device_bdf = optarg;
|
||||
break;
|
||||
|
|
@ -204,7 +210,12 @@ int main(int argc, char **argv)
|
|||
printf("Using device %s MSI-X[%d] (IRQ-%u)\n", device_bdf, msix,
|
||||
irq);
|
||||
} else {
|
||||
TEST_ASSERT(!irq_affinity,
|
||||
"Setting IRQ affinity (-a) requires a backing device (-d)");
|
||||
|
||||
eventfd = kvm_new_eventfd();
|
||||
irq = -1;
|
||||
irq_cpu = -1;
|
||||
}
|
||||
|
||||
pr_info("Injecting interrupts for GSI %d (guest vector 0x%x) %d times\n",
|
||||
|
|
@ -228,6 +239,11 @@ int main(int argc, char **argv)
|
|||
|
||||
kvm_route_msi(vm, gsi, vcpu, vector);
|
||||
|
||||
if (irq_affinity) {
|
||||
irq_cpu = kvm_random_u64(&kvm_rng) % get_nprocs();
|
||||
proc_irq_set_smp_affinity(irq, irq_cpu);
|
||||
}
|
||||
|
||||
for (j = 0; j < nr_vcpus; j++)
|
||||
TEST_ASSERT(!GUEST_RECEIVED_IRQ(vcpus[j]),
|
||||
"IRQ flag for vCPU %d not clear prior to test",
|
||||
|
|
@ -241,8 +257,8 @@ int main(int argc, char **argv)
|
|||
cpu_relax();
|
||||
|
||||
TEST_ASSERT(GUEST_RECEIVED_IRQ(vcpu),
|
||||
"vCPU %d timed out waiting for IRQ (vector 0x%x) from GSI %d\n",
|
||||
vcpu->id, vector, gsi);
|
||||
"vCPU %d timed out waiting for IRQ (vector 0x%x) from GSI %d (via CPU %d)\n",
|
||||
vcpu->id, vector, gsi, irq_cpu);
|
||||
|
||||
WRITE_AND_SYNC_TO_GUEST(vm, guest_received_irq[vcpu->id], false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user