IB/core: Namespace is a mandatory input parameter for address resolution
Subsystems (2)
PATCH 1/2 IB/core: Namespace is a mandatory input parameter for address resolution
From: Moni Shoua <[email protected]>
In function addr_resolve() the namespace is a required input parameter and not an output. It is passed later for searching the routing table and device addresses. Also, it shouldn't be copied back to the caller.
--- drivers/infiniband/core/addr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/infiniband/core/addr.c +5 -1
@@ -518,6 +518,11 @@ static int addr_resolve(struct sockaddr *src_in,struct dst_entry *dst;int ret; +if (!addr->net) { +pr_warn_ratelimited ("%s: missing namespace\n" , __func__); +return -EINVAL ; + } +if (src_in->sa_family ==AF_INET ) {struct rtable *rt =NULL ; const struct sockaddr_in *dst_in4 =
@@ -555,7 +560,6 @@ static int addr_resolve(struct sockaddr *src_in, } addr->bound_dev_if = ndev->ifindex; - addr->net =dev_net (ndev);dev_put (ndev);return ret;
Signature · 1 line
2.12.2
PATCH 2/2 IB/core: Don't resolve IP address to the loopback device
In reply to a message not in the archiveFrom: Moni Shoua <monis-VPRAkNaXOzVWk0Htik3J/[email protected]>
When resolving an IP address that is on the host of the caller the result from querying the routing table is the loopback device. This is not a valid response, because it doesn't represent the RDMA device and the port.
Therefore, callers need to check the resolved device and if it is a loopback device find an alternative way to resolve it. To avoid this we make sure that the response from rdma_resolve_ip() will not be the loopback device.
While that, we fix an static checker warning about dereferencing an unintitialized pointer using the same solution as in commit abeffce90c7f ("net/mlx5e: Fix a -Wmaybe-uninitialized warning") as a reference.
--- drivers/infiniband/core/addr.c | 40 +++++++++++++++++++++++++++++----------- drivers/infiniband/core/cma.c | 32 +++----------------------------- drivers/infiniband/core/verbs.c | 5 ----- 3 files changed, 32 insertions(+), 45 deletions(-)
drivers/infiniband/core/addr.c +29 -11
@@ -269,6 +269,7 @@ int rdma_translate_ip(const struct sockaddr *addr,return ret; ret =rdma_copy_addr (dev_addr, dev,NULL ); + dev_addr->bound_dev_if = dev->ifindex;if (vlan_id) *vlan_id =rdma_vlan_dev_vlan_id (dev);dev_put (dev);
@@ -281,6 +282,7 @@ int rdma_translate_ip(const struct sockaddr *addr, &((const struct sockaddr_in6 *)addr)->sin6_addr, dev, 1)) { ret =rdma_copy_addr (dev_addr, dev,NULL ); + dev_addr->bound_dev_if = dev->ifindex;if (vlan_id) *vlan_id =rdma_vlan_dev_vlan_id (dev);break ;
@@ -406,10 +408,10 @@ static int addr4_resolve(struct sockaddr_in *src_in, fl4.saddr = src_ip; fl4.flowi4_oif = addr->bound_dev_if; rt =ip_route_output_key (addr->net, &fl4); -if (IS_ERR (rt)) { - ret =PTR_ERR (rt); - goto out; - } + ret =PTR_ERR_OR_ZERO (rt); +if (ret) +return ret; + src_in->sin_family =AF_INET ; src_in->sin_addr.s_addr = fl4.saddr;
@@ -424,8 +426,6 @@ static int addr4_resolve(struct sockaddr_in *src_in, *prt = rt;return 0 ; -out: -return ret; }#if IS_ENABLED (CONFIG_IPV6 )
@@ -536,8 +536,12 @@ static int addr_resolve(struct sockaddr *src_in,if (resolve_neigh) ret =addr_resolve_neigh (&rt->dst, dst_in, addr, seq); - ndev = rt->dst.dev; -dev_hold (ndev); +if (addr->bound_dev_if) { + ndev =dev_get_by_index (addr->net, addr->bound_dev_if); + }else { + ndev = rt->dst.dev; +dev_hold (ndev); + }ip_rt_put (rt); }else {
@@ -553,13 +557,27 @@ static int addr_resolve(struct sockaddr *src_in,if (resolve_neigh) ret =addr_resolve_neigh (dst, dst_in, addr, seq); - ndev = dst->dev; -dev_hold (ndev); +if (addr->bound_dev_if) { + ndev =dev_get_by_index (addr->net, addr->bound_dev_if); + }else { + ndev = dst->dev; +dev_hold (ndev); + }dst_release (dst); } - addr->bound_dev_if = ndev->ifindex; +if (ndev->flags &IFF_LOOPBACK ) { + ret =rdma_translate_ip (dst_in, addr,NULL ); +/* +* Put the loopback device and get the translated +* device instead. +*/ +dev_put (ndev); + ndev =dev_get_by_index (addr->net, addr->bound_dev_if); + }else { + addr->bound_dev_if = ndev->ifindex; + }dev_put (ndev);return ret;
drivers/infiniband/core/cma.c +3 -29
@@ -623,22 +623,11 @@ static inline int cma_validate_port(struct ib_device *device, u8 port,if ((dev_type !=ARPHRD_INFINIBAND ) &&rdma_protocol_ib (device, port))return ret; -if (dev_type ==ARPHRD_ETHER &&rdma_protocol_roce (device, port)) { +if (dev_type ==ARPHRD_ETHER &&rdma_protocol_roce (device, port)) ndev =dev_get_by_index (&init_net, bound_if_index); -if (ndev && ndev->flags &IFF_LOOPBACK ) { -pr_info ("detected loopback device\n" ); -dev_put (ndev); - -if (!device->get_netdev) -return -EOPNOTSUPP ; - - ndev = device->get_netdev (device, port); -if (!ndev) -return -ENODEV ; - } - }else { +else gid_type =IB_GID_TYPE_IB ; - } + ret =ib_find_cached_gid_by_port (device, gid, gid_type, port, ndev,NULL );
@@ -2570,21 +2559,6 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) goto err2; } -if (ndev->flags &IFF_LOOPBACK ) { -dev_put (ndev); -if (!id_priv->id.device->get_netdev) { - ret = -EOPNOTSUPP ; - goto err2; - } - - ndev = id_priv->id.device->get_netdev (id_priv->id.device, - id_priv->id.port_num); -if (!ndev) { - ret = -ENODEV ; - goto err2; - } - } - supported_gids =roce_gid_type_mask_support (id_priv->id.device, id_priv->id.port_num); gid_type = cma_route_gid_type(addr->dev_addr.network,
drivers/infiniband/core/verbs.c +0 -5
@@ -506,11 +506,6 @@ int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, } resolved_dev =dev_get_by_index (&init_net, if_index); -if (resolved_dev->flags &IFF_LOOPBACK ) { -dev_put (resolved_dev); - resolved_dev = idev; -dev_hold (resolved_dev); - }rcu_read_lock ();if (resolved_dev != idev && !rdma_is_upper_dev_rcu (idev, resolved_dev))
Signature · 6 lines
2.12.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Leon Romanovsky
From: Moni Shoua <monis-VPRAkNaXOzVWk0Htik3J/[email protected]>
In function
addr_resolve()the namespace is a required input parameter and not an output. It is passed later for searching the routing table and device addresses. Also, it shouldn't be copied back to the caller.Fixes 565edd1d5555 ('IB/addr: Pass network namespace as a parameter')Cc <[email protected]> # v4.3+Signed-off-by Leon Romanovsky <[email protected]>
This series has been accepted into 4.13-rc, thanks.
Signature · 3 lines
Doug Ledford <[email protected]> GPG Key ID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD