Skip to contentSkip to conversation

RDMA/nldev: Add support for reporting ipoib netdev

PATCH In review Kamal Heib 3 participants 3 messages Sep 15, 2023 – Sep 18, 2023 InfiniBand

lore
Share & tools
lore

Kamal Heib

author
#0 lore raw

PATCH 1/1 RDMA/nldev: Add support for reporting ipoib netdev

This patch adds support for reporting the ipoib net device for a given RDMA device by calling ib_get_net_dev_by_params() when filling the port's info.

$ rdma link show mlx5_0/1
link mlx5_0/1 subnet_prefix fe80:0000:0000:0000 lid 66 sm_lid 3 lmc 0
	state ACTIVE physical_state LINK_UP netdev ibp196s0f0

---
v1: Check namespace and query pkey.

---
 drivers/infiniband/core/nldev.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/infiniband/core/nldev.c +26 -1
index d5d3e4f0de77..f3fa8143cdc7 100644
@@ -308,10 +308,12 @@ static int fill_port_info(struct sk_buff *msg,
 			  struct ib_device *device, u32 port,
 			  const struct net *net)
 {
+	struct net_device *ipoib_netdev = NULL;
 	struct net_device *netdev = NULL;
 	struct ib_port_attr attr;
-	int ret;
 	u64 cap_flags = 0;
+	u16 pkey;
+	int ret;
 
 	if (fill_nldev_handle(msg, device))
 		return -EMSGSIZE;
@@ -340,6 +342,26 @@ static int fill_port_info(struct sk_buff *msg,
 			return -EMSGSIZE;
 		if (nla_put_u8(msg, RDMA_NLDEV_ATTR_LMC, attr.lmc))
 			return -EMSGSIZE;
+
+		ret = ib_query_pkey(device, port, 0, &pkey);
+		if (ret)
+			goto out;
+
+		ipoib_netdev = ib_get_net_dev_by_params(device, port,
+							pkey,
+							NULL, NULL);
+		if (ipoib_netdev && net_eq(dev_net(ipoib_netdev), net)) {
+			ret = nla_put_u32(msg,
+					  RDMA_NLDEV_ATTR_NDEV_INDEX,
+					  ipoib_netdev->ifindex);
+			if (ret)
+				goto out;
+			ret = nla_put_string(msg,
+					     RDMA_NLDEV_ATTR_NDEV_NAME,
+					     ipoib_netdev->name);
+			if (ret)
+				goto out;
+		}
 	}
 	if (nla_put_u8(msg, RDMA_NLDEV_ATTR_PORT_STATE, attr.state))
 		return -EMSGSIZE;
@@ -357,6 +379,9 @@ static int fill_port_info(struct sk_buff *msg,
 	}
 
 out:
+	if (ipoib_netdev)
+		dev_put(ipoib_netdev);
+
 	if (netdev)
 		dev_put(netdev);
 	return ret;
Signature · 1 line
2.41.0
#1 lore raw
Quoted 50 lines · Kamal Heib

This patch adds support for reporting the ipoib net device for a given RDMA device by calling ib_get_net_dev_by_params() when filling the port's info.

$ rdma link show mlx5_0/1
link mlx5_0/1 subnet_prefix fe80:0000:0000:0000 lid 66 sm_lid 3 lmc 0
	state ACTIVE physical_state LINK_UP netdev ibp196s0f0

---
v1: Check namespace and query pkey.

---
 drivers/infiniband/core/nldev.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/infiniband/core/nldev.c +16 -1
index d5d3e4f0de77..f3fa8143cdc7 100644
@@ -308,10 +308,12 @@ static int fill_port_info(struct sk_buff *msg,
 			  struct ib_device *device, u32 port,
 			  const struct net *net)
 {
+	struct net_device *ipoib_netdev = NULL;
 	struct net_device *netdev = NULL;
 	struct ib_port_attr attr;
-	int ret;
 	u64 cap_flags = 0;
+	u16 pkey;
+	int ret;
 
 	if (fill_nldev_handle(msg, device))
 		return -EMSGSIZE;
@@ -340,6 +342,26 @@ static int fill_port_info(struct sk_buff *msg,
 			return -EMSGSIZE;
 		if (nla_put_u8(msg, RDMA_NLDEV_ATTR_LMC, attr.lmc))
 			return -EMSGSIZE;
+
+		ret = ib_query_pkey(device, port, 0, &pkey);
+		if (ret)
+			goto out;
+
+		ipoib_netdev = ib_get_net_dev_by_params(device, port,
+							pkey,
+							NULL, NULL);
+		if (ipoib_netdev && net_eq(dev_net(ipoib_netdev), net)) {
+			ret = nla_put_u32(msg,
+					  RDMA_NLDEV_ATTR_NDEV_INDEX,
+					  ipoib_netdev->ifindex);
+			if (ret)

drivers/infiniband/core/nldev.c static int fill_port_info(struct sk_buff *msg, · line 367

Quoted 10 lines
drivers/infiniband/core/nldev.c +7 -0
+				goto out;
+			ret = nla_put_string(msg,
+					     RDMA_NLDEV_ATTR_NDEV_NAME,
+					     ipoib_netdev->name);
+			if (ret)
+				goto out;
+		}
 	}
 	if (nla_put_u8(msg, RDMA_NLDEV_ATTR_PORT_STATE, attr.state))
 		return -EMSGSIZE;

You will leak ipoib_netdev here, need to change return to be "goto out".

Thanks

Quoted 13 lines
drivers/infiniband/core/nldev.c +3 -0
@@ -357,6 +379,9 @@ static int fill_port_info(struct sk_buff *msg,
 	}
 
 out:
+	if (ipoib_netdev)
+		dev_put(ipoib_netdev);
+
 	if (netdev)
 		dev_put(netdev);
 	return ret;
Signature · 1 line
2.41.0
#2 lore raw
In reply to Kamal Heib
Quoted 34 lines · Kamal Heib

This patch adds support for reporting the ipoib net device for a given RDMA device by calling ib_get_net_dev_by_params() when filling the port's info.

$ rdma link show mlx5_0/1
link mlx5_0/1 subnet_prefix fe80:0000:0000:0000 lid 66 sm_lid 3 lmc 0
	state ACTIVE physical_state LINK_UP netdev ibp196s0f0

---
v1: Check namespace and query pkey.

---
 drivers/infiniband/core/nldev.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/infiniband/core/nldev.c +3 -1
index d5d3e4f0de77..f3fa8143cdc7 100644
@@ -308,10 +308,12 @@ static int fill_port_info(struct sk_buff *msg,
 			  struct ib_device *device, u32 port,
 			  const struct net *net)
 {
+	struct net_device *ipoib_netdev = NULL;
 	struct net_device *netdev = NULL;
 	struct ib_port_attr attr;
-	int ret;
 	u64 cap_flags = 0;
+	u16 pkey;
+	int ret;
 
 	if (fill_nldev_handle(msg, device))
 		return -EMSGSIZE;

drivers/infiniband/core/nldev.c static int fill_port_info(struct sk_buff *msg, · line 348

Quoted 7 lines
drivers/infiniband/core/nldev.c +4 -0
@@ -340,6 +342,26 @@ static int fill_port_info(struct sk_buff *msg,
 			return -EMSGSIZE;
 		if (nla_put_u8(msg, RDMA_NLDEV_ATTR_LMC, attr.lmc))
 			return -EMSGSIZE;
+
+		ret = ib_query_pkey(device, port, 0, &pkey);
+		if (ret)
+			goto out;

That doesn't really make any sense..

The whole idea there is only one ipoib device doesn't even make sense.

I still don't like this at all.

Quoted 5 lines
drivers/infiniband/core/nldev.c +5 -0
+
+		ipoib_netdev = ib_get_net_dev_by_params(device, port,
+							pkey,
+							NULL, NULL);
+		if (ipoib_netdev && net_eq(dev_net(ipoib_netdev), net)) {

drivers/infiniband/core/nldev.c static int fill_port_info(struct sk_buff *msg, · line 363

Quoted 10 lines
drivers/infiniband/core/nldev.c +10 -0
+			ret = nla_put_u32(msg,
+					  RDMA_NLDEV_ATTR_NDEV_INDEX,
+					  ipoib_netdev->ifindex);
+			if (ret)
+				goto out;
+			ret = nla_put_string(msg,
+					     RDMA_NLDEV_ATTR_NDEV_NAME,
+					     ipoib_netdev->name);
+			if (ret)
+				goto out;

and I don't think the existing netlink attributes should be redefined to be about ipoib

Jason