[PATCH 0/2] KVM: selftests: Fixes for guest_memfd_test and FD double-close

From: Fuad Tabba

Date: Mon May 11 2026 - 07:43:02 EST


Hi folks,

Two more patches, standalone KVM selftests fixes that I'd like to
land before posting a pKVM selftests series, a follow-up to Will's
pKVM infrastructure series [1].

The first patch fixes a build failure I ran into on Debian Bookworm
(glibc 2.36): guest_memfd_test.c uses MADV_COLLAPSE unconditionally,
but the constant was only exposed in glibc 2.37. The fix follows the
established selftest idiom of providing a compile-time fallback to
the kernel-ABI value when the libc header does not define it.

The second patch fixes an FD double-close in kvm_vm_release().
kvm_vm_free() calls kvm_vm_release() internally, so a test that
calls kvm_vm_release() and then kvm_vm_free() without reopening the
VM in between double-closes vmp->fd and vmp->kvm_fd. Existing
in-tree callers reopen via vm_recreate_with_one_vcpu() and do not
hit this today. The double-close becomes a hard test failure for
the pKVM selftests I will submit, which release the VM and then
inspect host-mapped memory before freeing.

Based on Linux 7.1-rc3.

Cheers,
/fuad

[1] https://lore.kernel.org/all/20260105154939.11041-1-will@xxxxxxxxxx/

Fuad Tabba (2):
KVM: selftests: Fix MADV_COLLAPSE build failure on older toolchains
KVM: selftests: Fix FD double-close in kvm_vm_release()

tools/testing/selftests/kvm/guest_memfd_test.c | 4 ++++
tools/testing/selftests/kvm/lib/kvm_util.c | 10 ++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)

--
2.54.0.563.g4f69b47b94-goog