Hi Anatoly,

I feel there might be a point that needs attention.

The old rte_vfio_get_group_num function returns <= 0 to indicate failure,
while the new rte_vfio_get_group_num function returns < 0 to indicate failure.
Therefore, all DPDK code that checks the return value of the rte_vfio_get_group_num function should be modified.

For example, in the nbl net driver, there is the following code:
ret = rte_vfio_get_group_num(pathname, dev_name, &common->iommu_group_num);
if (ret <= 0) {
    NBL_LOG(ERR, "nbl vfio group number failed");
    return -1;
}

It should be modified to:
ret = rte_vfio_get_group_num(pathname, dev_name, &common->iommu_group_num);
if (ret < 0) {
    NBL_LOG(ERR, "nbl vfio group number failed");
    return -1;
}




------------------------------------------------------------------
发件人:Anatoly Burakov <anatoly.burakov@intel.com>
发送时间:2025年11月15日(周六) 01:40
收件人:dev<dev@dpdk.org>; Dimon<dimon.zhao@nebula-matrix.com>; Kyo Liu<kyo.liu@nebula-matrix.com>; Leon<leon.yu@nebula-matrix.com>; Sam<sam.chen@nebula-matrix.com>
主 题:[PATCH v2 07/19] net/nbl: do not use VFIO group bind API

The NBL driver currently uses group bind API, but it is using it only to
get group fd and nothing else. In context of NBL driver, this is the only
usage of VFIO API's in the driver, and it is not necessary to use it for
what NBL driver is trying to accomplish.

Use a direct `open()` call instead, and store the group fd in common
structure.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
drivers/net/nbl/nbl_common/nbl_userdev.c  | 18 +++++++++++-------
drivers/net/nbl/nbl_include/nbl_include.h |  1 +
2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/net/nbl/nbl_common/nbl_userdev.c b/drivers/net/nbl/nbl_common/nbl_userdev.c
index 566f3a11ee..d641ecd9a8 100644
--- a/drivers/net/nbl/nbl_common/nbl_userdev.c
+++ b/drivers/net/nbl/nbl_common/nbl_userdev.c
@@ -387,6 +387,13 @@ nbl_userdev_mem_event_callback(enum rte_mem_event type, const void *addr, size_t
  }
}

+static int nbl_open_group_fd(int iommu_group_num)
+{
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), RTE_VFIO_GROUP_FMT, iommu_group_num);
+ return open(path, O_RDWR);
+}
+
static int nbl_mdev_map_device(struct nbl_adapter *adapter)
{
  const struct rte_pci_device *pci_dev = adapter->pci_dev;
@@ -424,11 +431,12 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter)
  }

  NBL_LOG(DEBUG, "nbl vfio container %d", container);
- vfio_group_fd = rte_vfio_container_group_bind(container, common->iommu_group_num);
+ vfio_group_fd = nbl_open_group_fd(common->iommu_group_num);
  if (vfio_group_fd < 0) {
  NBL_LOG(ERR, "nbl vfio group bind failed, %d", vfio_group_fd);
  goto free_container;
  }
+ common->groupfd = vfio_group_fd;

  /* check if the group is viable */
  ret = ioctl(vfio_group_fd, VFIO_GROUP_GET_STATUS, &group_status);
@@ -535,7 +543,6 @@ static int nbl_mdev_map_device(struct nbl_adapter *adapter)
  }
free_group:
  close(vfio_group_fd);
- rte_vfio_clear_group(vfio_group_fd);
free_container:
  if (container_create)
  rte_vfio_container_destroy(container);
@@ -549,17 +556,14 @@ static int nbl_mdev_unmap_device(struct nbl_adapter *adapter)

  close(common->devfd);
  rte_mcfg_mem_read_lock();
- vfio_group_fd = rte_vfio_container_group_bind(nbl_default_container,
-            common->iommu_group_num);
+ vfio_group_fd = common->groupfd;
  NBL_LOG(DEBUG, "close vfio_group_fd %d", vfio_group_fd);
  ret = ioctl(vfio_group_fd, VFIO_GROUP_UNSET_CONTAINER, &nbl_default_container);
  if (ret)
  NBL_LOG(ERR, "unset container, error %i (%s) %d",
    errno, strerror(errno), ret);
  nbl_group_count--;
- ret = rte_vfio_container_group_unbind(nbl_default_container, common->iommu_group_num);
- if (ret)
-  NBL_LOG(ERR, "vfio container group unbind failed %d", ret);
+ close(vfio_group_fd);
  if (!nbl_group_count) {
  rte_mem_event_callback_unregister(NBL_USERDEV_EVENT_CLB_NAME, NULL);
  nbl_userdev_dma_free();
diff --git a/drivers/net/nbl/nbl_include/nbl_include.h b/drivers/net/nbl/nbl_include/nbl_include.h
index eeae6a3301..ba99b9f8e7 100644
--- a/drivers/net/nbl/nbl_include/nbl_include.h
+++ b/drivers/net/nbl/nbl_include/nbl_include.h
@@ -132,6 +132,7 @@ struct nbl_common_info {
  u16 vsi_id;
  u16 instance_id;
  int devfd;
+ int groupfd;
  int eventfd;
  int ifindex;
  int iommu_group_num;
--
2.47.3

本邮件所含信息及其任何附件为保密信息且可能属于专有信息。任何非指定接收人均无权访问本邮件。如果您不是该邮件的指定接收人,那么任何对本邮件内容进行披露,复制或使用的行为均是禁止的。如果您不是该邮件的指定接收人,请您立即通过邮件通知 compliance@nebula-matrix.com并立即删除您错误接受的邮件。
The information in this message and any attachments is confidential and may be privileged.  Access to this email by anyone other than the intended recipient is not authorized.  If you are not the intended recipient, disclosure, copying or use of the contents of this email is prohibited.  If you are not the intended recipient, please notify  compliance@nebula-matrix.com immediately by email, and please destroy the email you received in error.