From: sashiko-bot@kernel.org
To: "Andrey Drobyshev" <andrey.drobyshev@virtuozzo.com>
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH 1/1] vfio: Take the KVM reference only for drivers that read device->kvm
Date: Fri, 20 Nov 2026 15:55:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-225480@kernel.org> (raw)
In-Reply-To: <20261120154730.882393-2-andrey.drobyshev@virtuozzo.com>
> 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 <andrey.drobyshev@virtuozzo.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120154730.882393-1-andrey.drobyshev@virtuozzo.com?part=1
next prev parent reply other threads:[~2026-11-20 15:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 15:47 [PATCH 0/1] vfio: fix KVM reference leak on QEMU CPR Andrey Drobyshev
2026-11-20 15:47 ` [PATCH 1/1] vfio: Take the KVM reference only for drivers that read device->kvm Andrey Drobyshev
2026-11-20 15:55 ` sashiko-bot [this message]
2026-11-20 16:52 ` [PATCH 0/1] vfio: fix KVM reference leak on QEMU CPR Paolo Bonzini
2026-11-20 18:54 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-225480@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=andrey.drobyshev@virtuozzo.com \
--cc=eperezma@redhat.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox