Skip to contentSkip to conversation

RDMA/mlx5: Fix refcount inconsistency in mlx5_netdev_event

PATCH In review Shuhao Fu 2 participants 2 messages Oct 21, 2025 – Oct 27, 2025

Subsystems (2)
lore
Share & tools
lore

Shuhao Fu

author
#0 lore raw

PATCH 1/1 RDMA/mlx5: Fix refcount inconsistency in mlx5_netdev_event

Fix refcount inconsistency related to mlx5_ib_get_native_port_mdev.

Function mlx5_ib_get_native_port_mdev could increase the counter of mpi->mdev_refcnt if mpi is not master. To ensure refcount consistency, each call to mlx5_ib_get_native_port_mdev should have a corresponding call to mlx5_ib_put_native_port_mdev. In mlx5_netdev_event, two branches fail to do so, leading to a possible bug when unbinding.

Fixes 379013776222 ("RDMA/mlx5: Handle link status event only for LAG device")
Fixes 35b0aa67b298 ("RDMA/mlx5: Refactor netdev affinity code")
---
 drivers/infiniband/hw/mlx5/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/main.c +2 -2
index fc1e86f6c..0c4aa7c50 100644
@@ -247,7 +247,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
 
 		if (!netif_is_lag_master(ndev) && !netif_is_lag_port(ndev) &&
 		    !mlx5_core_mp_enabled(mdev))
-			return NOTIFY_DONE;
+			goto done;
 
 		if (mlx5_lag_is_roce(mdev) || mlx5_lag_is_sriov(mdev)) {
 			struct net_device *lag_ndev;
@@ -268,7 +268,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
 		if (ibdev->is_rep)
 			roce = mlx5_get_rep_roce(ibdev, ndev, upper, &port_num);
 		if (!roce)
-			return NOTIFY_DONE;
+			goto done;
 
 		ib_ndev = ib_device_get_netdev(&ibdev->ib_dev, port_num);
 
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 20 lines · Shuhao Fu

Fix refcount inconsistency related to mlx5_ib_get_native_port_mdev.

Function mlx5_ib_get_native_port_mdev could increase the counter of mpi->mdev_refcnt if mpi is not master. To ensure refcount consistency, each call to mlx5_ib_get_native_port_mdev should have a corresponding call to mlx5_ib_put_native_port_mdev. In mlx5_netdev_event, two branches fail to do so, leading to a possible bug when unbinding.

Fixes 379013776222 ("RDMA/mlx5: Handle link status event only for LAG device")
Fixes 35b0aa67b298 ("RDMA/mlx5: Refactor netdev affinity code")
---
 drivers/infiniband/hw/mlx5/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/main.c +0 -0
index fc1e86f6c..0c4aa7c50 100644

drivers/infiniband/hw/mlx5/main.c static int mlx5_netdev_event(struct notifier_block *this, · line 250

Quoted 5 lines
drivers/infiniband/hw/mlx5/main.c +1 -1
@@ -247,7 +247,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
 
 		if (!netif_is_lag_master(ndev) && !netif_is_lag_port(ndev) &&
 		    !mlx5_core_mp_enabled(mdev))
-			return NOTIFY_DONE;
+			goto done;

mdev_refcnt is increased only for MPV slave, but here we are checking if MPV is enabled. It is not in this leaf and "return NOTIFY_DONE" is the right thing to do.

drivers/infiniband/hw/mlx5/main.c static int mlx5_netdev_event(struct notifier_block *this, · line 271

Quoted 9 lines
drivers/infiniband/hw/mlx5/main.c +1 -1
 		if (mlx5_lag_is_roce(mdev) || mlx5_lag_is_sriov(mdev)) {
 			struct net_device *lag_ndev;
@@ -268,7 +268,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
 		if (ibdev->is_rep)
 			roce = mlx5_get_rep_roce(ibdev, ndev, upper, &port_num);
 		if (!roce)
-			return NOTIFY_DONE;
+			goto done;

It is not MPV flow either. There is nothing to change here.

Thanks

Quoted 6 lines
drivers/infiniband/hw/mlx5/main.c +0 -1
 		ib_ndev = ib_device_get_netdev(&ibdev->ib_dev, port_num);
 
-- 

2.39.5 (Apple Git-154)