[PATCH v2 2/4] KVM: arm64: selftests: Add test for GICD.num_LPIs
Zhou Wang
wangzhou1 at hisilicon.com
Sun Aug 24 19:39:52 PDT 2025
Add test case about GICD.num_LPIs. The default value should be 0, and it
can be modified before GIC init, but cannot be modified after GIC init.
Signed-off-by: Zhou Wang <wangzhou1 at hisilicon.com>
---
tools/testing/selftests/kvm/arm64/vgic_init.c | 33 +++++++++++++++++++
.../selftests/kvm/include/arm64/gic_v3.h | 2 ++
2 files changed, 35 insertions(+)
diff --git a/tools/testing/selftests/kvm/arm64/vgic_init.c b/tools/testing/selftests/kvm/arm64/vgic_init.c
index a8e0f46bc0ab..7e60443827e9 100644
--- a/tools/testing/selftests/kvm/arm64/vgic_init.c
+++ b/tools/testing/selftests/kvm/arm64/vgic_init.c
@@ -968,6 +968,38 @@ static void test_v3_sysregs(void)
kvm_vm_free(vm);
}
+static void test_v3_num_lpis(void)
+{
+ struct kvm_vcpu *vcpus[NR_VCPUS];
+ u32 num_lpis;
+ struct vm_gic vm;
+ u32 typer;
+ int ret;
+
+ vm = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
+ kvm_create_device(vm.vm, KVM_DEV_TYPE_ARM_VGIC_ITS);
+
+ kvm_device_attr_get(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
+ GICD_TYPER, &typer);
+ num_lpis = typer & GICD_TYPER_NUM_LPIS_MASK;
+ TEST_ASSERT(!num_lpis, "Default value of GICD.num_LPIs is not 0");
+
+ typer |= 10 << GICD_TYPER_NUM_LPIS_SHIFT;
+ ret = __kvm_device_attr_set(vm.gic_fd, KVM_DEV_ARM_VGIC_GRP_DIST_REGS,
+ GICD_TYPER, &typer);
+ TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_DEVICE_ATTR_SET, ret));
+
+ 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_DIST_REGS,
+ GICD_TYPER, &typer);
+ TEST_ASSERT(ret && errno == EBUSY,
+ "Changed GICD.num_LPIs after initializing the VGIC");
+
+ vm_gic_destroy(&vm);
+}
+
void run_tests(uint32_t gic_dev_type)
{
test_vcpus_then_vgic(gic_dev_type);
@@ -985,6 +1017,7 @@ void run_tests(uint32_t gic_dev_type)
test_v3_its_region();
test_v3_sysregs();
test_v3_nassgicap();
+ test_v3_num_lpis();
}
}
diff --git a/tools/testing/selftests/kvm/include/arm64/gic_v3.h b/tools/testing/selftests/kvm/include/arm64/gic_v3.h
index a76615fa39a1..c9f25cdd3651 100644
--- a/tools/testing/selftests/kvm/include/arm64/gic_v3.h
+++ b/tools/testing/selftests/kvm/include/arm64/gic_v3.h
@@ -85,6 +85,8 @@
#define GICD_TYPER_ESPI (1U << 8)
#define GICD_TYPER_ID_BITS(typer) ((((typer) >> 19) & 0x1f) + 1)
+#define GICD_TYPER_NUM_LPIS_MASK GENMASK(15, 11)
+#define GICD_TYPER_NUM_LPIS_SHIFT 11
#define GICD_TYPER_NUM_LPIS(typer) ((((typer) >> 11) & 0x1f) + 1)
#define GICD_TYPER_SPIS(typer) ((((typer) & 0x1f) + 1) * 32)
#define GICD_TYPER_ESPIS(typer) \
--
2.33.0
More information about the linux-arm-kernel
mailing list