[PATCH rdma-next v4 01/11] RDMA/mlx5: Move device async_ctx initialization

From: Edward Srouji

Date: Thu Feb 26 2026 - 09:19:02 EST


From: Chiara Meiohas <cmeiohas@xxxxxxxxxx>

Move the async_ctx initialization from mlx5_mkey_cache_init() to
mlx5_ib_stage_init_init() since the async_ctx is used by both the MR
cache and DEVX.

Also add the corresponding cleanup in mlx5_ib_stage_init_cleanup() to
properly release the async_ctx resources.

Signed-off-by: Chiara Meiohas <cmeiohas@xxxxxxxxxx>
Reviewed-by: Michael Guralnik <michaelgur@xxxxxxxxxx>
Signed-off-by: Edward Srouji <edwards@xxxxxxxxxx>
---
drivers/infiniband/hw/mlx5/main.c | 3 +++
drivers/infiniband/hw/mlx5/mr.c | 2 --
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 635002e684a55fcc2f6c42127f67abba38809b08..c4d2fc58e7a8a8fc65b4585a9e26aadffde899aa 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -4418,6 +4418,7 @@ static const struct uapi_definition mlx5_ib_defs[] = {

static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev)
{
+ mlx5_cmd_cleanup_async_ctx(&dev->async_ctx);
mlx5_ib_data_direct_cleanup(dev);
mlx5_ib_cleanup_multiport_master(dev);
WARN_ON(!xa_empty(&dev->odp_mkeys));
@@ -4487,6 +4488,8 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
if (err && err != -EOPNOTSUPP)
goto err_dd;

+ mlx5_cmd_init_async_ctx(mdev, &dev->async_ctx);
+
return 0;
err_dd:
mlx5_ib_data_direct_cleanup(dev);
diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index 665323b90b64f78d0f556bafddfacd42904feb87..6cb21290082079fcfa61d8a3b5de3970d38836ba 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -978,7 +978,6 @@ int mlx5_mkey_cache_init(struct mlx5_ib_dev *dev)
return -ENOMEM;
}

- mlx5_cmd_init_async_ctx(dev->mdev, &dev->async_ctx);
timer_setup(&dev->delay_timer, delay_time_func, 0);
mlx5_mkey_cache_debugfs_init(dev);
mutex_lock(&cache->rb_lock);
@@ -1040,7 +1039,6 @@ void mlx5_mkey_cache_cleanup(struct mlx5_ib_dev *dev)
flush_workqueue(dev->cache.wq);

mlx5_mkey_cache_debugfs_cleanup(dev);
- mlx5_cmd_cleanup_async_ctx(&dev->async_ctx);

/* At this point all entries are disabled and have no concurrent work. */
mlx5r_destroy_cache_entries(dev);

--
2.49.0