Skip to contentSkip to conversation

RDMA/core: Fix ENODEV error for iWARP test over vlan

PATCH In review Anumula Murali Mohan Reddy 3 participants 3 messages Nov 19, 2024 – Nov 25, 2024 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/core: Fix ENODEV error for iWARP test over vlan

If traffic is over vlan, cma_validate_port() fails to match net_device ifindex with bound_if_index and results in ENODEV error. As iWARP gid table is static, it contains entry corresponding to only one net device which is either real netdev or vlan netdev for cases like siw attached to a vlan interface.
This patch fixes the issue by assigning bound_if_index with net device index, if real net device obtained from bound if index matches with net device retrieved from gid table

Fixes f8ef1be816bf ("RDMA/cma: Avoid GID lookups on iWARP devices")
---
 drivers/infiniband/core/cma.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/infiniband/core/cma.c +16 -1
index 64ace0b968f0..97657e1810d8 100644
@@ -689,7 +689,7 @@ cma_validate_port(struct ib_device *device, u32 port,
 	const struct ib_gid_attr *sgid_attr = ERR_PTR(-ENODEV);
 	int bound_if_index = dev_addr->bound_dev_if;
 	int dev_type = dev_addr->dev_type;
-	struct net_device *ndev = NULL;
+	struct net_device *ndev = NULL, *pdev = NULL;
 
 	if (!rdma_dev_access_netns(device, id_priv->id.route.addr.dev_addr.net))
 		goto out;
@@ -714,6 +714,21 @@ cma_validate_port(struct ib_device *device, u32 port,
 
 		rcu_read_lock();
 		ndev = rcu_dereference(sgid_attr->ndev);
+		if (ndev->ifindex != bound_if_index) {
+			pdev = dev_get_by_index_rcu(dev_addr->net, bound_if_index);
+			if (pdev) {
+				if (is_vlan_dev(pdev)) {
+					pdev = vlan_dev_real_dev(pdev);
+					if (ndev->ifindex == pdev->ifindex)
+						bound_if_index = pdev->ifindex;
+				}
+				if (is_vlan_dev(ndev)) {
+					pdev = vlan_dev_real_dev(ndev);
+					if (bound_if_index == pdev->ifindex)
+						bound_if_index = ndev->ifindex;
+				}
+			}
+		}
 		if (!net_eq(dev_net(ndev), dev_addr->net) ||
 		    ndev->ifindex != bound_if_index) {
 			rdma_put_gid_attr(sgid_attr);
Signature · 1 line
2.39.3
#1 lore raw
Quoted 22 lines · Anumula Murali Mohan Reddy

If traffic is over vlan, cma_validate_port() fails to match net_device ifindex with bound_if_index and results in ENODEV error. As iWARP gid table is static, it contains entry corresponding to only one net device which is either real netdev or vlan netdev for cases like siw attached to a vlan interface.
This patch fixes the issue by assigning bound_if_index with net device index, if real net device obtained from bound if index matches with net device retrieved from gid table

Fixes f8ef1be816bf ("RDMA/cma: Avoid GID lookups on iWARP devices")
---
  drivers/infiniband/core/cma.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
drivers/infiniband/core/cma.c +0 -0
index 64ace0b968f0..97657e1810d8 100644

drivers/infiniband/core/cma.c cma_validate_port(struct ib_device *device, u32 port, · line 692

Quoted 5 lines
drivers/infiniband/core/cma.c +1 -1
@@ -689,7 +689,7 @@ cma_validate_port(struct ib_device *device, u32 port,
  	const struct ib_gid_attr *sgid_attr = ERR_PTR(-ENODEV);
  	int bound_if_index = dev_addr->bound_dev_if;
  	int dev_type = dev_addr->dev_type;
-	struct net_device *ndev = NULL;
+	struct net_device *ndev = NULL, *pdev = NULL;

In the original source code, the local variables lay out in the form of Reverse Christmas Tree. But the new code breaks the rule of Reverse Christmas Tree.

Zhu Yanjun

Quoted 25 lines
drivers/infiniband/core/cma.c +15 -0
  	if (!rdma_dev_access_netns(device, id_priv->id.route.addr.dev_addr.net))
  		goto out;
@@ -714,6 +714,21 @@ cma_validate_port(struct ib_device *device, u32 port,
 
  		rcu_read_lock();
  		ndev = rcu_dereference(sgid_attr->ndev);
+		if (ndev->ifindex != bound_if_index) {
+			pdev = dev_get_by_index_rcu(dev_addr->net, bound_if_index);
+			if (pdev) {
+				if (is_vlan_dev(pdev)) {
+					pdev = vlan_dev_real_dev(pdev);
+					if (ndev->ifindex == pdev->ifindex)
+						bound_if_index = pdev->ifindex;
+				}
+				if (is_vlan_dev(ndev)) {
+					pdev = vlan_dev_real_dev(ndev);
+					if (bound_if_index == pdev->ifindex)
+						bound_if_index = ndev->ifindex;
+				}
+			}
+		}
  		if (!net_eq(dev_net(ndev), dev_addr->net) ||
  		    ndev->ifindex != bound_if_index) {
  			rdma_put_gid_attr(sgid_attr);
maintainer
#2 lore raw
Quoted 18 lines · Zhu Yanjun
Quoted 17 lines · Anumula Murali Mohan Reddy

If traffic is over vlan, cma_validate_port() fails to match net_device ifindex with bound_if_index and results in ENODEV error. As iWARP gid table is static, it contains entry corresponding to only one net device which is either real netdev or vlan netdev for cases like siw attached to a vlan interface.
This patch fixes the issue by assigning bound_if_index with net device index, if real net device obtained from bound if index matches with net device retrieved from gid table

Fixes f8ef1be816bf ("RDMA/cma: Avoid GID lookups on iWARP devices")
---
  drivers/infiniband/core/cma.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/infiniband/core/cma.c cma_validate_port(struct ib_device *device, u32 port, · line 692

Quoted 10 lines
drivers/infiniband/core/cma.c +1 -1
index 64ace0b968f0..97657e1810d8 100644
@@ -689,7 +689,7 @@ cma_validate_port(struct ib_device *device, u32 port,
  	const struct ib_gid_attr *sgid_attr = ERR_PTR(-ENODEV);
  	int bound_if_index = dev_addr->bound_dev_if;
  	int dev_type = dev_addr->dev_type;
-	struct net_device *ndev = NULL;
+	struct net_device *ndev = NULL, *pdev = NULL;

In the original source code, the local variables lay out in the form of Reverse Christmas Tree.
But the new code breaks the rule of Reverse Christmas Tree.

There is no such rule outside of netdev world. I suggest to everyone in RDMA to stick to that practice as sometimes we need to send the code to netdev too and it is much easier to keep their coding style from the beginning.

However, for pure RDMA patches, we don't care.

Thanks

Quoted 28 lines

Zhu Yanjun

Quoted 23 lines
drivers/infiniband/core/cma.c +15 -0
  	if (!rdma_dev_access_netns(device, id_priv->id.route.addr.dev_addr.net))
  		goto out;
@@ -714,6 +714,21 @@ cma_validate_port(struct ib_device *device, u32 port,
  		rcu_read_lock();
  		ndev = rcu_dereference(sgid_attr->ndev);
+		if (ndev->ifindex != bound_if_index) {
+			pdev = dev_get_by_index_rcu(dev_addr->net, bound_if_index);
+			if (pdev) {
+				if (is_vlan_dev(pdev)) {
+					pdev = vlan_dev_real_dev(pdev);
+					if (ndev->ifindex == pdev->ifindex)
+						bound_if_index = pdev->ifindex;
+				}
+				if (is_vlan_dev(ndev)) {
+					pdev = vlan_dev_real_dev(ndev);
+					if (bound_if_index == pdev->ifindex)
+						bound_if_index = ndev->ifindex;
+				}
+			}
+		}
  		if (!net_eq(dev_net(ndev), dev_addr->net) ||
  		    ndev->ifindex != bound_if_index) {
  			rdma_put_gid_attr(sgid_attr);