]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: selftests: Add test for nASSGIcap attribute
authorRaghavendra Rao Ananta <rananta@google.com>
Thu, 24 Jul 2025 06:28:04 +0000 (23:28 -0700)
committerOliver Upton <oliver.upton@linux.dev>
Sat, 26 Jul 2025 15:45:52 +0000 (08:45 -0700)
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@google.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20250724062805.2658919-6-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
tools/testing/selftests/kvm/arm64/vgic_init.c

index b3b5fb0ff0a9aea7671434a763786203c5d3f946..743351aa998ed2eebaf4dcc79f6828ce7bfd3386 100644 (file)
 #include "kvm_util.h"
 #include "processor.h"
 #include "vgic.h"
+#include "gic_v3.h"
 
 #define NR_VCPUS               4
 
 #define REG_OFFSET(vcpu, offset) (((uint64_t)vcpu << 32) | offset)
 
-#define GICR_TYPER 0x8
-
 #define VGIC_DEV_IS_V2(_d) ((_d) == KVM_DEV_TYPE_ARM_VGIC_V2)
 #define VGIC_DEV_IS_V3(_d) ((_d) == KVM_DEV_TYPE_ARM_VGIC_V3)
 
@@ -675,6 +674,44 @@ static void test_v3_its_region(void)
        vm_gic_destroy(&v);
 }
 
+static void test_v3_nassgicap(void)
+{
+       struct kvm_vcpu *vcpus[NR_VCPUS];
+       bool has_nassgicap;
+       struct vm_gic vm;
+       u32 typer2;
+       int ret;
+
+       vm = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
+       kvm_device_attr_get(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
+                           GICD_TYPER2, &typer2);
+       has_nassgicap = typer2 & GICD_TYPER2_nASSGIcap;
+
+       typer2 |= GICD_TYPER2_nASSGIcap;
+       ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
+                                   GICD_TYPER2, &typer2);
+       if (has_nassgicap)
+               TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_DEVICE_ATTR_SET, ret));
+       else
+               TEST_ASSERT(ret && errno == EINVAL,
+                           "Enabled nASSGIcap even though it's unavailable");
+
+       typer2 &= ~GICD_TYPER2_nASSGIcap;
+       kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
+                           GICD_TYPER2, &typer2);
+
+       kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+                           KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
+
+       typer2 ^= GICD_TYPER2_nASSGIcap;
+       ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
+                                   GICD_TYPER2, &typer2);
+       TEST_ASSERT(ret && errno == EBUSY,
+                   "Changed 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 +767,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();
        }
 }