DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bing Zhao <bingz@nvidia.com>
To: <viacheslavo@nvidia.com>, <dev@dpdk.org>, <rasland@nvidia.com>
Cc: <orika@nvidia.com>, <dsosnowski@nvidia.com>,
	<suanmingm@nvidia.com>, <matan@nvidia.com>, <thomas@monjalon.net>,
	<bingz@nvidia.com>, Nupur Uttarwar <nuttarwar@nvidia.com>
Subject: [PATCH 3/4] net/mlx5: fix incorrect buddy mempool init
Date: Wed, 12 Nov 2025 09:47:39 +0200	[thread overview]
Message-ID: <20251112074739.8996-1-bingz@nvidia.com> (raw)

From: Nupur Uttarwar <nuttarwar@nvidia.com>

`buddy` was erroroneously declared as static. When multiple
threads call this routine, they set the same static variable
corrupting pool data and can cause potential double free when
releasing resources.

Fixes: b4dd7bcb0dcb ("net/mlx5/hws: add pool and buddy")

Signed-off-by: Nupur Uttarwar <nuttarwar@nvidia.com>
---
 drivers/net/mlx5/hws/mlx5dr_buddy.c | 1 +
 drivers/net/mlx5/hws/mlx5dr_pool.c  | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/hws/mlx5dr_buddy.c b/drivers/net/mlx5/hws/mlx5dr_buddy.c
index 394ca71217..abfbdf1be5 100644
--- a/drivers/net/mlx5/hws/mlx5dr_buddy.c
+++ b/drivers/net/mlx5/hws/mlx5dr_buddy.c
@@ -147,6 +147,7 @@ void mlx5dr_buddy_cleanup(struct mlx5dr_buddy_mem *buddy)
 
 	simple_free(buddy->num_free);
 	simple_free(buddy->bits);
+	simple_free(buddy);
 }
 
 int mlx5dr_buddy_alloc_mem(struct mlx5dr_buddy_mem *buddy, int order)
diff --git a/drivers/net/mlx5/hws/mlx5dr_pool.c b/drivers/net/mlx5/hws/mlx5dr_pool.c
index 8e3718ac42..e383027d3e 100644
--- a/drivers/net/mlx5/hws/mlx5dr_pool.c
+++ b/drivers/net/mlx5/hws/mlx5dr_pool.c
@@ -167,7 +167,7 @@ static struct mlx5dr_buddy_mem *
 mlx5dr_pool_buddy_get_next_buddy(struct mlx5dr_pool *pool, int idx,
 				 uint32_t order, bool *is_new_buddy)
 {
-	static struct mlx5dr_buddy_mem *buddy;
+	struct mlx5dr_buddy_mem *buddy;
 	uint32_t new_buddy_size;
 
 	buddy = pool->db.buddy_manager->buddies[idx];
@@ -271,7 +271,6 @@ static void mlx5dr_pool_buddy_db_uninit(struct mlx5dr_pool *pool)
 		buddy = pool->db.buddy_manager->buddies[i];
 		if (buddy) {
 			mlx5dr_buddy_cleanup(buddy);
-			simple_free(buddy);
 			pool->db.buddy_manager->buddies[i] = NULL;
 		}
 	}
-- 
2.34.1


             reply	other threads:[~2025-11-12  7:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-12  7:47 Bing Zhao [this message]
2025-11-12  9:48 ` Dariusz Sosnowski

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=20251112074739.8996-1-bingz@nvidia.com \
    --to=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=nuttarwar@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=suanmingm@nvidia.com \
    --cc=thomas@monjalon.net \
    --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).