]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Fix irqfd_test for non-x86 architectures
authorOliver Upton <oliver.upton@linux.dev>
Tue, 30 Sep 2025 19:33:02 +0000 (12:33 -0700)
committerMarc Zyngier <maz@kernel.org>
Mon, 13 Oct 2025 13:17:03 +0000 (14:17 +0100)
The KVM_IRQFD ioctl fails if no irqchip is present in-kernel, which
isn't too surprising as there's not much KVM can do for an IRQ if it
cannot resolve a destination.

As written the irqfd_test assumes that a 'default' VM created in
selftests has an in-kernel irqchip created implicitly. That may be the
case on x86 but it isn't necessarily true on other architectures.

Add an arch predicate indicating if 'default' VMs get an irqchip and
make the irqfd_test depend on it. Work around arm64 VGIC initialization
requirements by using vm_create_with_one_vcpu(), ignoring the created
vCPU as it isn't used for the test.

Reported-by: Sebastian Ott <sebott@redhat.com>
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Acked-by: Sean Christopherson <seanjc@google.com>
Fixes: 7e9b231c402a ("KVM: selftests: Add a KVM_IRQFD test to verify uniqueness requirements")
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
tools/testing/selftests/kvm/include/kvm_util.h
tools/testing/selftests/kvm/irqfd_test.c
tools/testing/selftests/kvm/lib/arm64/processor.c
tools/testing/selftests/kvm/lib/kvm_util.c
tools/testing/selftests/kvm/lib/s390/processor.c
tools/testing/selftests/kvm/lib/x86/processor.c

index 26cc30290e7617987a2ba9a40d08061af8c761d5..112d3f443a179f08fa34cc125e47150a0fa95a8b 100644 (file)
@@ -1273,4 +1273,6 @@ bool vm_is_gpa_protected(struct kvm_vm *vm, vm_paddr_t paddr);
 
 uint32_t guest_get_vcpuid(void);
 
+bool kvm_arch_has_default_irqchip(void);
+
 #endif /* SELFTEST_KVM_UTIL_H */
index 7c301b4c7005c8a961377664b07cea1075698235..5d7590d0186815badb32f73be67e38fcc2e7b048 100644 (file)
@@ -89,11 +89,19 @@ static void juggle_eventfd_primary(struct kvm_vm *vm, int eventfd)
 int main(int argc, char *argv[])
 {
        pthread_t racing_thread;
+       struct kvm_vcpu *unused;
        int r, i;
 
-       /* Create "full" VMs, as KVM_IRQFD requires an in-kernel IRQ chip. */
-       vm1 = vm_create(1);
-       vm2 = vm_create(1);
+       TEST_REQUIRE(kvm_arch_has_default_irqchip());
+
+       /*
+        * Create "full" VMs, as KVM_IRQFD requires an in-kernel IRQ chip. Also
+        * create an unused vCPU as certain architectures (like arm64) need to
+        * complete IRQ chip initialization after all possible vCPUs for a VM
+        * have been created.
+        */
+       vm1 = vm_create_with_one_vcpu(&unused, NULL);
+       vm2 = vm_create_with_one_vcpu(&unused, NULL);
 
        WRITE_ONCE(__eventfd, kvm_new_eventfd());
 
index 369a4c87dd8fb296d5ea91fa22460e747d8d2789..54f6d17c78f7335d95d701976b7cf8009fb84f9c 100644 (file)
@@ -725,3 +725,8 @@ void kvm_arch_vm_release(struct kvm_vm *vm)
        if (vm->arch.has_gic)
                close(vm->arch.gic_fd);
 }
+
+bool kvm_arch_has_default_irqchip(void)
+{
+       return request_vgic && kvm_supports_vgic_v3();
+}
index 6743fbd9bd6710ded8875492fce606490cf5a4a9..a35adfebfa23d4fa235b7605b2c0dc9873a73c6f 100644 (file)
@@ -2344,3 +2344,8 @@ bool vm_is_gpa_protected(struct kvm_vm *vm, vm_paddr_t paddr)
        pg = paddr >> vm->page_shift;
        return sparsebit_is_set(region->protected_phy_pages, pg);
 }
+
+__weak bool kvm_arch_has_default_irqchip(void)
+{
+       return false;
+}
index 20cfe970e3e34614b2fb20da08c73841274332ec..8ceeb17c819affa08523c1dd2d6644df58746575 100644 (file)
@@ -221,3 +221,8 @@ void vcpu_arch_dump(FILE *stream, struct kvm_vcpu *vcpu, uint8_t indent)
 void assert_on_unhandled_exception(struct kvm_vcpu *vcpu)
 {
 }
+
+bool kvm_arch_has_default_irqchip(void)
+{
+       return true;
+}
index c748cd9b2eefaf49c7ec79c6e612cc0541c53288..b418502c5ecc675b8e8afbe0bec9538be0399334 100644 (file)
@@ -1318,3 +1318,8 @@ bool sys_clocksource_is_based_on_tsc(void)
 
        return ret;
 }
+
+bool kvm_arch_has_default_irqchip(void)
+{
+       return true;
+}