> A device takes a reference to the KVM file of its group or device file
> 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.  The first VM then stays referenced for as long as the
> device is open: its file is not released, and its vcpus, mm and
> in-kernel PIT thread stay with it.
> 
> To see it, start QEMU with a vfio-pci device, run cpr-exec and trace
> kvm_create_vm() and kvm_destroy_vm().  The old VM is not destroyed at
> the exec, and two VMs stay alive until QEMU exits.  Without the device
> the old VM is destroyed at the exec.  The new VM also logs
> 
>   kvm: debugfs: duplicate directory <pid>-<fd>
> 
> because it gets the pid and fd number of the old one.
> 
> Only three drivers read device->kvm: KVMGT, vfio_ap and vfio-pci's
> zdev support.  vfio_ap reads it only in open_device(), zdev also at
> close, KVMGT also at close and while the guest runs.  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.
> 
> Fixes: 2b48f52f2bff ("vfio: fix deadlock between group lock and kvm lock")
> Signed-off-by: Andrey Drobyshev <[email protected]>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1


Reply via email to