[PATCH v3 4/4] KVM: arm64: selftests: Add test for nASSGIcap attribute
Raghavendra Rao Ananta
rananta at google.com
Fri Jun 13 08:52:38 PDT 2025
Extend vgic_init to test the nASSGIcap attribute, asserting that it is
configurable (within reason) prior to initializing the VGIC.
Additionally, check that userspace cannot set the attribute after the
VGIC has been initialized.
Signed-off-by: Raghavendra Rao Ananta <rananta at google.com>
Signed-off-by: Oliver Upton <oliver.upton at linux.dev>
---
tools/testing/selftests/kvm/arm64/vgic_init.c | 41 +++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/tools/testing/selftests/kvm/arm64/vgic_init.c b/tools/testing/selftests/kvm/arm64/vgic_init.c
index b3b5fb0ff0a9..aaecba432dbc 100644
--- a/tools/testing/selftests/kvm/arm64/vgic_init.c
+++ b/tools/testing/selftests/kvm/arm64/vgic_init.c
@@ -675,6 +675,46 @@ static void test_v3_its_region(void)
vm_gic_destroy(&v);
}
+static void test_v3_nassgicap(void)
+{
+ struct kvm_vcpu *vcpus[NR_VCPUS];
+ struct vm_gic vm;
+ __u8 nassgicap;
+ int ret;
+
+ vm = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
+ TEST_REQUIRE(!__kvm_has_device_attr(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_FEATURES,
+ KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap));
+
+ kvm_device_attr_get(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_FEATURES,
+ KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap, &nassgicap);
+ if (!nassgicap) {
+ nassgicap = true;
+ ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_FEATURES,
+ KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap, &nassgicap);
+ TEST_ASSERT(ret && errno == EINVAL,
+ "Enabled nASSGIcap even though it's unavailable");
+ } else {
+ nassgicap = false;
+ kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_FEATURES,
+ KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap, &nassgicap);
+
+ nassgicap = true;
+ kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_FEATURES,
+ KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap, &nassgicap);
+ }
+
+ kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
+
+ ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_FEATURES,
+ KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap, &nassgicap);
+ TEST_ASSERT(ret && errno == EBUSY,
+ "Configured nASSGIcap after initializing the VGIC");
+
+ vm_gic_destroy(&vm);
+}
+
/*
* Returns 0 if it's possible to create GIC device of a given type (V2 or V3).
*/
@@ -730,6 +770,7 @@ void run_tests(uint32_t gic_dev_type)
test_v3_last_bit_single_rdist();
test_v3_redist_ipa_range_check_at_vcpu_run();
test_v3_its_region();
+ test_v3_nassgicap();
}
}
--
2.50.0.rc2.692.g299adb8693-goog
More information about the linux-arm-kernel
mailing list