DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bing Zhao <bingz@nvidia.com>
To: <viacheslavo@nvidia.com>, <matan@nvidia.com>
Cc: <dev@dpdk.org>, <rasland@nvidia.com>,
	Dmitry Kozlyuk <dkozlyuk@nvidia.com>
Subject: [PATCH] common/mlx5: fix shared MR ranges allocation
Date: Tue, 23 Nov 2021 14:48:35 +0200	[thread overview]
Message-ID: <20211123124835.17514-1-bingz@nvidia.com> (raw)

Memory regions (MRs) were allocated in one chunk of memory with a
mempool registration object. However, MRs can be reused among
different mempool registrations.

When the registration that allocated the MRs originally was
destroyed, the dangling pointers to the MRs could be left in other
registrations sharing these MRs.

Splitting the memory allocation of registration structure and MRs in
this commit solves this pointer reference issue.

Fixes: 690b2a88c2f7 ("common/mlx5: add mempool registration facilities")

Signed-off-by: Bing Zhao <bingz@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Reviewed-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
---
 drivers/common/mlx5/mlx5_common_mr.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/common/mlx5/mlx5_common_mr.c b/drivers/common/mlx5/mlx5_common_mr.c
index 47121d8ff7..01f35ebcdf 100644
--- a/drivers/common/mlx5/mlx5_common_mr.c
+++ b/drivers/common/mlx5/mlx5_common_mr.c
@@ -1515,15 +1515,23 @@ mlx5_mempool_reg_create(struct rte_mempool *mp, unsigned int mrs_n,
 	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;
@@ -1544,6 +1552,7 @@ 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);
 }
-- 
2.27.0


             reply	other threads:[~2021-11-23 12:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-23 12:48 Bing Zhao [this message]
2021-11-23 22:38 ` Raslan Darawsheh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211123124835.17514-1-bingz@nvidia.com \
    --to=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dkozlyuk@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).