Skip to content

Commit b712afa

Browse files
ouptonMarc Zyngier
authored andcommitted
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>
1 parent a5022da commit b712afa

7 files changed

Lines changed: 21 additions & 7 deletions

File tree

tools/testing/selftests/kvm/arm64/arch_timer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ struct kvm_vm *test_vm_create(void)
184184
unsigned int i;
185185
int nr_vcpus = test_args.nr_vcpus;
186186

187+
TEST_REQUIRE(kvm_supports_vgic_v3());
188+
187189
vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus);
188190

189191
vm_init_descriptor_tables(vm);
@@ -205,7 +207,6 @@ struct kvm_vm *test_vm_create(void)
205207

206208
test_init_timer_irq(vm);
207209
gic_fd = vgic_v3_setup(vm, nr_vcpus, 64);
208-
__TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3");
209210

210211
/* Make all the test's cmdline args visible to the guest */
211212
sync_global_to_guest(vm, test_args);

tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,6 @@ static void test_vm_create(struct kvm_vm **vm, struct kvm_vcpu **vcpu,
952952

953953
test_init_timer_irq(*vm, *vcpu);
954954
gic_fd = vgic_v3_setup(*vm, 1, 64);
955-
__TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3");
956955

957956
sync_global_to_guest(*vm, test_args);
958957
sync_global_to_guest(*vm, CVAL_MAX);
@@ -1042,6 +1041,8 @@ int main(int argc, char *argv[])
10421041
/* Tell stdout not to buffer its content */
10431042
setbuf(stdout, NULL);
10441043

1044+
TEST_REQUIRE(kvm_supports_vgic_v3());
1045+
10451046
if (!parse_args(argc, argv))
10461047
exit(KSFT_SKIP);
10471048

tools/testing/selftests/kvm/arm64/vgic_irq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,6 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split)
752752
vcpu_args_set(vcpu, 1, args_gva);
753753

754754
gic_fd = vgic_v3_setup(vm, 1, nr_irqs);
755-
__TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3, skipping");
756755

757756
vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT,
758757
guest_irq_handlers[args.eoi_split][args.level_sensitive]);
@@ -802,6 +801,8 @@ int main(int argc, char **argv)
802801
int opt;
803802
bool eoi_split = false;
804803

804+
TEST_REQUIRE(kvm_supports_vgic_v3());
805+
805806
while ((opt = getopt(argc, argv, "hn:e:l:")) != -1) {
806807
switch (opt) {
807808
case 'n':

tools/testing/selftests/kvm/arm64/vgic_lpi_stress.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ static void setup_test_data(void)
215215
static void setup_gic(void)
216216
{
217217
gic_fd = vgic_v3_setup(vm, test_data.nr_cpus, 64);
218-
__TEST_REQUIRE(gic_fd >= 0, "Failed to create GICv3");
219-
220218
its_fd = vgic_its_setup(vm);
221219
}
222220

@@ -374,6 +372,8 @@ int main(int argc, char **argv)
374372
u32 nr_threads;
375373
int c;
376374

375+
TEST_REQUIRE(kvm_supports_vgic_v3());
376+
377377
while ((c = getopt(argc, argv, "hv:d:e:i:")) != -1) {
378378
switch (c) {
379379
case 'v':

tools/testing/selftests/kvm/arm64/vpmu_counter_access.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,6 @@ static void create_vpmu_vm(void *guest_code)
436436
vpmu_vm.vcpu = aarch64_vcpu_add(vpmu_vm.vm, 0, &init, guest_code);
437437
vcpu_init_descriptor_tables(vpmu_vm.vcpu);
438438
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");
441439

442440
/* Make sure that PMUv3 support is indicated in the ID register */
443441
dfr0 = vcpu_get_reg(vpmu_vm.vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64DFR0_EL1));
@@ -634,6 +632,7 @@ int main(void)
634632
uint64_t i, pmcr_n;
635633

636634
TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_PMU_V3));
635+
TEST_REQUIRE(kvm_supports_vgic_v3());
637636

638637
pmcr_n = get_pmcr_n_limit();
639638
for (i = 0; i <= pmcr_n; i++) {

tools/testing/selftests/kvm/include/arm64/vgic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
((uint64_t)(flags) << 12) | \
1717
index)
1818

19+
bool kvm_supports_vgic_v3(void);
1920
int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs);
2021

2122
#define VGIC_MAX_RESERVED 1023

tools/testing/selftests/kvm/lib/arm64/vgic.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
#include "gic.h"
1616
#include "gic_v3.h"
1717

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+
1829
/*
1930
* vGIC-v3 default host setup
2031
*

0 commit comments

Comments
 (0)