mlx5 PMD supports probing a device where PF kernel netdevs
are part of a netdev bonding device in the Linux kernel.
In such scenario, there is only IB device exposed
which mlx5 PMD later uses to configure the device.
This IB device is created only one of the PFs.
PMD allowed probing this device by any of the PFs.
As part of the logic for allowing this, mlx5 common driver
checked if the name of IB device contained "bond", but this is not
always the case and depends on existence of specific udev rules.
This patch fixes that by attempting to resolve, through sysfs,
if any of the netdevs related to probed PCI device
are part of the bonding netdev, instead of relying on device name.
Fixes: f956d3d4c33c ("net/mlx5: fix probing with secondary bonding member")
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Dariusz Sosnowski <[email protected]>
---
drivers/common/mlx5/linux/mlx5_common_os.c | 86 ++++++++++++++++++++--
drivers/common/mlx5/linux/mlx5_common_os.h | 9 +++
2 files changed, 90 insertions(+), 5 deletions(-)
diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c
b/drivers/common/mlx5/linux/mlx5_common_os.c
index 926b56e419..fc7e9ecddc 100644
--- a/drivers/common/mlx5/linux/mlx5_common_os.c
+++ b/drivers/common/mlx5/linux/mlx5_common_os.c
@@ -560,6 +560,14 @@ mlx5_os_pd_prepare(struct mlx5_common_device *cdev)
#endif /* HAVE_IBV_FLOW_DV_SUPPORT */
}
+static bool
+pci_addr_partial_match(const struct rte_pci_addr *addr1, const struct
rte_pci_addr *addr2)
+{
+ return addr1->domain == addr2->domain &&
+ addr1->bus == addr2->bus &&
+ addr1->devid == addr2->devid;
+}
+
static struct ibv_device *
mlx5_os_get_ibv_device(const struct rte_pci_device *pci_dev)
{
@@ -581,17 +589,23 @@ mlx5_os_get_ibv_device(const struct rte_pci_device
*pci_dev)
}
ret1 = mlx5_get_device_guid(addr, guid1, sizeof(guid1));
while (n-- > 0) {
+ bool pci_partial_match;
+ bool guid_match;
+ bool bond_match;
+
DRV_LOG(DEBUG, "Checking device \"%s\"..", ibv_list[n]->name);
if (mlx5_get_pci_addr(ibv_list[n]->ibdev_path, &paddr) != 0)
continue;
if (ret1 > 0)
ret2 = mlx5_get_device_guid(&paddr, guid2,
sizeof(guid2));
+ guid_match = ret1 > 0 && ret2 > 0 && memcmp(guid1, guid2,
sizeof(guid1)) == 0;
+ pci_partial_match = pci_addr_partial_match(addr, &paddr);
/* Bond device can bond secondary PCIe */
- if ((strstr(ibv_list[n]->name, "bond") && !is_vf_dev &&
- ((ret1 > 0 && ret2 > 0 && !memcmp(guid1, guid2,
sizeof(guid1))) ||
- (addr->domain == paddr.domain && addr->bus == paddr.bus &&
- addr->devid == paddr.devid))) ||
- !rte_pci_addr_cmp(addr, &paddr)) {
+ bond_match = !is_vf_dev &&
+ mlx5_os_is_device_bond(ibv_list[n]) &&
+ (guid_match || pci_partial_match);
+ /* IB device matches either through bond or directly. */
+ if (bond_match || !rte_pci_addr_cmp(addr, &paddr)) {
ibv_match = ibv_list[n];
break;
}
@@ -1160,3 +1174,65 @@ mlx5_os_interrupt_handler_destroy(struct rte_intr_handle
*intr_handle,
mlx5_intr_callback_unregister(intr_handle, cb, cb_arg);
rte_intr_instance_free(intr_handle);
}
+
+RTE_EXPORT_INTERNAL_SYMBOL(mlx5_os_is_device_bond)
+bool
+mlx5_os_is_device_bond(const void *dev)
+{
+ const struct ibv_device *ibdev;
+ char path[PATH_MAX];
+ struct dirent *e;
+ DIR *net_dir;
+ bool result;
+ int ret;
+
+ if (dev == NULL)
+ return false;
+ ibdev = dev;
+
+ DRV_LOG(DEBUG, "Checking if %s ibdev belongs to bond", ibdev->name);
+
+ ret = snprintf(path, sizeof(path), "%s/device/net", ibdev->ibdev_path);
+ if (ret < 0 || ret >= (int)sizeof(path)) {
+ DRV_LOG(DEBUG, "Unable to get netdevs path for IB device %s",
ibdev->name);
+ return false;
+ }
+
+ net_dir = opendir(path);
+ if (net_dir == NULL) {
+ DRV_LOG(DEBUG, "Unable to open directory %s (%s)", path,
rte_strerror(errno));
+ return false;
+ }
+
+ result = false;
+ while ((e = readdir(net_dir)) != NULL) {
+ if (e->d_name[0] == '.')
+ continue;
+
+ DRV_LOG(DEBUG, "Checking if %s netdev related to %s ibdev
belongs to bond",
+ e->d_name, ibdev->name);
+
+ ret = snprintf(path, sizeof(path),
"/sys/class/net/%s/master/bonding", e->d_name);
+ if (ret < 0 || ret >= (int)sizeof(path)) {
+ DRV_LOG(DEBUG, "Unable to get bond path for %s netdev",
e->d_name);
+ continue;
+ }
+
+ if (access(path, F_OK) == 0) {
+ /* At least one associated netdev is part of a bond. */
+ DRV_LOG(DEBUG, "Bonding path exists for %s netdev",
e->d_name);
+ result = true;
+ goto end;
+ }
+
+ DRV_LOG(DEBUG, "Unable to access bond path for %s netdev (%s)",
+ e->d_name, rte_strerror(errno));
+ }
+
+ DRV_LOG(DEBUG, "No bonded netdev related to %s ibdev found",
+ ibdev->name);
+
+end:
+ closedir(net_dir);
+ return result;
+}
diff --git a/drivers/common/mlx5/linux/mlx5_common_os.h
b/drivers/common/mlx5/linux/mlx5_common_os.h
index 2e2c54f1fa..7d4e3c5fe8 100644
--- a/drivers/common/mlx5/linux/mlx5_common_os.h
+++ b/drivers/common/mlx5/linux/mlx5_common_os.h
@@ -317,4 +317,13 @@ void
mlx5_os_interrupt_handler_destroy(struct rte_intr_handle *intr_handle,
rte_intr_callback_fn cb, void *cb_arg);
+/**
+ * Return true if given IB device is associated with a networking bond.
+ *
+ * @param dev[in]
+ * Pointer to IB device.
+ */
+__rte_internal
+bool mlx5_os_is_device_bond(const void *dev);
+
#endif /* RTE_PMD_MLX5_COMMON_OS_H_ */
--
2.47.3