From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 2/2] KVM: remove the VM's debugfs directory when its fd is released
Date: Thu, 5 Nov 2026 14:17:33 +0200 [thread overview]
Message-ID: <20261105121733.643754-3-andrey.drobyshev@virtuozzo.com> (raw)
In-Reply-To: <20261105121733.643754-1-andrey.drobyshev@virtuozzo.com>
The directory under /sys/kernel/debug/kvm is named <pid>-<fd>, but is
removed only together with the VM. A VM can outlive its fd: VFIO keeps
a reference to it for an open passthrough device, and QEMU's cpr-exec
closes the fd and creates a new VM in the same process, often on the
same fd number. The new VM then finds its directory taken, logs
"duplicate directory" and runs without debugfs stats. Seen on every
other live update of a vGPU VM.
Remove only the directory when the fd is released: the name belongs to
the fd, which is free to reuse from then on. The stat data stays until
kvm_destroy_vm(): an open stat file reaches it through the inode at
release, which debugfs runs even after the file was removed.
Two things change with that: the destroy uevent no longer carries
STATS_PATH, and a VM that lives on after its fd on the vcpu fds has
no stats directory for that time.
https://virtuozzo.atlassian.net/browse/VSTOR-150597
Feature: fix ms/kvm
Assisted-by: LLM
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
virt/kvm/kvm_main.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 8d92a649c063..9a0ee933a6a3 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -995,21 +995,28 @@ static umode_t kvm_stats_debugfs_mode(const struct _kvm_stats_desc *pdesc)
}
+static void kvm_remove_vm_debugfs(struct kvm *kvm)
+{
+ if (IS_ERR(kvm->debugfs_dentry))
+ return;
+
+ debugfs_remove_recursive(kvm->debugfs_dentry);
+ kvm->debugfs_dentry = ERR_PTR(-ENOENT);
+}
+
static void kvm_destroy_vm_debugfs(struct kvm *kvm)
{
int i;
int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc +
kvm_vcpu_stats_header.num_desc;
- if (IS_ERR(kvm->debugfs_dentry))
- return;
-
- debugfs_remove_recursive(kvm->debugfs_dentry);
+ kvm_remove_vm_debugfs(kvm);
if (kvm->debugfs_stat_data) {
for (i = 0; i < kvm_debugfs_num_entries; i++)
kfree(kvm->debugfs_stat_data[i]);
kfree(kvm->debugfs_stat_data);
+ kvm->debugfs_stat_data = NULL;
}
}
@@ -1364,6 +1371,9 @@ static int kvm_vm_release(struct inode *inode, struct file *filp)
kvm_irqfd_release(kvm);
+ /* The directory is named after this fd, which is free to reuse now */
+ kvm_remove_vm_debugfs(kvm);
+
kvm_put_kvm(kvm);
return 0;
}
--
2.47.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-05 12:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 12:17 [Devel] [PATCH hci-8.1 v2 0/2] vfio, KVM: kvm reference leak and debugfs clash on live update Andrey Drobyshev
2026-11-05 12:17 ` [Devel] [PATCH hci-8.1 1/2] vfio: take the kvm reference only for drivers that read device->kvm Andrey Drobyshev
2026-11-05 12:23 ` no-reply
2026-11-05 12:54 ` Konstantin Khorenko
2026-11-05 12:17 ` Andrey Drobyshev [this message]
2026-11-05 12:24 ` [Devel] [PATCH hci-8.1 2/2] KVM: remove the VM's debugfs directory when its fd is released no-reply
2026-11-05 12:54 ` Konstantin Khorenko
2026-11-05 12:54 ` [Devel] [PATCH hci-8.1 v2 0/2] vfio, KVM: kvm reference leak and debugfs clash on live update Konstantin Khorenko
-- strict thread matches above, loose matches on Subject: below --
2026-10-30 14:49 [Devel] [PATCH hci-8.1 0/2] vfio: prevent kvm reference leak on qemu-update Andrey Drobyshev
2026-10-30 14:49 ` [Devel] [PATCH hci-8.1 2/2] KVM: remove the VM's debugfs directory when its fd is released Andrey Drobyshev
2026-11-04 20:08 ` Konstantin Khorenko
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=20261105121733.643754-3-andrey.drobyshev@virtuozzo.com \
--to=andrey.drobyshev@virtuozzo.com \
--cc=devel@openvz.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.