]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: mana: Change the function signature of mana_get_primary_netdev_rcu
authorLong Li <longli@microsoft.com>
Wed, 12 Mar 2025 23:15:31 +0000 (16:15 -0700)
committerLeon Romanovsky <leon@kernel.org>
Thu, 13 Mar 2025 12:03:02 +0000 (08:03 -0400)
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>
drivers/infiniband/hw/mana/device.c
drivers/infiniband/hw/mana/mana_ib.h
drivers/net/ethernet/microsoft/mana/mana_en.c
include/net/mana/mana.h

index d1a02c54a236f99ab4699246dcc8a22290c40cfc..9357a9845c2ca6b81c9120aeb094a8078ee137ca 100644 (file)
@@ -98,10 +98,8 @@ static int mana_ib_probe(struct auxiliary_device *adev,
        dev->ib_dev.num_comp_vectors = mdev->gdma_context->max_num_queues;
        dev->ib_dev.dev.parent = mdev->gdma_context->dev;
 
-       rcu_read_lock(); /* required to get primary netdev */
-       ndev = mana_get_primary_netdev_rcu(mc, 0);
+       ndev = mana_get_primary_netdev(mc, 0, &dev->dev_tracker);
        if (!ndev) {
-               rcu_read_unlock();
                ret = -ENODEV;
                ibdev_err(&dev->ib_dev, "Failed to get netdev for IB port 1");
                goto free_ib_device;
@@ -109,7 +107,8 @@ static int mana_ib_probe(struct auxiliary_device *adev,
        ether_addr_copy(mac_addr, ndev->dev_addr);
        addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, ndev->dev_addr);
        ret = ib_device_set_netdev(&dev->ib_dev, ndev, 1);
-       rcu_read_unlock();
+       /* mana_get_primary_netdev() returns ndev with refcount held */
+       netdev_put(ndev, &dev->dev_tracker);
        if (ret) {
                ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
                goto free_ib_device;
index 77fc1032eda8fa668523108f44e0eca7dfd43c75..81a7e7474462fca2b24aa4e75ecddfd1976f7843 100644 (file)
@@ -78,6 +78,7 @@ struct mana_ib_dev {
        struct xarray qp_table_wq;
        struct mana_ib_adapter_caps adapter_caps;
        struct dma_pool *av_pool;
+       netdevice_tracker dev_tracker;
 };
 
 struct mana_ib_wq {
index aa1e47233fe50cc5b9f06ce9aa97a9e6d1dd8f0d..4e870b11f946676445a349c412f35725555db5bb 100644 (file)
@@ -3131,21 +3131,27 @@ out:
        kfree(ac);
 }
 
-struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index)
+struct net_device *mana_get_primary_netdev(struct mana_context *ac,
+                                          u32 port_index,
+                                          netdevice_tracker *tracker)
 {
        struct net_device *ndev;
 
-       RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
-                        "Taking primary netdev without holding the RCU read lock");
        if (port_index >= ac->num_ports)
                return NULL;
 
-       /* When mana is used in netvsc, the upper netdevice should be returned. */
-       if (ac->ports[port_index]->flags & IFF_SLAVE)
-               ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]);
-       else
+       rcu_read_lock();
+
+       /* If mana is used in netvsc, the upper netdevice should be returned. */
+       ndev = netdev_master_upper_dev_get_rcu(ac->ports[port_index]);
+
+       /* If there is no upper device, use the parent Ethernet device */
+       if (!ndev)
                ndev = ac->ports[port_index];
 
+       netdev_hold(ndev, tracker, GFP_ATOMIC);
+       rcu_read_unlock();
+
        return ndev;
 }
-EXPORT_SYMBOL_NS(mana_get_primary_netdev_rcu, "NET_MANA");
+EXPORT_SYMBOL_NS(mana_get_primary_netdev, "NET_MANA");
index 0d00b24eacafdedc8722a2ad55490ab65c0344db..0f78065de8fe42446af0f1d8dde2dfb970c205d5 100644 (file)
@@ -827,5 +827,7 @@ int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id,
                   u32 doorbell_pg_id);
 void mana_uncfg_vport(struct mana_port_context *apc);
 
-struct net_device *mana_get_primary_netdev_rcu(struct mana_context *ac, u32 port_index);
+struct net_device *mana_get_primary_netdev(struct mana_context *ac,
+                                          u32 port_index,
+                                          netdevice_tracker *tracker);
 #endif /* _MANA_H */