KVM: arm64: selftests: Close the GIC FD in arch_timer_edge_cases
authorZenghui Yu <yuzenghui@huawei.com>
Sun, 8 Jun 2025 09:54:02 +0000 (17:54 +0800)
committerMarc Zyngier <maz@kernel.org>
Thu, 19 Jun 2025 08:58:21 +0000 (09:58 +0100)
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 <yuzenghui@huawei.com>
Reviewed-by: Miguel Luis <miguel.luis@oracle.com>
Reviewed-by: Sebastian Ott <sebott@redhat.com>
Link: https://lore.kernel.org/r/20250608095402.1131-1-yuzenghui@huawei.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c

index b4d22b3ab7cc081a5501323eddf2114a1ec79f0b..4e71740a098be4cd9d487e0426b5c763443ae115 100644 (file)
@@ -954,6 +954,8 @@ static void test_init_timer_irq(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
        pr_debug("ptimer_irq: %d; vtimer_irq: %d\n", ptimer_irq, vtimer_irq);
 }
 
+static int gic_fd;
+
 static void test_vm_create(struct kvm_vm **vm, struct kvm_vcpu **vcpu,
                           enum arch_timer timer)
 {
@@ -968,12 +970,20 @@ static void test_vm_create(struct kvm_vm **vm, struct kvm_vcpu **vcpu,
        vcpu_args_set(*vcpu, 1, timer);
 
        test_init_timer_irq(*vm, *vcpu);
-       vgic_v3_setup(*vm, 1, 64);
+       gic_fd = vgic_v3_setup(*vm, 1, 64);
+       __TEST_REQUIRE(gic_fd >= 0, "Failed to create vgic-v3");
+
        sync_global_to_guest(*vm, test_args);
        sync_global_to_guest(*vm, CVAL_MAX);
        sync_global_to_guest(*vm, DEF_CNT);
 }
 
+static void test_vm_cleanup(struct kvm_vm *vm)
+{
+       close(gic_fd);
+       kvm_vm_free(vm);
+}
+
 static void test_print_help(char *name)
 {
        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[])
        if (test_args.test_virtual) {
                test_vm_create(&vm, &vcpu, VIRTUAL);
                test_run(vm, vcpu);
-               kvm_vm_free(vm);
+               test_vm_cleanup(vm);
        }
 
        if (test_args.test_physical) {
                test_vm_create(&vm, &vcpu, PHYSICAL);
                test_run(vm, vcpu);
-               kvm_vm_free(vm);
+               test_vm_cleanup(vm);
        }
 
        return 0;