linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd
@ 2022-02-17  3:49 Reiji Watanabe
  2022-02-17  3:49 ` [PATCH 2/2] KVM: arm64: selftests: Introduce get_set_regs_perf test Reiji Watanabe
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Reiji Watanabe @ 2022-02-17  3:49 UTC (permalink / raw)
  To: Marc Zyngier, kvmarm, kvm
  Cc: linux-arm-kernel, James Morse, Alexandru Elisei, Suzuki K Poulose,
	Andrew Jones, Paolo Bonzini, Will Deacon, Peter Shier,
	Ricardo Koller, Oliver Upton, Jing Zhang, Raghavendra Rao Anata,
	Reiji Watanabe

kvm_vm_elf_load() and elfhdr_get() open one file each, but they
never close the opened file descriptor.  If a test repeatedly
creates and destroys a VM with vm_create_with_vcpus(), which
(directly or indirectly) calls those two functions, the test
might end up getting a open failure with EMFILE.
Fix those two functions to close the file descriptor.

Signed-off-by: Reiji Watanabe <reijiw@google.com>
---
 tools/testing/selftests/kvm/lib/elf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/kvm/lib/elf.c b/tools/testing/selftests/kvm/lib/elf.c
index 13e8e3dcf984..9b23537a3caa 100644
--- a/tools/testing/selftests/kvm/lib/elf.c
+++ b/tools/testing/selftests/kvm/lib/elf.c
@@ -91,6 +91,7 @@ static void elfhdr_get(const char *filename, Elf64_Ehdr *hdrp)
 		"  hdrp->e_shentsize: %x\n"
 		"  expected: %zx",
 		hdrp->e_shentsize, sizeof(Elf64_Shdr));
+	close(fd);
 }
 
 /* VM ELF Load
@@ -190,4 +191,5 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename)
 				phdr.p_filesz);
 		}
 	}
+	close(fd);
 }
-- 
2.35.1.473.g83b2b277ed-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-06-16 14:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-17  3:49 [PATCH 1/2] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd Reiji Watanabe
2022-02-17  3:49 ` [PATCH 2/2] KVM: arm64: selftests: Introduce get_set_regs_perf test Reiji Watanabe
2022-02-17  4:52   ` Oliver Upton
2022-02-17  9:11     ` Marc Zyngier
2022-02-19  4:50       ` Reiji Watanabe
2022-02-19  9:42         ` Marc Zyngier
2022-02-19  3:53     ` Reiji Watanabe
2022-02-17  3:55 ` [PATCH 1/2] KVM: selftests: kvm_vm_elf_load() and elfhdr_get() should close fd Oliver Upton
2022-06-16 14:07 ` Andrew Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).