[PATCH v17 10/26] vfio: split get device info from setup
David Marchand
david.marchand at redhat.com
Tue Sep 15 17:24:53 CEST 2026
On Thu, 10 Sept 2026 at 14:54, Anatoly Burakov
<anatoly.burakov at intel.com> wrote:
>
> Currently, setup gets device info as part of setup, while the separate get
> device info API also calls setup if the fd is zero. Untangle these two APIs
> and make each do one thing, and adjust all existing callers.
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
> ---
> drivers/bus/cdx/cdx_vfio.c | 12 ++++++++--
> drivers/bus/pci/linux/pci_vfio.c | 18 ++++++++++----
> drivers/bus/platform/platform.c | 9 ++++++-
> drivers/crypto/bcmfs/bcmfs_vfio.c | 8 ++++++-
> lib/eal/freebsd/eal.c | 12 ++++++++--
> lib/eal/include/dev_vfio.h | 23 +++++++-----------
> lib/eal/linux/eal_vfio.c | 40 +++++++++----------------------
> 7 files changed, 68 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/bus/cdx/cdx_vfio.c b/drivers/bus/cdx/cdx_vfio.c
> index 02a34d6f18..531e4ccc8d 100644
> --- a/drivers/bus/cdx/cdx_vfio.c
> +++ b/drivers/bus/cdx/cdx_vfio.c
> @@ -401,10 +401,14 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev)
> return -1;
>
> ret = dev_vfio_setup_device(RTE_CDX_BUS_DEVICES_PATH, dev_name,
> - &vfio_dev_fd, &device_info);
> + &vfio_dev_fd);
> if (ret)
> return ret;
>
> + ret = dev_vfio_get_device_info(vfio_dev_fd, &device_info);
> + if (ret)
> + goto err_vfio_dev_fd;
> +
> /* allocate vfio_res and get region info */
> vfio_res = rte_zmalloc("VFIO_RES", sizeof(*vfio_res), 0);
> if (vfio_res == NULL) {
> @@ -510,10 +514,14 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev)
> }
>
> ret = dev_vfio_setup_device(RTE_CDX_BUS_DEVICES_PATH, dev_name,
> - &vfio_dev_fd, &device_info);
> + &vfio_dev_fd);
> if (ret)
> return ret;
>
> + ret = dev_vfio_get_device_info(vfio_dev_fd, &device_info);
> + if (ret)
> + goto err_vfio_dev_fd;
> +
> /* map MMIO regions */
> maps = vfio_res->maps;
>
> diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
> index 3e87e759f5..0363a4a6c5 100644
> --- a/drivers/bus/pci/linux/pci_vfio.c
> +++ b/drivers/bus/pci/linux/pci_vfio.c
> @@ -753,10 +753,14 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
> loc->domain, loc->bus, loc->devid, loc->function);
>
> ret = dev_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
> - &vfio_dev_fd, &device_info);
> + &vfio_dev_fd);
> if (ret)
> return ret;
>
> + ret = dev_vfio_get_device_info(vfio_dev_fd, &device_info);
> + if (ret)
> + goto err_vfio_dev_fd;
> +
> if (rte_intr_dev_fd_set(dev->intr_handle, vfio_dev_fd))
> goto err_vfio_dev_fd;
>
> @@ -962,10 +966,14 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)
> }
>
> ret = dev_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
> - &vfio_dev_fd, &device_info);
> + &vfio_dev_fd);
> if (ret)
> return ret;
>
> + ret = dev_vfio_get_device_info(vfio_dev_fd, &device_info);
> + if (ret)
> + goto err_vfio_dev_fd;
> +
> ret = pci_vfio_fill_regions(dev, vfio_dev_fd, &device_info);
> if (ret)
> goto err_vfio_dev_fd;
> @@ -1195,12 +1203,14 @@ pci_vfio_ioport_map(struct rte_pci_device *dev, int bar,
> if (vfio_dev_fd < 0) {
> return -1;
> } else if (vfio_dev_fd == 0) {
Not the fault of this patch, but comparing a FD against 0 is a bad sign...
> - if (dev_vfio_get_device_info(rte_pci_get_sysfs_path(), pci_addr,
> - &vfio_dev_fd, &device_info) != 0)
> + if (dev_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
> + &vfio_dev_fd) != 0)
> return -1;
> /* save vfio_dev_fd so it can be used during release */
> if (rte_intr_dev_fd_set(dev->intr_handle, vfio_dev_fd) != 0)
> return -1;
> + if (dev_vfio_get_device_info(vfio_dev_fd, &device_info) != 0)
> + return -1;
>
> if (pci_vfio_fill_regions(dev, vfio_dev_fd, &device_info) != 0)
> return -1;
And we have various leaks in case VFIO fails...
I'll make a note to fix this later as this is already present, unless
you can have a look.
--
David Marchand
More information about the dev
mailing list