Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Gokul K <gokul02k@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org
Cc: Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, Peter Gonda <pgonda@google.com>,
	Jing Zhang <jingzhangos@google.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] KVM: selftests: Close /dev/sev when an SEV VM is released
Date: Tue,  1 Dec 2026 14:36:30 +0530	[thread overview]
Message-ID: <20261201090632.2482795-2-gokul02k@gmail.com> (raw)
In-Reply-To: <20261201090632.2482795-1-gokul02k@gmail.com>

Every SEV VM opens /dev/sev and stores the descriptor in
vm->arch.sev_fd: kvm_init_vm_address_properties() does it for the SEV VM
types, and sev_vm_init() and sev_es_vm_init() for SEV VMs of the default
type. Nothing ever closes it. kvm_vm_release() does call
kvm_arch_vm_release(), however x86 never provided one: the __weak stub in
lib/kvm_util.c is empty, and arm64 is currently the only architecture
that overrides it, to close its GIC fd.

The descriptor therefore stays open for the lifetime of the process, so a
test that creates and frees SEV VMs in a loop accumulates one per VM.

Add an x86 kvm_arch_vm_release() that closes it, mirroring arm64.
vm->arch.sev_fd is -1 unless one was opened, so guard on that.

Fixes: ae20eef5323c ("KVM: selftests: Add library for creating and interacting with SEV guests")
Signed-off-by: Gokul K <gokul02k@gmail.com>
---
 tools/testing/selftests/kvm/lib/x86/processor.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testing/selftests/kvm/lib/x86/processor.c
index ee8a1715d844..b716c53b6721 100644
--- a/tools/testing/selftests/kvm/lib/x86/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86/processor.c
@@ -1347,6 +1347,12 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits)
 	}
 }
 
+void kvm_arch_vm_release(struct kvm_vm *vm)
+{
+	if (vm->arch.sev_fd >= 0)
+		kvm_free_fd(vm->arch.sev_fd);
+}
+
 void kvm_init_vm_address_properties(struct kvm_vm *vm)
 {
 	u32 gpa_bits = kvm_cpu_property(X86_PROPERTY_GUEST_MAX_PHY_ADDR);
-- 
2.54.0



  reply	other threads:[~2026-12-01  9:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:06 [PATCH 0/3] KVM: selftests: Fix three leaked resources Gokul K
2026-12-01  9:06 ` Gokul K [this message]
2026-12-01  9:06 ` [PATCH 2/3] KVM: selftests: Close the SEV fd opened for each KVM_SEV_INIT2 ioctl Gokul K
2026-12-01  9:06 ` [PATCH 3/3] KVM: selftests: Free the stats id string when no stats are defined Gokul K
2026-12-01  9:12   ` sashiko-bot

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=20261201090632.2482795-2-gokul02k@gmail.com \
    --to=gokul02k@gmail.com \
    --cc=jingzhangos@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=pgonda@google.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