From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org, Nipun Gupta <nipun.gupta@amd.com>,
Nikhil Agarwal <nikhil.agarwal@amd.com>,
Chenbo Xia <chenbox@nvidia.com>,
Tomasz Duszynski <tduszynski@marvell.com>,
Ajit Khaparde <ajit.khaparde@broadcom.com>,
Vikas Gupta <vikas.gupta@broadcom.com>,
Bruce Richardson <bruce.richardson@intel.com>,
Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v2 06/19] vfio: split get device info from setup
Date: Fri, 14 Nov 2025 17:40:16 +0000 [thread overview]
Message-ID: <f09c844e899a86cd0eb33404905e5e51d4bf1400.1763142008.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <cover.1763142007.git.anatoly.burakov@intel.com> <cover.1763142007.git.anatoly.burakov@intel.com>
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 (adjusting respective callers).
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
drivers/bus/cdx/cdx_vfio.c | 12 ++++++++--
drivers/bus/pci/linux/pci_vfio.c | 18 ++++++++++----
drivers/bus/platform/platform.c | 8 ++++++-
drivers/crypto/bcmfs/bcmfs_vfio.c | 8 ++++++-
lib/eal/freebsd/eal.c | 3 +--
lib/eal/include/rte_vfio.h | 23 +++++++-----------
lib/eal/linux/eal_vfio.c | 40 +++++++++----------------------
7 files changed, 58 insertions(+), 54 deletions(-)
diff --git a/drivers/bus/cdx/cdx_vfio.c b/drivers/bus/cdx/cdx_vfio.c
index 11fe3265d2..7a44ff441a 100644
--- a/drivers/bus/cdx/cdx_vfio.c
+++ b/drivers/bus/cdx/cdx_vfio.c
@@ -401,7 +401,11 @@ cdx_vfio_map_resource_primary(struct rte_cdx_device *dev)
return -1;
ret = rte_vfio_setup_device(RTE_CDX_BUS_DEVICES_PATH, dev_name,
- &vfio_dev_fd, &device_info);
+ &vfio_dev_fd);
+ if (ret)
+ return ret;
+
+ ret = rte_vfio_get_device_info(vfio_dev_fd, &device_info);
if (ret)
return ret;
@@ -510,7 +514,11 @@ cdx_vfio_map_resource_secondary(struct rte_cdx_device *dev)
}
ret = rte_vfio_setup_device(RTE_CDX_BUS_DEVICES_PATH, dev_name,
- &vfio_dev_fd, &device_info);
+ &vfio_dev_fd);
+ if (ret)
+ return ret;
+
+ ret = rte_vfio_get_device_info(vfio_dev_fd, &device_info);
if (ret)
return ret;
diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index 8562fdcc6b..47b3f1dec8 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -753,7 +753,11 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
loc->domain, loc->bus, loc->devid, loc->function);
ret = rte_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
- &vfio_dev_fd, &device_info);
+ &vfio_dev_fd);
+ if (ret)
+ return ret;
+
+ ret = rte_vfio_get_device_info(vfio_dev_fd, &device_info);
if (ret)
return ret;
@@ -962,7 +966,11 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)
}
ret = rte_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
- &vfio_dev_fd, &device_info);
+ &vfio_dev_fd);
+ if (ret)
+ return ret;
+
+ ret = rte_vfio_get_device_info(vfio_dev_fd, &device_info);
if (ret)
return ret;
@@ -1194,8 +1202,10 @@ pci_vfio_ioport_map(struct rte_pci_device *dev, int bar,
if (vfio_dev_fd < 0) {
return -1;
} else if (vfio_dev_fd == 0) {
- if (rte_vfio_get_device_info(rte_pci_get_sysfs_path(), pci_addr,
- &vfio_dev_fd, &device_info) != 0)
+ if (rte_vfio_setup_device(rte_pci_get_sysfs_path(), pci_addr,
+ &vfio_dev_fd) != 0)
+ return -1;
+ if (rte_vfio_get_device_info(vfio_dev_fd, &device_info) != 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)
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index f6673cf181..d831c2c9b5 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -328,12 +328,18 @@ device_setup(struct rte_platform_device *pdev)
const char *name = pdev->name;
int ret;
- ret = rte_vfio_setup_device(PLATFORM_BUS_DEVICES_PATH, name, &pdev->dev_fd, &dev_info);
+ ret = rte_vfio_setup_device(PLATFORM_BUS_DEVICES_PATH, name, &pdev->dev_fd);
if (ret) {
PLATFORM_LOG_LINE(ERR, "failed to setup %s", name);
return -ENODEV;
}
+ ret = rte_vfio_get_device_info(pdev->dev_fd, &dev_info);
+ if (ret) {
+ PLATFORM_LOG_LINE(ERR, "failed to get device info for %s", name);
+ return -ENODEV;
+ }
+
/* This is an extra check to confirm that platform device was initialized
* by a kernel vfio-platform driver. On kernels that predate vfio-platform
* driver this flag obviously does not exist. In such scenarios this
diff --git a/drivers/crypto/bcmfs/bcmfs_vfio.c b/drivers/crypto/bcmfs/bcmfs_vfio.c
index e7f7ed994c..d00aaf1bb7 100644
--- a/drivers/crypto/bcmfs/bcmfs_vfio.c
+++ b/drivers/crypto/bcmfs/bcmfs_vfio.c
@@ -25,12 +25,18 @@ vfio_map_dev_obj(const char *path, const char *dev_obj,
struct vfio_device_info d_info = { .argsz = sizeof(d_info) };
struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
- ret = rte_vfio_setup_device(path, dev_obj, dev_fd, &d_info);
+ ret = rte_vfio_setup_device(path, dev_obj, dev_fd);
if (ret) {
BCMFS_LOG(ERR, "VFIO Setting for device failed");
return ret;
}
+ ret = rte_vfio_get_device_info(*dev_fd, &d_info);
+ if (ret) {
+ BCMFS_LOG(ERR, "VFIO Getting device info failed");
+ goto map_failed;
+ }
+
/* getting device region info*/
ret = ioctl(*dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);
if (ret < 0) {
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index a4d6cfe0a4..a7360db7a7 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -814,8 +814,7 @@ rte_eal_vfio_get_vf_token(__rte_unused rte_uuid_t vf_token)
RTE_EXPORT_INTERNAL_SYMBOL(rte_vfio_setup_device)
int rte_vfio_setup_device(__rte_unused const char *sysfs_base,
__rte_unused const char *dev_addr,
- __rte_unused int *vfio_dev_fd,
- __rte_unused struct vfio_device_info *device_info)
+ __rte_unused int *vfio_dev_fd)
{
rte_errno = ENOTSUP;
return -1;
diff --git a/lib/eal/include/rte_vfio.h b/lib/eal/include/rte_vfio.h
index aedb5fb41c..e7e2ee950b 100644
--- a/lib/eal/include/rte_vfio.h
+++ b/lib/eal/include/rte_vfio.h
@@ -55,10 +55,7 @@ struct vfio_device_info;
* device location.
*
* @param vfio_dev_fd
- * VFIO fd.
- *
- * @param device_info
- * Device information.
+ * Pointer to VFIO fd, will be set to the opened device fd on success.
*
* @return
* 0 on success.
@@ -67,7 +64,7 @@ struct vfio_device_info;
*/
__rte_internal
int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
- int *vfio_dev_fd, struct vfio_device_info *device_info);
+ int *vfio_dev_fd);
/**
* @internal
@@ -187,19 +184,16 @@ rte_vfio_get_group_num(const char *sysfs_base,
* @internal
* Get device information.
*
+ * This function retrieves VFIO device information from an already opened
+ * device. The device must be opened with rte_vfio_setup_device() first.
+ *
* This function is only relevant to Linux and will return an error on BSD.
*
- * @param sysfs_base
- * sysfs path prefix.
- *
- * @param dev_addr
- * device location.
- *
* @param vfio_dev_fd
- * VFIO fd.
+ * VFIO device fd (must be a valid, already opened fd).
*
* @param device_info
- * Device information.
+ * Pointer to device information structure to be filled.
*
* @return
* 0 on success.
@@ -207,8 +201,7 @@ rte_vfio_get_group_num(const char *sysfs_base,
*/
__rte_internal
int
-rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr,
- int *vfio_dev_fd, struct vfio_device_info *device_info);
+rte_vfio_get_device_info(int vfio_dev_fd, struct vfio_device_info *device_info);
/**
* @internal
diff --git a/lib/eal/linux/eal_vfio.c b/lib/eal/linux/eal_vfio.c
index 29dd1758e4..02fec64658 100644
--- a/lib/eal/linux/eal_vfio.c
+++ b/lib/eal/linux/eal_vfio.c
@@ -758,7 +758,7 @@ rte_vfio_clear_group(int vfio_group_fd)
RTE_EXPORT_INTERNAL_SYMBOL(rte_vfio_setup_device)
int
rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
- int *vfio_dev_fd, struct vfio_device_info *device_info)
+ int *vfio_dev_fd)
{
struct vfio_group_status group_status = {
.argsz = sizeof(group_status)
@@ -975,7 +975,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
*vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD,
dev);
if (*vfio_dev_fd >= 0)
- goto dev_get_info;
+ goto out;
}
/* get a file descriptor for the device */
@@ -992,18 +992,8 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
return -1;
}
- /* test and setup the device */
-dev_get_info:
- ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
- if (ret) {
- EAL_LOG(ERR, "%s cannot get device info, "
- "error %i (%s)", dev_addr, errno,
- strerror(errno));
- close(*vfio_dev_fd);
- close(vfio_group_fd);
- rte_vfio_clear_group(vfio_group_fd);
- return -1;
- }
+ /* device is now set up */
+out:
vfio_group_device_get(vfio_group_fd);
return 0;
@@ -1217,26 +1207,18 @@ vfio_set_iommu_type(int vfio_container_fd)
RTE_EXPORT_INTERNAL_SYMBOL(rte_vfio_get_device_info)
int
-rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr,
- int *vfio_dev_fd, struct vfio_device_info *device_info)
+rte_vfio_get_device_info(int vfio_dev_fd, struct vfio_device_info *device_info)
{
int ret;
- if (device_info == NULL || *vfio_dev_fd < 0)
+ if (device_info == NULL || vfio_dev_fd < 0)
return -1;
- if (*vfio_dev_fd == 0) {
- ret = rte_vfio_setup_device(sysfs_base, dev_addr,
- vfio_dev_fd, device_info);
- if (ret)
- return -1;
- } else {
- ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
- if (ret) {
- EAL_LOG(ERR, "%s cannot get device info, error %i (%s)",
- dev_addr, errno, strerror(errno));
- return -1;
- }
+ ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
+ if (ret) {
+ EAL_LOG(ERR, "Cannot get device info, error %i (%s)",
+ errno, strerror(errno));
+ return -1;
}
return 0;
--
2.47.3
next prev parent reply other threads:[~2025-11-14 17:41 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-28 16:43 [PATCH v1 0/8] Support VFIO cdev API in DPDK Anatoly Burakov
2025-10-28 16:43 ` [PATCH v1 1/8] uapi: update to v6.17 and add iommufd.h Anatoly Burakov
2025-10-28 16:43 ` [PATCH v1 2/8] vfio: add container device assignment API Anatoly Burakov
2025-10-28 16:43 ` [PATCH v1 3/8] vhost: remove group-related API from drivers Anatoly Burakov
2025-10-28 16:43 ` [PATCH v1 4/8] vfio: do not setup the device on get device info Anatoly Burakov
2025-10-28 16:43 ` [PATCH v1 5/8] vfio: cleanup and refactor Anatoly Burakov
2025-10-28 16:43 ` [PATCH v1 6/8] vfio: introduce cdev mode Anatoly Burakov
2025-10-28 16:43 ` [PATCH v1 7/8] doc: deprecate VFIO group-based APIs Anatoly Burakov
2025-10-28 16:43 ` [PATCH v1 8/8] vfio: deprecate group-based API Anatoly Burakov
2025-10-29 9:50 ` 回复:[PATCH v1 0/8] Support VFIO cdev API in DPDK Dimon
2025-10-29 12:03 ` Burakov, Anatoly
2025-10-30 9:21 ` [PATCH " David Marchand
2025-10-30 10:11 ` Burakov, Anatoly
2025-11-14 17:40 ` [PATCH v2 00/19] " Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 01/19] doc: add deprecation notice for VFIO API Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 02/19] doc: add deprecation notice for vDPA driver API Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 03/19] uapi: update to v6.17 and add iommufd.h Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 04/19] vfio: make all functions internal Anatoly Burakov
2025-11-14 18:18 ` Stephen Hemminger
2025-11-14 17:40 ` [PATCH v2 05/19] vfio: add container device assignment API Anatoly Burakov
2025-11-14 17:40 ` Anatoly Burakov [this message]
2025-11-14 17:40 ` [PATCH v2 07/19] net/nbl: do not use VFIO group bind API Anatoly Burakov
2025-11-15 8:31 ` 回复:[PATCH " Dimon
2025-11-14 17:40 ` [PATCH v2 08/19] net/ntnic: use container device assignment API Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 09/19] vdpa/ifc: " Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 10/19] vdpa/nfp: " Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 11/19] vdpa/sfc: " Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 12/19] vhost: remove group-related API from drivers Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 13/19] vfio: cleanup and refactor Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 14/19] bus/pci: use the new VFIO mode API Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 15/19] bus/fslmc: " Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 16/19] net/hinic3: " Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 17/19] net/ntnic: " Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 18/19] vfio: remove group API functions Anatoly Burakov
2025-11-14 17:40 ` [PATCH v2 19/19] vfio: introduce cdev mode Anatoly Burakov
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=f09c844e899a86cd0eb33404905e5e51d4bf1400.1763142008.git.anatoly.burakov@intel.com \
--to=anatoly.burakov@intel.com \
--cc=ajit.khaparde@broadcom.com \
--cc=bruce.richardson@intel.com \
--cc=chenbox@nvidia.com \
--cc=dev@dpdk.org \
--cc=nikhil.agarwal@amd.com \
--cc=nipun.gupta@amd.com \
--cc=roretzla@linux.microsoft.com \
--cc=tduszynski@marvell.com \
--cc=vikas.gupta@broadcom.com \
/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;
as well as URLs for NNTP newsgroup(s).