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 1/2] KVM: selftests: Free the VM when the SEV smoke test's guest completes
Date: Sat, 8 Aug 2026 13:40:49 +0530 [thread overview]
Message-ID: <20260808081050.408657-2-gokul02k@gmail.com> (raw)
In-Reply-To: <20260808081050.408657-1-gokul02k@gmail.com>
test_sev() returns directly out of the UCALL_DONE case rather than
leaving the loop, so the plain-SEV path skips the kvm_vm_free() at the
end of the function. The SEV-ES path is unaffected; it breaks out of
the loop and frees the VM correctly.
main() invokes test_sev() once per supported SEV VM type, so a full run
leaks a VM and its file descriptors. Nothing fails today because the
process exits shortly afterwards, which is presumably why this was not
noticed, but the leak also means the plain-SEV path never exercises VM
teardown.
Use a goto so UCALL_DONE joins the existing exit path. A plain break
would only leave the switch statement and spin the loop again.
Fixes: be250ff437fa ("KVM: selftests: Add a basic SEV smoke test")
Signed-off-by: Gokul K <gokul02k@gmail.com>
---
tools/testing/selftests/kvm/x86/sev_smoke_test.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/x86/sev_smoke_test.c b/tools/testing/selftests/kvm/x86/sev_smoke_test.c
index 6b2cbe2a90b7..646ae93e3c46 100644
--- a/tools/testing/selftests/kvm/x86/sev_smoke_test.c
+++ b/tools/testing/selftests/kvm/x86/sev_smoke_test.c
@@ -178,7 +178,7 @@ static void test_sev(void *guest_code, u32 type, u64 policy)
case UCALL_SYNC:
continue;
case UCALL_DONE:
- return;
+ goto done;
case UCALL_ABORT:
REPORT_GUEST_ASSERT(uc);
default:
@@ -187,6 +187,7 @@ static void test_sev(void *guest_code, u32 type, u64 policy)
}
}
+done:
kvm_vm_free(vm);
}
--
2.54.0
next prev parent reply other threads:[~2026-08-08 8:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 8:10 [PATCH 0/2] KVM: selftests: Fix two VMs leaked on early returns Gokul K
2026-08-08 8:10 ` Gokul K [this message]
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
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=20260808081050.408657-2-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