Re: [PATCH 2/2] KVM: selftests: Fix FD double-close in kvm_vm_release()
From: Ackerley Tng
Date: Tue May 12 2026 - 16:41:00 EST
Fuad Tabba <tabba@xxxxxxxxxx> writes:
I agree that perhaps in this case manually setting up the memslot after
mmap()-ing anonymous memory is better since it's more explicit about
what is being tested.
> kvm_vm_release() closes vmp->fd and vmp->kvm_fd unconditionally, and
> kvm_vm_free() calls kvm_vm_release() at teardown. A test that calls
> kvm_vm_release() and then kvm_vm_free() without a
> vm_recreate_with_one_vcpu() in between double-closes both FDs. Since
> kvm_close() asserts on close() failure, the second close trips
> TEST_ASSERT and aborts the test, or, if the FD was recycled, silently
> closes an unrelated file.
>
Never thought about this fd-recycling case, I think this change still
has value in avoiding the silent closing of some other file.
>
> [...snip...]
>