Skip to content

Commit a8445cf

Browse files
longlimsftrleon
authored andcommitted
net: mana: Change the function signature of mana_get_primary_netdev_rcu
Change mana_get_primary_netdev_rcu() to mana_get_primary_netdev(), and return the ndev with refcount held. The caller is responsible for dropping the refcount. Also drop the check for IFF_SLAVE as it is not necessary if the upper device is present. Signed-off-by: Long Li <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 0a924de commit a8445cf

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

drivers/infiniband/hw/mana/device.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,17 @@ static int mana_ib_probe(struct auxiliary_device *adev,
9898
dev->ib_dev.num_comp_vectors = mdev->gdma_context->max_num_queues;
9999
dev->ib_dev.dev.parent = mdev->gdma_context->dev;
100100

101-
rcu_read_lock(); /* required to get primary netdev */
102-
ndev = mana_get_primary_netdev_rcu(mc, 0);
101+
ndev = mana_get_primary_netdev(mc, 0, &dev->dev_tracker);
103102
if (!ndev) {
104-
rcu_read_unlock();
105103
ret = -ENODEV;
106104
ibdev_err(&dev->ib_dev, "Failed to get netdev for IB port 1");
107105
goto free_ib_device;
108106
}
109107
ether_addr_copy(mac_addr, ndev->dev_addr);
110108
addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, ndev->dev_addr);
111109
ret = ib_device_set_netdev(&dev->ib_dev, ndev, 1);
112-
rcu_read_unlock();
110+
/* mana_get_primary_netdev() returns ndev with refcount held */
111+
netdev_put(ndev, &dev->dev_tracker);
113112
if (ret) {
114113
ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
115114
goto free_ib_device;

drivers/infiniband/hw/mana/mana_ib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct mana_ib_dev {
7878
struct xarray qp_table_wq;
7979
struct mana_ib_adapter_caps adapter_caps;
8080
struct dma_pool *av_pool;
81+
netdevice_tracker dev_tracker;
8182
};
8283

8384
struct mana_ib_wq {

drivers/net/ethernet/microsoft/mana/mana_en.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,21 +3131,27 @@ void mana_remove(struct gdma_dev *gd, bool suspending)
31313131
kfree(ac);
31323132
}
31333133

3134-
struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index)
3134+
struct net_device *mana_get_primary_netdev(struct mana_context *ac,
3135+
u32 port_index,
3136+
netdevice_tracker *tracker)
31353137
{
31363138
struct net_device *ndev;
31373139

3138-
RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
3139-
"Taking primary netdev without holding the RCU read lock");
31403140
if (port_index >= ac->num_ports)
31413141
return NULL;
31423142

3143-
/* When mana is used in netvsc, the upper netdevice should be returned. */
3144-
if (ac->ports[port_index]->flags & IFF_SLAVE)
3145-
ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]);
3146-
else
3143+
rcu_read_lock();
3144+
3145+
/* If mana is used in netvsc, the upper netdevice should be returned. */
3146+
ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]);
3147+
3148+
/* If there is no upper device, use the parent Ethernet device */
3149+
if (!ndev)
31473150
ndev = ac->ports[port_index];
31483151

3152+
netdev_hold(ndev, tracker, GFP_ATOMIC);
3153+
rcu_read_unlock();
3154+
31493155
return ndev;
31503156
}
3151-
EXPORT_SYMBOL_NS(mana_get_primary_netdev_rcu, "NET_MANA");
3157+
EXPORT_SYMBOL_NS(mana_get_primary_netdev, "NET_MANA");

include/net/mana/mana.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,5 +827,7 @@ int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id,
827827
u32 doorbell_pg_id);
828828
void mana_uncfg_vport(struct mana_port_context *apc);
829829

830-
struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index);
830+
struct net_device *mana_get_primary_netdev(struct mana_context *ac,
831+
u32 port_index,
832+
netdevice_tracker *tracker);
831833
#endif /* _MANA_H */

0 commit comments

Comments
 (0)