Skip to content

Commit

Permalink
selftests: KVM: Free the GIC FD when cleaning up in arch_timer
Browse files Browse the repository at this point in the history
[ Upstream commit 21db838 ]

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 <oupton@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220406235615.1447180-4-oupton@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
oupton authored and gregkh committed Apr 27, 2022
1 parent 4fb89f3 commit f828c2d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tools/testing/selftests/kvm/aarch64/arch_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,12 @@ static void test_init_timer_irq(struct kvm_vm *vm)
pr_debug("ptimer_irq: %d; vtimer_irq: %d\n", ptimer_irq, vtimer_irq);
}

static int gic_fd;

static struct kvm_vm *test_vm_create(void)
{
struct kvm_vm *vm;
unsigned int i;
int ret;
int nr_vcpus = test_args.nr_vcpus;

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

ucall_init(vm, NULL);
test_init_timer_irq(vm);
ret = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
if (ret < 0) {
gic_fd = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
if (gic_fd < 0) {
print_skip("Failed to create vgic-v3");
exit(KSFT_SKIP);
}
Expand All @@ -395,6 +396,12 @@ static struct kvm_vm *test_vm_create(void)
return vm;
}

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] [-n nr_vcpus] [-i iterations] [-p timer_period_ms]\n",
Expand Down Expand Up @@ -478,7 +485,7 @@ int main(int argc, char *argv[])

vm = test_vm_create();
test_run(vm);
kvm_vm_free(vm);
test_vm_cleanup(vm);

return 0;
}

0 comments on commit f828c2d

Please sign in to comment.