Skip to content

Commit 56a1498

Browse files
Zenghui YuMarc Zyngier
authored andcommitted
KVM: arm64: selftests: Close the GIC FD in arch_timer_edge_cases
Close the GIC FD to free the reference it holds to the VM so that we can correctly clean up the VM. This also gets rid of the "KVM: debugfs: duplicate directory 395722-4" warning when running arch_timer_edge_cases. Signed-off-by: Zenghui Yu <[email protected]> Reviewed-by: Miguel Luis <[email protected]> Reviewed-by: Sebastian Ott <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 1fbe686 commit 56a1498

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ static void test_init_timer_irq(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
954954
pr_debug("ptimer_irq: %d; vtimer_irq: %d\n", ptimer_irq, vtimer_irq);
955955
}
956956

957+
static int gic_fd;
958+
957959
static void test_vm_create(struct kvm_vm **vm, struct kvm_vcpu **vcpu,
958960
enum arch_timer timer)
959961
{
@@ -968,12 +970,20 @@ static void test_vm_create(struct kvm_vm **vm, struct kvm_vcpu **vcpu,
968970
vcpu_args_set(*vcpu, 1, timer);
969971

970972
test_init_timer_irq(*vm, *vcpu);
971-
vgic_v3_setup(*vm, 1, 64);
973+
gic_fd = vgic_v3_setup(*vm, 1, 64);
974+
__TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3");
975+
972976
sync_global_to_guest(*vm, test_args);
973977
sync_global_to_guest(*vm, CVAL_MAX);
974978
sync_global_to_guest(*vm, DEF_CNT);
975979
}
976980

981+
static void test_vm_cleanup(struct kvm_vm *vm)
982+
{
983+
close(gic_fd);
984+
kvm_vm_free(vm);
985+
}
986+
977987
static void test_print_help(char *name)
978988
{
979989
pr_info("Usage: %s [-h] [-b] [-i iterations] [-l long_wait_ms] [-p] [-v]\n"
@@ -1060,13 +1070,13 @@ int main(int argc, char *argv[])
10601070
if (test_args.test_virtual) {
10611071
test_vm_create(&vm, &vcpu, VIRTUAL);
10621072
test_run(vm, vcpu);
1063-
kvm_vm_free(vm);
1073+
test_vm_cleanup(vm);
10641074
}
10651075

10661076
if (test_args.test_physical) {
10671077
test_vm_create(&vm, &vcpu, PHYSICAL);
10681078
test_run(vm, vcpu);
1069-
kvm_vm_free(vm);
1079+
test_vm_cleanup(vm);
10701080
}
10711081

10721082
return 0;

0 commit comments

Comments
 (0)