Skip to contentSkip to conversation

RDMA: Fix netdev tracker in ib_device_set_netdev

PATCH Superseded David Ahern 3 participants 5 messages Jul 9, 2024 – Jul 11, 2024 InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 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()")
---
 drivers/infiniband/core/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/device.c +1 -1
index 55aa7aa32d4a..7ddaec923569 100644
@@ -2167,7 +2167,7 @@ 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);
Signature · 1 line
2.30.2
#1 lore raw
Quoted 16 lines · David Ahern

If a netdev has already been assigned, ib_device_set_netdev needs to release the reference on the older 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()")
---
 drivers/infiniband/core/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/core/device.c +0 -0
index 55aa7aa32d4a..7ddaec923569 100644

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

Quoted 5 lines
drivers/infiniband/core/device.c +1 -1
@@ -2167,7 +2167,7 @@ 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);

It should stay netdev_tracker_free() and not netdev_put(). We are calling to __dev_put(old_ndev) later in the function.

Thanks

Quoted 5 lines
drivers/infiniband/core/device.c +0 -0
 	if (ndev)
 		netdev_hold(ndev, &pdata->netdev_tracker, GFP_ATOMIC);
 	rcu_assign_pointer(pdata->netdev, ndev);
Signature · 1 line
2.30.2
#2 lore raw
Quoted 7 lines · Leon Romanovsky
Quoted 7 lines
drivers/infiniband/core/device.c +0 -0
index 55aa7aa32d4a..7ddaec923569 100644
@@ -2167,7 +2167,7 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
 	}
 
Quoted 7 lines

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

Quoted 3 lines
drivers/infiniband/core/device.c +1 -1
 	if (old_ndev)
-		netdev_tracker_free(ndev, &pdata->netdev_tracker);
+		netdev_put(old_ndev, &pdata->netdev_tracker);

It should stay netdev_tracker_free() and not netdev_put(). We are calling to __dev_put(old_ndev) later in the function.

missed that and KASAN and refcount debugging did not complain ...

Anyways, why have the 2 split apart? ie., why not remove the __dev_put and just do netdev_put here? old_ndev is not needed in between calls. Asymmetric calls like this are always confusing.

#3 lore raw
Quoted 16 lines · David Ahern
Quoted 7 lines · Leon Romanovsky
Quoted 7 lines
drivers/infiniband/core/device.c +0 -0
index 55aa7aa32d4a..7ddaec923569 100644
@@ -2167,7 +2167,7 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
 	}
 
Quoted 7 lines

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

Quoted 3 lines
drivers/infiniband/core/device.c +1 -1
 	if (old_ndev)
-		netdev_tracker_free(ndev, &pdata->netdev_tracker);
+		netdev_put(old_ndev, &pdata->netdev_tracker);

It should stay netdev_tracker_free() and not netdev_put(). We are calling to __dev_put(old_ndev) later in the function.

Quoted 5 lines

missed that and KASAN and refcount debugging did not complain ...

Anyways, why have the 2 split apart? ie., why not remove the __dev_put and just do netdev_put here? old_ndev is not needed in between calls. Asymmetric calls like this are always confusing.

You probably can combine them, but to do so instead of __dev_put() and not netdev_tracker_free().

Thanks

#4 lore raw
In reply to David Ahern
Quoted 16 lines · David Ahern
Quoted 7 lines · Leon Romanovsky
Quoted 7 lines
drivers/infiniband/core/device.c +0 -0
index 55aa7aa32d4a..7ddaec923569 100644
@@ -2167,7 +2167,7 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
 	}
 
Quoted 7 lines

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

Quoted 3 lines
drivers/infiniband/core/device.c +1 -1
 	if (old_ndev)
-		netdev_tracker_free(ndev, &pdata->netdev_tracker);
+		netdev_put(old_ndev, &pdata->netdev_tracker);

It should stay netdev_tracker_free() and not netdev_put(). We are calling to __dev_put(old_ndev) later in the function.

Quoted 5 lines

missed that and KASAN and refcount debugging did not complain ...

Anyways, why have the 2 split apart? ie., why not remove the __dev_put and just do netdev_put here? old_ndev is not needed in between calls. Asymmetric calls like this are always confusing.

Maybe it is Ok like this:

@@ -2166,15 +2166,14 @@ int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,

                return 0;
        }

+ rcu_assign_pointer(pdata->netdev, 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;

}

Don't like that we drop the ref and leave the pdata->netdev assigned to something with no ref, even though it is OK for RCU reasons..

Jason