src/dpdk/drivers/net/mlx5/mlx5_mr.c
static void
mlx5_mr_update_ext_mp_cb(struct rte_mempool *mp, void *opaque,
			 struct rte_mempool_memhdr *memhdr,
			 unsigned mem_idx __rte_unused)
{
	struct mr_update_mp_data *data = opaque;
	struct rte_eth_dev *dev = data->dev;
	struct mlx5_priv *priv = dev->data->dev_private;
	struct mlx5_dev_ctx_shared *sh = priv->sh;
	struct mlx5_mr_ctrl *mr_ctrl = data->mr_ctrl;
	struct mlx5_mr *mr = NULL;
	uintptr_t addr = (uintptr_t)memhdr->addr;
	size_t len = memhdr->len;
	struct mr_cache_entry entry;
	uint32_t lkey;

	MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
	/* If already registered, it should return. */
	rte_rwlock_read_lock(&sh->share_cache.rwlock);
	lkey = mlx5_mr_lookup_cache(&sh->share_cache, &entry, addr);
	rte_rwlock_read_unlock(&sh->share_cache.rwlock);
	if (lkey != UINT32_MAX)
		return;
	DRV_LOG(DEBUG, "port %u register MR for chunk #%d of mempool (%s)",
		dev->data->port_id, mem_idx, mp->name);
	mr = mlx5_create_mr_ext(sh->pd, addr, len, mp->socket_id,
				sh->share_cache.reg_mr_cb);
	if (!mr) {
		DRV_LOG(WARNING,
			"port %u unable to allocate a new MR of"
			" mempool (%s).",
			dev->data->port_id, mp->name);
		data->ret = -1;
		return;
	}
	rte_rwlock_write_lock(&sh->share_cache.rwlock);
	LIST_INSERT_HEAD(&sh->share_cache.mr_list, mr, mr);
	/* Insert to the global cache table. */
	mlx5_mr_insert_cache(&sh->share_cache, mr);
	rte_rwlock_write_unlock(&sh->share_cache.rwlock);
	/* Insert to the local cache table */
	mlx5_mr_addr2mr_bh(sh->pd, &priv->mp_id, &sh->share_cache,
			   mr_ctrl, addr, priv->config.mr_ext_memseg_en);
}
/**
 * Called during rte_mempool_mem_iter() by mlx5_mr_update_ext_mp().
 *
 * Externally allocated chunk is registered and a MR is created for the chunk.
 * The MR object is added to the global list. If memseg list of a MR object
 * (mr->msl) is null, the MR object can be regarded as externally allocated
 * memory.
 *
 * Once external memory is registered, it should be static. If the memory is
 * freed and the virtual address range has different physical memory mapped
 * again, it may cause crash on device due to the wrong translation entry. PMD
 * can't track the free event of the external memory for now.
 */


Once external memory is registered, it should be static. If the memory is
freed and the virtual address range has different physical memory mapped
again, it may cause crash on device due to the wrong translation entry. PMD
can't track the free event of the external memory for now.
Once external memory is registered it should be static . If the memory is freed and the virtual address range has different physical memory mapped again it may cause crash on device due to the wrong translation entry . PMD can ' t track the free event of the external memory for now .
static void
mlx5_mr_update_ext_mp_cb(struct rte_mempool *mp, void *opaque,
			 struct rte_mempool_memhdr *memhdr,
			 unsigned mem_idx __rte_unused)
{
	struct mr_update_mp_data *data = opaque;
	struct rte_eth_dev *dev = data->dev;
	struct mlx5_priv *priv = dev->data->dev_private;
	struct mlx5_dev_ctx_shared *sh = priv->sh;
	struct mlx5_mr_ctrl *mr_ctrl = data->mr_ctrl;
	struct mlx5_mr *mr = NULL;
	uintptr_t addr = (uintptr_t)memhdr->addr;
	size_t len = memhdr->len;
	struct mr_cache_entry entry;
	uint32_t lkey;
	MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
	rte_rwlock_read_lock(&sh->share_cache.rwlock);
	lkey = mlx5_mr_lookup_cache(&sh->share_cache, &entry, addr);
	rte_rwlock_read_unlock(&sh->share_cache.rwlock);
	if (lkey != UINT32_MAX)
		return;
	DRV_LOG(DEBUG, "port %u register MR for chunk #%d of mempool (%s)",
		dev->data->port_id, mem_idx, mp->name);
	mr = mlx5_create_mr_ext(sh->pd, addr, len, mp->socket_id,
				sh->share_cache.reg_mr_cb);
	if (!mr) {
		DRV_LOG(WARNING,
			"port %u unable to allocate a new MR of"
			" mempool (%s).",
			dev->data->port_id, mp->name);
		data->ret = -1;
		return;
	}
	rte_rwlock_write_lock(&sh->share_cache.rwlock);
	LIST_INSERT_HEAD(&sh->share_cache.mr_list, mr, mr);
	mlx5_mr_insert_cache(&sh->share_cache, mr);
	rte_rwlock_write_unlock(&sh->share_cache.rwlock);
	mlx5_mr_addr2mr_bh(sh->pd, &priv->mp_id, &sh->share_cache,
			   mr_ctrl, addr, priv->config.mr_ext_memseg_en);
}
static void mlx5_mr_update_ext_mp_cb ( struct rte_mempool * mp , void * opaque , struct rte_mempool_memhdr * memhdr , unsigned mem_idx __rte_unused ) { struct mr_update_mp_data * data = opaque ; struct rte_eth_dev * dev = data -> dev ; struct mlx5_priv * priv = dev -> data -> dev_private ; struct mlx5_dev_ctx_shared * sh = priv -> sh ; struct mlx5_mr_ctrl * mr_ctrl = data -> mr_ctrl ; struct mlx5_mr * mr = NULL ; uintptr_t addr = ( uintptr_t ) memhdr -> addr ; size_t len = memhdr -> len ; struct mr_cache_entry entry ; uint32_t lkey ; MLX5_ASSERT ( rte_eal_process_type ( ) == RTE_PROC_PRIMARY ) ; rte_rwlock_read_lock ( & sh -> share_cache . rwlock ) ; lkey = mlx5_mr_lookup_cache ( & sh -> share_cache , & entry , addr ) ; rte_rwlock_read_unlock ( & sh -> share_cache . rwlock ) ; if ( lkey != UINT32_MAX ) return ; DRV_LOG ( DEBUG , " " , dev -> data -> port_id , mem_idx , mp -> name ) ; mr = mlx5_create_mr_ext ( sh -> pd , addr , len , mp -> socket_id , sh -> share_cache . reg_mr_cb ) ; if ( ! mr ) { DRV_LOG ( WARNING , " " " " , dev -> data -> port_id , mp -> name ) ; data -> ret = -1 ; return ; } rte_rwlock_write_lock ( & sh -> share_cache . rwlock ) ; LIST_INSERT_HEAD ( & sh -> share_cache . mr_list , mr , mr ) ; mlx5_mr_insert_cache ( & sh -> share_cache , mr ) ; rte_rwlock_write_unlock ( & sh -> share_cache . rwlock ) ; mlx5_mr_addr2mr_bh ( sh -> pd , & priv -> mp_id , & sh -> share_cache , mr_ctrl , addr , priv -> config . mr_ext_memseg_en ) ; }
Called during rte_mempool_mem_iter() by mlx5_mr_update_ext_mp().
Called during rte_mempool_mem_iter () by mlx5_mr_update_ext_mp () .
/* If already registered, it should return. */ /* Insert to the global cache table. */ /* Insert to the local cache table */