Skip to content

Commit 21db838

Browse files
ouptonMarc Zyngier
authored andcommitted
selftests: KVM: Free the GIC FD when cleaning up in arch_timer
In order to correctly destroy a VM, all references to the VM must be freed. The arch_timer selftest creates a VGIC for the guest, which itself holds a reference to the VM. Close the GIC FD when cleaning up a VM. Signed-off-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 386ba26 commit 21db838

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,12 @@ static void test_init_timer_irq(struct kvm_vm *vm)
362362
pr_debug("ptimer_irq: %d; vtimer_irq: %d\n", ptimer_irq, vtimer_irq);
363363
}
364364

365+
static int gic_fd;
366+
365367
static struct kvm_vm *test_vm_create(void)
366368
{
367369
struct kvm_vm *vm;
368370
unsigned int i;
369-
int ret;
370371
int nr_vcpus = test_args.nr_vcpus;
371372

372373
vm = vm_create_default_with_vcpus(nr_vcpus, 0, 0, guest_code, NULL);
@@ -383,8 +384,8 @@ static struct kvm_vm *test_vm_create(void)
383384

384385
ucall_init(vm, NULL);
385386
test_init_timer_irq(vm);
386-
ret = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
387-
if (ret < 0) {
387+
gic_fd = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
388+
if (gic_fd < 0) {
388389
print_skip("Failed to create vgic-v3");
389390
exit(KSFT_SKIP);
390391
}
@@ -395,6 +396,12 @@ static struct kvm_vm *test_vm_create(void)
395396
return vm;
396397
}
397398

399+
static void test_vm_cleanup(struct kvm_vm *vm)
400+
{
401+
close(gic_fd);
402+
kvm_vm_free(vm);
403+
}
404+
398405
static void test_print_help(char *name)
399406
{
400407
pr_info("Usage: %s [-h] [-n nr_vcpus] [-i iterations] [-p timer_period_ms]\n",
@@ -478,7 +485,7 @@ int main(int argc, char *argv[])
478485

479486
vm = test_vm_create();
480487
test_run(vm);
481-
kvm_vm_free(vm);
488+
test_vm_cleanup(vm);
482489

483490
return 0;
484491
}

0 commit comments

Comments
 (0)