Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: selftests: Add helper to check for VGICv3 support

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>

authored by

Oliver Upton and committed by
Marc Zyngier
b712afa7 a5022da5

+21 -7
+2 -1
tools/testing/selftests/kvm/arm64/arch_timer.c
··· 184 184 unsigned int i; 185 185 int nr_vcpus = test_args.nr_vcpus; 186 186 187 + TEST_REQUIRE(kvm_supports_vgic_v3()); 188 + 187 189 vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus); 188 190 189 191 vm_init_descriptor_tables(vm); ··· 207 205 208 206 test_init_timer_irq(vm); 209 207 gic_fd = vgic_v3_setup(vm, nr_vcpus, 64); 210 - __TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3"); 211 208 212 209 /* Make all the test's cmdline args visible to the guest */ 213 210 sync_global_to_guest(vm, test_args);
+2 -1
tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
··· 952 952 953 953 test_init_timer_irq(*vm, *vcpu); 954 954 gic_fd = vgic_v3_setup(*vm, 1, 64); 955 - __TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3"); 956 955 957 956 sync_global_to_guest(*vm, test_args); 958 957 sync_global_to_guest(*vm, CVAL_MAX); ··· 1040 1041 1041 1042 /* Tell stdout not to buffer its content */ 1042 1043 setbuf(stdout, NULL); 1044 + 1045 + TEST_REQUIRE(kvm_supports_vgic_v3()); 1043 1046 1044 1047 if (!parse_args(argc, argv)) 1045 1048 exit(KSFT_SKIP);
+2 -1
tools/testing/selftests/kvm/arm64/vgic_irq.c
··· 752 752 vcpu_args_set(vcpu, 1, args_gva); 753 753 754 754 gic_fd = vgic_v3_setup(vm, 1, nr_irqs); 755 - __TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3, skipping"); 756 755 757 756 vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT, 758 757 guest_irq_handlers[args.eoi_split][args.level_sensitive]); ··· 800 801 bool level_sensitive = false; 801 802 int opt; 802 803 bool eoi_split = false; 804 + 805 + TEST_REQUIRE(kvm_supports_vgic_v3()); 803 806 804 807 while ((opt = getopt(argc, argv, "hn:e:l:")) != -1) { 805 808 switch (opt) {
+2 -2
tools/testing/selftests/kvm/arm64/vgic_lpi_stress.c
··· 215 215 static void setup_gic(void) 216 216 { 217 217 gic_fd = vgic_v3_setup(vm, test_data.nr_cpus, 64); 218 - __TEST_REQUIRE(gic_fd >= 0, "Failed to create GICv3"); 219 - 220 218 its_fd = vgic_its_setup(vm); 221 219 } 222 220 ··· 371 373 { 372 374 u32 nr_threads; 373 375 int c; 376 + 377 + TEST_REQUIRE(kvm_supports_vgic_v3()); 374 378 375 379 while ((c = getopt(argc, argv, "hv:d:e:i:")) != -1) { 376 380 switch (c) {
+1 -2
tools/testing/selftests/kvm/arm64/vpmu_counter_access.c
··· 436 436 vpmu_vm.vcpu = aarch64_vcpu_add(vpmu_vm.vm, 0, &init, guest_code); 437 437 vcpu_init_descriptor_tables(vpmu_vm.vcpu); 438 438 vpmu_vm.gic_fd = vgic_v3_setup(vpmu_vm.vm, 1, 64); 439 - __TEST_REQUIRE(vpmu_vm.gic_fd >= 0, 440 - "Failed to create vgic-v3, skipping"); 441 439 442 440 /* Make sure that PMUv3 support is indicated in the ID register */ 443 441 dfr0 = vcpu_get_reg(vpmu_vm.vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1)); ··· 632 634 uint64_t i, pmcr_n; 633 635 634 636 TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_PMU_V3)); 637 + TEST_REQUIRE(kvm_supports_vgic_v3()); 635 638 636 639 pmcr_n = get_pmcr_n_limit(); 637 640 for (i = 0; i <= pmcr_n; i++) {
+1
tools/testing/selftests/kvm/include/arm64/vgic.h
··· 16 16 ((uint64_t)(flags) << 12) | \ 17 17 index) 18 18 19 + bool kvm_supports_vgic_v3(void); 19 20 int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs); 20 21 21 22 #define VGIC_MAX_RESERVED 1023
+11
tools/testing/selftests/kvm/lib/arm64/vgic.c
··· 15 15 #include "gic.h" 16 16 #include "gic_v3.h" 17 17 18 + bool kvm_supports_vgic_v3(void) 19 + { 20 + struct kvm_vm *vm = vm_create_barebones(); 21 + int r; 22 + 23 + r = __kvm_test_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3); 24 + kvm_vm_free(vm); 25 + 26 + return !r; 27 + } 28 + 18 29 /* 19 30 * vGIC-v3 default host setup 20 31 *