From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: solal.pirelli@gmail.com, i.maximets@samsung.com, stable@dpdk.org
Subject: [dpdk-dev] [PATCH v3] mem: fix undefined behavior in NUMA code
Date: Fri, 21 Sep 2018 10:27:22 +0100 [thread overview]
Message-ID: <2f0bea6a3860143bfbcf31142440a0e4db7c7933.1537521888.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <7e4178219213303b982e505ae4cb4387d9d3814a.1537447684.git.anatoly.burakov@intel.com>
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 <anatoly.burakov@intel.com>
---
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
next prev parent reply other threads:[~2018-09-21 9:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20180829122139epcas1p13ad45026365d788c072f2ed7a38349fb@epcas1p1.samsung.com>
2018-08-29 12:21 ` [dpdk-dev] [PATCH] " Anatoly Burakov
2018-08-29 13:02 ` Ilya Maximets
2018-09-20 12:50 ` [dpdk-dev] [PATCH v2] " Anatoly Burakov
2018-09-21 6:47 ` Ilya Maximets
2018-09-21 8:57 ` Burakov, Anatoly
2018-09-21 9:27 ` Anatoly Burakov [this message]
2018-09-21 11:02 ` [dpdk-dev] [PATCH v3] " Ilya Maximets
2018-10-03 22:36 ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2f0bea6a3860143bfbcf31142440a0e4db7c7933.1537521888.git.anatoly.burakov@intel.com \
--to=anatoly.burakov@intel.com \
--cc=dev@dpdk.org \
--cc=i.maximets@samsung.com \
--cc=solal.pirelli@gmail.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).