[PATCH 2/2] lib/graph: rte_malloc for cache-aligned structs
Stephen Hemminger
stephen at networkplumber.org
Tue Jun 17 15:27:16 CEST 2025
On Tue, 17 Jun 2025 11:52:08 +0100
Marat Khalili <marat.khalili at 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 at huawei.com>
There is a way to get aligned memory,
#include <stdlib.h>
int posix_memalign(void **memptr, size_t alignment, size_t size);
void *aligned_alloc(size_t alignment, size_t size);
More information about the dev
mailing list