[Devel] [PATCH hci-8.1 2/2] KVM: remove the VM's debugfs directory when its fd is released
Andrey Drobyshev
andrey.drobyshev at virtuozzo.com
Fri Oct 30 17:49:33 MSK 2026
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 the directory when the fd is released: the name belongs to the
fd, which is free to reuse from then on. kvm_destroy_vm() keeps its
call for a VM that never got an fd.
https://virtuozzo.atlassian.net/browse/VSTOR-150597
Signed-off-by: Andrey Drobyshev <andrey.drobyshev at virtuozzo.com>
---
virt/kvm/kvm_main.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 8d92a649c063..5e9b8a9ba8b4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1005,11 +1005,13 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
return;
debugfs_remove_recursive(kvm->debugfs_dentry);
+ kvm->debugfs_dentry = ERR_PTR(-ENOENT);
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 +1366,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_destroy_vm_debugfs(kvm);
+
kvm_put_kvm(kvm);
return 0;
}
--
2.47.1
More information about the Devel
mailing list