From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 2ADB1322C for ; Fri, 30 Nov 2018 00:13:41 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from yskoh@mellanox.com) with ESMTPS (AES256-SHA encrypted); 30 Nov 2018 01:19:30 +0200 Received: from scfae-sc-2.mti.labs.mlnx (scfae-sc-2.mti.labs.mlnx [10.101.0.96]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id wATNCW7b032075; Fri, 30 Nov 2018 01:13:35 +0200 From: Yongseok Koh To: Anatoly Burakov Cc: Ilya Maximets , dpdk stable Date: Thu, 29 Nov 2018 15:10:31 -0800 Message-Id: <20181129231202.30436-37-yskoh@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181129231202.30436-1-yskoh@mellanox.com> References: <20181129231202.30436-1-yskoh@mellanox.com> Subject: [dpdk-stable] patch 'mem: fix undefined behavior in NUMA-aware mapping' has been queued to LTS release 17.11.5 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Nov 2018 23:13:41 -0000 Hi, FYI, your patch has been queued to LTS release 17.11.5 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/01/18. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. If the code is different (ie: not only metadata diffs), due for example to a change in context or macro names, please double check it. Thanks. Yongseok --- >>From df37e777d07eff975fbf500dc5f3313ddc756ae5 Mon Sep 17 00:00:00 2001 From: Anatoly Burakov Date: Fri, 21 Sep 2018 10:27:22 +0100 Subject: [PATCH] mem: fix undefined behavior in NUMA-aware mapping [ upstream commit b1621823eacbe4669a4b581d6c420db08f9e6505 ] When NUMA-aware hugepages config option is set, we rely on libnuma to tell the kernel to allocate hugepages on a specific NUMA node. However, we allocate node mask before we check if NUMA is available in the first place, which, according to the manpage [1], causes undefined behaviour. Fix by only using nodemask when we have NUMA available. [1] https://linux.die.net/man/3/numa_alloc_onnode Bugzilla ID: 20 Fixes: 1b72605d2416 ("mem: balanced allocation of hugepages") Signed-off-by: Anatoly Burakov Acked-by: Ilya Maximets --- lib/librte_eal/linuxapp/eal/eal_memory.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 0675809b7..8d0456b56 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -396,7 +396,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, int node_id = -1; int essential_prev = 0; int oldpolicy; - struct bitmask *oldmask = numa_allocate_nodemask(); + struct bitmask *oldmask = NULL; bool have_numa = true; unsigned long maxnode = 0; @@ -408,6 +408,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, if (orig && have_numa) { RTE_LOG(DEBUG, EAL, "Trying to obtain current memory policy.\n"); + oldmask = numa_allocate_nodemask(); if (get_mempolicy(&oldpolicy, oldmask->maskp, oldmask->size + 1, 0, 0) < 0) { RTE_LOG(ERR, EAL, @@ -603,7 +604,8 @@ out: numa_set_localalloc(); } } - numa_free_cpumask(oldmask); + if (oldmask != NULL) + numa_free_cpumask(oldmask); #endif return i; } -- 2.11.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2018-11-29 15:01:46.882720528 -0800 +++ 0037-mem-fix-undefined-behavior-in-NUMA-aware-mapping.patch 2018-11-29 15:01:45.055965000 -0800 @@ -1,8 +1,10 @@ -From b1621823eacbe4669a4b581d6c420db08f9e6505 Mon Sep 17 00:00:00 2001 +From df37e777d07eff975fbf500dc5f3313ddc756ae5 Mon Sep 17 00:00:00 2001 From: Anatoly Burakov Date: Fri, 21 Sep 2018 10:27:22 +0100 Subject: [PATCH] mem: fix undefined behavior in NUMA-aware mapping +[ upstream commit b1621823eacbe4669a4b581d6c420db08f9e6505 ] + When NUMA-aware hugepages config option is set, we rely on libnuma to tell the kernel to allocate hugepages on a specific NUMA node. However, we allocate node mask before we check if @@ -15,7 +17,6 @@ Bugzilla ID: 20 Fixes: 1b72605d2416 ("mem: balanced allocation of hugepages") -Cc: stable@dpdk.org Signed-off-by: Anatoly Burakov Acked-by: Ilya Maximets @@ -24,10 +25,10 @@ 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c -index e3ac24815..78bfa2241 100644 +index 0675809b7..8d0456b56 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c -@@ -264,7 +264,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, +@@ -396,7 +396,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, int node_id = -1; int essential_prev = 0; int oldpolicy; @@ -36,15 +37,15 @@ bool have_numa = true; unsigned long maxnode = 0; -@@ -276,6 +276,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, +@@ -408,6 +408,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, - if (have_numa) { + if (orig && have_numa) { RTE_LOG(DEBUG, EAL, "Trying to obtain current memory policy.\n"); + oldmask = numa_allocate_nodemask(); if (get_mempolicy(&oldpolicy, oldmask->maskp, oldmask->size + 1, 0, 0) < 0) { RTE_LOG(ERR, EAL, -@@ -403,7 +404,8 @@ out: +@@ -603,7 +604,8 @@ out: numa_set_localalloc(); } }