From 5c979f026c1319c712e7fa4882ec3a4ef3e2101b Mon Sep 17 00:00:00 2001
From: Jianyong Wu <jianyong.wu@arm.com>
Date: Fri, 3 Dec 2021 17:11:39 +0800
Subject: [PATCH 5/7] cpu/numa: fix failure when hot-remove cpu

when hot-remove cpu, the map from cpu to numa will set to NUMA_NO_NODE
which will lead to failure as the map is used by others. thus we need a
specific map to descrip the unpluged cpu.
Here we introduce a new map to descrip the unpluged cpu map.

Singed-off-by: Jianyong Wu <jianyong.wu@arm.com>
---
 arch/arm64/include/asm/smp.h |  2 ++
 arch/arm64/kernel/setup.c    | 14 ++++++++++++++
 arch/arm64/kernel/smp.c      |  5 ++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
index fc55f5a57a06..7949f6090eed 100644
--- a/arch/arm64/include/asm/smp.h
+++ b/arch/arm64/include/asm/smp.h
@@ -47,6 +47,8 @@ DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
  */
 extern u64 __cpu_logical_map[NR_CPUS];
 extern u64 cpu_logical_map(unsigned int cpu);
+extern u64 get_acpicpu_numa_node(unsigned int cpu);
+extern int set_acpicpu_numa_node(unsigned int cpu, unsigned int node);
 
 static inline void set_cpu_logical_map(unsigned int cpu, u64 hwid)
 {
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index be5f85b0a24d..68d7a7894e10 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -284,6 +284,20 @@ static int __init reserve_memblock_reserved_regions(void)
 }
 arch_initcall(reserve_memblock_reserved_regions);
 
+u64 __acpicpu_node_map[NR_CPUS] = { [0 ... NR_CPUS-1] = NUMA_NO_NODE };
+
+u64 get_acpicpu_numa_node(unsigned int cpu)
+{
+	return __acpicpu_node_map[cpu];
+}
+
+int set_acpicpu_numa_node(unsigned int cpu, unsigned int node)
+{
+	__acpicpu_node_map[cpu] = node;
+
+	return 0;
+}
+
 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
 
 u64 cpu_logical_map(unsigned int cpu)
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 8ab68ec01090..0c07921b0b61 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -557,7 +557,10 @@ static int set_numa_node_for_cpu(acpi_handle handle, int cpu)
 	/* will evaluate _PXM */
 	node_id = acpi_get_node(handle);
 	if (node_id != NUMA_NO_NODE)
+	{
+		set_acpicpu_numa_node(cpu, node_id);
 		set_cpu_numa_node(cpu, node_id);
+	}
 #endif
 	return 0;
 }
@@ -565,7 +568,7 @@ static int set_numa_node_for_cpu(acpi_handle handle, int cpu)
 static void unset_numa_node_for_cpu(int cpu)
 {
 #ifdef CONFIG_ACPI_NUMA
-	set_cpu_numa_node(cpu, NUMA_NO_NODE);
+	set_acpicpu_numa_node(cpu, NUMA_NO_NODE);
 #endif
 }
 
-- 
2.17.1

