From 4f8e6befe7c6045b082dc5b95afd5a1c00e30bf0 Mon Sep 17 00:00:00 2001 From: Michael Baum Date: Tue, 4 Feb 2020 15:36:09 +0200 Subject: [PATCH] net/mlx5: fix memory regions release deadlock The mpx5 PMD maintains the list of devices for those the memory operation callback routines must be invoked to keep the device MRs (MR is the entity backing the hardware DMA transactions) consistent with the mapped memory. Each device context in the list is protected with dedicated lock on per device basis, which might be taken inside the callback routine. When device is closing the PMD frees all MRs by calling mlx5_mr_release(), that might call rte_free() under the taken device lock. If this rte_free call triggers the entire memory segment freeing it, in its turn, invokes the callback routine and attempt to take the lock inside this one causes the deadlock. The patch proposes the remove the device from the callback list first and then call mlx5_mr_release() and free the remaining device MRs explicitly. Fixes: 0e3d0525b2f2 ("net/mlx5: fix memory event callback list") Cc: stable@dpdk.org Signed-off-by: Michael Baum Acked-by: Viacheslav Ovsiienko Acked-by: Matan Azrad --- drivers/net/mlx5/mlx5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 7a79722fb7..b4ec6cba1a 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -679,12 +679,12 @@ mlx5_free_shared_ibctx(struct mlx5_ibv_shared *sh) MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); if (--sh->refcnt) goto exit; - /* Release created Memory Regions. */ - mlx5_mr_release(sh); /* Remove from memory callback device list. */ rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock); LIST_REMOVE(sh, mem_event_cb); rte_rwlock_write_unlock(&mlx5_shared_data->mem_event_rwlock); + /* Release created Memory Regions. */ + mlx5_mr_release(sh); /* Remove context from the global device list. */ LIST_REMOVE(sh, next); /* -- 2.20.1