提交 386ba265 编写于 作者: O Oliver Upton 提交者: Marc Zyngier

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: c340f789 ("KVM: selftests: Add vgic initialization for dirty log perf test for ARM")
Reviewed-by: NJing Zhang <jingzhangos@google.com>
Signed-off-by: NOliver Upton <oupton@google.com>
Signed-off-by: NMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220406235615.1447180-3-oupton@google.com
上级 a44a4cc1
...@@ -18,11 +18,40 @@ ...@@ -18,11 +18,40 @@
#include "test_util.h" #include "test_util.h"
#include "perf_test_util.h" #include "perf_test_util.h"
#include "guest_modes.h" #include "guest_modes.h"
#ifdef __aarch64__ #ifdef __aarch64__
#include "aarch64/vgic.h" #include "aarch64/vgic.h"
#define GICD_BASE_GPA 0x8000000ULL #define GICD_BASE_GPA 0x8000000ULL
#define GICR_BASE_GPA 0x80A0000ULL #define GICR_BASE_GPA 0x80A0000ULL
static int gic_fd;
static void arch_setup_vm(struct kvm_vm *vm, unsigned int nr_vcpus)
{
/*
* The test can still run even if hardware does not support GICv3, as it
* is only an optimization to reduce guest exits.
*/
gic_fd = vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
}
static void arch_cleanup_vm(struct kvm_vm *vm)
{
if (gic_fd > 0)
close(gic_fd);
}
#else /* __aarch64__ */
static void arch_setup_vm(struct kvm_vm *vm, unsigned int nr_vcpus)
{
}
static void arch_cleanup_vm(struct kvm_vm *vm)
{
}
#endif #endif
/* How many host loops to run by default (one KVM_GET_DIRTY_LOG for each loop)*/ /* 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) ...@@ -206,9 +235,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
vm_enable_cap(vm, &cap); vm_enable_cap(vm, &cap);
} }
#ifdef __aarch64__ arch_setup_vm(vm, nr_vcpus);
vgic_v3_setup(vm, nr_vcpus, 64, GICD_BASE_GPA, GICR_BASE_GPA);
#endif
/* Start the iterations */ /* Start the iterations */
iteration = 0; iteration = 0;
...@@ -302,6 +329,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) ...@@ -302,6 +329,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
} }
free_bitmaps(bitmaps, p->slots); free_bitmaps(bitmaps, p->slots);
arch_cleanup_vm(vm);
perf_test_destroy_vm(vm); perf_test_destroy_vm(vm);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册