From: Marat Khalili <marat.khalili@huawei.com>
To: Jerin Jacob <jerinj@marvell.com>,
Kiran Kumar K <kirankumark@marvell.com>,
Nithin Dabilpuram <ndabilpuram@marvell.com>,
Zhirun Yan <yanzhirun_163@163.com>
Cc: <dev@dpdk.org>
Subject: [PATCH 2/2] lib/graph: rte_malloc for cache-aligned structs
Date: Tue, 17 Jun 2025 11:52:08 +0100 [thread overview]
Message-ID: <20250617105209.50526-2-marat.khalili@huawei.com> (raw)
In-Reply-To: <20250617105209.50526-1-marat.khalili@huawei.com>
This was flagged by undefined behaviour sanitizer: struct
rte_graph_cluster_stats is declared as `__rte_cache_aligned` but was
allocated using stdlib realloc which caused misaligned allocation. More
than one test needs to be executed in series in order to reproduce the
problem using graph_autotest, e.g:
app/dpdk-test --no-huge --no-pci -m128 graph_autotest graph_autotest
First sanitizer message (similar ones follow):
lib/graph/graph_stats.c:209:13: runtime error: member access within
misaligned address 0x606000008ea0 for type 'struct
rte_graph_cluster_stats', which requires 64 byte alignment
To fix the issue replace realloc calls with rte_malloc and rte_realloc
specifying correct alignment, use rte_free to free the result.
Signed-off-by: Marat Khalili <marat.khalili@huawei.com>
---
lib/graph/graph_stats.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c
index 57cd72e7cc..7ae8ee4987 100644
--- a/lib/graph/graph_stats.c
+++ b/lib/graph/graph_stats.c
@@ -203,7 +203,7 @@ stats_mem_init(struct cluster *cluster,
cluster_node_size += cluster->nb_graphs * sizeof(struct rte_node *);
cluster_node_size = RTE_ALIGN(cluster_node_size, RTE_CACHE_LINE_SIZE);
- stats = realloc(NULL, sz);
+ stats = rte_malloc(NULL, sz, RTE_CACHE_LINE_SIZE);
if (stats) {
memset(stats, 0, sz);
stats->fn = fn;
@@ -248,7 +248,8 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
}
/* Hey, it is a new node, allocate space for it in the reel */
- stats = realloc(stats, stats->sz + stats->cluster_node_size);
+ stats = rte_realloc(stats, stats->sz + stats->cluster_node_size,
+ RTE_CACHE_LINE_SIZE);
if (stats == NULL)
SET_ERR_JMP(ENOMEM, err, "Realloc failed");
*stats_in = NULL;
@@ -301,7 +302,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
return 0;
free:
- free(stats);
+ rte_free(stats);
err:
return -rte_errno;
}
@@ -309,7 +310,7 @@ stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
static void
stats_mem_fini(struct rte_graph_cluster_stats *stats)
{
- free(stats);
+ rte_free(stats);
}
static void
--
2.43.0
next prev parent reply other threads:[~2025-06-17 10:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 10:52 [PATCH 1/2] lib/graph: avoid memset(NULL, 0, 0) Marat Khalili
2025-06-17 10:52 ` Marat Khalili [this message]
2025-06-17 12:46 ` [PATCH 2/2] lib/graph: rte_malloc for cache-aligned structs Jerin Jacob
2025-06-17 13:27 ` Stephen Hemminger
2025-06-17 14:16 ` Jerin Jacob
2025-06-17 12:41 ` [PATCH 1/2] lib/graph: avoid memset(NULL, 0, 0) Jerin Jacob
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=20250617105209.50526-2-marat.khalili@huawei.com \
--to=marat.khalili@huawei.com \
--cc=dev@dpdk.org \
--cc=jerinj@marvell.com \
--cc=kirankumark@marvell.com \
--cc=ndabilpuram@marvell.com \
--cc=yanzhirun_163@163.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).