KVM: selftests: Explicitly close guest_memfd files in some gmem tests
authorDongli Zhang <dongli.zhang@oracle.com>
Tue, 27 Feb 2024 01:57:16 +0000 (17:57 -0800)
committerSean Christopherson <seanjc@google.com>
Tue, 5 Mar 2024 21:31:20 +0000 (13:31 -0800)
Explicitly close() guest_memfd files in various guest_memfd and
private_mem_conversions tests, there's no reason to keep the files open
until the test exits.

Fixes: 8a89efd43423 ("KVM: selftests: Add basic selftest for guest_memfd()")
Fixes: 43f623f350ce ("KVM: selftests: Add x86-only selftest for private memory conversions")
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
Link: https://lore.kernel.org/r/20240227015716.27284-1-dongli.zhang@oracle.com
[sean: massage changelog]
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/guest_memfd_test.c
tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c

index c78a98c1a915ce9a95261206ee6b10cb258b2955..92eae206baa62ec410460fd18938b2777da58775 100644 (file)
@@ -167,6 +167,9 @@ static void test_create_guest_memfd_multiple(struct kvm_vm *vm)
        TEST_ASSERT(ret != -1, "memfd fstat should succeed");
        TEST_ASSERT(st1.st_size == 4096, "first memfd st_size should still match requested size");
        TEST_ASSERT(st1.st_ino != st2.st_ino, "different memfd should have different inode numbers");
+
+       close(fd2);
+       close(fd1);
 }
 
 int main(int argc, char *argv[])
index 65ad38b6be1f1ad45afa085f5dbfb6402d581bb4..e0f642d2a3c4b562d186d4551583b6f5699d661b 100644 (file)
@@ -434,6 +434,8 @@ static void test_mem_conversions(enum vm_mem_backing_src_type src_type, uint32_t
 
        r = fallocate(memfd, FALLOC_FL_KEEP_SIZE, 0, memfd_size);
        TEST_ASSERT(!r, __KVM_SYSCALL_ERROR("fallocate()", r));
+
+       close(memfd);
 }
 
 static void usage(const char *cmd)