[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
Thu Nov 5 15:54:22 MSK 2026


I won't apply this version, please send v3 with the changes below.

On Thu, 5 Nov 2026 14:17:33 +0200, Andrey Drobyshev wrote:
> 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.

Item 3 of the cover letter reply: test patch 1 alone. If the duplicate
directory is gone, drop this patch. If not, name in the message what
still holds the old VM.

Why: with patch 1, VFIO takes no kvm reference for nvidia-vgpu-vfio.
The VM fd, the vcpu fds and the device fds are all close-on-exec. So
on cpr-exec the old VM is destroyed, and its directory removed, before
the new QEMU creates its VM. What can still hold a VM past its fd is
KVMGT, vfio_ap, zdev, a guest_memfd fd or an open stats file, and
none of the three drivers is built in our x86_64 kernels.

> +	/* The directory is named after this fd, which is free to reuse now */
> +	kvm_remove_vm_debugfs(kvm);

Item 4 of the cover letter reply: if the patch stays, rename the
directory with debugfs_change_name() to a name that cannot clash,
instead of removing it. Then drop the "Two things change" paragraph.

Why: on powerpc the XICS and XIVE devices create a file in this
directory and remove it when their device fd is released. If the VM fd
is closed first, the recursive removal here frees that dentry, and the
device release then removes freed memory. Our x86_64 kernels are not
hit, but the code should not carry that. My v1 reply asked to remove
only the directory and missed this case, sorry. A rename keeps every
child dentry valid until kvm_destroy_vm(), and STATS_PATH and the vcpu
stats keep working.

> Feature: fix ms/kvm
>
> Assisted-by: LLM

Item 5 of the cover letter reply: drop the Assisted-by line here, it
goes into the cover letter. Put a blank line before Feature:.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team



More information about the Devel mailing list