The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: selftests: Fix two VMs leaked on early returns
@ 2026-08-08  8:10 Gokul K
  2026-08-08  8:10 ` [PATCH 1/2] KVM: selftests: Free the VM when the SEV smoke test's guest completes Gokul K
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Gokul K @ 2026-08-08  8:10 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: Shuah Khan, kvm, linux-kselftest, linux-kernel

Two x86 selftests create a VM and then take an early return that skips the
kvm_vm_free() at the end of the function.

Patch 1 is the plain-SEV path of sev_smoke_test(), which returns straight
out of the UCALL_DONE case instead of leaving the loop.  The SEV-ES path
next to it breaks out and frees correctly.

Patch 2 is nx_huge_pages_test, which returns as soon as it has confirmed
that disabling NX huge pages is denied without CAP_SYS_BOOT.  This one is
not an unusual error path: nx_huge_pages_test.sh runs the test without
CAP_SYS_BOOT for any non-root user, so a normal run always takes it.

Neither leak causes a failure today, since the process exits shortly
afterwards.  They do mean those paths never exercise VM teardown.

The two patches are independent and either can be applied on its own.

Found by auditing every function under tools/testing/selftests/kvm/ that
creates a VM and later calls kvm_vm_free(), looking for returns in
between.  Seven other hits were false positives, mostly returns after
REPORT_GUEST_ASSERT() or TEST_FAIL(), which abort the process and make
the return unreachable.  Two more that do look real, in get-reg-list.c
and arm64/external_aborts.c, are left out here because they belong to
different maintainers.

Compile-tested only.  This host has neither SEV (kvm_amd sev=N) nor
hugetlb configured, so both tests SKIP rather than run.

Note patch 1 touches sev_smoke_test.c, which an unrelated patch I sent
earlier also touches [1].  They modify different functions, do not
conflict, and neither depends on the other.

[1] https://lore.kernel.org/all/20260807071026.195503-1-gokul02k@gmail.com/

Gokul K (2):
  KVM: selftests: Free the VM when the SEV smoke test's guest completes
  KVM: selftests: Free the VM when NX hugepage disabling is denied

 tools/testing/selftests/kvm/x86/nx_huge_pages_test.c | 1 +
 tools/testing/selftests/kvm/x86/sev_smoke_test.c     | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

-- 
2.54.0



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

end of thread, other threads:[~2026-08-10 13:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-08  8:10 [PATCH 0/2] KVM: selftests: Fix two VMs leaked on early returns Gokul K
2026-08-08  8:10 ` [PATCH 1/2] KVM: selftests: Free the VM when the SEV smoke test's guest completes Gokul K
2026-08-08  8:10 ` [PATCH 2/2] KVM: selftests: Free the VM when NX hugepage disabling is denied Gokul K
2026-08-10 13:37   ` Sean Christopherson
2026-08-10 13:35 ` [PATCH 0/2] KVM: selftests: Fix two VMs leaked on early returns Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox