[Devel] [PATCH hci-8.1 v3 1/1] vfio: take the kvm reference only for drivers that read device->kvm

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Thu Nov 5 17:22:50 MSK 2026


> A device takes a reference to its group's kvm at the first open and
> drops it at the last close, so that device->kvm stays valid for the
> driver in between. QEMU's cpr-exec and cpr-transfer keep the device
> open while the VM is re-created, so the first VM stays referenced for
> as long as the device is: its vcpus, mm and in-kernel PIT thread with
> it. Seen as a second KVM instance in debugfs after a live update of a
> vGPU VM.
> 
> Only three drivers read device->kvm: KVMGT, vfio_ap and vfio-pci's
> zdev support, all in open_device(), the first and the last at close
> too. Let them say so with needs_kvm_ref. Without it device->kvm stays
> NULL and no reference is taken, so the device can't keep a VM alive.
> Tested with nvidia-vgpu-vfio 595.71.03 on RTX 6000 Ada SR-IOV VFs, a
> vfio-pci variant driver that doesn't read the pointer: a grep for kvm
> over its sources (nvidia-595.71.03/nvidia-vgpu-vfio) finds only the
> kvm_host.h include and a comment.
> 
> Fixes: 2b48f52f2bff ("vfio: fix deadlock between group lock and kvm lock")
> https://virtuozzo.atlassian.net/browse/VSTOR-150597
> 
> Feature: fix ms/vfio
> Signed-off-by: Andrey Drobyshev <andrey.drobyshev at virtuozzo.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261105141759.750676-1-andrey.drobyshev@virtuozzo.com?part=1




More information about the Devel mailing list