[PATCH rdma-next 3/9] RDMA/mlx5: Flush system error and slave port event work

From: Edward Srouji

Date: Sun Nov 22 2026 - 12:39:56 EST


Work queued on mlx5_ib_event_wq holds no references, and nothing waits
for the work of the system error and slave port notifiers once they
are unregistered. Their handlers can then use the device after
__mlx5_ib_remove() frees it, or work->mpi after mlx5r_mp_remove()
frees it.

Flush the workqueue after unregistering them: the system error
notifier in its stage cleanup, and the slave port notifier in
mlx5r_mp_remove() and mlx5_ib_cleanup_multiport_master(), after
dropping mlx5_ib_multiport_mutex, which the slave port handler takes.
The system error notifier stays registered until after
ib_unregister_device(), as commit ebc2164a4cd4 ("RDMA/mlx5: Fix UMR
hang in LAG error state unload") requires.

Fixes: 5d44adebbb7e ("IB/mlx5: Free mpi in mp_slave mode")
Fixes: ebc2164a4cd4 ("RDMA/mlx5: Fix UMR hang in LAG error state unload")
Reviewed-by: Michael Gur <michaelgur@xxxxxxxxxx>
Signed-off-by: Edward Srouji <edwards@xxxxxxxxxx>
---
drivers/infiniband/hw/mlx5/main.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 4504ba112034f4a5cfad16183602f209941c8835..775c3612a427a66ccb597595e149e3eada486add 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -3248,6 +3248,7 @@ static int mlx5_ib_stage_sys_error_notifier_init(struct mlx5_ib_dev *dev)
static void mlx5_ib_stage_sys_error_notifier_cleanup(struct mlx5_ib_dev *dev)
{
mlx5_notifier_unregister(dev->mdev, &dev->sys_error_events);
+ flush_workqueue(mlx5_ib_event_wq);
}

static int mlx5_ib_get_plane_num(struct mlx5_core_dev *mdev, u8 *num_plane)
@@ -4085,6 +4086,7 @@ static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev)
mlx5_ib_dbg(dev, "removing from devlist\n");
list_del(&dev->ib_dev_list);
mutex_unlock(&mlx5_ib_multiport_mutex);
+ flush_workqueue(mlx5_ib_event_wq);

mlx5_nic_vport_disable_roce(dev->mdev);
}
@@ -5323,6 +5325,7 @@ static void mlx5r_mp_remove(struct auxiliary_device *adev)
else
list_del(&mpi->list);
mutex_unlock(&mlx5_ib_multiport_mutex);
+ flush_workqueue(mlx5_ib_event_wq);
kfree(mpi);
}


--
2.49.0