diff --git a/0016-Fix-out-of-memory-handling-buffer-growing-for-nodes-.patch b/0016-Fix-out-of-memory-handling-buffer-growing-for-nodes-.patch new file mode 100644 index 0000000000000000000000000000000000000000..914a14af2b21bfe880402fe2d6a0f6b592a7de1b --- /dev/null +++ b/0016-Fix-out-of-memory-handling-buffer-growing-for-nodes-.patch @@ -0,0 +1,54 @@ +From a4cd34c58144f7f39cf4f2cea690774b1ac65292 Mon Sep 17 00:00:00 2001 +From: Andi Kleen +Date: Mon, 30 Jun 2025 15:38:54 -0700 +Subject: [PATCH] Fix out of memory handling buffer growing for nodes probing + +When the buffer was too small in the first try, but the second +allocation fails free the original buffer before returning. + +Handle the case when the fallback buffer is used, also only in +out of memory situations. + +Signed-off-by: Andi Kleen + +Conflict: NA +Reference: https://github.com/numactl/numactl/commit/a4cd34c58144f7f39cf4f2cea690774b1ac65292 +--- + libnuma.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/libnuma.c b/libnuma.c +index 380e8a6..8b0393b 100644 +--- a/libnuma.c ++++ b/libnuma.c +@@ -423,13 +423,16 @@ set_nodemask_size(void) + done: + if (nodemask_sz == 0) {/* fall back on error */ + int pol; +- unsigned long *mask = NULL; ++ unsigned long *mask = NULL, *origmask; + nodemask_sz = 16; + do { + nodemask_sz <<= 1; ++ origmask = mask; + mask = realloc(mask, nodemask_sz / 8 + sizeof(unsigned long)); +- if (!mask) ++ if (!mask) { ++ free(origmask); + return; ++ } + } while (get_mempolicy(&pol, mask, nodemask_sz + 1, 0, 0) < 0 && errno == EINVAL && + nodemask_sz < 4096*8); + free(mask); +@@ -1478,7 +1481,7 @@ numa_node_to_cpus_v1(int node, unsigned long *buffer, int bufferlen) + } + + free(line); +- memcpy(buffer, mask, buflen_needed); ++ memmove(buffer, mask, buflen_needed); + + /* slightly racy, see above */ + if (node_cpu_mask_v1[node]) { +-- +2.33.0 + diff --git a/0017-Handle-parallel-allocation-races-with-other-thread-f.patch b/0017-Handle-parallel-allocation-races-with-other-thread-f.patch new file mode 100644 index 0000000000000000000000000000000000000000..be64ea54241c4ab681308923c6287f3d116a8726 --- /dev/null +++ b/0017-Handle-parallel-allocation-races-with-other-thread-f.patch @@ -0,0 +1,51 @@ +From f0ad3520e4182827dce87aab78a686849809b507 Mon Sep 17 00:00:00 2001 +From: Andi Kleen +Date: Mon, 30 Jun 2025 16:52:47 -0700 +Subject: [PATCH] Handle parallel allocation races with other thread for node + mask + +Avoid a potential memory leak when multiple threads are initializing +at the same time. + +Fixes #247 + +Signed-off-by: Andi Kleen + +Conflict: NA +Reference: https://github.com/numactl/numactl/commit/f0ad3520e4182827dce87aab78a686849809b507 +--- + libnuma.c | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/libnuma.c b/libnuma.c +index e27f99f..192faff 100644 +--- a/libnuma.c ++++ b/libnuma.c +@@ -1415,7 +1415,14 @@ numa_parse_bitmap_v2(char *line, struct bitmask *mask) + static void init_node_cpu_mask_v2(void) + { + int nnodes = numa_max_possible_node_v2_int() + 1; +- node_cpu_mask_v2 = calloc (nnodes, sizeof(struct bitmask *)); ++ struct bitmask **new_ncm, **null_ncm = NULL; ++ new_ncm = calloc (nnodes, sizeof(struct bitmask *)); ++ /* Check for races with another thread */ ++ if (new_ncm && !__atomic_compare_exchange_n(&node_cpu_mask_v2, &null_ncm, ++ new_ncm, 1, ++ __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE)) { ++ free(new_ncm); ++ } + } + + static void cleanup_node_cpu_mask_v2(void) +@@ -1535,7 +1542,7 @@ numa_node_to_cpus_v2(int node, struct bitmask *buffer) + size_t len = 0; + struct bitmask *mask; + +- if (!node_cpu_mask_v2) ++ if (!__atomic_load_n(&node_cpu_mask_v2, __ATOMIC_CONSUME)) + init_node_cpu_mask_v2(); + + if (node > nnodes) { +-- +2.33.0 + diff --git a/0018-__atomic_compare_exchange_n-may-fail-and-cause-a-seg.patch b/0018-__atomic_compare_exchange_n-may-fail-and-cause-a-seg.patch new file mode 100644 index 0000000000000000000000000000000000000000..2c24a354e0278399280d238abf75a2c8c28d46eb --- /dev/null +++ b/0018-__atomic_compare_exchange_n-may-fail-and-cause-a-seg.patch @@ -0,0 +1,30 @@ +From b34da01b0017946a1a77057c247cfc6d231a0215 Mon Sep 17 00:00:00 2001 +From: dreamingxxx +Date: Mon, 4 Aug 2025 19:30:02 +0800 +Subject: [PATCH] __atomic_compare_exchange_n may fail and cause a segmentation + fault so use strong variation + +Signed-off-by: dreamingxxx + +Conflict: NA +Reference: https://github.com/numactl/numactl/commit/b34da01b0017946a1a77057c247cfc6d231a0215 +--- + libnuma.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libnuma.c b/libnuma.c +index 01282d3..b4cba4e 100644 +--- a/libnuma.c ++++ b/libnuma.c +@@ -1419,7 +1419,7 @@ static void init_node_cpu_mask_v2(void) + new_ncm = calloc (nnodes, sizeof(struct bitmask *)); + /* Check for races with another thread */ + if (new_ncm && !__atomic_compare_exchange_n(&node_cpu_mask_v2, &null_ncm, +- new_ncm, 1, ++ new_ncm, 0, + __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE)) { + free(new_ncm); + } +-- +2.33.0 + diff --git a/numactl.spec b/numactl.spec index 9eb55a0bc095fe3baf29b3c74056ae2a7ba4dfb4..20873b2a7c2474c30f5fc57cbb243bee230c378a 100644 --- a/numactl.spec +++ b/numactl.spec @@ -1,6 +1,6 @@ Name: numactl Version: 2.0.16 -Release: 13 +Release: 14 Summary: Library for tuning for Non Uniform Memory Access machines License: GPLv2 URL: https://github.com/numactl/numactl @@ -22,6 +22,9 @@ Patch0012: 0012-libnuma-Fix-incorrect-print-and-exit-of-numa_preferr.patch Patch0013: 0013-fix-the-using-of-the-uninitialized-value.patch Patch0014: 0014-backport-Make-numa_available-respect-EPERM.patch Patch0015: 0015-backport-fix-nodemask-allocation-size-for-get_mempolicy.patch +Patch0016: 0016-Fix-out-of-memory-handling-buffer-growing-for-nodes-.patch +Patch0017: 0017-Handle-parallel-allocation-races-with-other-thread-f.patch +Patch0018: 0018-__atomic_compare_exchange_n-may-fail-and-cause-a-seg.patch %description Simple NUMA policy support. It consists of a numactl program to run other @@ -90,6 +93,9 @@ LD_LIBRARY_PATH=$(pwd)/.libs make check %{_mandir}/man3/*.3* %changelog +* Mon Sep 8 2025 xujunming - 2.0.16-14 +- backport patches from upstream + * Tue Jul 01 2025 wangxiao - 2.0.16-13 - delete macros in changelog