From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 6819D1B19; Fri, 21 Sep 2018 11:27:25 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 02:27:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,284,1534834800"; d="scan'208";a="85416524" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 21 Sep 2018 02:27:23 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w8L9RMjx003750; Fri, 21 Sep 2018 10:27:22 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w8L9RMql030439; Fri, 21 Sep 2018 10:27:22 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w8L9RMlp030432; Fri, 21 Sep 2018 10:27:22 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: solal.pirelli@gmail.com, i.maximets@samsung.com, stable@dpdk.org Date: Fri, 21 Sep 2018 10:27:22 +0100 Message-Id: <2f0bea6a3860143bfbcf31142440a0e4db7c7933.1537521888.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <7e4178219213303b982e505ae4cb4387d9d3814a.1537447684.git.anatoly.burakov@intel.com> References: <7e4178219213303b982e505ae4cb4387d9d3814a.1537447684.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH v3] mem: fix undefined behavior in NUMA code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Sep 2018 09:27:27 -0000 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") Cc: i.maximets@samsung.com Cc: stable@dpdk.org Signed-off-by: Anatoly Burakov --- Notes: v3: - Fix potential memory leak if socket-mem was not specified v2: - Improve readability as per Ilya's comment 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 @@ -263,7 +263,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; @@ -275,6 +275,7 @@ 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) { RTE_LOG(ERR, EAL, @@ -402,7 +403,8 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi, numa_set_localalloc(); } } - numa_free_cpumask(oldmask); + if (oldmask != NULL) + numa_free_cpumask(oldmask); #endif return i; } -- 2.17.1