aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Koller <[email protected]>2022-10-17 19:58:23 +0000
committerMarc Zyngier <[email protected]>2022-11-10 19:10:27 +0000
commitb6b03b86c0250a80b671313dbc0d7bcdbab78f41 (patch)
tree8b900c4b40e2ed21b0684849f789ddb3c6fcaa2d
parent228f324dc718f702e8777164c4e2e7426824fb13 (diff)
KVM: selftests: Add missing close and munmap in __vm_mem_region_delete()
Deleting a memslot (when freeing a VM) is not closing the backing fd, nor it's unmapping the alias mapping. Fix by adding the missing close and munmap. Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Reviewed-by: Ben Gardon <[email protected]> Signed-off-by: Ricardo Koller <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
-rw-r--r--tools/testing/selftests/kvm/lib/kvm_util.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index f1cb1627161f..19e37fb7de7c 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -586,6 +586,12 @@ static void __vm_mem_region_delete(struct kvm_vm *vm,
sparsebit_free(&region->unused_phy_pages);
ret = munmap(region->mmap_start, region->mmap_size);
TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("munmap()", ret));
+ if (region->fd >= 0) {
+ /* There's an extra map when using shared memory. */
+ ret = munmap(region->mmap_alias, region->mmap_size);
+ TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("munmap()", ret));
+ close(region->fd);
+ }
free(region);
}