From c3fbdba15a8b3d80c1f5e6026e636030b3692437 Mon Sep 17 00:00:00 2001 From: Cédric Le Goater Date: Wed, 26 Mar 2025 08:51:07 +0100 Subject: vfio: Move vfio_kvm_device_fd() into helpers.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The vfio_kvm_device_add/del_fd() routines opening the VFIO pseudo device are defined in "helpers.c". Move 'vfio_kvm_device_fd' definition there and its declaration into "vfio-helpers.h" to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h". Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-22-clg@redhat.com Reviewed-by: Zhenzhong Duan Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-23-clg@redhat.com Signed-off-by: Cédric Le Goater --- hw/vfio/helpers.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'hw/vfio/helpers.c') diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 7ddc9797ef..48bd61d528 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -106,6 +106,17 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, return true; } +#ifdef CONFIG_KVM +/* + * We have a single VFIO pseudo device per KVM VM. Once created it lives + * for the life of the VM. Closing the file descriptor only drops our + * reference to it and the device's reference to kvm. Therefore once + * initialized, this file descriptor is only released on QEMU exit and + * we'll re-use it should another vfio device be attached before then. + */ +int vfio_kvm_device_fd = -1; +#endif + int vfio_kvm_device_add_fd(int fd, Error **errp) { #ifdef CONFIG_KVM -- cgit 1.4.1