Skip to content

Commit 367bad7

Browse files
longlimsftgregkh
authored andcommitted
net: mana: Change the function signature of mana_get_primary_netdev_rcu
commit a8445cf upstream. 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 <longli@microsoft.com> Link: https://patch.msgid.link/1741821332-9392-1-git-send-email-longli@linuxonhyperv.com Signed-off-by: Leon Romanovsky <leon@kernel.org> Fixes: 1df03a4 ("RDMA/mana_ib: Set correct device into ib") Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 40daf04 commit 367bad7

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
@@ -84,18 +84,17 @@ static int mana_ib_probe(struct auxiliary_device *adev,
8484
dev->ib_dev.num_comp_vectors = mdev->gdma_context->max_num_queues;
8585
dev->ib_dev.dev.parent = mdev->gdma_context->dev;
8686

87-
rcu_read_lock(); /* required to get primary netdev */
88-
ndev = mana_get_primary_netdev_rcu(mc, 0);
87+
ndev = mana_get_primary_netdev(mc, 0, &dev->dev_tracker);
8988
if (!ndev) {
90-
rcu_read_unlock();
9189
ret = -ENODEV;
9290
ibdev_err(&dev->ib_dev, "Failed to get netdev for IB port 1");
9391
goto free_ib_device;
9492
}
9593
ether_addr_copy(mac_addr, ndev->dev_addr);
9694
addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, ndev->dev_addr);
9795
ret = ib_device_set_netdev(&dev->ib_dev, ndev, 1);
98-
rcu_read_unlock();
96+
/* mana_get_primary_netdev() returns ndev with refcount held */
97+
netdev_put(ndev, &dev->dev_tracker);
9998
if (ret) {
10099
ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
101100
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
@@ -64,6 +64,7 @@ struct mana_ib_dev {
6464
struct gdma_queue **eqs;
6565
struct xarray qp_table_wq;
6666
struct mana_ib_adapter_caps adapter_caps;
67+
netdevice_tracker dev_tracker;
6768
};
6869

6970
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
@@ -3000,21 +3000,27 @@ void mana_remove(struct gdma_dev *gd, bool suspending)
30003000
kfree(ac);
30013001
}
30023002

3003-
struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index)
3003+
struct net_device *mana_get_primary_netdev(struct mana_context *ac,
3004+
u32 port_index,
3005+
netdevice_tracker *tracker)
30043006
{
30053007
struct net_device *ndev;
30063008

3007-
RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
3008-
"Taking primary netdev without holding the RCU read lock");
30093009
if (port_index >= ac->num_ports)
30103010
return NULL;
30113011

3012-
/* When mana is used in netvsc, the upper netdevice should be returned. */
3013-
if (ac->ports[port_index]->flags & IFF_SLAVE)
3014-
ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]);
3015-
else
3012+
rcu_read_lock();
3013+
3014+
/* If mana is used in netvsc, the upper netdevice should be returned. */
3015+
ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]);
3016+
3017+
/* If there is no upper device, use the parent Ethernet device */
3018+
if (!ndev)
30163019
ndev = ac->ports[port_index];
30173020

3021+
netdev_hold(ndev, tracker, GFP_ATOMIC);
3022+
rcu_read_unlock();
3023+
30183024
return ndev;
30193025
}
3020-
EXPORT_SYMBOL_NS(mana_get_primary_netdev_rcu, NET_MANA);
3026+
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
@@ -819,5 +819,7 @@ int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id,
819819
u32 doorbell_pg_id);
820820
void mana_uncfg_vport(struct mana_port_context *apc);
821821

822-
struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index);
822+
struct net_device *mana_get_primary_netdev(struct mana_context *ac,
823+
u32 port_index,
824+
netdevice_tracker *tracker);
823825
#endif /* _MANA_H */

0 commit comments

Comments
 (0)