Skip to contentSkip to conversation

kselftest: kvm/arm64: Skip tests if we can't create a vgic-v3

PATCH Superseded Mark Brown 4 participants 8 messages Jan 25, 2022 – Jan 26, 2022

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 kselftest: kvm/arm64: Skip tests if we can't create a vgic-v3

The arch_timer and vgic_irq kselftests assume that they can create a vgic-v3, using the library function vgic_v3_setup() which aborts with a test failure if it is not possible to do so. Since vgic-v3 can only be instantiated on systems where the host has GICv3 this leads to false positives on older systems where that is not the case.

Fix this by changing vgic_v3_setup() to return an error if the vgic can't be instantiated and have the callers skip if this happens. We could also exit flagging a skip in vgic_v3_setup() but this would prevent future test cases conditionally deciding which GIC to use or generally doing more complex output.

---
 tools/testing/selftests/kvm/aarch64/arch_timer.c | 7 ++++++-
 tools/testing/selftests/kvm/aarch64/vgic_irq.c   | 5 +++++
 tools/testing/selftests/kvm/lib/aarch64/vgic.c   | 4 +++-
 3 files changed, 14 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/aarch64/arch_timer.c +6 -1
index 9ad38bd360a4..791d38404652 100644
@@ -366,6 +366,7 @@ static struct kvm_vm *test_vm_create(void)
 {
 	struct kvm_vm *vm;
 	unsigned int i;
+	int ret;
 	int nr_vcpus = test_args.nr_vcpus;
 
 	vm = vm_create_default_with_vcpus(nr_vcpus, 0, 0, guest_code, NULL);
@@ -382,7 +383,11 @@ static struct kvm_vm *test_vm_create(void)
 
 	ucall_init(vm, NULL);
 	test_init_timer_irq(vm);
-	vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
+	ret = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
+	if (ret < 0) {
+		pr_info("Failed to create vgic-v3, skipping\n");
+		exit(KSFT_SKIP);
+	}
 
 	/* Make all the test's cmdline args visible to the guest */
 	sync_global_to_guest(vm, test_args);
tools/testing/selftests/kvm/aarch64/vgic_irq.c +5 -0
index e6c7d7f8fbd1..8c6b61b8e6aa 100644
@@ -761,6 +761,11 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split)
 
 	gic_fd = vgic_v3_setup(vm, 1, nr_irqs,
 			GICD_BASE_GPA, GICR_BASE_GPA);
+	if (gic_fd < 0) {
+		pr_info("Failed to create vgic-v3, skipping\n");
+		exit(KSFT_SKIP);
+	}
+
 
 	vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT,
 		guest_irq_handlers[args.eoi_split][args.level_sensitive]);
tools/testing/selftests/kvm/lib/aarch64/vgic.c +3 -1
index b3a0fca0d780..647c18733e1b 100644
@@ -52,7 +52,9 @@ int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs,
 			nr_vcpus, nr_vcpus_created);
 
 	/* Distributor setup */
-	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, false);
+	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, true);
+	if (gic_fd == -1)
+		return -1;
 
 	kvm_device_access(gic_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS,
 			0, &nr_irqs, true);
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 65 lines · Mark Brown

The arch_timer and vgic_irq kselftests assume that they can create a vgic-v3, using the library function vgic_v3_setup() which aborts with a test failure if it is not possible to do so. Since vgic-v3 can only be instantiated on systems where the host has GICv3 this leads to false positives on older systems where that is not the case.

Fix this by changing vgic_v3_setup() to return an error if the vgic can't be instantiated and have the callers skip if this happens. We could also exit flagging a skip in vgic_v3_setup() but this would prevent future test cases conditionally deciding which GIC to use or generally doing more complex output.

---
  tools/testing/selftests/kvm/aarch64/arch_timer.c | 7 ++++++-
  tools/testing/selftests/kvm/aarch64/vgic_irq.c   | 5 +++++
  tools/testing/selftests/kvm/lib/aarch64/vgic.c   | 4 +++-
  3 files changed, 14 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/aarch64/arch_timer.c +6 -1
index 9ad38bd360a4..791d38404652 100644
@@ -366,6 +366,7 @@ static struct kvm_vm *test_vm_create(void)
  {
  	struct kvm_vm *vm;
  	unsigned int i;
+	int ret;
  	int nr_vcpus = test_args.nr_vcpus;
 
  	vm = vm_create_default_with_vcpus(nr_vcpus, 0, 0, guest_code, NULL);
@@ -382,7 +383,11 @@ static struct kvm_vm *test_vm_create(void)
 
  	ucall_init(vm, NULL);
  	test_init_timer_irq(vm);
-	vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
+	ret = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
+	if (ret < 0) {
+		pr_info("Failed to create vgic-v3, skipping\n");
+		exit(KSFT_SKIP);
+	}
 
  	/* Make all the test's cmdline args visible to the guest */
  	sync_global_to_guest(vm, test_args);
tools/testing/selftests/kvm/aarch64/vgic_irq.c +5 -0
index e6c7d7f8fbd1..8c6b61b8e6aa 100644
@@ -761,6 +761,11 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split)
 
  	gic_fd = vgic_v3_setup(vm, 1, nr_irqs,
  			GICD_BASE_GPA, GICR_BASE_GPA);
+	if (gic_fd < 0) {
+		pr_info("Failed to create vgic-v3, skipping\n");
+		exit(KSFT_SKIP);
+	}
+
 
  	vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT,
  		guest_irq_handlers[args.eoi_split][args.level_sensitive]);
tools/testing/selftests/kvm/lib/aarch64/vgic.c +0 -0
index b3a0fca0d780..647c18733e1b 100644

tools/testing/selftests/kvm/lib/aarch64/vgic.c int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs, · line 55

Quoted 5 lines
tools/testing/selftests/kvm/lib/aarch64/vgic.c +1 -1
@@ -52,7 +52,9 @@ int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs,
  			nr_vcpus, nr_vcpus_created);
 
  	/* Distributor setup */
-	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, false);
+	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, true);

Assume the flag change is intentional. The reason isn't obvious in the change log

tools/testing/selftests/kvm/lib/aarch64/vgic.c int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs, · line 60

Quoted 6 lines
tools/testing/selftests/kvm/lib/aarch64/vgic.c +2 -0
+	if (gic_fd == -1)
+		return -1;
 
  	kvm_device_access(gic_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS,
  			0, &nr_irqs, true);

Looks good to me otherwise - thanks for adding the skips

thanks,
-- Shuah

Reviewed-by on v1 1/1
#2 lore raw
In reply to Mark Brown
Quoted 82 lines · Mark Brown

The arch_timer and vgic_irq kselftests assume that they can create a vgic-v3, using the library function vgic_v3_setup() which aborts with a test failure if it is not possible to do so. Since vgic-v3 can only be instantiated on systems where the host has GICv3 this leads to false positives on older systems where that is not the case.

Fix this by changing vgic_v3_setup() to return an error if the vgic can't be instantiated and have the callers skip if this happens. We could also exit flagging a skip in vgic_v3_setup() but this would prevent future test cases conditionally deciding which GIC to use or generally doing more complex output.

---
 tools/testing/selftests/kvm/aarch64/arch_timer.c | 7 ++++++-
 tools/testing/selftests/kvm/aarch64/vgic_irq.c   | 5 +++++
 tools/testing/selftests/kvm/lib/aarch64/vgic.c   | 4 +++-
 3 files changed, 14 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/aarch64/arch_timer.c +6 -1
index 9ad38bd360a4..791d38404652 100644
@@ -366,6 +366,7 @@ static struct kvm_vm *test_vm_create(void)
 {
 	struct kvm_vm *vm;
 	unsigned int i;
+	int ret;
 	int nr_vcpus = test_args.nr_vcpus;
 
 	vm = vm_create_default_with_vcpus(nr_vcpus, 0, 0, guest_code, NULL);
@@ -382,7 +383,11 @@ static struct kvm_vm *test_vm_create(void)
 
 	ucall_init(vm, NULL);
 	test_init_timer_irq(vm);
-	vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
+	ret = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
+	if (ret < 0) {
+		pr_info("Failed to create vgic-v3, skipping\n");
+		exit(KSFT_SKIP);
+	}
 
 	/* Make all the test's cmdline args visible to the guest */
 	sync_global_to_guest(vm, test_args);
tools/testing/selftests/kvm/aarch64/vgic_irq.c +5 -0
index e6c7d7f8fbd1..8c6b61b8e6aa 100644
@@ -761,6 +761,11 @@ static void test_vgic(uint32_t nr_irqs, bool level_sensitive, bool eoi_split)
 
 	gic_fd = vgic_v3_setup(vm, 1, nr_irqs,
 			GICD_BASE_GPA, GICR_BASE_GPA);
+	if (gic_fd < 0) {
+		pr_info("Failed to create vgic-v3, skipping\n");
+		exit(KSFT_SKIP);
+	}
+
 
 	vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT,
 		guest_irq_handlers[args.eoi_split][args.level_sensitive]);
tools/testing/selftests/kvm/lib/aarch64/vgic.c +3 -1
index b3a0fca0d780..647c18733e1b 100644
@@ -52,7 +52,9 @@ int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs,
 			nr_vcpus, nr_vcpus_created);
 
 	/* Distributor setup */
-	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, false);
+	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, true);
+	if (gic_fd == -1)
+		return -1;
 
 	kvm_device_access(gic_fd, KVM_DEV_ARM_VGIC_GRP_NR_IRQS,
 			0, &nr_irqs, true);
Signature · 6 lines
2.30.2

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
maintainer
#3 lore raw
In reply to Mark Brown
Quoted 20 lines · Mark Brown

The arch_timer and vgic_irq kselftests assume that they can create a vgic-v3, using the library function vgic_v3_setup() which aborts with a test failure if it is not possible to do so. Since vgic-v3 can only be instantiated on systems where the host has GICv3 this leads to false positives on older systems where that is not the case.

Fix this by changing vgic_v3_setup() to return an error if the vgic can't be instantiated and have the callers skip if this happens. We could also exit flagging a skip in vgic_v3_setup() but this would prevent future test cases conditionally deciding which GIC to use or generally doing more complex output.

---
 tools/testing/selftests/kvm/aarch64/arch_timer.c | 7 ++++++-
 tools/testing/selftests/kvm/aarch64/vgic_irq.c   | 5 +++++
 tools/testing/selftests/kvm/lib/aarch64/vgic.c   | 4 +++-
 3 files changed, 14 insertions(+), 2 deletions(-)

[...]

tools/testing/selftests/kvm/lib/aarch64/vgic.c int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs, · line 55

Quoted 10 lines
tools/testing/selftests/kvm/lib/aarch64/vgic.c +1 -1
index b3a0fca0d780..647c18733e1b 100644
@@ -52,7 +52,9 @@ int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs,
 			nr_vcpus, nr_vcpus_created);
 
 	/* Distributor setup */
-	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, false);
+	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, true);

So you now only test whether it is possible to create a virtual GICv3, but don't actually create it. How does this work?

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author
#4 lore raw
Quoted 8 lines · Marc Zyngier

tools/testing/selftests/kvm/lib/aarch64/vgic.c int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs, · line 55

Quoted 3 lines · Mark Brown
tools/testing/selftests/kvm/lib/aarch64/vgic.c +1 -1
 	/* Distributor setup */
-	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, false);
+	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, true);

So you now only test whether it is possible to create a virtual GICv3, but don't actually create it. How does this work?

Oh, that's rather obscure in the API - so the file descriptor returned if the test flag is specified can't actually be used?

maintainer
#5 lore raw
Quoted 11 lines · Mark Brown
Quoted 8 lines · Marc Zyngier

tools/testing/selftests/kvm/lib/aarch64/vgic.c int vgic_v3_setup(struct kvm_vm *vm, unsigned int nr_vcpus, uint32_t nr_irqs, · line 55

Quoted 3 lines · Mark Brown
tools/testing/selftests/kvm/lib/aarch64/vgic.c +1 -1
 	/* Distributor setup */
-	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, false);
+	gic_fd = kvm_create_device(vm, KVM_DEV_TYPE_ARM_VGIC_V3, true);

So you now only test whether it is possible to create a virtual GICv3, but don't actually create it. How does this work?

Quoted 2 lines

Oh, that's rather obscure in the API - so the file descriptor returned if the test flag is specified can't actually be used?

No file descriptor is returned at all from the kernel, so you should always get -1 as populated by kvm_create_device().

See virt/kvm/kvm_main.c::kvm_ioctl_create_device().

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author
#6 lore raw
Quoted 5 lines · Marc Zyngier
Quoted 2 lines · Mark Brown
Quoted 2 lines

So you now only test whether it is possible to create a virtual GICv3, but don't actually create it. How does this work?

Quoted 7 lines
Quoted 2 lines

Oh, that's rather obscure in the API - so the file descriptor returned if the test flag is specified can't actually be used?

No file descriptor is returned at all from the kernel, so you should always get -1 as populated by kvm_create_device().

See virt/kvm/kvm_main.c::kvm_ioctl_create_device().

Ugh, right - the descriptor is returned separately to the return code but is then mapped onto the return code by the library since the library just aborts on error in the non-test case and in the test case the kernel returns an inverted boolean which gets passed straight through. Like I say the API seems a bit confusing here.

maintainer
#7 lore raw

aOn Wed, 26 Jan 2022 13:21:17 +0000,

Quoted 14 lines · Mark Brown

[1 <text/plain; us-ascii (7bit)>]

Quoted 10 lines · Marc Zyngier
Quoted 5 lines · Mark Brown
Quoted 2 lines

So you now only test whether it is possible to create a virtual GICv3, but don't actually create it. How does this work?

Oh, that's rather obscure in the API - so the file descriptor returned if the test flag is specified can't actually be used?

No file descriptor is returned at all from the kernel, so you should always get -1 as populated by kvm_create_device().

Quoted 7 lines
Quoted 1 line

See virt/kvm/kvm_main.c::kvm_ioctl_create_device().

Ugh, right - the descriptor is returned separately to the return code but is then mapped onto the return code by the library since the library just aborts on error in the non-test case and in the test case the kernel returns an inverted boolean which gets passed straight through. Like I say the API seems a bit confusing here.

That's a very... "kind" way of putting it.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.