Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/cma: Use rdma_read_gid_attr_ndev_rcu to access netdev

To access the netdevice of the GID attribute, use an existing API
rdma_read_gid_attr_ndev_rcu().

This further reduces dependency on open access to netdevice of GID
attribute.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

authored by

Parav Pandit and committed by
Jason Gunthorpe
adb4a57a a70c0739

+13 -2
+1
drivers/infiniband/core/addr.c
··· 45 45 #include <net/addrconf.h> 46 46 #include <net/ip6_route.h> 47 47 #include <rdma/ib_addr.h> 48 + #include <rdma/ib_cache.h> 48 49 #include <rdma/ib_sa.h> 49 50 #include <rdma/ib.h> 50 51 #include <rdma/rdma_netlink.h>
+1
drivers/infiniband/core/cache.c
··· 1249 1249 read_unlock_irqrestore(&table->rwlock, flags); 1250 1250 return ndev; 1251 1251 } 1252 + EXPORT_SYMBOL(rdma_read_gid_attr_ndev_rcu); 1252 1253 1253 1254 static int get_lower_dev_vlan(struct net_device *lower_dev, void *data) 1254 1255 {
+10 -2
drivers/infiniband/core/cma.c
··· 1486 1486 roce_get_net_dev_by_cm_event(const struct ib_cm_event *ib_event) 1487 1487 { 1488 1488 const struct ib_gid_attr *sgid_attr = NULL; 1489 + struct net_device *ndev; 1489 1490 1490 1491 if (ib_event->event == IB_CM_REQ_RECEIVED) 1491 1492 sgid_attr = ib_event->param.req_rcvd.ppath_sgid_attr; ··· 1495 1494 1496 1495 if (!sgid_attr) 1497 1496 return NULL; 1498 - dev_hold(sgid_attr->ndev); 1499 - return sgid_attr->ndev; 1497 + 1498 + rcu_read_lock(); 1499 + ndev = rdma_read_gid_attr_ndev_rcu(sgid_attr); 1500 + if (IS_ERR(ndev)) 1501 + ndev = NULL; 1502 + else 1503 + dev_hold(ndev); 1504 + rcu_read_unlock(); 1505 + return ndev; 1500 1506 } 1501 1507 1502 1508 static struct net_device *cma_get_net_dev(const struct ib_cm_event *ib_event,
+1
include/rdma/ib_cache.h
··· 56 56 57 57 int rdma_read_gid_l2_fields(const struct ib_gid_attr *attr, 58 58 u16 *vlan_id, u8 *smac); 59 + struct net_device *rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr); 59 60 60 61 /** 61 62 * ib_get_cached_pkey - Returns a cached PKey table entry