return;
DRV_LOG(DEBUG, "freeing MR(%p):", (void *)mr);
dereg_mr_cb(&mr->pmd_mr);
- if (mr->ms_bmp != NULL)
- rte_bitmap_free(mr->ms_bmp);
+ rte_bitmap_free(mr->ms_bmp);
mlx5_free(mr);
}
struct mlx5_mempool_reg *mpr = NULL;
mpr = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
- sizeof(*mpr) + mrs_n * sizeof(mpr->mrs[0]),
+ sizeof(struct mlx5_mempool_reg),
RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
if (mpr == NULL) {
DRV_LOG(ERR, "Cannot allocate mempool %s registration object",
mp->name);
return NULL;
}
+ mpr->mrs = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
+ mrs_n * sizeof(struct mlx5_mempool_mr),
+ RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
+ if (!mpr->mrs) {
+ DRV_LOG(ERR, "Cannot allocate mempool %s registration MRs",
+ mp->name);
+ mlx5_free(mpr);
+ return NULL;
+ }
mpr->mp = mp;
- mpr->mrs = (struct mlx5_mempool_mr *)(mpr + 1);
mpr->mrs_n = mrs_n;
mpr->is_extmem = is_extmem;
return mpr;
* Destroy a mempool registration object.
*
* @param standalone
- * Whether @p mpr owns its MRs excludively, i.e. they are not shared.
+ * Whether @p mpr owns its MRs exclusively, i.e. they are not shared.
*/
static void
mlx5_mempool_reg_destroy(struct mlx5_mr_share_cache *share_cache,
for (i = 0; i < mpr->mrs_n; i++)
share_cache->dereg_mr_cb(&mpr->mrs[i].pmd_mr);
+ mlx5_free(mpr->mrs);
}
mlx5_free(mpr);
}
for (i = 0; i < mpr->mrs_n; i++) {
const struct mlx5_pmd_mr *mr = &mpr->mrs[i].pmd_mr;
- uintptr_t mr_addr = (uintptr_t)mr->addr;
+ uintptr_t mr_start = (uintptr_t)mr->addr;
+ uintptr_t mr_end = mr_start + mr->len;
- if (mr_addr <= addr) {
+ if (mr_start <= addr && addr < mr_end) {
lkey = rte_cpu_to_be_32(mr->lkey);
- entry->start = mr_addr;
- entry->end = mr_addr + mr->len;
+ entry->start = mr_start;
+ entry->end = mr_end;
entry->lkey = lkey;
break;
}
dev_gen);
struct mlx5_common_device *cdev =
container_of(share_cache, struct mlx5_common_device, mr_scache);
+ bool external, mprq, pinned = false;
/* Recover MPRQ mempool. */
- if (RTE_MBUF_HAS_EXTBUF(mb) &&
- mb->shinfo->free_cb == mlx5_mprq_buf_free_cb) {
+ external = RTE_MBUF_HAS_EXTBUF(mb);
+ if (external && mb->shinfo->free_cb == mlx5_mprq_buf_free_cb) {
+ mprq = true;
buf = mb->shinfo->fcb_opaque;
mp = buf->mp;
} else {
+ mprq = false;
mp = mlx5_mb2mp(mb);
+ pinned = rte_pktmbuf_priv_flags(mp) &
+ RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF;
+ }
+ if (!external || mprq || pinned) {
+ lkey = mlx5_mr_mempool2mr_bh(mr_ctrl, mp, addr);
+ if (lkey != UINT32_MAX)
+ return lkey;
+ /* MPRQ is always registered. */
+ MLX5_ASSERT(!mprq);
}
- lkey = mlx5_mr_mempool2mr_bh(mr_ctrl, mp, addr);
- if (lkey != UINT32_MAX)
- return lkey;
/* Register pinned external memory if the mempool is not used for Rx. */
- if (cdev->config.mr_mempool_reg_en &&
- (rte_pktmbuf_priv_flags(mp) & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)) {
+ if (cdev->config.mr_mempool_reg_en && pinned) {
if (mlx5_mr_mempool_register(cdev, mp, true) < 0)
return UINT32_MAX;
lkey = mlx5_mr_mempool2mr_bh(mr_ctrl, mp, addr);