Skip to content

Commit 386ba26

Browse files
ouptonMarc Zyngier
authored andcommitted
selftests: KVM: Don't leak GIC FD across dirty log test iterations
dirty_log_perf_test instantiates a VGICv3 for the guest (if supported by hardware) to reduce the overhead of guest exits. However, the test does not actually close the GIC fd when cleaning up the VM between test iterations, meaning that the VM is never actually destroyed in the kernel. While this is generally a bad idea, the bug was detected from the kernel spewing about duplicate debugfs entries as subsequent VMs happen to reuse the same FD even though the debugfs directory is still present. Abstract away the notion of setup/cleanup of the GIC FD from the test by creating arch-specific helpers for test setup/cleanup. Close the GIC FD on VM cleanup and do nothing for the other architectures. Fixes: c340f78 ("KVM: selftests: Add vgic initialization for dirty log perf test for ARM") Reviewed-by: Jing Zhang <[email protected]> Signed-off-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a44a4cc commit 386ba26

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

tools/testing/selftests/kvm/dirty_log_perf_test.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,40 @@
1818
#include "test_util.h"
1919
#include "perf_test_util.h"
2020
#include "guest_modes.h"
21+
2122
#ifdef __aarch64__
2223
#include "aarch64/vgic.h"
2324

2425
#define GICD_BASE_GPA 0x8000000ULL
2526
#define GICR_BASE_GPA 0x80A0000ULL
27+
28+
static int gic_fd;
29+
30+
static void arch_setup_vm(struct kvm_vm *vm, unsigned int nr_vcpus)
31+
{
32+
/*
33+
* The test can still run even if hardware does not support GICv3, as it
34+
* is only an optimization to reduce guest exits.
35+
*/
36+
gic_fd = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
37+
}
38+
39+
static void arch_cleanup_vm(struct kvm_vm *vm)
40+
{
41+
if (gic_fd > 0)
42+
close(gic_fd);
43+
}
44+
45+
#else /* __aarch64__ */
46+
47+
static void arch_setup_vm(struct kvm_vm *vm, unsigned int nr_vcpus)
48+
{
49+
}
50+
51+
static void arch_cleanup_vm(struct kvm_vm *vm)
52+
{
53+
}
54+
2655
#endif
2756

2857
/* How many host loops to run by default (one KVM_GET_DIRTY_LOG for each loop)*/
@@ -206,9 +235,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
206235
vm_enable_cap(vm, &cap);
207236
}
208237

209-
#ifdef __aarch64__
210-
vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
211-
#endif
238+
arch_setup_vm(vm, nr_vcpus);
212239

213240
/* Start the iterations */
214241
iteration = 0;
@@ -302,6 +329,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
302329
}
303330

304331
free_bitmaps(bitmaps, p->slots);
332+
arch_cleanup_vm(vm);
305333
perf_test_destroy_vm(vm);
306334
}
307335

0 commit comments

Comments
 (0)