Linux-MIPS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware
@ 2019-09-12 10:15 Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 1/8] arm64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for arm64 Yunsheng Lin
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN:

[   42.970381] ==================================================================
[   42.977595] BUG: KASAN: global-out-of-bounds in __bitmap_weight+0x48/0xb0
[   42.984370] Read of size 8 at addr ffff20008cdf8790 by task kworker/0:1/13
[   42.991230]
[   42.992712] CPU: 0 PID: 13 Comm: kworker/0:1 Tainted: G           O      5.2.0-rc4-g8bde06a-dirty #3
[   43.001830] Hardware name: Huawei TaiShan 2280 V2/BC82AMDA, BIOS TA BIOS 2280-A CS V2.B050.01 08/08/2019
[   43.011298] Workqueue: events work_for_cpu_fn
[   43.015643] Call trace:
[   43.018078]  dump_backtrace+0x0/0x1e8
[   43.021727]  show_stack+0x14/0x20
[   43.025031]  dump_stack+0xc4/0xfc
[   43.028335]  print_address_description+0x178/0x270
[   43.033113]  __kasan_report+0x164/0x1b8
[   43.036936]  kasan_report+0xc/0x18
[   43.040325]  __asan_load8+0x84/0xa8
[   43.043801]  __bitmap_weight+0x48/0xb0
[   43.047552]  hclge_init_ae_dev+0x988/0x1e78 [hclge]
[   43.052418]  hnae3_register_ae_dev+0xcc/0x278 [hnae3]
[   43.057467]  hns3_probe+0xe0/0x120 [hns3]
[   43.061464]  local_pci_probe+0x74/0xf0
[   43.065200]  work_for_cpu_fn+0x2c/0x48
[   43.068937]  process_one_work+0x3c0/0x878
[   43.072934]  worker_thread+0x400/0x670
[   43.076670]  kthread+0x1b0/0x1b8
[   43.079885]  ret_from_fork+0x10/0x18
[   43.083446]
[   43.084925] The buggy address belongs to the variable:
[   43.090052]  numa_distance+0x30/0x40
[   43.093613]
[   43.095091] Memory state around the buggy address:
[   43.099870]  ffff20008cdf8680: fa fa fa fa 04 fa fa fa fa fa fa fa 00 00 fa fa
[   43.107078]  ffff20008cdf8700: fa fa fa fa 04 fa fa fa fa fa fa fa 00 fa fa fa
[   43.114286] >ffff20008cdf8780: fa fa fa fa 00 00 00 00 00 00 00 00 fa fa fa fa
[   43.121494]                          ^
[   43.125230]  ffff20008cdf8800: 01 fa fa fa fa fa fa fa 04 fa fa fa fa fa fa fa
[   43.132439]  ffff20008cdf8880: fa fa fa fa fa fa fa fa 00 00 fa fa fa fa fa fa
[   43.139646] ==================================================================

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

Note:
1. Only arm64 has been compile tested and tested on real board.
2. x86 has been compile tested with defconfig.
3. Other arch has not been compile tested or tested on real board.

Change log:
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change, drop sh arch change since it always return cpu_online_mask.

Yunsheng Lin (8):
  arm64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for arm64
  x86: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for x86
  alpha: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for alpha
  powerpc: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for
    powerpc
  s390: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for s390
  sparc64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for
    sparc64
  mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips
  mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for
    loongson64

 arch/alpha/include/asm/topology.h                | 2 +-
 arch/arm64/include/asm/numa.h                    | 3 +++
 arch/arm64/mm/numa.c                             | 5 ++++-
 arch/mips/include/asm/mach-ip27/topology.h       | 4 ++--
 arch/mips/include/asm/mach-loongson64/topology.h | 4 +++-
 arch/powerpc/include/asm/topology.h              | 4 ++--
 arch/s390/include/asm/topology.h                 | 3 +++
 arch/sparc/include/asm/topology_64.h             | 4 ++--
 arch/x86/include/asm/topology.h                  | 3 +++
 arch/x86/mm/numa.c                               | 7 +++++--
 10 files changed, 28 insertions(+), 11 deletions(-)

-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 1/8] arm64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for arm64
  2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
@ 2019-09-12 10:15 ` Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 2/8] x86: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for x86 Yunsheng Lin
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN.

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

Also there is a debuging version of node_to_cpumask_map(), which only
is used when CONFIG_DEBUG_PER_CPU_MAPS is defined, this patch changes
it to handle NUMA_NO_NODE as the normal node_to_cpumask_map(). And "fix"
a sign "bug" since it is for debugging and should catch all the error
cases.

[1] https://lore.kernel.org/patchwork/patch/1125789/
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Suggested-by: Michal Hocko <mhocko@kernel.org>
---
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change.
---
 arch/arm64/include/asm/numa.h | 3 +++
 arch/arm64/mm/numa.c          | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/numa.h b/arch/arm64/include/asm/numa.h
index 626ad01..c8a4b31 100644
--- a/arch/arm64/include/asm/numa.h
+++ b/arch/arm64/include/asm/numa.h
@@ -25,6 +25,9 @@ const struct cpumask *cpumask_of_node(int node);
 /* Returns a pointer to the cpumask of CPUs on Node 'node'. */
 static inline const struct cpumask *cpumask_of_node(int node)
 {
+	if (node == NUMA_NO_NODE)
+		return cpu_online_mask;
+
 	return node_to_cpumask_map[node];
 }
 #endif
diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c
index 4f241cc..bef4bdd 100644
--- a/arch/arm64/mm/numa.c
+++ b/arch/arm64/mm/numa.c
@@ -46,7 +46,10 @@ EXPORT_SYMBOL(node_to_cpumask_map);
  */
 const struct cpumask *cpumask_of_node(int node)
 {
-	if (WARN_ON(node >= nr_node_ids))
+	if (node == NUMA_NO_NODE)
+		return cpu_online_mask;
+
+	if (WARN_ON((unsigned int)node >= nr_node_ids))
 		return cpu_none_mask;
 
 	if (WARN_ON(node_to_cpumask_map[node] == NULL))
-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 2/8] x86: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for x86
  2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 1/8] arm64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for arm64 Yunsheng Lin
@ 2019-09-12 10:15 ` Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 3/8] alpha: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for alpha Yunsheng Lin
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN.

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

Also there is a debuging version of node_to_cpumask_map(), which only
is used when CONFIG_DEBUG_PER_CPU_MAPS is defined, this patch changes
it to handle NUMA_NO_NODE as the normal node_to_cpumask_map(). And "fix"
a sign "bug" since it is for debugging and should catch all the error
cases.

[1] https://lore.kernel.org/patchwork/patch/1125789/
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Suggested-by: Michal Hocko <mhocko@kernel.org>
---
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change.
---
 arch/x86/include/asm/topology.h | 3 +++
 arch/x86/mm/numa.c              | 7 +++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index 4b14d23..7fa82e1 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -69,6 +69,9 @@ extern const struct cpumask *cpumask_of_node(int node);
 /* Returns a pointer to the cpumask of CPUs on Node 'node'. */
 static inline const struct cpumask *cpumask_of_node(int node)
 {
+	if (node == NUMA_NO_NODE)
+		return cpu_online_mask;
+
 	return node_to_cpumask_map[node];
 }
 #endif
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index e6dad60..c676ffb 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -861,9 +861,12 @@ void numa_remove_cpu(int cpu)
  */
 const struct cpumask *cpumask_of_node(int node)
 {
-	if (node >= nr_node_ids) {
+	if (node == NUMA_NO_NODE)
+		return cpu_online_mask;
+
+	if ((unsigned int)node >= nr_node_ids) {
 		printk(KERN_WARNING
-			"cpumask_of_node(%d): node > nr_node_ids(%u)\n",
+			"cpumask_of_node(%d): node >= nr_node_ids(%u)\n",
 			node, nr_node_ids);
 		dump_stack();
 		return cpu_none_mask;
-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 3/8] alpha: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for alpha
  2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 1/8] arm64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for arm64 Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 2/8] x86: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for x86 Yunsheng Lin
@ 2019-09-12 10:15 ` Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 4/8] powerpc: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for powerpc Yunsheng Lin
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN.

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

Since this arch was already NUMA_NO_NODE aware, this patch only changes
it to return cpu_online_mask.

[1] https://lore.kernel.org/patchwork/patch/1125789/
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Suggested-by: Michal Hocko <mhocko@kernel.org>
---
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change.
---
 arch/alpha/include/asm/topology.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/alpha/include/asm/topology.h b/arch/alpha/include/asm/topology.h
index 5a77a40..836c9e2 100644
--- a/arch/alpha/include/asm/topology.h
+++ b/arch/alpha/include/asm/topology.h
@@ -31,7 +31,7 @@ static const struct cpumask *cpumask_of_node(int node)
 	int cpu;
 
 	if (node == NUMA_NO_NODE)
-		return cpu_all_mask;
+		return cpu_online_mask;
 
 	cpumask_clear(&node_to_cpumask_map[node]);
 
-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 4/8] powerpc: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for powerpc
  2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
                   ` (2 preceding siblings ...)
  2019-09-12 10:15 ` [PATCH v3 3/8] alpha: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for alpha Yunsheng Lin
@ 2019-09-12 10:15 ` Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 5/8] s390: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for s390 Yunsheng Lin
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN.

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

Since this arch was already NUMA_NO_NODE aware, this patch only changes
it to return cpu_online_mask and use NUMA_NO_NODE instead of "-1".

[1] https://lore.kernel.org/patchwork/patch/1125789/
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Suggested-by: Michal Hocko <mhocko@kernel.org>
---
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change.
---
 arch/powerpc/include/asm/topology.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
index 2f7e1ea..107f5cd 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -17,8 +17,8 @@ struct device_node;
 
 #include <asm/mmzone.h>
 
-#define cpumask_of_node(node) ((node) == -1 ?				\
-			       cpu_all_mask :				\
+#define cpumask_of_node(node) ((node) == NUMA_NO_NODE ?			\
+			       cpu_online_mask :			\
 			       node_to_cpumask_map[node])
 
 struct pci_bus;
-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 5/8] s390: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for s390
  2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
                   ` (3 preceding siblings ...)
  2019-09-12 10:15 ` [PATCH v3 4/8] powerpc: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for powerpc Yunsheng Lin
@ 2019-09-12 10:15 ` Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 6/8] sparc64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for sparc64 Yunsheng Lin
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN.

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

[1] https://lore.kernel.org/patchwork/patch/1125789/
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Suggested-by: Michal Hocko <mhocko@kernel.org>
---
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change.
---
 arch/s390/include/asm/topology.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/s390/include/asm/topology.h b/arch/s390/include/asm/topology.h
index cca406f..1bd2e73 100644
--- a/arch/s390/include/asm/topology.h
+++ b/arch/s390/include/asm/topology.h
@@ -78,6 +78,9 @@ static inline int cpu_to_node(int cpu)
 #define cpumask_of_node cpumask_of_node
 static inline const struct cpumask *cpumask_of_node(int node)
 {
+	if (node == NUMA_NO_NODE)
+		return cpu_online_mask;
+
 	return &node_to_cpumask_map[node];
 }
 
-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 6/8] sparc64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for sparc64
  2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
                   ` (4 preceding siblings ...)
  2019-09-12 10:15 ` [PATCH v3 5/8] s390: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for s390 Yunsheng Lin
@ 2019-09-12 10:15 ` Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips Yunsheng Lin
  2019-09-12 10:15 ` [PATCH v3 8/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for loongson64 Yunsheng Lin
  7 siblings, 0 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN.

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

Since this arch was already NUMA_NO_NODE aware, this patch only changes
it to return cpu_online_mask and use NUMA_NO_NODE instead of "-1".

[1] https://lore.kernel.org/patchwork/patch/1125789/
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Suggested-by: Michal Hocko <mhocko@kernel.org>
---
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change.
---
 arch/sparc/include/asm/topology_64.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/include/asm/topology_64.h b/arch/sparc/include/asm/topology_64.h
index 34c628a..34f9240 100644
--- a/arch/sparc/include/asm/topology_64.h
+++ b/arch/sparc/include/asm/topology_64.h
@@ -11,8 +11,8 @@ static inline int cpu_to_node(int cpu)
 	return numa_cpu_lookup_table[cpu];
 }
 
-#define cpumask_of_node(node) ((node) == -1 ?				\
-			       cpu_all_mask :				\
+#define cpumask_of_node(node) ((node) == NUMA_NO_NODE ?			\
+			       cpu_online_mask :			\
 			       &numa_cpumask_lookup_table[node])
 
 struct pci_bus;
-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips
  2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
                   ` (5 preceding siblings ...)
  2019-09-12 10:15 ` [PATCH v3 6/8] sparc64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for sparc64 Yunsheng Lin
@ 2019-09-12 10:15 ` Yunsheng Lin
  2019-09-15  5:49   ` Mike Rapoport
  2019-09-12 10:15 ` [PATCH v3 8/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for loongson64 Yunsheng Lin
  7 siblings, 1 reply; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN.

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

Since this arch was already NUMA_NO_NODE aware, this patch only changes
it to return cpu_online_mask and use NUMA_NO_NODE instead of "-1".

[1] https://lore.kernel.org/patchwork/patch/1125789/
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Suggested-by: Michal Hocko <mhocko@kernel.org>
---
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change.
---
 arch/mips/include/asm/mach-ip27/topology.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/include/asm/mach-ip27/topology.h b/arch/mips/include/asm/mach-ip27/topology.h
index 965f079..04505e6 100644
--- a/arch/mips/include/asm/mach-ip27/topology.h
+++ b/arch/mips/include/asm/mach-ip27/topology.h
@@ -15,8 +15,8 @@ struct cpuinfo_ip27 {
 extern struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
 
 #define cpu_to_node(cpu)	(sn_cpu_info[(cpu)].p_nodeid)
-#define cpumask_of_node(node)	((node) == -1 ?				\
-				 cpu_all_mask :				\
+#define cpumask_of_node(node)	((node) == NUMA_NO_NODE ?		\
+				 cpu_online_mask :			\
 				 &hub_data(node)->h_cpus)
 struct pci_bus;
 extern int pcibus_to_node(struct pci_bus *);
-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 8/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for loongson64
  2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
                   ` (6 preceding siblings ...)
  2019-09-12 10:15 ` [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips Yunsheng Lin
@ 2019-09-12 10:15 ` Yunsheng Lin
  7 siblings, 0 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-12 10:15 UTC (permalink / raw)
  To: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc
  Cc: akpm, rppt, anshuman.khandual, tglx, cai, robin.murphy,
	linux-arm-kernel, linux-kernel, hpa, x86, dave.hansen, luto,
	peterz, len.brown, axboe, dledford, jeffrey.t.kirsher,
	linux-alpha, naveen.n.rao, mwb, linuxppc-dev, linux-s390,
	linux-sh, sparclinux, tbogendoerfer, linux-mips, rafael, mhocko,
	gregkh

When passing the return value of dev_to_node() to cpumask_of_node()
without checking the node id if the node id is NUMA_NO_NODE, there is
global-out-of-bounds detected by KASAN.

From the discussion [1], NUMA_NO_NODE really means no node affinity,
which also means all cpus should be usable. So the cpumask_of_node()
should always return all cpus online when user passes the node id
as NUMA_NO_NODE, just like similar semantic that page allocator handles
NUMA_NO_NODE.

But we cannot really copy the page allocator logic. Simply because the
page allocator doesn't enforce the near node affinity. It just picks it
up as a preferred node but then it is free to fallback to any other numa
node. This is not the case here and node_to_cpumask_map will only restrict
to the particular node's cpus which would have really non deterministic
behavior depending on where the code is executed. So in fact we really
want to return cpu_online_mask for NUMA_NO_NODE.

[1] https://lore.kernel.org/patchwork/patch/1125789/
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Suggested-by: Michal Hocko <mhocko@kernel.org>
---
V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
    for NUMA_NO_NODE case, and change the commit log to better justify
    the change.
---
 arch/mips/include/asm/mach-loongson64/topology.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/mach-loongson64/topology.h b/arch/mips/include/asm/mach-loongson64/topology.h
index 7ff819a..2207e2e 100644
--- a/arch/mips/include/asm/mach-loongson64/topology.h
+++ b/arch/mips/include/asm/mach-loongson64/topology.h
@@ -5,7 +5,9 @@
 #ifdef CONFIG_NUMA
 
 #define cpu_to_node(cpu)	(cpu_logical_map(cpu) >> 2)
-#define cpumask_of_node(node)	(&__node_data[(node)]->cpumask)
+#define cpumask_of_node(node)  ((node) == NUMA_NO_NODE ?	\
+				cpu_online_mask :		\
+				(&__node_data[(node)]->cpumask)
 
 struct pci_bus;
 extern int pcibus_to_node(struct pci_bus *);
-- 
2.8.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips
  2019-09-12 10:15 ` [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips Yunsheng Lin
@ 2019-09-15  5:49   ` Mike Rapoport
  2019-09-15  6:13     ` Yunsheng Lin
  0 siblings, 1 reply; 13+ messages in thread
From: Mike Rapoport @ 2019-09-15  5:49 UTC (permalink / raw)
  To: Yunsheng Lin
  Cc: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc, akpm,
	anshuman.khandual, tglx, cai, robin.murphy, linux-arm-kernel,
	linux-kernel, hpa, x86, dave.hansen, luto, peterz, len.brown,
	axboe, dledford, jeffrey.t.kirsher, linux-alpha, naveen.n.rao,
	mwb, linuxppc-dev, linux-s390, linux-sh, sparclinux,
	tbogendoerfer, linux-mips, rafael, mhocko, gregkh

Hi,

On Thu, Sep 12, 2019 at 06:15:33PM +0800, Yunsheng Lin wrote:
> When passing the return value of dev_to_node() to cpumask_of_node()
> without checking the node id if the node id is NUMA_NO_NODE, there is
> global-out-of-bounds detected by KASAN.
> 
> From the discussion [1], NUMA_NO_NODE really means no node affinity,
> which also means all cpus should be usable. So the cpumask_of_node()
> should always return all cpus online when user passes the node id
> as NUMA_NO_NODE, just like similar semantic that page allocator handles
> NUMA_NO_NODE.
> 
> But we cannot really copy the page allocator logic. Simply because the
> page allocator doesn't enforce the near node affinity. It just picks it
> up as a preferred node but then it is free to fallback to any other numa
> node. This is not the case here and node_to_cpumask_map will only restrict
> to the particular node's cpus which would have really non deterministic
> behavior depending on where the code is executed. So in fact we really
> want to return cpu_online_mask for NUMA_NO_NODE.
> 
> Since this arch was already NUMA_NO_NODE aware, this patch only changes
> it to return cpu_online_mask and use NUMA_NO_NODE instead of "-1".
> 
> [1] https://lore.kernel.org/patchwork/patch/1125789/
> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
> Suggested-by: Michal Hocko <mhocko@kernel.org>
> ---
> V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
>     for NUMA_NO_NODE case, and change the commit log to better justify
>     the change.
> ---
>  arch/mips/include/asm/mach-ip27/topology.h | 4 ++--

Nit: the subject says "mips:", but this patch only touches sgi-ip27 and
loongson is updated as a separate patch. I don't see why both patches
cannot be merged. Moreover, the whole set can be made as a single patch,
IMHO.

>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/mips/include/asm/mach-ip27/topology.h b/arch/mips/include/asm/mach-ip27/topology.h
> index 965f079..04505e6 100644
> --- a/arch/mips/include/asm/mach-ip27/topology.h
> +++ b/arch/mips/include/asm/mach-ip27/topology.h
> @@ -15,8 +15,8 @@ struct cpuinfo_ip27 {
>  extern struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
>  
>  #define cpu_to_node(cpu)	(sn_cpu_info[(cpu)].p_nodeid)
> -#define cpumask_of_node(node)	((node) == -1 ?				\
> -				 cpu_all_mask :				\
> +#define cpumask_of_node(node)	((node) == NUMA_NO_NODE ?		\
> +				 cpu_online_mask :			\
>  				 &hub_data(node)->h_cpus)
>  struct pci_bus;
>  extern int pcibus_to_node(struct pci_bus *);
> -- 
> 2.8.1
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips
  2019-09-15  5:49   ` Mike Rapoport
@ 2019-09-15  6:13     ` Yunsheng Lin
  2019-09-15  6:46       ` Mike Rapoport
  0 siblings, 1 reply; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-15  6:13 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc, akpm,
	anshuman.khandual, tglx, cai, robin.murphy, linux-arm-kernel,
	linux-kernel, hpa, x86, dave.hansen, luto, peterz, len.brown,
	axboe, dledford, jeffrey.t.kirsher, linux-alpha, naveen.n.rao,
	mwb, linuxppc-dev, linux-s390, linux-sh, sparclinux,
	tbogendoerfer, linux-mips, rafael, mhocko, gregkh

On 2019/9/15 13:49, Mike Rapoport wrote:
> Hi,
> 
> On Thu, Sep 12, 2019 at 06:15:33PM +0800, Yunsheng Lin wrote:
>> When passing the return value of dev_to_node() to cpumask_of_node()
>> without checking the node id if the node id is NUMA_NO_NODE, there is
>> global-out-of-bounds detected by KASAN.
>>
>> From the discussion [1], NUMA_NO_NODE really means no node affinity,
>> which also means all cpus should be usable. So the cpumask_of_node()
>> should always return all cpus online when user passes the node id
>> as NUMA_NO_NODE, just like similar semantic that page allocator handles
>> NUMA_NO_NODE.
>>
>> But we cannot really copy the page allocator logic. Simply because the
>> page allocator doesn't enforce the near node affinity. It just picks it
>> up as a preferred node but then it is free to fallback to any other numa
>> node. This is not the case here and node_to_cpumask_map will only restrict
>> to the particular node's cpus which would have really non deterministic
>> behavior depending on where the code is executed. So in fact we really
>> want to return cpu_online_mask for NUMA_NO_NODE.
>>
>> Since this arch was already NUMA_NO_NODE aware, this patch only changes
>> it to return cpu_online_mask and use NUMA_NO_NODE instead of "-1".
>>
>> [1] https://lore.kernel.org/patchwork/patch/1125789/
>> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
>> Suggested-by: Michal Hocko <mhocko@kernel.org>
>> ---
>> V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
>>     for NUMA_NO_NODE case, and change the commit log to better justify
>>     the change.
>> ---
>>  arch/mips/include/asm/mach-ip27/topology.h | 4 ++--
> 
> Nit: the subject says "mips:", but this patch only touches sgi-ip27 and
> loongson is updated as a separate patch. I don't see why both patches
> cannot be merged. Moreover, the whole set can be made as a single patch,
> IMHO.

Thanks for reviewing.

As this patchset touches a few files, which may has different maintainer.
I am not sure if a separate patch for different arch will make the merging
process easy, or a single patch will make the merging process easy?

It can be made as a single patch if a single patch will make the merging
process easy.

> 
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/mips/include/asm/mach-ip27/topology.h b/arch/mips/include/asm/mach-ip27/topology.h
>> index 965f079..04505e6 100644
>> --- a/arch/mips/include/asm/mach-ip27/topology.h
>> +++ b/arch/mips/include/asm/mach-ip27/topology.h
>> @@ -15,8 +15,8 @@ struct cpuinfo_ip27 {
>>  extern struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
>>  
>>  #define cpu_to_node(cpu)	(sn_cpu_info[(cpu)].p_nodeid)
>> -#define cpumask_of_node(node)	((node) == -1 ?				\
>> -				 cpu_all_mask :				\
>> +#define cpumask_of_node(node)	((node) == NUMA_NO_NODE ?		\
>> +				 cpu_online_mask :			\
>>  				 &hub_data(node)->h_cpus)
>>  struct pci_bus;
>>  extern int pcibus_to_node(struct pci_bus *);
>> -- 
>> 2.8.1
>>
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips
  2019-09-15  6:13     ` Yunsheng Lin
@ 2019-09-15  6:46       ` Mike Rapoport
  2019-09-15  6:51         ` Yunsheng Lin
  0 siblings, 1 reply; 13+ messages in thread
From: Mike Rapoport @ 2019-09-15  6:46 UTC (permalink / raw)
  To: Yunsheng Lin
  Cc: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc, akpm,
	anshuman.khandual, tglx, cai, robin.murphy, linux-arm-kernel,
	linux-kernel, hpa, x86, dave.hansen, luto, peterz, len.brown,
	axboe, dledford, jeffrey.t.kirsher, linux-alpha, naveen.n.rao,
	mwb, linuxppc-dev, linux-s390, linux-sh, sparclinux,
	tbogendoerfer, linux-mips, rafael, mhocko, gregkh

On Sun, Sep 15, 2019 at 02:13:51PM +0800, Yunsheng Lin wrote:
> On 2019/9/15 13:49, Mike Rapoport wrote:
> > Hi,
> > 
> > On Thu, Sep 12, 2019 at 06:15:33PM +0800, Yunsheng Lin wrote:
> >> When passing the return value of dev_to_node() to cpumask_of_node()
> >> without checking the node id if the node id is NUMA_NO_NODE, there is
> >> global-out-of-bounds detected by KASAN.
> >>
> >> From the discussion [1], NUMA_NO_NODE really means no node affinity,
> >> which also means all cpus should be usable. So the cpumask_of_node()
> >> should always return all cpus online when user passes the node id
> >> as NUMA_NO_NODE, just like similar semantic that page allocator handles
> >> NUMA_NO_NODE.
> >>
> >> But we cannot really copy the page allocator logic. Simply because the
> >> page allocator doesn't enforce the near node affinity. It just picks it
> >> up as a preferred node but then it is free to fallback to any other numa
> >> node. This is not the case here and node_to_cpumask_map will only restrict
> >> to the particular node's cpus which would have really non deterministic
> >> behavior depending on where the code is executed. So in fact we really
> >> want to return cpu_online_mask for NUMA_NO_NODE.
> >>
> >> Since this arch was already NUMA_NO_NODE aware, this patch only changes
> >> it to return cpu_online_mask and use NUMA_NO_NODE instead of "-1".
> >>
> >> [1] https://lore.kernel.org/patchwork/patch/1125789/
> >> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
> >> Suggested-by: Michal Hocko <mhocko@kernel.org>
> >> ---
> >> V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
> >>     for NUMA_NO_NODE case, and change the commit log to better justify
> >>     the change.
> >> ---
> >>  arch/mips/include/asm/mach-ip27/topology.h | 4 ++--
> > 
> > Nit: the subject says "mips:", but this patch only touches sgi-ip27 and
> > loongson is updated as a separate patch. I don't see why both patches
> > cannot be merged. Moreover, the whole set can be made as a single patch,
> > IMHO.
> 
> Thanks for reviewing.
> 
> As this patchset touches a few files, which may has different maintainer.
> I am not sure if a separate patch for different arch will make the merging
> process easy, or a single patch will make the merging process easy?

The set makes the same logical change to several definitions of
cpumask_of_node(). It's appropriate to have all these changes in a single
patch.
 
> It can be made as a single patch if a single patch will make the merging
> process easy.
> 
> > 
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/arch/mips/include/asm/mach-ip27/topology.h b/arch/mips/include/asm/mach-ip27/topology.h
> >> index 965f079..04505e6 100644
> >> --- a/arch/mips/include/asm/mach-ip27/topology.h
> >> +++ b/arch/mips/include/asm/mach-ip27/topology.h
> >> @@ -15,8 +15,8 @@ struct cpuinfo_ip27 {
> >>  extern struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
> >>  
> >>  #define cpu_to_node(cpu)	(sn_cpu_info[(cpu)].p_nodeid)
> >> -#define cpumask_of_node(node)	((node) == -1 ?				\
> >> -				 cpu_all_mask :				\
> >> +#define cpumask_of_node(node)	((node) == NUMA_NO_NODE ?		\
> >> +				 cpu_online_mask :			\
> >>  				 &hub_data(node)->h_cpus)
> >>  struct pci_bus;
> >>  extern int pcibus_to_node(struct pci_bus *);
> >> -- 
> >> 2.8.1
> >>
> > 
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips
  2019-09-15  6:46       ` Mike Rapoport
@ 2019-09-15  6:51         ` Yunsheng Lin
  0 siblings, 0 replies; 13+ messages in thread
From: Yunsheng Lin @ 2019-09-15  6:51 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: catalin.marinas, will, mingo, bp, rth, ink, mattst88, benh,
	paulus, mpe, heiko.carstens, gor, borntraeger, ysato, dalias,
	davem, ralf, paul.burton, jhogan, jiaxun.yang, chenhc, akpm,
	anshuman.khandual, tglx, cai, robin.murphy, linux-arm-kernel,
	linux-kernel, hpa, x86, dave.hansen, luto, peterz, len.brown,
	axboe, dledford, jeffrey.t.kirsher, linux-alpha, naveen.n.rao,
	mwb, linuxppc-dev, linux-s390, linux-sh, sparclinux,
	tbogendoerfer, linux-mips, rafael, mhocko, gregkh

On 2019/9/15 14:46, Mike Rapoport wrote:
> On Sun, Sep 15, 2019 at 02:13:51PM +0800, Yunsheng Lin wrote:
>> On 2019/9/15 13:49, Mike Rapoport wrote:
>>> Hi,
>>>
>>> On Thu, Sep 12, 2019 at 06:15:33PM +0800, Yunsheng Lin wrote:
>>>> When passing the return value of dev_to_node() to cpumask_of_node()
>>>> without checking the node id if the node id is NUMA_NO_NODE, there is
>>>> global-out-of-bounds detected by KASAN.
>>>>
>>>> From the discussion [1], NUMA_NO_NODE really means no node affinity,
>>>> which also means all cpus should be usable. So the cpumask_of_node()
>>>> should always return all cpus online when user passes the node id
>>>> as NUMA_NO_NODE, just like similar semantic that page allocator handles
>>>> NUMA_NO_NODE.
>>>>
>>>> But we cannot really copy the page allocator logic. Simply because the
>>>> page allocator doesn't enforce the near node affinity. It just picks it
>>>> up as a preferred node but then it is free to fallback to any other numa
>>>> node. This is not the case here and node_to_cpumask_map will only restrict
>>>> to the particular node's cpus which would have really non deterministic
>>>> behavior depending on where the code is executed. So in fact we really
>>>> want to return cpu_online_mask for NUMA_NO_NODE.
>>>>
>>>> Since this arch was already NUMA_NO_NODE aware, this patch only changes
>>>> it to return cpu_online_mask and use NUMA_NO_NODE instead of "-1".
>>>>
>>>> [1] https://lore.kernel.org/patchwork/patch/1125789/
>>>> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
>>>> Suggested-by: Michal Hocko <mhocko@kernel.org>
>>>> ---
>>>> V3: Change to only handle NUMA_NO_NODE, and return cpu_online_mask
>>>>     for NUMA_NO_NODE case, and change the commit log to better justify
>>>>     the change.
>>>> ---
>>>>  arch/mips/include/asm/mach-ip27/topology.h | 4 ++--
>>>
>>> Nit: the subject says "mips:", but this patch only touches sgi-ip27 and
>>> loongson is updated as a separate patch. I don't see why both patches
>>> cannot be merged. Moreover, the whole set can be made as a single patch,
>>> IMHO.
>>
>> Thanks for reviewing.
>>
>> As this patchset touches a few files, which may has different maintainer.
>> I am not sure if a separate patch for different arch will make the merging
>> process easy, or a single patch will make the merging process easy?
> 
> The set makes the same logical change to several definitions of
> cpumask_of_node(). It's appropriate to have all these changes in a single
> patch.

Ok, thanks.
Will have all these changes in a single patch.


>  
>> It can be made as a single patch if a single patch will make the merging
>> process easy.
>>
>>>
>>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/arch/mips/include/asm/mach-ip27/topology.h b/arch/mips/include/asm/mach-ip27/topology.h
>>>> index 965f079..04505e6 100644
>>>> --- a/arch/mips/include/asm/mach-ip27/topology.h
>>>> +++ b/arch/mips/include/asm/mach-ip27/topology.h
>>>> @@ -15,8 +15,8 @@ struct cpuinfo_ip27 {
>>>>  extern struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
>>>>  
>>>>  #define cpu_to_node(cpu)	(sn_cpu_info[(cpu)].p_nodeid)
>>>> -#define cpumask_of_node(node)	((node) == -1 ?				\
>>>> -				 cpu_all_mask :				\
>>>> +#define cpumask_of_node(node)	((node) == NUMA_NO_NODE ?		\
>>>> +				 cpu_online_mask :			\
>>>>  				 &hub_data(node)->h_cpus)
>>>>  struct pci_bus;
>>>>  extern int pcibus_to_node(struct pci_bus *);
>>>> -- 
>>>> 2.8.1
>>>>
>>>
>>
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, back to index

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-12 10:15 [PATCH v3 0/8] make node_to_cpumask_map() NUMA_NO_NODE aware Yunsheng Lin
2019-09-12 10:15 ` [PATCH v3 1/8] arm64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for arm64 Yunsheng Lin
2019-09-12 10:15 ` [PATCH v3 2/8] x86: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for x86 Yunsheng Lin
2019-09-12 10:15 ` [PATCH v3 3/8] alpha: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for alpha Yunsheng Lin
2019-09-12 10:15 ` [PATCH v3 4/8] powerpc: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for powerpc Yunsheng Lin
2019-09-12 10:15 ` [PATCH v3 5/8] s390: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for s390 Yunsheng Lin
2019-09-12 10:15 ` [PATCH v3 6/8] sparc64: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for sparc64 Yunsheng Lin
2019-09-12 10:15 ` [PATCH v3 7/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for mips Yunsheng Lin
2019-09-15  5:49   ` Mike Rapoport
2019-09-15  6:13     ` Yunsheng Lin
2019-09-15  6:46       ` Mike Rapoport
2019-09-15  6:51         ` Yunsheng Lin
2019-09-12 10:15 ` [PATCH v3 8/8] mips: numa: make node_to_cpumask_map() NUMA_NO_NODE aware for loongson64 Yunsheng Lin

Linux-MIPS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mips/0 linux-mips/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mips linux-mips/ https://lore.kernel.org/linux-mips \
		linux-mips@vger.kernel.org linux-mips@archiver.kernel.org
	public-inbox-index linux-mips


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-mips


AGPL code for this site: git clone https://public-inbox.org/ public-inbox