[Devel] [PATCH hci-8.1 2/2] KVM: remove the VM's debugfs directory when its fd is released
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Nov 4 23:08:34 MSK 2026
I won't apply this version, please send v2 with the changes below.
On Fri, 30 Oct 2026 16:49:33 +0200, Andrey Drobyshev wrote:
> + /* The directory is named after this fd, which is free to reuse now */
> + kvm_destroy_vm_debugfs(kvm);
Item 4 of the cover letter reply: at fd release remove only the
directory. Keep freeing debugfs_stat_data in kvm_destroy_vm(), moved
out from under the IS_ERR(kvm->debugfs_dentry) early return.
Why: an open stats file holds a reference to the kvm, not to its stat
data. kvm_debugfs_release() reads inode->i_private, the stat data, to
find the kvm it has to put, and debugfs calls it even after the file
was removed. Before this patch the stat data lived as long as the kvm,
so that was safe. Now it is freed at fd release: open
/sys/kernel/debug/kvm/<pid>-<fd>/exits, let QEMU exit, close the file,
and the release reads freed memory and puts whatever kvm pointer it
finds there. This hits any VM shutdown that races with a stats reader,
not only a live update.
> + kvm->debugfs_dentry = ERR_PTR(-ENOENT);
Item 5 of the cover letter reply: say in the message that the destroy
uevent no longer carries STATS_PATH, and that the stats go away for a
VM that keeps running on its vcpu fds after the VM fd is closed.
Why: kvm_destroy_vm() sends the destroy uevent, and the uevent adds
STATS_PATH only for a valid dentry. Both changes look acceptable, but
a reader of the message should know about them.
Item 6 of the cover letter reply: single space after a period, and the
Feature: line.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
More information about the Devel
mailing list