From: Raffaele Tranfaglia Check that KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION uses the whole 12-bit index field: registering the first region with index 256 must fail with -EINVAL, and reading the characteristics of the non-existent region 256 must fail with -ENOENT. Before the fix, index 256 aliased index 0 in both cases. Signed-off-by: Raffaele Tranfaglia --- tools/testing/selftests/kvm/arm64/vgic_init.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/testing/selftests/kvm/arm64/vgic_init.c b/tools/testing/selftests/kvm/arm64/vgic_init.c index 5a30f3cb039b..5752ddedbaf8 100644 --- a/tools/testing/selftests/kvm/arm64/vgic_init.c +++ b/tools/testing/selftests/kvm/arm64/vgic_init.c @@ -274,6 +274,13 @@ static void subtest_v3_redist_regions(struct vm_gic *v) TEST_ASSERT(ret && errno == EINVAL, "attempt to register the first rdist region with index != 0"); + /* The index field is 12 bits wide: 256 must not alias index 0. */ + addr = REDIST_REGION_ATTR_ADDR(2, 0x200000, 0, 256); + ret = __kvm_device_attr_set(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR, + KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION, &addr); + TEST_ASSERT(ret && errno == EINVAL, + "attempt to register the first rdist region with index 256"); + addr = REDIST_REGION_ATTR_ADDR(2, 0x201000, 0, 1); ret = __kvm_device_attr_set(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR, KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION, &addr); @@ -346,6 +353,12 @@ static void subtest_v3_redist_regions(struct vm_gic *v) KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION, &addr); TEST_ASSERT(ret && errno == ENOENT, "read characteristics of non existing region"); + addr = REDIST_REGION_ATTR_ADDR(0, 0, 0, 256); + ret = __kvm_device_attr_get(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR, + KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION, &addr); + TEST_ASSERT(ret && errno == ENOENT, + "read characteristics of non existing region #256"); + addr = 0x260000; kvm_device_attr_set(v->gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR, KVM_VGIC_V3_ADDR_TYPE_DIST, &addr); -- 2.56.0