Skip to content

Commit 1883458

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Add test for legacy GICv3 REDIST base partially above IPA range
Add a new test into vgic_init which checks that the first vcpu fails to run if there is not sufficient REDIST space below the addressable IPA range. This only applies to the KVM_VGIC_V3_ADDR_TYPE_REDIST legacy API as the required REDIST space is not know when setting the DIST region. Note that using the REDIST_REGION API results in a different check at first vcpu run: that the number of redist regions is enough for all vcpus. And there is already a test for that case in, the first step of test_v3_new_redist_regions. Reviewed-by: Eric Auger <[email protected]> Signed-off-by: Ricardo Koller <[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 2dcd9aa commit 1883458

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,39 @@ static void test_v3_last_bit_single_rdist(void)
565565
vm_gic_destroy(&v);
566566
}
567567

568+
/* Uses the legacy REDIST region API. */
569+
static void test_v3_redist_ipa_range_check_at_vcpu_run(void)
570+
{
571+
struct vm_gic v;
572+
int ret, i;
573+
uint64_t addr;
574+
575+
v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, 1);
576+
577+
/* Set space for 3 redists, we have 1 vcpu, so this succeeds. */
578+
addr = max_phys_size - (3 * 2 * 0x10000);
579+
kvm_device_access(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
580+
KVM_VGIC_V3_ADDR_TYPE_REDIST, &addr, true);
581+
582+
addr = 0x00000;
583+
kvm_device_access(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_ADDR,
584+
KVM_VGIC_V3_ADDR_TYPE_DIST, &addr, true);
585+
586+
/* Add the rest of the VCPUs */
587+
for (i = 1; i < NR_VCPUS; ++i)
588+
vm_vcpu_add_default(v.vm, i, guest_code);
589+
590+
kvm_device_access(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
591+
KVM_DEV_ARM_VGIC_CTRL_INIT, NULL, true);
592+
593+
/* Attempt to run a vcpu without enough redist space. */
594+
ret = run_vcpu(v.vm, 2);
595+
TEST_ASSERT(ret && errno == EINVAL,
596+
"redist base+size above PA range detected on 1st vcpu run");
597+
598+
vm_gic_destroy(&v);
599+
}
600+
568601
/*
569602
* Returns 0 if it's possible to create GIC device of a given type (V2 or V3).
570603
*/
@@ -616,6 +649,7 @@ void run_tests(uint32_t gic_dev_type)
616649
test_v3_typer_accesses();
617650
test_v3_last_bit_redist_regions();
618651
test_v3_last_bit_single_rdist();
652+
test_v3_redist_ipa_range_check_at_vcpu_run();
619653
}
620654
}
621655

0 commit comments

Comments
 (0)