Subject: [PATCH 1/3] powerpc/numa: Set numa_node for all possible cpus

From: Srikar Dronamraju <[email-masked]>
Date: Wed, 11 Mar 2020 16:32:35 +0530

A Powerpc system with multiple possible nodes and with CONFIG_NUMA
enabled always used to have a node 0, even if node 0 does not any cpus
or memory attached to it. As per PAPR, node affinity of a cpu is only
available once its present / online. For all cpus that are possible but
not present, cpu_to_node() would point to node 0.

To ensure a cpuless, memoryless dummy node is not online, powerpc need
to make sure all possible but not present cpu_to_node are set to a
proper node.

Cc: [email-masked]
Cc: [email-masked]
Cc: [email-masked]
Cc: Michal Hocko <[email-masked]>
Cc: Mel Gorman <[email-masked]>
Cc: Vlastimil Babka <[email-masked]>
Cc: "Kirill A. Shutemov" <[email-masked]>
Cc: Christopher Lameter <[email-masked]>
Cc: Michael Ellerman <[email-masked]>
Cc: Andrew Morton <[email-masked]>
Cc: Linus Torvalds <[email-masked]>
Signed-off-by: Srikar Dronamraju <[email-masked]>
---
 arch/powerpc/mm/numa.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 8a399db..54dcd49 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -931,8 +931,20 @@ void __init mem_topology_setup(void)
 
 	reset_numa_cpu_lookup_table();
 
-	for_each_present_cpu(cpu)
-		numa_setup_cpu(cpu);
+	for_each_possible_cpu(cpu) {
+		/*
+		 * Powerpc with CONFIG_NUMA always used to have a node 0,
+		 * even if it was memoryless or cpuless. For all cpus that
+		 * are possible but not present, cpu_to_node() would point
+		 * to node 0. To remove a cpuless, memoryless dummy node,
+		 * powerpc need to make sure all possible but not present
+		 * cpu_to_node are set to a proper node.
+		 */
+		if (cpu_present(cpu))
+			numa_setup_cpu(cpu);
+		else
+			set_cpu_numa_node(cpu, first_online_node);
+	}
 }
 
 void __init initmem_init(void)
-- 
1.8.3.1