From b7cdfefe409609bf37484934699a10a14bb9f9a3 Mon Sep 17 00:00:00 2001 From: Ilyes Ben Hamouda Date: Tue, 17 Aug 2021 14:49:09 +0200 Subject: [PATCH] eal: fix crash when allocating memory on a control thread By using rte_malloc(), the choice of a numa socket in case of SOCKET_ID_ANY is 0. This may lead to control thread crash in alloc_seg() when numa node 0 is not used. Let's choose the first numa socket where memory is available. Note: malloc_get_numa_socket is no longer small(contains a loop). Hence, inline keyword was removed. PR=74909 Fixes: b94580d6887e ("malloc: avoid unknown socket id") Signed-off-by: Ilyes Ben Hamouda Acked-by: Olivier Matz --- lib/eal/common/malloc_heap.c | 18 ++++++++++++++++++ lib/eal/common/malloc_heap.h | 11 ----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c index ee400f38ec..054d92bc7d 100644 --- a/lib/eal/common/malloc_heap.c +++ b/lib/eal/common/malloc_heap.c @@ -694,6 +694,24 @@ alloc_unlock: return ret; } +static unsigned +malloc_get_numa_socket(void) +{ + const struct internal_config *internal_conf = + eal_get_internal_configuration(); + unsigned socket_id = rte_socket_id(); + + if (socket_id != (unsigned)SOCKET_ID_ANY) + return socket_id; + + /* return first id where memory is available, otherwise 0 */ + for (socket_id = 0; socket_id < RTE_MAX_NUMA_NODES; ++socket_id) + if (internal_conf->socket_mem[socket_id] != 0) + return socket_id; + + return 0; +} + void * malloc_heap_alloc(const char *type, size_t size, int socket_arg, unsigned int flags, size_t align, size_t bound, bool contig) diff --git a/lib/eal/common/malloc_heap.h b/lib/eal/common/malloc_heap.h index 3a6ec6ecf0..3a29d024b4 100644 --- a/lib/eal/common/malloc_heap.h +++ b/lib/eal/common/malloc_heap.h @@ -33,17 +33,6 @@ struct malloc_heap { char name[RTE_HEAP_NAME_MAX_LEN]; } __rte_cache_aligned; -static inline unsigned -malloc_get_numa_socket(void) -{ - unsigned socket_id = rte_socket_id(); - - if (socket_id == (unsigned)SOCKET_ID_ANY) - return 0; - - return socket_id; -} - void * malloc_heap_alloc(const char *type, size_t size, int socket, unsigned int flags, size_t align, size_t bound, bool contig); -- 2.20.1