]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: selftests: Add helper to check for VGICv3 support
authorOliver Upton <oliver.upton@linux.dev>
Wed, 17 Sep 2025 21:20:33 +0000 (14:20 -0700)
committerMarc Zyngier <maz@kernel.org>
Wed, 24 Sep 2025 18:23:32 +0000 (19:23 +0100)
Introduce a proper predicate for probing VGICv3 by performing a 'test'
creation of the device on a dummy VM.

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
tools/testing/selftests/kvm/arm64/arch_timer.c
tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
tools/testing/selftests/kvm/arm64/vgic_irq.c
tools/testing/selftests/kvm/arm64/vgic_lpi_stress.c
tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
tools/testing/selftests/kvm/include/arm64/vgic.h
tools/testing/selftests/kvm/lib/arm64/vgic.c

index eeba1cc87ff82bb6f93b98a51f6c9702fe0e2a70..aaf4285f832adf84c34e5c63012275602313ddea 100644 (file)
@@ -184,6 +184,8 @@ struct kvm_vm *test_vm_create(void)
        unsigned int i;
        int nr_vcpus = test_args.nr_vcpus;
 
+       TEST_REQUIRE(kvm_supports_vgic_v3());
+
        vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus);
 
        vm_init_descriptor_tables(vm);
@@ -205,7 +207,6 @@ struct kvm_vm *test_vm_create(void)
 
        test_init_timer_irq(vm);
        gic_fd = vgic_v3_setup(vm, nr_vcpus, 64);
-       __TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3");
 
        /* Make all the test's cmdline args visible to the guest */
        sync_global_to_guest(vm, test_args);
index ce74d069cb7bc17934234d1b3aea422f1bc93a44..d349d80d8418221f2b2e87819a974da482ac8009 100644 (file)
@@ -952,7 +952,6 @@ static void test_vm_create(struct kvm_vm **vm, struct kvm_vcpu **vcpu,
 
        test_init_timer_irq(*vm, *vcpu);
        gic_fd = vgic_v3_setup(*vm, 1, 64);
-       __TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3");
 
        sync_global_to_guest(*vm, test_args);
        sync_global_to_guest(*vm, CVAL_MAX);
@@ -1042,6 +1041,8 @@ int main(int argc, char *argv[])
        /* Tell stdout not to buffer its content */
        setbuf(stdout, NULL);
 
+       TEST_REQUIRE(kvm_supports_vgic_v3());
+
        if (!parse_args(argc, argv))
                exit(KSFT_SKIP);
 
index a09dd423c2d72ad91b6aa46a4b7ffb5028511ab5..9fc9e8e44ecdcbc677518104de056b6ce2312407 100644 (file)
@@ -752,7 +752,6 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split)
        vcpu_args_set(vcpu, 1, args_gva);
 
        gic_fd = vgic_v3_setup(vm, 1, nr_irqs);
-       __TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3, skipping");
 
        vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT,
                guest_irq_handlers[args.eoi_split][args.level_sensitive]);
@@ -802,6 +801,8 @@ int main(int argc, char **argv)
        int opt;
        bool eoi_split = false;
 
+       TEST_REQUIRE(kvm_supports_vgic_v3());
+
        while ((opt = getopt(argc, argv, "hn:e:l:")) != -1) {
                switch (opt) {
                case 'n':
index fc4fe52fb6f84dc6015a7cafc58d19d1950d8033..cc2b21d374af8fe2a4cc755cf212649dd353102e 100644 (file)
@@ -215,8 +215,6 @@ static void setup_test_data(void)
 static void setup_gic(void)
 {
        gic_fd = vgic_v3_setup(vm, test_data.nr_cpus, 64);
-       __TEST_REQUIRE(gic_fd >= 0, "Failed to create GICv3");
-
        its_fd = vgic_its_setup(vm);
 }
 
@@ -374,6 +372,8 @@ int main(int argc, char **argv)
        u32 nr_threads;
        int c;
 
+       TEST_REQUIRE(kvm_supports_vgic_v3());
+
        while ((c = getopt(argc, argv, "hv:d:e:i:")) != -1) {
                switch (c) {
                case 'v':
index a0c4ab8391559741a3e22e74869dcabd83c08393..01f61657de45497472b5a4aba52a3c163d282360 100644 (file)
@@ -436,8 +436,6 @@ static void create_vpmu_vm(void *guest_code)
        vpmu_vm.vcpu = aarch64_vcpu_add(vpmu_vm.vm, 0, &init, guest_code);
        vcpu_init_descriptor_tables(vpmu_vm.vcpu);
        vpmu_vm.gic_fd = vgic_v3_setup(vpmu_vm.vm, 1, 64);
-       __TEST_REQUIRE(vpmu_vm.gic_fd >= 0,
-                      "Failed to create vgic-v3, skipping");
 
        /* Make sure that PMUv3 support is indicated in the ID register */
        dfr0 = vcpu_get_reg(vpmu_vm.vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1));
@@ -634,6 +632,7 @@ int main(void)
        uint64_t i, pmcr_n;
 
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_PMU_V3));
+       TEST_REQUIRE(kvm_supports_vgic_v3());
 
        pmcr_n = get_pmcr_n_limit();
        for (i = 0; i <= pmcr_n; i++) {
index c481d0c00a5d221943a363f7334454879f461df3..b858fa8195b4c321980f0319772d4ad4be096545 100644 (file)
@@ -16,6 +16,7 @@
        ((uint64_t)(flags) << 12) | \
        index)
 
+bool kvm_supports_vgic_v3(void);
 int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs);
 
 #define VGIC_MAX_RESERVED      1023
index 64e7937955637509db57e90a2610d0125e756d86..661744c6532e9a66a7e08c6261e229d754846d7d 100644 (file)
 #include "gic.h"
 #include "gic_v3.h"
 
+bool kvm_supports_vgic_v3(void)
+{
+       struct kvm_vm *vm = vm_create_barebones();
+       int r;
+
+       r = __kvm_test_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3);
+       kvm_vm_free(vm);
+
+       return !r;
+}
+
 /*
  * vGIC-v3 default host setup
  *