From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 3E6491B113 for ; Wed, 21 Nov 2018 17:49:49 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B4D08F4FB; Wed, 21 Nov 2018 16:49:48 +0000 (UTC) Received: from ktraynor.remote.csb (unknown [10.36.118.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58EC75C221; Wed, 21 Nov 2018 16:49:47 +0000 (UTC) From: Kevin Traynor To: Anatoly Burakov Cc: Ilya Maximets , dpdk stable Date: Wed, 21 Nov 2018 16:47:26 +0000 Message-Id: <20181121164828.32249-12-ktraynor@redhat.com> In-Reply-To: <20181121164828.32249-1-ktraynor@redhat.com> References: <20181121164828.32249-1-ktraynor@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 21 Nov 2018 16:49:48 +0000 (UTC) Subject: [dpdk-stable] patch 'mem: fix undefined behavior in NUMA-aware mapping' has been queued to stable release 18.08.1 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: Wed, 21 Nov 2018 16:49:49 -0000 Hi, FYI, your patch has been queued to stable release 18.08.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/27/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. Kevin Traynor --- >>From 2e003e3e3bd3bed9bdf5235349106bdb9d14dd01 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 dbf19499e..7747ee6df 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -264,5 +264,5 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, int essential_prev = 0; int oldpolicy; - struct bitmask *oldmask = numa_allocate_nodemask(); + struct bitmask *oldmask = NULL; bool have_numa = true; unsigned long maxnode = 0; @@ -276,4 +276,5 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, if (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) { @@ -403,5 +404,6 @@ out: } } - numa_free_cpumask(oldmask); + if (oldmask != NULL) + numa_free_cpumask(oldmask); #endif return i; -- 2.19.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2018-11-21 16:44:31.260841932 +0000 +++ 0012-mem-fix-undefined-behavior-in-NUMA-aware-mapping.patch 2018-11-21 16:44:30.000000000 +0000 @@ -1,8 +1,10 @@ -From b1621823eacbe4669a4b581d6c420db08f9e6505 Mon Sep 17 00:00:00 2001 +From 2e003e3e3bd3bed9bdf5235349106bdb9d14dd01 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,23 +25,23 @@ 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 dbf19499e..7747ee6df 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c -@@ -265,5 +265,5 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, +@@ -264,5 +264,5 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, int essential_prev = 0; int oldpolicy; - struct bitmask *oldmask = numa_allocate_nodemask(); + struct bitmask *oldmask = NULL; bool have_numa = true; unsigned long maxnode = 0; -@@ -277,4 +277,5 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, +@@ -276,4 +276,5 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, if (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) { -@@ -404,5 +405,6 @@ out: +@@ -403,5 +404,6 @@ out: } } - numa_free_cpumask(oldmask);