]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Fall back to split IRQ chip if full in-kernel chip is unsupported
authorSean Christopherson <seanjc@google.com>
Wed, 11 Jun 2025 21:35:55 +0000 (14:35 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 20 Jun 2025 20:52:51 +0000 (13:52 -0700)
Now that KVM x86 allows compiling out support for in-kernel I/O APIC (and
PIC and PIT) emulation, i.e. allows disabling KVM_CREATE_IRQCHIP for all
intents and purposes, fall back to a split IRQ chip for x86 if creating
the full in-kernel version fails with ENOTTY.

Acked-by: Kai Huang <kai.huang@intel.com>
Link: https://lore.kernel.org/r/20250611213557.294358-17-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/lib/kvm_util.c

index a055343a7bf7586a2f43d9e5072b1a032d3093fc..93a921deeb9938875d81d95836931a4076c77f73 100644 (file)
@@ -1716,7 +1716,18 @@ void *addr_gpa2alias(struct kvm_vm *vm, vm_paddr_t gpa)
 /* Create an interrupt controller chip for the specified VM. */
 void vm_create_irqchip(struct kvm_vm *vm)
 {
-       vm_ioctl(vm, KVM_CREATE_IRQCHIP, NULL);
+       int r;
+
+       /*
+        * Allocate a fully in-kernel IRQ chip by default, but fall back to a
+        * split model (x86 only) if that fails (KVM x86 allows compiling out
+        * support for KVM_CREATE_IRQCHIP).
+        */
+       r = __vm_ioctl(vm, KVM_CREATE_IRQCHIP, NULL);
+       if (r && errno == ENOTTY && kvm_has_cap(KVM_CAP_SPLIT_IRQCHIP))
+               vm_enable_cap(vm, KVM_CAP_SPLIT_IRQCHIP, 24);
+       else
+               TEST_ASSERT_VM_VCPU_IOCTL(!r, KVM_CREATE_IRQCHIP, r, vm);
 
        vm->has_irqchip = true;
 }