DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jerin Jacob <jerinjacobk@gmail.com>
To: Marat Khalili <marat.khalili@huawei.com>,
	 Stephen Hemminger <stephen@networkplumber.org>,
	Thomas Monjalon <thomas@monjalon.net>,
	 David Marchand <david.marchand@redhat.com>
Cc: Jerin Jacob <jerinj@marvell.com>,
	Kiran Kumar K <kirankumark@marvell.com>,
	 Nithin Dabilpuram <ndabilpuram@marvell.com>,
	Zhirun Yan <yanzhirun_163@163.com>,
	dev@dpdk.org
Subject: Re: [PATCH 2/2] lib/graph: rte_malloc for cache-aligned structs
Date: Tue, 17 Jun 2025 18:16:05 +0530	[thread overview]
Message-ID: <CALBAE1N19pB_D6w-LYE0v-vT+RYb7XGoPO-2eTjpgRHw8dzm+w@mail.gmail.com> (raw)
In-Reply-To: <20250617105209.50526-2-marat.khalili@huawei.com>

On Tue, Jun 17, 2025 at 4:32 PM Marat Khalili <marat.khalili@huawei.com> wrote:
>
> 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>


Since this memory is used in slowpath, heap memory is fine.
I think, better fix will be to remove cache alignment from
rte_graph_cluster_stats.
Not sure it will call for ABI change though.Run
devtools/test-meson-builds.sh to validate any ABI breakage.






> ---
>  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
>

  reply	other threads:[~2025-06-17 12:46 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 ` [PATCH 2/2] lib/graph: rte_malloc for cache-aligned structs Marat Khalili
2025-06-17 12:46   ` Jerin Jacob [this message]
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=CALBAE1N19pB_D6w-LYE0v-vT+RYb7XGoPO-2eTjpgRHw8dzm+w@mail.gmail.com \
    --to=jerinjacobk@gmail.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=kirankumark@marvell.com \
    --cc=marat.khalili@huawei.com \
    --cc=ndabilpuram@marvell.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    --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).