Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1620345

[PATCH 1/3] x86/numa_emulation: fix potential memory leak

Path csiph.com!news.mixmin.net!aioe.org!news.servidellagleba.it!bofh.it!news.nic.it!robomod
From Wei Yang <richard.weiyang@gmail.com>
Newsgroups linux.kernel
Subject [PATCH 1/3] x86/numa_emulation: fix potential memory leak
Date Mon, 10 Apr 2017 19:00:04 +0200
Message-ID <tuKPy-3hW-67@gated-at.bofh.it> (permalink)
References <tuKPw-3hW-19@gated-at.bofh.it>
X-Original-To kirill@shutemov.name, bp@alien8.de, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, tj@kernel.org
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b5ahTAkVBemCoUc9iwqluyPYbpJV2TlzsuCFY7f3sNE=; b=Ag/XdFC0PGEWKVjz/TNtMi7ljI+smX8ehLIk/8xQ5V61koqrm2f4W7DrI6J1OrQqOp G8/KxXC2SWypbA42jXa0adDW48sSnUPY+IV/sb2x26Yit+vOv3j10/nqv5u5w8Bxsyul 0dGAAeDClhWWBkUkGAiuAP17slU3uhYvbctwuZqvltPmr763D8HJNhY3UG7gP4mB4vFE U3voC8pe3od/vapebV1D7SAEGsbqghNXQJAg2+CqKboXrPWe2lxSioewhPUy6uz1dKBY RKCU6dL3Q/69mBA6cokmmbaGH3yC/u+/4dNdTydv/0M8Lyf6W+j8n9EKDy8s0S9Pe2W2 acQQ==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b5ahTAkVBemCoUc9iwqluyPYbpJV2TlzsuCFY7f3sNE=; b=Y+7vTZwF0kh3IyiE6tKIwDmESiRXB4A+2cgCmzxiQB2b0BcwUQGMXK7Cz9mqGBBiXK WaGa1MEu/sSCm/hEy46QiKCPI4mqTFLdeXBfjsIu9YSYezb7U2igqhzxXLHv5SEfTdbj //GQprGvsnN5ZSo6KtQ53yvU2XRdha7+KCfUPzT6zpTIUSRhZrWWZLeGuBsUU+yX1qA+ IeX9Il6CWiopY/lNWq6/eoNb5hR5+KiM8A3FIkimSaZj6TWIZur/FCwwaKf5KBpuTBKe w0o2vw02aCpbKjc57XvsDgglaQ8g1VHBlYMEChnjd6On7cx0jFslxVo1AOMoKRGxiblH tZ8Q==
X-Gm-Message-State AFeK/H0wQ3O0oag1lJPAcz0vnwcJDZoGh+zd9CKBNQI4v80W0meZd3TCOE5IZuLRze6fPg==
X-Received by 10.98.87.216 with SMTP id i85mr57190442pfj.151.1491843431280; Mon, 10 Apr 2017 09:57:11 -0700 (PDT)
X-Mailer git-send-email 2.11.0
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 67
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, Wei Yang <richard.weiyang@gmail.com>
X-Original-Date Tue, 11 Apr 2017 00:56:50 +0800
X-Original-Message-ID <20170410165652.50250-2-richard.weiyang@gmail.com>
X-Original-References <20170410165652.50250-1-richard.weiyang@gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1620345

Show key headers only | View raw


numa_emulation() needs to allocate a space for phys_dist[] temporarily,
while current code may miss to release this when dfl_phys_nid ==
NUMA_NO_NODE. It is observed in code review instead of in a real case.

This patch fixes this by re-order the code path.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 arch/x86/mm/numa_emulation.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/arch/x86/mm/numa_emulation.c b/arch/x86/mm/numa_emulation.c
index a8f90ce3dedf..eb017c816de6 100644
--- a/arch/x86/mm/numa_emulation.c
+++ b/arch/x86/mm/numa_emulation.c
@@ -353,6 +353,24 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
 		goto no_emu;
 	}
 
+	/*
+	 * Determine the max emulated nid and the default phys nid to use
+	 * for unmapped nodes.
+	 */
+	max_emu_nid = 0;
+	dfl_phys_nid = NUMA_NO_NODE;
+	for (i = 0; i < ARRAY_SIZE(emu_nid_to_phys); i++) {
+		if (emu_nid_to_phys[i] != NUMA_NO_NODE) {
+			max_emu_nid = i;
+			if (dfl_phys_nid == NUMA_NO_NODE)
+				dfl_phys_nid = emu_nid_to_phys[i];
+		}
+	}
+	if (dfl_phys_nid == NUMA_NO_NODE) {
+		pr_warning("NUMA: Warning: can't determine default physical node, disabling emulation\n");
+		goto no_emu;
+	}
+
 	/* copy the physical distance table */
 	if (numa_dist_cnt) {
 		u64 phys;
@@ -372,24 +390,6 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
 					node_distance(i, j);
 	}
 
-	/*
-	 * Determine the max emulated nid and the default phys nid to use
-	 * for unmapped nodes.
-	 */
-	max_emu_nid = 0;
-	dfl_phys_nid = NUMA_NO_NODE;
-	for (i = 0; i < ARRAY_SIZE(emu_nid_to_phys); i++) {
-		if (emu_nid_to_phys[i] != NUMA_NO_NODE) {
-			max_emu_nid = i;
-			if (dfl_phys_nid == NUMA_NO_NODE)
-				dfl_phys_nid = emu_nid_to_phys[i];
-		}
-	}
-	if (dfl_phys_nid == NUMA_NO_NODE) {
-		pr_warning("NUMA: Warning: can't determine default physical node, disabling emulation\n");
-		goto no_emu;
-	}
-
 	/* commit */
 	*numa_meminfo = ei;
 
-- 
2.11.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/3] Refine numa_emulation Wei Yang <richard.weiyang@gmail.com> - 2017-04-10 19:00 +0200
  [PATCH 1/3] x86/numa_emulation: fix potential memory leak Wei Yang <richard.weiyang@gmail.com> - 2017-04-10 19:00 +0200
    Re: [PATCH 1/3] x86/numa_emulation: fix potential memory leak David Rientjes <rientjes@google.com> - 2017-04-11 02:20 +0200
  [PATCH 2/3] x86/numa_emulation: assign physnode_mask directly from numa_nodes_parsed Wei Yang <richard.weiyang@gmail.com> - 2017-04-10 19:00 +0200
    Re: [PATCH 2/3] x86/numa_emulation: assign physnode_mask directly  from numa_nodes_parsed David Rientjes <rientjes@google.com> - 2017-04-11 02:30 +0200
      Re: [PATCH 2/3] x86/numa_emulation: assign physnode_mask directly  from numa_nodes_parsed Wei Yang <richard.weiyang@gmail.com> - 2017-04-11 03:50 +0200

csiph-web