mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gokul K <gokul02k@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>,
	kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 0/2] KVM: selftests: Fix two VMs leaked on early returns
Date: Tue, 11 Aug 2026 10:30:27 +0530	[thread overview]
Message-ID: <20260811050029.530698-1-gokul02k@gmail.com> (raw)

Two x86 selftests create a VM and then take an early return that skips the
kvm_vm_free() at the end of the function.  Both now jump to that existing
cleanup instead.

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.

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 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 and do not
conflict in either order.

v2:
 - nx_huge_pages_test: goto the existing cleanup instead of open-coding
   kvm_vm_free() before the return, matching patch 1 (Sean)
 - Drop the claims that these paths never exercise VM teardown, and that
   the nx_huge_pages path is not obscure.  Neither justification holds
   up: teardown still happens, just at process exit, and how often a
   leaking path runs does not change whether it should be fixed (Sean)
 - Rebase onto current kvm-x86/next

[1] https://lore.kernel.org/all/20260807071026.195503-1-gokul02k@gmail.com/
v1: https://lore.kernel.org/all/20260808081050.408657-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 | 3 ++-
 tools/testing/selftests/kvm/x86/sev_smoke_test.c     | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

-- 
2.54.0



             reply	other threads:[~2026-08-11  5:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11  5:00 Gokul K [this message]
2026-08-11  5:00 ` [PATCH v2 1/2] KVM: selftests: Free the VM when the SEV smoke test's guest completes Gokul K
2026-08-11  5:00 ` [PATCH v2 2/2] KVM: selftests: Free the VM when NX hugepage disabling is denied Gokul K
2026-09-21 14:05 ` [PATCH v2 0/2] KVM: selftests: Fix two VMs leaked on early returns Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260811050029.530698-1-gokul02k@gmail.com \
    --to=gokul02k@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®