Skip to contentSkip to conversation

RDMA: Fix netdev tracker in ib_device_set_netdev

PATCH Applied David Ahern 2 participants 4 messages Jul 10, 2024 – Jul 11, 2024 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 RDMA: Fix netdev tracker in ib_device_set_netdev

If a netdev has already been assigned, ib_device_set_netdev needs to release the reference on the older netdev but it is mistakenly being called for the new netdev. Fix it and in the process use netdev_put to be symmetrical with the netdev_hold.

Fixes 09f530f0c6d6 ("RDMA: Add netdevice_tracker to ib_device_set_netdev()")

---
v2
- remove __dev_put now that netdev_put is used

 drivers/infiniband/core/device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/core/device.c +1 -2
index 55aa7aa32d4a..9b99112baf47 100644
@@ -2167,14 +2167,13 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
 	}
 
 	if (old_ndev)
-		netdev_tracker_free(ndev, &pdata->netdev_tracker);
+		netdev_put(old_ndev, &pdata->netdev_tracker);
 	if (ndev)
 		netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
 	rcu_assign_pointer(pdata->netdev, ndev);
 	spin_unlock_irqrestore(&pdata->netdev_lock, flags);
 
 	add_ndev_hash(pdata);
-	__dev_put(old_ndev);
 
 	return 0;
 }
Signature · 1 line
2.39.3 (Apple Git-146)
#1 lore raw
Quoted 21 lines · David Ahern

If a netdev has already been assigned, ib_device_set_netdev needs to release the reference on the older netdev but it is mistakenly being called for the new netdev. Fix it and in the process use netdev_put to be symmetrical with the netdev_hold.

Fixes 09f530f0c6d6 ("RDMA: Add netdevice_tracker to ib_device_set_netdev()")

---
v2
- remove __dev_put now that netdev_put is used

 drivers/infiniband/core/device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/core/device.c +0 -0
index 55aa7aa32d4a..9b99112baf47 100644
@@ -2167,14 +2167,13 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
 	}
 

drivers/infiniband/core/device.c int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev, · line 2177

Quoted 10 lines
drivers/infiniband/core/device.c +1 -2
 	if (old_ndev)
-		netdev_tracker_free(ndev, &pdata->netdev_tracker);
+		netdev_put(old_ndev, &pdata->netdev_tracker);
 	if (ndev)
 		netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
 	rcu_assign_pointer(pdata->netdev, ndev);
 	spin_unlock_irqrestore(&pdata->netdev_lock, flags);
 
 	add_ndev_hash(pdata);
-	__dev_put(old_ndev);

I applied with the following change:

drivers/infiniband/core/device.c +2 -4
index 49a2ddaf5a38..1f867b7f7020 100644
@@ -2184,14 +2184,12 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
                return 0;
        }
 
-       if (old_ndev)
-               netdev_put(old_ndev, &pdata->netdev_tracker);
-       if (ndev)
-               netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
+       netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
        rcu_assign_pointer(pdata->netdev, ndev);
        spin_unlock_irqrestore(&pdata->netdev_lock, flags);
 
        add_ndev_hash(pdata);
+       netdev_put(old_ndev, &pdata->netdev_tracker);
 
        return 0;
 }
Quoted 7 lines
drivers/infiniband/core/device.c +0 -1
 	return 0;
 }
-- 

2.39.3 (Apple Git-146)

#2 lore raw
Quoted 45 lines · Leon Romanovsky
Quoted 21 lines · David Ahern

If a netdev has already been assigned, ib_device_set_netdev needs to release the reference on the older netdev but it is mistakenly being called for the new netdev. Fix it and in the process use netdev_put to be symmetrical with the netdev_hold.

Fixes 09f530f0c6d6 ("RDMA: Add netdevice_tracker to ib_device_set_netdev()")

---
v2
- remove __dev_put now that netdev_put is used

 drivers/infiniband/core/device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/core/device.c +0 -0
index 55aa7aa32d4a..9b99112baf47 100644
@@ -2167,14 +2167,13 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
 	}
 

drivers/infiniband/core/device.c int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev, · line 2177

Quoted 10 lines
drivers/infiniband/core/device.c +1 -2
 	if (old_ndev)
-		netdev_tracker_free(ndev, &pdata->netdev_tracker);
+		netdev_put(old_ndev, &pdata->netdev_tracker);
 	if (ndev)
 		netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
 	rcu_assign_pointer(pdata->netdev, ndev);
 	spin_unlock_irqrestore(&pdata->netdev_lock, flags);
 
 	add_ndev_hash(pdata);
-	__dev_put(old_ndev);

I applied with the following change:

drivers/infiniband/core/device.c +0 -3
index 49a2ddaf5a38..1f867b7f7020 100644
@@ -2184,14 +2184,12 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
                return 0;
        }
 
-       if (old_ndev)
-               netdev_put(old_ndev, &pdata->netdev_tracker);
-       if (ndev)

drivers/infiniband/core/device.c int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev, · line 2195

Quoted 10 lines
drivers/infiniband/core/device.c +2 -1
-               netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
+       netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
        rcu_assign_pointer(pdata->netdev, ndev);
        spin_unlock_irqrestore(&pdata->netdev_lock, flags);
 
        add_ndev_hash(pdata);
+       netdev_put(old_ndev, &pdata->netdev_tracker);
 
        return 0;
 }

The final version is:

drivers/infiniband/core/device.c +2 -5
index 49a2ddaf5a38..9c31eef9f590 100644
@@ -2184,15 +2184,12 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
                return 0;
        }
 
-       if (old_ndev)
-               netdev_put(old_ndev, &pdata->netdev_tracker);
-       if (ndev)
-               netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
+       netdev_put(old_ndev, &pdata->netdev_tracker);
+       netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
        rcu_assign_pointer(pdata->netdev, ndev);
        spin_unlock_irqrestore(&pdata->netdev_lock, flags);
 
        add_ndev_hash(pdata);
-
        return 0;
 }
 EXPORT_SYMBOL(ib_device_set_netdev);
Quoted 10 lines
Quoted 9 lines
drivers/infiniband/core/device.c +0 -1
 	return 0;
 }
-- 

2.39.3 (Apple Git-146)

#3 lore raw
In reply to David Ahern
Quoted 6 lines · David Ahern

If a netdev has already been assigned, ib_device_set_netdev needs to release the reference on the older netdev but it is mistakenly being called for the new netdev. Fix it and in the process use netdev_put to be symmetrical with the netdev_hold.

Applied, thanks!

[1/1] RDMA: Fix netdev tracker in ib_device_set_netdev

      https://git.kernel.org/rdma/rdma/c/bbff20fb3e6a00

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>