Skip to content

Commit 6a4aa4c

Browse files
Merge patch series "Add ACPI NUMA support for RISC-V"
Haibo Xu <[email protected]> says: This patch series enable RISC-V ACPI NUMA support which was based on the recently approved ACPI ECR[1]. Patch 1/4 add RISC-V specific acpi_numa.c file to parse NUMA information from SRAT and SLIT ACPI tables. Patch 2/4 add the common SRAT RINTC affinity structure handler. Patch 3/4 change the ACPI_NUMA to a hidden option since it would be selected by default on all supported platform. Patch 4/4 replace pr_info with pr_debug in arch_acpi_numa_init() to avoid potential boot noise on ACPI platforms that are not NUMA. Based-on: https://github.com/linux-riscv/linux-riscv/tree/for-next [1] https://drive.google.com/file/d/1YTdDx2IPm5IeZjAW932EYU-tUtgS08tX/view?usp=sharing Testing: Since the ACPI AIA/PLIC support patch set is still under upstream review, hence it is tested using the poll based HVC SBI console and RAM disk. 1) Build latest Qemu with the following patch backported vlsunil/qemu@42bd4ee 2) Build latest EDK-II https://github.com/tianocore/edk2/blob/master/OvmfPkg/RiscVVirt/README.md 3) Build Linux with the following configs enabled CONFIG_RISCV_SBI_V01=y CONFIG_SERIAL_EARLYCON_RISCV_SBI=y CONFIG_NONPORTABLE=y CONFIG_HVC_RISCV_SBI=y CONFIG_NUMA=y CONFIG_ACPI_NUMA=y 4) Build buildroot rootfs.cpio 5) Launch the Qemu machine qemu-system-riscv64 -nographic \ -machine virt,pflash0=pflash0,pflash1=pflash1 -smp 4 -m 8G \ -blockdev node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \ -blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \ -object memory-backend-ram,size=4G,id=m0 \ -object memory-backend-ram,size=4G,id=m1 \ -numa node,memdev=m0,cpus=0-1,nodeid=0 \ -numa node,memdev=m1,cpus=2-3,nodeid=1 \ -numa dist,src=0,dst=1,val=30 \ -kernel linux/arch/riscv/boot/Image \ -initrd buildroot/output/images/rootfs.cpio \ -append "root=/dev/ram ro console=hvc0 earlycon=sbi" [ 0.000000] ACPI: SRAT: Node 0 PXM 0 [mem 0x80000000-0x17fffffff] [ 0.000000] ACPI: SRAT: Node 1 PXM 1 [mem 0x180000000-0x27fffffff] [ 0.000000] NUMA: NODE_DATA [mem 0x17fe3bc40-0x17fe3cfff] [ 0.000000] NUMA: NODE_DATA [mem 0x27fff4c40-0x27fff5fff] ... [ 0.000000] ACPI: NUMA: SRAT: PXM 0 -> HARTID 0x0 -> Node 0 [ 0.000000] ACPI: NUMA: SRAT: PXM 0 -> HARTID 0x1 -> Node 0 [ 0.000000] ACPI: NUMA: SRAT: PXM 1 -> HARTID 0x2 -> Node 1 [ 0.000000] ACPI: NUMA: SRAT: PXM 1 -> HARTID 0x3 -> Node 1 * b4-shazam-merge: ACPI: NUMA: replace pr_info with pr_debug in arch_acpi_numa_init ACPI: NUMA: change the ACPI_NUMA to a hidden option ACPI: NUMA: Add handler for SRAT RINTC affinity structure ACPI: RISCV: Add NUMA support based on SRAT and SLIT Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents f557af0 + 5f76d42 commit 6a4aa4c

File tree

12 files changed

+187
-18
lines changed

12 files changed

+187
-18
lines changed

arch/arm64/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,6 @@ config HOTPLUG_CPU
14711471
config NUMA
14721472
bool "NUMA Memory Allocation and Scheduler Support"
14731473
select GENERIC_ARCH_NUMA
1474-
select ACPI_NUMA if ACPI
14751474
select OF_NUMA
14761475
select HAVE_SETUP_PER_CPU_AREA
14771476
select NEED_PER_CPU_EMBED_FIRST_CHUNK

arch/loongarch/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ config NR_CPUS
473473
config NUMA
474474
bool "NUMA Support"
475475
select SMP
476-
select ACPI_NUMA if ACPI
477476
help
478477
Say Y to compile the kernel with NUMA (Non-Uniform Memory Access)
479478
support. This option improves performance on systems with more

arch/riscv/include/asm/acpi.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }
6161

6262
void acpi_init_rintc_map(void);
6363
struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
64-
u32 get_acpi_id_for_cpu(int cpu);
64+
static inline u32 get_acpi_id_for_cpu(int cpu)
65+
{
66+
return acpi_cpu_get_madt_rintc(cpu)->uid;
67+
}
68+
6569
int acpi_get_riscv_isa(struct acpi_table_header *table,
6670
unsigned int cpu, const char **isa);
6771

68-
static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
6972
void acpi_get_cbo_block_size(struct acpi_table_header *table, u32 *cbom_size,
7073
u32 *cboz_size, u32 *cbop_size);
7174
#else
@@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,
8790

8891
#endif /* CONFIG_ACPI */
8992

93+
#ifdef CONFIG_ACPI_NUMA
94+
int acpi_numa_get_nid(unsigned int cpu);
95+
void acpi_map_cpus_to_nodes(void);
96+
#else
97+
static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
98+
static inline void acpi_map_cpus_to_nodes(void) { }
99+
#endif /* CONFIG_ACPI_NUMA */
100+
90101
#endif /*_ASM_ACPI_H*/

arch/riscv/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ obj-$(CONFIG_COMPAT) += compat_vdso/
110110

111111
obj-$(CONFIG_64BIT) += pi/
112112
obj-$(CONFIG_ACPI) += acpi.o
113+
obj-$(CONFIG_ACPI_NUMA) += acpi_numa.o

arch/riscv/kernel/acpi.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
191191
return &cpu_madt_rintc[cpu];
192192
}
193193

194-
u32 get_acpi_id_for_cpu(int cpu)
195-
{
196-
return acpi_cpu_get_madt_rintc(cpu)->uid;
197-
}
198-
199194
/*
200195
* __acpi_map_table() will be called before paging_init(), so early_ioremap()
201196
* or early_memremap() should be called here to for ACPI table mapping.

arch/riscv/kernel/acpi_numa.c

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* ACPI 6.6 based NUMA setup for RISCV
4+
* Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c
5+
*
6+
* Copyright 2004 Andi Kleen, SuSE Labs.
7+
* Copyright (C) 2013-2016, Linaro Ltd.
8+
* Author: Hanjun Guo <[email protected]>
9+
* Copyright (C) 2024 Intel Corporation.
10+
*
11+
* Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
12+
*
13+
* Called from acpi_numa_init while reading the SRAT and SLIT tables.
14+
* Assumes all memory regions belonging to a single proximity domain
15+
* are in one chunk. Holes between them will be included in the node.
16+
*/
17+
18+
#define pr_fmt(fmt) "ACPI: NUMA: " fmt
19+
20+
#include <linux/acpi.h>
21+
#include <linux/bitmap.h>
22+
#include <linux/kernel.h>
23+
#include <linux/mm.h>
24+
#include <linux/memblock.h>
25+
#include <linux/mmzone.h>
26+
#include <linux/module.h>
27+
#include <linux/topology.h>
28+
29+
#include <asm/numa.h>
30+
31+
static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
32+
33+
int __init acpi_numa_get_nid(unsigned int cpu)
34+
{
35+
return acpi_early_node_map[cpu];
36+
}
37+
38+
static inline int get_cpu_for_acpi_id(u32 uid)
39+
{
40+
int cpu;
41+
42+
for (cpu = 0; cpu < nr_cpu_ids; cpu++)
43+
if (uid == get_acpi_id_for_cpu(cpu))
44+
return cpu;
45+
46+
return -EINVAL;
47+
}
48+
49+
static int __init acpi_parse_rintc_pxm(union acpi_subtable_headers *header,
50+
const unsigned long end)
51+
{
52+
struct acpi_srat_rintc_affinity *pa;
53+
int cpu, pxm, node;
54+
55+
if (srat_disabled())
56+
return -EINVAL;
57+
58+
pa = (struct acpi_srat_rintc_affinity *)header;
59+
if (!pa)
60+
return -EINVAL;
61+
62+
if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
63+
return 0;
64+
65+
pxm = pa->proximity_domain;
66+
node = pxm_to_node(pxm);
67+
68+
/*
69+
* If we can't map the UID to a logical cpu this
70+
* means that the UID is not part of possible cpus
71+
* so we do not need a NUMA mapping for it, skip
72+
* the SRAT entry and keep parsing.
73+
*/
74+
cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid);
75+
if (cpu < 0)
76+
return 0;
77+
78+
acpi_early_node_map[cpu] = node;
79+
pr_info("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n", pxm,
80+
cpuid_to_hartid_map(cpu), node);
81+
82+
return 0;
83+
}
84+
85+
void __init acpi_map_cpus_to_nodes(void)
86+
{
87+
int i;
88+
89+
/*
90+
* In ACPI, SMP and CPU NUMA information is provided in separate
91+
* static tables, namely the MADT and the SRAT.
92+
*
93+
* Thus, it is simpler to first create the cpu logical map through
94+
* an MADT walk and then map the logical cpus to their node ids
95+
* as separate steps.
96+
*/
97+
acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
98+
ACPI_SRAT_TYPE_RINTC_AFFINITY, acpi_parse_rintc_pxm, 0);
99+
100+
for (i = 0; i < nr_cpu_ids; i++)
101+
early_map_cpu_to_node(i, acpi_numa_get_nid(i));
102+
}
103+
104+
/* Callback for Proximity Domain -> logical node ID mapping */
105+
void __init acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa)
106+
{
107+
int pxm, node;
108+
109+
if (srat_disabled())
110+
return;
111+
112+
if (pa->header.length < sizeof(struct acpi_srat_rintc_affinity)) {
113+
pr_err("SRAT: Invalid SRAT header length: %d\n", pa->header.length);
114+
bad_srat();
115+
return;
116+
}
117+
118+
if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
119+
return;
120+
121+
pxm = pa->proximity_domain;
122+
node = acpi_map_pxm_to_node(pxm);
123+
124+
if (node == NUMA_NO_NODE) {
125+
pr_err("SRAT: Too many proximity domains %d\n", pxm);
126+
bad_srat();
127+
return;
128+
}
129+
130+
node_set(node, numa_nodes_parsed);
131+
}

arch/riscv/kernel/setup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)
281281
setup_smp();
282282
#endif
283283

284-
if (!acpi_disabled)
284+
if (!acpi_disabled) {
285285
acpi_init_rintc_map();
286+
acpi_map_cpus_to_nodes();
287+
}
286288

287289
riscv_init_cbo_blocksizes();
288290
riscv_fill_hwcap();

arch/riscv/kernel/smpboot.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
9696
if (hart == cpuid_to_hartid_map(0)) {
9797
BUG_ON(found_boot_cpu);
9898
found_boot_cpu = true;
99-
early_map_cpu_to_node(0, acpi_numa_get_nid(cpu_count));
10099
return 0;
101100
}
102101

@@ -106,7 +105,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
106105
}
107106

108107
cpuid_to_hartid_map(cpu_count) = hart;
109-
early_map_cpu_to_node(cpu_count, acpi_numa_get_nid(cpu_count));
110108
cpu_count++;
111109

112110
return 0;

drivers/acpi/numa/Kconfig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
config ACPI_NUMA
3-
bool "NUMA support"
4-
depends on NUMA
5-
depends on (X86 || ARM64 || LOONGARCH)
6-
default y if ARM64
3+
def_bool NUMA && !X86
74

85
config ACPI_HMAT
96
bool "ACPI Heterogeneous Memory Attribute Table Support"

drivers/acpi/numa/srat.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header)
167167
}
168168
}
169169
break;
170+
171+
case ACPI_SRAT_TYPE_RINTC_AFFINITY:
172+
{
173+
struct acpi_srat_rintc_affinity *p =
174+
(struct acpi_srat_rintc_affinity *)header;
175+
pr_debug("SRAT Processor (acpi id[0x%04x]) in proximity domain %d %s\n",
176+
p->acpi_processor_uid,
177+
p->proximity_domain,
178+
(p->flags & ACPI_SRAT_RINTC_ENABLED) ?
179+
"enabled" : "disabled");
180+
}
181+
break;
182+
170183
default:
171184
pr_warn("Found unsupported SRAT entry (type = 0x%x)\n",
172185
header->type);
@@ -450,6 +463,21 @@ acpi_parse_gi_affinity(union acpi_subtable_headers *header,
450463
}
451464
#endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */
452465

466+
static int __init
467+
acpi_parse_rintc_affinity(union acpi_subtable_headers *header,
468+
const unsigned long end)
469+
{
470+
struct acpi_srat_rintc_affinity *rintc_affinity;
471+
472+
rintc_affinity = (struct acpi_srat_rintc_affinity *)header;
473+
acpi_table_print_srat_entry(&header->common);
474+
475+
/* let architecture-dependent part to do it */
476+
acpi_numa_rintc_affinity_init(rintc_affinity);
477+
478+
return 0;
479+
}
480+
453481
static int __init acpi_parse_srat(struct acpi_table_header *table)
454482
{
455483
struct acpi_table_srat *srat = (struct acpi_table_srat *)table;
@@ -485,7 +513,7 @@ int __init acpi_numa_init(void)
485513

486514
/* SRAT: System Resource Affinity Table */
487515
if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
488-
struct acpi_subtable_proc srat_proc[4];
516+
struct acpi_subtable_proc srat_proc[5];
489517

490518
memset(srat_proc, 0, sizeof(srat_proc));
491519
srat_proc[0].id = ACPI_SRAT_TYPE_CPU_AFFINITY;
@@ -496,6 +524,8 @@ int __init acpi_numa_init(void)
496524
srat_proc[2].handler = acpi_parse_gicc_affinity;
497525
srat_proc[3].id = ACPI_SRAT_TYPE_GENERIC_AFFINITY;
498526
srat_proc[3].handler = acpi_parse_gi_affinity;
527+
srat_proc[4].id = ACPI_SRAT_TYPE_RINTC_AFFINITY;
528+
srat_proc[4].handler = acpi_parse_rintc_affinity;
499529

500530
acpi_table_parse_entries_array(ACPI_SIG_SRAT,
501531
sizeof(struct acpi_table_srat),

0 commit comments

Comments
 (0)