[Devel] [PATCH hci-8.1 0/2] vfio: prevent kvm reference leak on qemu-update

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:31 +0200, Andrey Drobyshev wrote:
> Andrey Drobyshev (2):
>   vfio: move an open device's kvm reference when its group gets a new
>     kvm
>   KVM: remove the VM's debugfs directory when its fd is released

What to change for v2:

1. Patch 1, code and commit message: do not change device->kvm under a
   driver that still uses it after open_device(). In tree that is
   KVMGT: it registers its page-track notifier on device->kvm at open
   and unregisters it from device->kvm at close. Check what the NVIDIA
   vGPU driver does with vdev->kvm after open and say in the message
   which driver the change was tested with.

2. Patch 1, code comment and commit message: give the real reason to
   skip NULL, the lock order (details in the patch reply), and drop
   "the new kvm, if any, arrives on its own". Update the kernel-doc of
   vfio_file_set_kvm() too.

3. Patch 1, commit message: add a Fixes tag for 2b48f52f2bff ("vfio:
   fix deadlock between group lock and kvm lock").

4. Patch 2, code: 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. This version has a
   use-after-free.

5. Patch 2, commit message: say 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.

6. Both patches: single space after a period, in the messages and in
   the new code comments, and add the Feature: line.

7. Cover letter: write one. Say what goes wrong on a live update of a
   vGPU VM, what each patch does, and how it was tested. In the subject
   "qemu-update" becomes "live update", and "kvm reference leak" covers
   patch 1 only.

Separate, not needed for v2:

1. Patch 1 should go to mainline too, I created a task for that:
   https://virtuozzo.atlassian.net/browse/VSTOR-153437

Details on items 1-6 are in the replies to the patches.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team



More information about the Devel mailing list