Skip to content

Commit 3e197f1

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Add init ITS device test
Add some ITS device init tests: general KVM device tests (address not defined already, address aligned) and tests for the ITS region being within the addressable IPA range. Signed-off-by: Ricardo Koller <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1883458 commit 3e197f1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tools/testing/selftests/kvm/aarch64/vgic_init.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,47 @@ static void test_v3_redist_ipa_range_check_at_vcpu_run(void)
598598
vm_gic_destroy(&v);
599599
}
600600

601+
static void test_v3_its_region(void)
602+
{
603+
struct vm_gic v;
604+
uint64_t addr;
605+
int its_fd, ret;
606+
607+
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS);
608+
its_fd = kvm_create_device(v.vm, KVM_DEV_TYPE_ARM_VGIC_ITS, false);
609+
610+
addr = 0x401000;
611+
ret = _kvm_device_access(its_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
612+
KVM_VGIC_ITS_ADDR_TYPE, &addr, true);
613+
TEST_ASSERT(ret && errno == EINVAL,
614+
"ITS region with misaligned address");
615+
616+
addr = max_phys_size;
617+
ret = _kvm_device_access(its_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
618+
KVM_VGIC_ITS_ADDR_TYPE, &addr, true);
619+
TEST_ASSERT(ret && errno == E2BIG,
620+
"register ITS region with base address beyond IPA range");
621+
622+
addr = max_phys_size - 0x10000;
623+
ret = _kvm_device_access(its_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
624+
KVM_VGIC_ITS_ADDR_TYPE, &addr, true);
625+
TEST_ASSERT(ret && errno == E2BIG,
626+
"Half of ITS region is beyond IPA range");
627+
628+
/* This one succeeds setting the ITS base */
629+
addr = 0x400000;
630+
kvm_device_access(its_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
631+
KVM_VGIC_ITS_ADDR_TYPE, &addr, true);
632+
633+
addr = 0x300000;
634+
ret = _kvm_device_access(its_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
635+
KVM_VGIC_ITS_ADDR_TYPE, &addr, true);
636+
TEST_ASSERT(ret && errno == EEXIST, "ITS base set again");
637+
638+
close(its_fd);
639+
vm_gic_destroy(&v);
640+
}
641+
601642
/*
602643
* Returns 0 if it's possible to create GIC device of a given type (V2 or V3).
603644
*/
@@ -650,6 +691,7 @@ void run_tests(uint32_t gic_dev_type)
650691
test_v3_last_bit_redist_regions();
651692
test_v3_last_bit_single_rdist();
652693
test_v3_redist_ipa_range_check_at_vcpu_run();
694+
test_v3_its_region();
653695
}
654696
}
655697

0 commit comments

Comments
 (0)