From 992e6df3dafebf0625a59a51136a5e07a361000f Mon Sep 17 00:00:00 2001 From: Jiawei Wang Date: Mon, 2 Nov 2020 04:22:28 +0200 Subject: [PATCH] common/mlx5: free MR resource on device DMA unmap mlx5 PMD created the MR (Memory Region) resource on the mlx5_dma_map call to make the memory available for DMA operations. On the mlx5_dma_unmap call the MR resource was not freed but inserted to MR Free list for further garbage collection. Actual MR resource destroying happened on device stop call. That caused the runtime out of memory in case of application performed multiple DMA map/unmap calls. The fix immediately frees the MR resource on mlx5_dma_unmap call not engaging the list. The export for mlx5_mr_free function from common PMD part is added as well. Fixes: 989e999d9305 ("net/mlx5: support PCI device DMA map and unmap") Cc: stable@dpdk.org Signed-off-by: Jiawei Wang Acked-by: Viacheslav Ovsiienko --- drivers/common/mlx5/mlx5_common_mr.c | 12 ++++++------ drivers/common/mlx5/mlx5_common_mr.h | 4 ++++ drivers/common/mlx5/version.map | 1 + drivers/net/mlx5/mlx5_mr.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/common/mlx5/mlx5_common_mr.c b/drivers/common/mlx5/mlx5_common_mr.c index 23324c0fc7..7c25541dc4 100644 --- a/drivers/common/mlx5/mlx5_common_mr.c +++ b/drivers/common/mlx5/mlx5_common_mr.c @@ -436,8 +436,8 @@ mlx5_mr_lookup_cache(struct mlx5_mr_share_cache *share_cache, * @param mr * Pointer to MR to free. */ -static void -mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb) +void +mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb) { if (mr == NULL) return; @@ -492,7 +492,7 @@ mlx5_mr_garbage_collect(struct mlx5_mr_share_cache *share_cache) struct mlx5_mr *mr = mr_next; mr_next = LIST_NEXT(mr, mr); - mr_free(mr, share_cache->dereg_mr_cb); + mlx5_mr_free(mr, share_cache->dereg_mr_cb); } } @@ -702,7 +702,7 @@ alloc_resources: data.start = RTE_ALIGN_FLOOR(addr, msl->page_sz); data.end = data.start + msl->page_sz; rte_mcfg_mem_read_unlock(); - mr_free(mr, share_cache->dereg_mr_cb); + mlx5_mr_free(mr, share_cache->dereg_mr_cb); goto alloc_resources; } MLX5_ASSERT(data.msl == data_re.msl); @@ -725,7 +725,7 @@ alloc_resources: * Must be unlocked before calling rte_free() because * mlx5_mr_mem_event_free_cb() can be called inside. */ - mr_free(mr, share_cache->dereg_mr_cb); + mlx5_mr_free(mr, share_cache->dereg_mr_cb); return entry->lkey; } /* @@ -801,7 +801,7 @@ err_nolock: * calling rte_free() because mlx5_mr_mem_event_free_cb() can be called * inside. */ - mr_free(mr, share_cache->dereg_mr_cb); + mlx5_mr_free(mr, share_cache->dereg_mr_cb); return UINT32_MAX; } diff --git a/drivers/common/mlx5/mlx5_common_mr.h b/drivers/common/mlx5/mlx5_common_mr.h index a2c426df2b..da0a0f0c79 100644 --- a/drivers/common/mlx5/mlx5_common_mr.h +++ b/drivers/common/mlx5/mlx5_common_mr.h @@ -171,4 +171,8 @@ mlx5_common_verbs_reg_mr(void *pd, void *addr, size_t length, __rte_internal void mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr); + +__rte_internal +void +mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb); #endif /* RTE_PMD_MLX5_COMMON_MR_H_ */ diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map index 52fde50fbf..17dd11f635 100644 --- a/drivers/common/mlx5/version.map +++ b/drivers/common/mlx5/version.map @@ -65,6 +65,7 @@ INTERNAL { mlx5_mr_lookup_list; mlx5_mr_create_primary; mlx5_mr_flush_local_cache; + mlx5_mr_free; mlx5_nl_allmulti; mlx5_nl_devlink_family_id_get; diff --git a/drivers/net/mlx5/mlx5_mr.c b/drivers/net/mlx5/mlx5_mr.c index c308eccefb..8b20ee3f83 100644 --- a/drivers/net/mlx5/mlx5_mr.c +++ b/drivers/net/mlx5/mlx5_mr.c @@ -404,7 +404,7 @@ mlx5_dma_unmap(struct rte_pci_device *pdev, void *addr, return -1; } LIST_REMOVE(mr, mr); - LIST_INSERT_HEAD(&sh->share_cache.mr_free_list, mr, mr); + mlx5_mr_free(mr, sh->share_cache.dereg_mr_cb); DEBUG("port %u remove MR(%p) from list", dev->data->port_id, (void *)mr); mlx5_mr_rebuild_cache(&sh->share_cache); -- 2.20.1