linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Add ACPI NUMA support for RISC-V
@ 2024-01-31  2:31 Haibo Xu
  2024-01-31  2:31 ` [PATCH 1/4] ACPICA: SRAT: Add RISC-V RINTC affinity structure Haibo Xu
                   ` (5 more replies)
  0 siblings, 6 replies; 20+ messages in thread
From: Haibo Xu @ 2024-01-31  2:31 UTC (permalink / raw)
  Cc: xiaobo55x, ajones, sunilvl, Haibo Xu, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Rafael J. Wysocki, Len Brown,
	Robert Moore, Conor Dooley, Guo Ren, Björn Töpel,
	Alexandre Ghiti, Greentime Hu, Anup Patel, Sami Tolvanen,
	Jisheng Zhang, Clément Léger, Baoquan He,
	Greg Kroah-Hartman, Chen Jiahao, Arnd Bergmann, James Morse,
	Evan Green, Samuel Holland, Yang Li, Tony Luck, Ard Biesheuvel,
	Yuntao Wang, Dan Williams, Dave Hansen, Alison Schofield,
	linux-riscv, linux-kernel, linux-acpi, acpica-devel

This patch series enable RISC-V ACPI NUMA support which was based on
the recently approved ACPI ECR[1].

Patch 1/4 is generated from the acpica PR[2] and should be merged through
the acpica project. Due to this dependency, other 3 patches can only be
merged after the corresponding ACPICA patch was pulled into linux.

Patch 2/4 add the common SRAT RINTC affinity structure handler.
Patch 3/4 add RISC-V specific acpi_numa.c file to parse NUMA information
from SRAT and SLIT ACPI tables.
Patch 4/4 add corresponding ACPI_NUMA config for RISC-V Kconfig. 

Based-on: https://github.com/linux-riscv/linux-riscv/tree/for-next

[1] https://mantis.uefi.org/mantis/view.php?id=2433
[2] https://github.com/acpica/acpica/pull/926

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
   https://lore.kernel.org/all/20240129094200.3581037-1-haibo1.xu@intel.com/
   https://github.com/vlsunil/qemu/commit/42bd4eeefd5d4410a68f02d54fee406d8a1269b0

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_HVC_RISCV_SBI=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

Haibo Xu (4):
  ACPICA: SRAT: Add RISC-V RINTC affinity structure
  ACPI: NUMA: Add handler for SRAT RINTC affinity structure
  ACPI: RISCV: Add NUMA support based on SRAT and SLIT
  ACPI: RISCV: Enable ACPI based NUMA

 arch/riscv/Kconfig            |   1 +
 arch/riscv/include/asm/acpi.h |  15 +++-
 arch/riscv/kernel/Makefile    |   1 +
 arch/riscv/kernel/acpi.c      |   5 --
 arch/riscv/kernel/acpi_numa.c | 133 ++++++++++++++++++++++++++++++++++
 arch/riscv/kernel/setup.c     |   4 +-
 arch/riscv/kernel/smpboot.c   |   2 -
 drivers/acpi/numa/Kconfig     |   2 +-
 drivers/acpi/numa/srat.c      |  35 ++++++++-
 include/acpi/actbl3.h         |  18 ++++-
 include/linux/acpi.h          |   7 ++
 11 files changed, 209 insertions(+), 14 deletions(-)
 create mode 100644 arch/riscv/kernel/acpi_numa.c

-- 
2.34.1


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

* [PATCH 1/4] ACPICA: SRAT: Add RISC-V RINTC affinity structure
  2024-01-31  2:31 [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
@ 2024-01-31  2:31 ` Haibo Xu
  2024-02-12 13:31   ` Rafael J. Wysocki
  2024-01-31  2:31 ` [PATCH 2/4] ACPI: NUMA: Add handler for SRAT " Haibo Xu
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 20+ messages in thread
From: Haibo Xu @ 2024-01-31  2:31 UTC (permalink / raw)
  Cc: xiaobo55x, ajones, sunilvl, Haibo Xu, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Rafael J. Wysocki, Len Brown,
	Robert Moore, Conor Dooley, Guo Ren, Anup Patel, Alexandre Ghiti,
	Greentime Hu, Jisheng Zhang, Sami Tolvanen,
	Clément Léger, Baoquan He, Greg Kroah-Hartman,
	Chen Jiahao, Arnd Bergmann, James Morse, Evan Green,
	Samuel Holland, Marc Zyngier, Tony Luck, Ard Biesheuvel,
	Yuntao Wang, Dave Hansen, Alison Schofield, linux-riscv,
	linux-kernel, linux-acpi, acpica-devel

ACPICA commit 93caddbf2f620769052c59ec471f018281dc3a24

Add definition of RISC-V Interrupt Controller(RINTC)
affinity structure which was approved by UEFI forum
and will be part of next ACPI spec version(6.6).

Link: https://github.com/acpica/acpica/commit/93caddbf
Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
---
 include/acpi/actbl3.h | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/include/acpi/actbl3.h b/include/acpi/actbl3.h
index c080d579a546..5202e3fc9b41 100644
--- a/include/acpi/actbl3.h
+++ b/include/acpi/actbl3.h
@@ -192,7 +192,8 @@ enum acpi_srat_type {
 	ACPI_SRAT_TYPE_GIC_ITS_AFFINITY = 4,	/* ACPI 6.2 */
 	ACPI_SRAT_TYPE_GENERIC_AFFINITY = 5,	/* ACPI 6.3 */
 	ACPI_SRAT_TYPE_GENERIC_PORT_AFFINITY = 6,	/* ACPI 6.4 */
-	ACPI_SRAT_TYPE_RESERVED = 7	/* 7 and greater are reserved */
+	ACPI_SRAT_TYPE_RINTC_AFFINITY = 7,	/* ACPI 6.6 */
+	ACPI_SRAT_TYPE_RESERVED = 8	/* 8 and greater are reserved */
 };
 
 /*
@@ -296,6 +297,21 @@ struct acpi_srat_generic_affinity {
 #define ACPI_SRAT_GENERIC_AFFINITY_ENABLED     (1)	/* 00: Use affinity structure */
 #define ACPI_SRAT_ARCHITECTURAL_TRANSACTIONS   (1<<1)	/* ACPI 6.4 */
 
+/* 7: RINTC Affinity (ACPI 6.6) */
+
+struct acpi_srat_rintc_affinity {
+	struct acpi_subtable_header header;
+	u16 reserved;           /* Reserved, must be zero */
+	u32 proximity_domain;
+	u32 acpi_processor_uid;
+	u32 flags;
+	u32 clock_domain;
+};
+
+/* Flags for struct acpi_srat_rintc_affinity */
+
+#define ACPI_SRAT_RINTC_ENABLED     (1)	/* 00: Use affinity structure */
+
 /*******************************************************************************
  *
  * STAO - Status Override Table (_STA override) - ACPI 6.0
-- 
2.34.1


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

* [PATCH 2/4] ACPI: NUMA: Add handler for SRAT RINTC affinity structure
  2024-01-31  2:31 [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
  2024-01-31  2:31 ` [PATCH 1/4] ACPICA: SRAT: Add RISC-V RINTC affinity structure Haibo Xu
@ 2024-01-31  2:31 ` Haibo Xu
  2024-03-05  4:41   ` Sunil V L
  2024-01-31  2:32 ` [PATCH 3/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT Haibo Xu
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 20+ messages in thread
From: Haibo Xu @ 2024-01-31  2:31 UTC (permalink / raw)
  Cc: xiaobo55x, ajones, sunilvl, Haibo Xu, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Rafael J. Wysocki, Len Brown,
	Robert Moore, Conor Dooley, Guo Ren, Anup Patel, Alexandre Ghiti,
	Greentime Hu, Baoquan He, Jisheng Zhang, Sami Tolvanen,
	Clément Léger, Greg Kroah-Hartman, Arnd Bergmann,
	Chen Jiahao, James Morse, Evan Green, Samuel Holland,
	Ard Biesheuvel, Tony Luck, Yuntao Wang, Alison Schofield,
	Dave Hansen, linux-riscv, linux-kernel, linux-acpi, acpica-devel

Add RINTC affinity structure handler during parsing SRAT table.
The ARCH specific implementation will be added in next patch.

Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
---
 drivers/acpi/numa/srat.c | 32 +++++++++++++++++++++++++++++++-
 include/linux/acpi.h     |  3 +++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
index 0214518fc582..503abcf6125d 100644
--- a/drivers/acpi/numa/srat.c
+++ b/drivers/acpi/numa/srat.c
@@ -165,6 +165,19 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header)
 		}
 	}
 	break;
+
+	case ACPI_SRAT_TYPE_RINTC_AFFINITY:
+		{
+			struct acpi_srat_rintc_affinity *p =
+			    (struct acpi_srat_rintc_affinity *)header;
+			pr_debug("SRAT Processor (acpi id[0x%04x]) in proximity domain %d %s\n",
+				 p->acpi_processor_uid,
+				 p->proximity_domain,
+				 (p->flags & ACPI_SRAT_RINTC_ENABLED) ?
+				 "enabled" : "disabled");
+		}
+		break;
+
 	default:
 		pr_warn("Found unsupported SRAT entry (type = 0x%x)\n",
 			header->type);
@@ -448,6 +461,21 @@ acpi_parse_gi_affinity(union acpi_subtable_headers *header,
 }
 #endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */
 
+static int __init
+acpi_parse_rintc_affinity(union acpi_subtable_headers *header,
+			 const unsigned long end)
+{
+	struct acpi_srat_rintc_affinity *rintc_affinity;
+
+	rintc_affinity = (struct acpi_srat_rintc_affinity *)header;
+	acpi_table_print_srat_entry(&header->common);
+
+	/* let architecture-dependent part to do it */
+	acpi_numa_rintc_affinity_init(rintc_affinity);
+
+	return 0;
+}
+
 static int __initdata parsed_numa_memblks;
 
 static int __init
@@ -501,7 +529,7 @@ int __init acpi_numa_init(void)
 
 	/* SRAT: System Resource Affinity Table */
 	if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
-		struct acpi_subtable_proc srat_proc[4];
+		struct acpi_subtable_proc srat_proc[5];
 
 		memset(srat_proc, 0, sizeof(srat_proc));
 		srat_proc[0].id = ACPI_SRAT_TYPE_CPU_AFFINITY;
@@ -512,6 +540,8 @@ int __init acpi_numa_init(void)
 		srat_proc[2].handler = acpi_parse_gicc_affinity;
 		srat_proc[3].id = ACPI_SRAT_TYPE_GENERIC_AFFINITY;
 		srat_proc[3].handler = acpi_parse_gi_affinity;
+		srat_proc[4].id = ACPI_SRAT_TYPE_RINTC_AFFINITY;
+		srat_proc[4].handler = acpi_parse_rintc_affinity;
 
 		acpi_table_parse_entries_array(ACPI_SIG_SRAT,
 					sizeof(struct acpi_table_srat),
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index b7165e52b3c6..a65273db55c6 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -269,6 +269,9 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
 
 int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
 
+static inline void
+acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) { }
+
 #ifndef PHYS_CPUID_INVALID
 typedef u32 phys_cpuid_t;
 #define PHYS_CPUID_INVALID (phys_cpuid_t)(-1)
-- 
2.34.1


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

* [PATCH 3/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT
  2024-01-31  2:31 [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
  2024-01-31  2:31 ` [PATCH 1/4] ACPICA: SRAT: Add RISC-V RINTC affinity structure Haibo Xu
  2024-01-31  2:31 ` [PATCH 2/4] ACPI: NUMA: Add handler for SRAT " Haibo Xu
@ 2024-01-31  2:32 ` Haibo Xu
  2024-03-05  5:24   ` Sunil V L
  2024-01-31  2:32 ` [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA Haibo Xu
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 20+ messages in thread
From: Haibo Xu @ 2024-01-31  2:32 UTC (permalink / raw)
  Cc: xiaobo55x, ajones, sunilvl, Haibo Xu, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Rafael J. Wysocki, Len Brown,
	Robert Moore, Conor Dooley, Guo Ren, Björn Töpel,
	Alexandre Ghiti, Greentime Hu, Baoquan He,
	Clément Léger, Sami Tolvanen, Jisheng Zhang,
	Greg Kroah-Hartman, Arnd Bergmann, Chen Jiahao, James Morse,
	Evan Green, Samuel Holland, Anup Patel, Ard Biesheuvel,
	Tony Luck, Yuntao Wang, Dan Williams, Alison Schofield,
	linux-riscv, linux-kernel, linux-acpi, acpica-devel

Add acpi_numa.c file to enable parse NUMA information from
ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and
memory nodes to proximity domain mapping, while SLIT table
provide the distance metrics between proximity domains.

Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
---
 arch/riscv/include/asm/acpi.h |  15 +++-
 arch/riscv/kernel/Makefile    |   1 +
 arch/riscv/kernel/acpi.c      |   5 --
 arch/riscv/kernel/acpi_numa.c | 133 ++++++++++++++++++++++++++++++++++
 arch/riscv/kernel/setup.c     |   4 +-
 arch/riscv/kernel/smpboot.c   |   2 -
 drivers/acpi/numa/srat.c      |   3 +-
 include/linux/acpi.h          |   4 +
 8 files changed, 156 insertions(+), 11 deletions(-)
 create mode 100644 arch/riscv/kernel/acpi_numa.c

diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h
index 7dad0cf9d701..e0a1f84404f3 100644
--- a/arch/riscv/include/asm/acpi.h
+++ b/arch/riscv/include/asm/acpi.h
@@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }
 
 void acpi_init_rintc_map(void);
 struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
-u32 get_acpi_id_for_cpu(int cpu);
+static inline u32 get_acpi_id_for_cpu(int cpu)
+{
+	return acpi_cpu_get_madt_rintc(cpu)->uid;
+}
+
 int acpi_get_riscv_isa(struct acpi_table_header *table,
 		       unsigned int cpu, const char **isa);
 
-static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
 void acpi_get_cbo_block_size(struct acpi_table_header *table, u32 *cbom_size,
 			     u32 *cboz_size, u32 *cbop_size);
 #else
@@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,
 
 #endif /* CONFIG_ACPI */
 
+#ifdef CONFIG_ACPI_NUMA
+int acpi_numa_get_nid(unsigned int cpu);
+void acpi_map_cpus_to_nodes(void);
+#else
+static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
+static inline void acpi_map_cpus_to_nodes(void) { }
+#endif /* CONFIG_ACPI_NUMA */
+
 #endif /*_ASM_ACPI_H*/
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index f71910718053..5d3e9cf89b76 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -105,3 +105,4 @@ obj-$(CONFIG_COMPAT)		+= compat_vdso/
 
 obj-$(CONFIG_64BIT)		+= pi/
 obj-$(CONFIG_ACPI)		+= acpi.o
+obj-$(CONFIG_ACPI_NUMA)	+= acpi_numa.o
diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c
index e619edc8b0cc..040bdbfea2b4 100644
--- a/arch/riscv/kernel/acpi.c
+++ b/arch/riscv/kernel/acpi.c
@@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
 	return &cpu_madt_rintc[cpu];
 }
 
-u32 get_acpi_id_for_cpu(int cpu)
-{
-	return acpi_cpu_get_madt_rintc(cpu)->uid;
-}
-
 /*
  * __acpi_map_table() will be called before paging_init(), so early_ioremap()
  * or early_memremap() should be called here to for ACPI table mapping.
diff --git a/arch/riscv/kernel/acpi_numa.c b/arch/riscv/kernel/acpi_numa.c
new file mode 100644
index 000000000000..493642a61457
--- /dev/null
+++ b/arch/riscv/kernel/acpi_numa.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ACPI 6.6 based NUMA setup for RISCV
+ * Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c
+ *
+ * Copyright 2004 Andi Kleen, SuSE Labs.
+ * Copyright (C) 2013-2016, Linaro Ltd.
+ *		Author: Hanjun Guo <hanjun.guo@linaro.org>
+ * Copyright (C) 2024 Intel Corporation.
+ *
+ * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
+ *
+ * Called from acpi_numa_init while reading the SRAT and SLIT tables.
+ * Assumes all memory regions belonging to a single proximity domain
+ * are in one chunk. Holes between them will be included in the node.
+ */
+
+#define pr_fmt(fmt) "ACPI: NUMA: " fmt
+
+#include <linux/acpi.h>
+#include <linux/bitmap.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/memblock.h>
+#include <linux/mmzone.h>
+#include <linux/module.h>
+#include <linux/topology.h>
+
+#include <asm/numa.h>
+
+static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
+
+int __init acpi_numa_get_nid(unsigned int cpu)
+{
+	return acpi_early_node_map[cpu];
+}
+
+static inline int get_cpu_for_acpi_id(u32 uid)
+{
+	int cpu;
+
+	for (cpu = 0; cpu < nr_cpu_ids; cpu++)
+		if (uid == get_acpi_id_for_cpu(cpu))
+			return cpu;
+
+	return -EINVAL;
+}
+
+static int __init acpi_parse_rintc_pxm(union acpi_subtable_headers *header,
+				      const unsigned long end)
+{
+	struct acpi_srat_rintc_affinity *pa;
+	int cpu, pxm, node;
+
+	if (srat_disabled())
+		return -EINVAL;
+
+	pa = (struct acpi_srat_rintc_affinity *)header;
+	if (!pa)
+		return -EINVAL;
+
+	if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
+		return 0;
+
+	pxm = pa->proximity_domain;
+	node = pxm_to_node(pxm);
+
+	/*
+	 * If we can't map the UID to a logical cpu this
+	 * means that the UID is not part of possible cpus
+	 * so we do not need a NUMA mapping for it, skip
+	 * the SRAT entry and keep parsing.
+	 */
+	cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid);
+	if (cpu < 0)
+		return 0;
+
+	acpi_early_node_map[cpu] = node;
+	pr_info("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n", pxm,
+		cpuid_to_hartid_map(cpu), node);
+
+	return 0;
+}
+
+void __init acpi_map_cpus_to_nodes(void)
+{
+	int i;
+
+	/*
+	 * In ACPI, SMP and CPU NUMA information is provided in separate
+	 * static tables, namely the MADT and the SRAT.
+	 *
+	 * Thus, it is simpler to first create the cpu logical map through
+	 * an MADT walk and then map the logical cpus to their node ids
+	 * as separate steps.
+	 */
+	acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
+					    ACPI_SRAT_TYPE_RINTC_AFFINITY,
+					    acpi_parse_rintc_pxm, 0);
+
+	for (i = 0; i < nr_cpu_ids; i++)
+		early_map_cpu_to_node(i, acpi_numa_get_nid(i));
+}
+
+/* Callback for Proximity Domain -> logical node ID mapping */
+void __init acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa)
+{
+	int pxm, node;
+
+	if (srat_disabled())
+		return;
+
+	if (pa->header.length < sizeof(struct acpi_srat_rintc_affinity)) {
+		pr_err("SRAT: Invalid SRAT header length: %d\n",
+			pa->header.length);
+		bad_srat();
+		return;
+	}
+
+	if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
+		return;
+
+	pxm = pa->proximity_domain;
+	node = acpi_map_pxm_to_node(pxm);
+
+	if (node == NUMA_NO_NODE) {
+		pr_err("SRAT: Too many proximity domains %d\n", pxm);
+		bad_srat();
+		return;
+	}
+
+	node_set(node, numa_nodes_parsed);
+}
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 4f73c0ae44b2..a2cde65b69e9 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)
 	setup_smp();
 #endif
 
-	if (!acpi_disabled)
+	if (!acpi_disabled) {
 		acpi_init_rintc_map();
+		acpi_map_cpus_to_nodes();
+	}
 
 	riscv_init_cbo_blocksizes();
 	riscv_fill_hwcap();
diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index 519b6bd946e5..b188d83d1ec4 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -101,7 +101,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
 	if (hart == cpuid_to_hartid_map(0)) {
 		BUG_ON(found_boot_cpu);
 		found_boot_cpu = true;
-		early_map_cpu_to_node(0, acpi_numa_get_nid(cpu_count));
 		return 0;
 	}
 
@@ -111,7 +110,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
 	}
 
 	cpuid_to_hartid_map(cpu_count) = hart;
-	early_map_cpu_to_node(cpu_count, acpi_numa_get_nid(cpu_count));
 	cpu_count++;
 
 	return 0;
diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
index 503abcf6125d..1f0462cef47c 100644
--- a/drivers/acpi/numa/srat.c
+++ b/drivers/acpi/numa/srat.c
@@ -219,7 +219,8 @@ int __init srat_disabled(void)
 	return acpi_numa < 0;
 }
 
-#if defined(CONFIG_X86) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
+#if defined(CONFIG_X86) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || \
+	defined(CONFIG_RISCV)
 /*
  * Callback for SLIT parsing.  pxm_to_node() returns NUMA_NO_NODE for
  * I/O localities since SRAT does not list them.  I/O localities are
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index a65273db55c6..be78a9d28927 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -269,8 +269,12 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
 
 int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
 
+#ifdef CONFIG_RISCV
+void acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa);
+#else
 static inline void
 acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) { }
+#endif
 
 #ifndef PHYS_CPUID_INVALID
 typedef u32 phys_cpuid_t;
-- 
2.34.1


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

* [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA
  2024-01-31  2:31 [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
                   ` (2 preceding siblings ...)
  2024-01-31  2:32 ` [PATCH 3/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT Haibo Xu
@ 2024-01-31  2:32 ` Haibo Xu
  2024-01-31  9:33   ` Arnd Bergmann
  2024-03-05  5:26   ` Sunil V L
  2024-03-05  2:30 ` [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
  2024-03-05  4:44 ` Sunil V L
  5 siblings, 2 replies; 20+ messages in thread
From: Haibo Xu @ 2024-01-31  2:32 UTC (permalink / raw)
  Cc: xiaobo55x, ajones, sunilvl, Haibo Xu, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Rafael J. Wysocki, Len Brown,
	Robert Moore, Conor Dooley, Guo Ren, Anup Patel, Alexandre Ghiti,
	Greentime Hu, Sami Tolvanen, Jisheng Zhang,
	Clément Léger, Baoquan He, Greg Kroah-Hartman,
	Chen Jiahao, Arnd Bergmann, James Morse, Russell King (Oracle),
	Evan Green, Samuel Holland, Ard Biesheuvel, Tony Luck,
	Yuntao Wang, Dave Hansen, Dan Williams, Alison Schofield,
	linux-riscv, linux-kernel, linux-acpi, acpica-devel

Enable ACPI based NUMA for RISCV in Kconfig.

Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
---
 arch/riscv/Kconfig        | 1 +
 drivers/acpi/numa/Kconfig | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index bffbd869a068..e586ab959f34 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -438,6 +438,7 @@ config NUMA
 	select HAVE_SETUP_PER_CPU_AREA
 	select NEED_PER_CPU_EMBED_FIRST_CHUNK
 	select NEED_PER_CPU_PAGE_FIRST_CHUNK
+	select ACPI_NUMA if ACPI
 	select OF_NUMA
 	select USE_PERCPU_NUMA_NODE_ID
 	help
diff --git a/drivers/acpi/numa/Kconfig b/drivers/acpi/numa/Kconfig
index 849c2bd820b9..525297c44250 100644
--- a/drivers/acpi/numa/Kconfig
+++ b/drivers/acpi/numa/Kconfig
@@ -2,7 +2,7 @@
 config ACPI_NUMA
 	bool "NUMA support"
 	depends on NUMA
-	depends on (X86 || ARM64 || LOONGARCH)
+	depends on (X86 || ARM64 || LOONGARCH || RISCV)
 	default y if ARM64
 
 config ACPI_HMAT
-- 
2.34.1


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

* Re: [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA
  2024-01-31  2:32 ` [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA Haibo Xu
@ 2024-01-31  9:33   ` Arnd Bergmann
  2024-02-01  2:58     ` Haibo Xu
  2024-03-05  5:26   ` Sunil V L
  1 sibling, 1 reply; 20+ messages in thread
From: Arnd Bergmann @ 2024-01-31  9:33 UTC (permalink / raw)
  To: Haibo Xu
  Cc: Alison Schofield, Rafael J . Wysocki, Dave Hansen, linux-kernel,
	Conor.Dooley, guoren, Jisheng Zhang, James Morse, linux-riscv,
	Ard Biesheuvel, Baoquan He, acpica-devel, Robert Moore,
	linux-acpi, Sami Tolvanen, Greentime Hu, Len Brown, Albert Ou,
	Alexandre Ghiti, Dan Williams, Chen Jiahao, Yuntao Wang,
	Paul Walmsley, Clément Léger, xiaobo55x, Anup Patel,
	Tony Luck, Greg Kroah-Hartman, Russell King, Samuel Holland,
	Evan Green, Palmer Dabbelt, Andrew Jones

On Wed, Jan 31, 2024, at 03:32, Haibo Xu wrote:
> diff --git a/drivers/acpi/numa/Kconfig b/drivers/acpi/numa/Kconfig
> index 849c2bd820b9..525297c44250 100644
> --- a/drivers/acpi/numa/Kconfig
> +++ b/drivers/acpi/numa/Kconfig
> @@ -2,7 +2,7 @@
>  config ACPI_NUMA
>  	bool "NUMA support"
>  	depends on NUMA
> -	depends on (X86 || ARM64 || LOONGARCH)
> +	depends on (X86 || ARM64 || LOONGARCH || RISCV)

The dependency is no longer needed now since these are
the four architectures that support ACPI now that IA64
is gone.

All of them also 'select ACPI_NUMA' by default, though on
x86 this can still be disabled by manually turning off
CONFIG_X86_64_ACPI_NUMA. I suspect we don't actually ever
want to turn it off on x86 either, so I guess the Kconfig
option can just be removed entirely.

     Arnd

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

* Re: [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA
  2024-01-31  9:33   ` Arnd Bergmann
@ 2024-02-01  2:58     ` Haibo Xu
  2024-02-01  5:52       ` Arnd Bergmann
  0 siblings, 1 reply; 20+ messages in thread
From: Haibo Xu @ 2024-02-01  2:58 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Haibo Xu, Alison Schofield, Rafael J . Wysocki, Dave Hansen,
	linux-kernel, Conor.Dooley, guoren, Jisheng Zhang, James Morse,
	linux-riscv, Ard Biesheuvel, Baoquan He, acpica-devel,
	Robert Moore, linux-acpi, Sami Tolvanen, Greentime Hu, Len Brown,
	Albert Ou, Alexandre Ghiti, Dan Williams, Chen Jiahao,
	Yuntao Wang, Paul Walmsley, Clément Léger, Anup Patel,
	Tony Luck, Greg Kroah-Hartman, Russell King, Samuel Holland,
	Evan Green, Palmer Dabbelt, Andrew Jones

On Wed, Jan 31, 2024 at 5:33 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Wed, Jan 31, 2024, at 03:32, Haibo Xu wrote:
> > diff --git a/drivers/acpi/numa/Kconfig b/drivers/acpi/numa/Kconfig
> > index 849c2bd820b9..525297c44250 100644
> > --- a/drivers/acpi/numa/Kconfig
> > +++ b/drivers/acpi/numa/Kconfig
> > @@ -2,7 +2,7 @@
> >  config ACPI_NUMA
> >       bool "NUMA support"
> >       depends on NUMA
> > -     depends on (X86 || ARM64 || LOONGARCH)
> > +     depends on (X86 || ARM64 || LOONGARCH || RISCV)
>
> The dependency is no longer needed now since these are
> the four architectures that support ACPI now that IA64
> is gone.
>
> All of them also 'select ACPI_NUMA' by default, though on
> x86 this can still be disabled by manually turning off
> CONFIG_X86_64_ACPI_NUMA. I suspect we don't actually ever
> want to turn it off on x86 either, so I guess the Kconfig
> option can just be removed entirely.
>

Good catch! Will revert the change in the next version.

To remove the dependency entirely, I think we need a separate patch for it.
What's your opinion?

Regards,
Haibo

>      Arnd

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

* Re: [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA
  2024-02-01  2:58     ` Haibo Xu
@ 2024-02-01  5:52       ` Arnd Bergmann
  0 siblings, 0 replies; 20+ messages in thread
From: Arnd Bergmann @ 2024-02-01  5:52 UTC (permalink / raw)
  To: Haibo Xu
  Cc: Haibo Xu, Alison Schofield, Rafael J . Wysocki, Dave Hansen,
	linux-kernel, Conor.Dooley, guoren, Jisheng Zhang, James Morse,
	linux-riscv, Ard Biesheuvel, Baoquan He, acpica-devel,
	Robert Moore, linux-acpi, Sami Tolvanen, Greentime Hu, Len Brown,
	Albert Ou, Alexandre Ghiti, Dan Williams, Chen Jiahao,
	Yuntao Wang, Paul Walmsley, Clément Léger, Anup Patel,
	Tony Luck, Greg Kroah-Hartman, Russell King, Samuel Holland,
	Evan Green, Palmer Dabbelt, Andrew Jones

On Thu, Feb 1, 2024, at 03:58, Haibo Xu wrote:
> On Wed, Jan 31, 2024 at 5:33 PM Arnd Bergmann <arnd@arndb.de> wrote:
>>
>> On Wed, Jan 31, 2024, at 03:32, Haibo Xu wrote:
>> > diff --git a/drivers/acpi/numa/Kconfig b/drivers/acpi/numa/Kconfig
>> > index 849c2bd820b9..525297c44250 100644
>> > --- a/drivers/acpi/numa/Kconfig
>> > +++ b/drivers/acpi/numa/Kconfig
>> > @@ -2,7 +2,7 @@
>> >  config ACPI_NUMA
>> >       bool "NUMA support"
>> >       depends on NUMA
>> > -     depends on (X86 || ARM64 || LOONGARCH)
>> > +     depends on (X86 || ARM64 || LOONGARCH || RISCV)
>>
>> The dependency is no longer needed now since these are
>> the four architectures that support ACPI now that IA64
>> is gone.
>>
>> All of them also 'select ACPI_NUMA' by default, though on
>> x86 this can still be disabled by manually turning off
>> CONFIG_X86_64_ACPI_NUMA. I suspect we don't actually ever
>> want to turn it off on x86 either, so I guess the Kconfig
>> option can just be removed entirely.
>>
>
> Good catch! Will revert the change in the next version.
>
> To remove the dependency entirely, I think we need a separate patch for it.
> What's your opinion?

Agreed, that last bit would need to be acked by the x86
maintainers then, as it only affects them in practice.

     Arnd

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

* Re: [PATCH 1/4] ACPICA: SRAT: Add RISC-V RINTC affinity structure
  2024-01-31  2:31 ` [PATCH 1/4] ACPICA: SRAT: Add RISC-V RINTC affinity structure Haibo Xu
@ 2024-02-12 13:31   ` Rafael J. Wysocki
  2024-02-18  7:18     ` Haibo Xu
  0 siblings, 1 reply; 20+ messages in thread
From: Rafael J. Wysocki @ 2024-02-12 13:31 UTC (permalink / raw)
  To: Haibo Xu
  Cc: xiaobo55x, ajones, sunilvl, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Rafael J. Wysocki, Len Brown, Robert Moore,
	Conor Dooley, Guo Ren, Anup Patel, Alexandre Ghiti, Greentime Hu,
	Jisheng Zhang, Sami Tolvanen, Clément Léger,
	Baoquan He, Greg Kroah-Hartman, Chen Jiahao, Arnd Bergmann,
	James Morse, Evan Green, Samuel Holland, Marc Zyngier, Tony Luck,
	Ard Biesheuvel, Yuntao Wang, Dave Hansen, Alison Schofield,
	linux-riscv, linux-kernel, linux-acpi, acpica-devel

On Wed, Jan 31, 2024 at 3:18 AM Haibo Xu <haibo1.xu@intel.com> wrote:
>
> ACPICA commit 93caddbf2f620769052c59ec471f018281dc3a24

Not really.

> Add definition of RISC-V Interrupt Controller(RINTC)
> affinity structure which was approved by UEFI forum
> and will be part of next ACPI spec version(6.6).
>
> Link: https://github.com/acpica/acpica/commit/93caddbf

And this doesn't point to an upstream ACPICA PR.

> Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> ---
>  include/acpi/actbl3.h | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/include/acpi/actbl3.h b/include/acpi/actbl3.h
> index c080d579a546..5202e3fc9b41 100644
> --- a/include/acpi/actbl3.h
> +++ b/include/acpi/actbl3.h
> @@ -192,7 +192,8 @@ enum acpi_srat_type {
>         ACPI_SRAT_TYPE_GIC_ITS_AFFINITY = 4,    /* ACPI 6.2 */
>         ACPI_SRAT_TYPE_GENERIC_AFFINITY = 5,    /* ACPI 6.3 */
>         ACPI_SRAT_TYPE_GENERIC_PORT_AFFINITY = 6,       /* ACPI 6.4 */
> -       ACPI_SRAT_TYPE_RESERVED = 7     /* 7 and greater are reserved */
> +       ACPI_SRAT_TYPE_RINTC_AFFINITY = 7,      /* ACPI 6.6 */
> +       ACPI_SRAT_TYPE_RESERVED = 8     /* 8 and greater are reserved */
>  };
>
>  /*
> @@ -296,6 +297,21 @@ struct acpi_srat_generic_affinity {
>  #define ACPI_SRAT_GENERIC_AFFINITY_ENABLED     (1)     /* 00: Use affinity structure */
>  #define ACPI_SRAT_ARCHITECTURAL_TRANSACTIONS   (1<<1)  /* ACPI 6.4 */
>
> +/* 7: RINTC Affinity (ACPI 6.6) */
> +
> +struct acpi_srat_rintc_affinity {
> +       struct acpi_subtable_header header;
> +       u16 reserved;           /* Reserved, must be zero */
> +       u32 proximity_domain;
> +       u32 acpi_processor_uid;
> +       u32 flags;
> +       u32 clock_domain;
> +};
> +
> +/* Flags for struct acpi_srat_rintc_affinity */
> +
> +#define ACPI_SRAT_RINTC_ENABLED     (1)        /* 00: Use affinity structure */
> +
>  /*******************************************************************************
>   *
>   * STAO - Status Override Table (_STA override) - ACPI 6.0
> --
> 2.34.1
>

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

* Re: [PATCH 1/4] ACPICA: SRAT: Add RISC-V RINTC affinity structure
  2024-02-12 13:31   ` Rafael J. Wysocki
@ 2024-02-18  7:18     ` Haibo Xu
  0 siblings, 0 replies; 20+ messages in thread
From: Haibo Xu @ 2024-02-18  7:18 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Haibo Xu, ajones, sunilvl, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Len Brown, Robert Moore, Conor Dooley, Guo Ren,
	Anup Patel, Alexandre Ghiti, Greentime Hu, Jisheng Zhang,
	Sami Tolvanen, Clément Léger, Baoquan He,
	Greg Kroah-Hartman, Chen Jiahao, Arnd Bergmann, James Morse,
	Evan Green, Samuel Holland, Marc Zyngier, Tony Luck,
	Ard Biesheuvel, Yuntao Wang, Dave Hansen, Alison Schofield,
	linux-riscv, linux-kernel, linux-acpi, acpica-devel

On Mon, Feb 12, 2024 at 9:31 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Wed, Jan 31, 2024 at 3:18 AM Haibo Xu <haibo1.xu@intel.com> wrote:
> >
> > ACPICA commit 93caddbf2f620769052c59ec471f018281dc3a24
>
> Not really.
>
> > Add definition of RISC-V Interrupt Controller(RINTC)
> > affinity structure which was approved by UEFI forum
> > and will be part of next ACPI spec version(6.6).
> >
> > Link: https://github.com/acpica/acpica/commit/93caddbf
>
> And this doesn't point to an upstream ACPICA PR.
>

Hi Rafael,

This patch was generated by the acpica/generate/linux/gen-patch.sh and
should be merged
through the ACPICA project. To include it in this series is just to
serve as a reference.

BTW, the corresponding ACPICA patch is still under review and please
refer to the following
link for the status.

https://github.com/acpica/acpica/pull/926

Regards,
Haibo

> > Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> > ---
> >  include/acpi/actbl3.h | 18 +++++++++++++++++-
> >  1 file changed, 17 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/acpi/actbl3.h b/include/acpi/actbl3.h
> > index c080d579a546..5202e3fc9b41 100644
> > --- a/include/acpi/actbl3.h
> > +++ b/include/acpi/actbl3.h
> > @@ -192,7 +192,8 @@ enum acpi_srat_type {
> >         ACPI_SRAT_TYPE_GIC_ITS_AFFINITY = 4,    /* ACPI 6.2 */
> >         ACPI_SRAT_TYPE_GENERIC_AFFINITY = 5,    /* ACPI 6.3 */
> >         ACPI_SRAT_TYPE_GENERIC_PORT_AFFINITY = 6,       /* ACPI 6.4 */
> > -       ACPI_SRAT_TYPE_RESERVED = 7     /* 7 and greater are reserved */
> > +       ACPI_SRAT_TYPE_RINTC_AFFINITY = 7,      /* ACPI 6.6 */
> > +       ACPI_SRAT_TYPE_RESERVED = 8     /* 8 and greater are reserved */
> >  };
> >
> >  /*
> > @@ -296,6 +297,21 @@ struct acpi_srat_generic_affinity {
> >  #define ACPI_SRAT_GENERIC_AFFINITY_ENABLED     (1)     /* 00: Use affinity structure */
> >  #define ACPI_SRAT_ARCHITECTURAL_TRANSACTIONS   (1<<1)  /* ACPI 6.4 */
> >
> > +/* 7: RINTC Affinity (ACPI 6.6) */
> > +
> > +struct acpi_srat_rintc_affinity {
> > +       struct acpi_subtable_header header;
> > +       u16 reserved;           /* Reserved, must be zero */
> > +       u32 proximity_domain;
> > +       u32 acpi_processor_uid;
> > +       u32 flags;
> > +       u32 clock_domain;
> > +};
> > +
> > +/* Flags for struct acpi_srat_rintc_affinity */
> > +
> > +#define ACPI_SRAT_RINTC_ENABLED     (1)        /* 00: Use affinity structure */
> > +
> >  /*******************************************************************************
> >   *
> >   * STAO - Status Override Table (_STA override) - ACPI 6.0
> > --
> > 2.34.1
> >

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

* Re: [PATCH 0/4] Add ACPI NUMA support for RISC-V
  2024-01-31  2:31 [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
                   ` (3 preceding siblings ...)
  2024-01-31  2:32 ` [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA Haibo Xu
@ 2024-03-05  2:30 ` Haibo Xu
  2024-03-05  4:44 ` Sunil V L
  5 siblings, 0 replies; 20+ messages in thread
From: Haibo Xu @ 2024-03-05  2:30 UTC (permalink / raw)
  To: Haibo Xu
  Cc: ajones, sunilvl, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Björn Töpel, Alexandre Ghiti, Greentime Hu,
	Anup Patel, Sami Tolvanen, Jisheng Zhang,
	Clément Léger, Baoquan He, Greg Kroah-Hartman,
	Chen Jiahao, Arnd Bergmann, James Morse, Evan Green,
	Samuel Holland, Yang Li, Tony Luck, Ard Biesheuvel, Yuntao Wang,
	Dan Williams, Dave Hansen, Alison Schofield, linux-riscv,
	linux-kernel, linux-acpi, acpica-devel

Hi Sunil,

Could you help review this patch set?

Thanks,
Haibo

On Wed, Jan 31, 2024 at 10:18 AM Haibo Xu <haibo1.xu@intel.com> wrote:
>
> This patch series enable RISC-V ACPI NUMA support which was based on
> the recently approved ACPI ECR[1].
>
> Patch 1/4 is generated from the acpica PR[2] and should be merged through
> the acpica project. Due to this dependency, other 3 patches can only be
> merged after the corresponding ACPICA patch was pulled into linux.
>
> Patch 2/4 add the common SRAT RINTC affinity structure handler.
> Patch 3/4 add RISC-V specific acpi_numa.c file to parse NUMA information
> from SRAT and SLIT ACPI tables.
> Patch 4/4 add corresponding ACPI_NUMA config for RISC-V Kconfig.
>
> Based-on: https://github.com/linux-riscv/linux-riscv/tree/for-next
>
> [1] https://mantis.uefi.org/mantis/view.php?id=2433
> [2] https://github.com/acpica/acpica/pull/926
>
> 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
>    https://lore.kernel.org/all/20240129094200.3581037-1-haibo1.xu@intel.com/
>    https://github.com/vlsunil/qemu/commit/42bd4eeefd5d4410a68f02d54fee406d8a1269b0
>
> 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_HVC_RISCV_SBI=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
>
> Haibo Xu (4):
>   ACPICA: SRAT: Add RISC-V RINTC affinity structure
>   ACPI: NUMA: Add handler for SRAT RINTC affinity structure
>   ACPI: RISCV: Add NUMA support based on SRAT and SLIT
>   ACPI: RISCV: Enable ACPI based NUMA
>
>  arch/riscv/Kconfig            |   1 +
>  arch/riscv/include/asm/acpi.h |  15 +++-
>  arch/riscv/kernel/Makefile    |   1 +
>  arch/riscv/kernel/acpi.c      |   5 --
>  arch/riscv/kernel/acpi_numa.c | 133 ++++++++++++++++++++++++++++++++++
>  arch/riscv/kernel/setup.c     |   4 +-
>  arch/riscv/kernel/smpboot.c   |   2 -
>  drivers/acpi/numa/Kconfig     |   2 +-
>  drivers/acpi/numa/srat.c      |  35 ++++++++-
>  include/acpi/actbl3.h         |  18 ++++-
>  include/linux/acpi.h          |   7 ++
>  11 files changed, 209 insertions(+), 14 deletions(-)
>  create mode 100644 arch/riscv/kernel/acpi_numa.c
>
> --
> 2.34.1
>

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

* Re: [PATCH 2/4] ACPI: NUMA: Add handler for SRAT RINTC affinity structure
  2024-01-31  2:31 ` [PATCH 2/4] ACPI: NUMA: Add handler for SRAT " Haibo Xu
@ 2024-03-05  4:41   ` Sunil V L
  2024-03-05  8:42     ` Haibo Xu
  0 siblings, 1 reply; 20+ messages in thread
From: Sunil V L @ 2024-03-05  4:41 UTC (permalink / raw)
  To: Haibo Xu
  Cc: xiaobo55x, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Anup Patel, Alexandre Ghiti, Greentime Hu, Baoquan He,
	Jisheng Zhang, Sami Tolvanen, Clément Léger,
	Greg Kroah-Hartman, Arnd Bergmann, Chen Jiahao, James Morse,
	Evan Green, Samuel Holland, Ard Biesheuvel, Tony Luck,
	Yuntao Wang, Alison Schofield, Dave Hansen, linux-riscv,
	linux-kernel, linux-acpi, acpica-devel

Hi Haibo,

On Wed, Jan 31, 2024 at 10:31:59AM +0800, Haibo Xu wrote:
> Add RINTC affinity structure handler during parsing SRAT table.
> The ARCH specific implementation will be added in next patch.
> 
> Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> ---
>  drivers/acpi/numa/srat.c | 32 +++++++++++++++++++++++++++++++-
>  include/linux/acpi.h     |  3 +++
>  2 files changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> index 0214518fc582..503abcf6125d 100644
> --- a/drivers/acpi/numa/srat.c
> +++ b/drivers/acpi/numa/srat.c
> @@ -165,6 +165,19 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header)
>  		}
>  	}
>  	break;
> +
> +	case ACPI_SRAT_TYPE_RINTC_AFFINITY:
> +		{
> +			struct acpi_srat_rintc_affinity *p =
> +			    (struct acpi_srat_rintc_affinity *)header;
> +			pr_debug("SRAT Processor (acpi id[0x%04x]) in proximity domain %d %s\n",
> +				 p->acpi_processor_uid,
> +				 p->proximity_domain,
> +				 (p->flags & ACPI_SRAT_RINTC_ENABLED) ?
> +				 "enabled" : "disabled");
> +		}
> +		break;
> +
>  	default:
>  		pr_warn("Found unsupported SRAT entry (type = 0x%x)\n",
>  			header->type);
> @@ -448,6 +461,21 @@ acpi_parse_gi_affinity(union acpi_subtable_headers *header,
>  }
>  #endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */
>  
> +static int __init
> +acpi_parse_rintc_affinity(union acpi_subtable_headers *header,
> +			 const unsigned long end)
Alignment doesn't look right. Could you please run checkpatch on all
the patches?

> +{
> +	struct acpi_srat_rintc_affinity *rintc_affinity;
> +
> +	rintc_affinity = (struct acpi_srat_rintc_affinity *)header;
> +	acpi_table_print_srat_entry(&header->common);
> +
> +	/* let architecture-dependent part to do it */
> +	acpi_numa_rintc_affinity_init(rintc_affinity);
> +
Is it required to have this commit first prior to architecture
functionality? I am wondering whether it is logically better to
implement the function first and then consume in next commit?

> +	return 0;
> +}
> +
>  static int __initdata parsed_numa_memblks;
>  
>  static int __init
> @@ -501,7 +529,7 @@ int __init acpi_numa_init(void)
>  
>  	/* SRAT: System Resource Affinity Table */
>  	if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
> -		struct acpi_subtable_proc srat_proc[4];
> +		struct acpi_subtable_proc srat_proc[5];
>  
>  		memset(srat_proc, 0, sizeof(srat_proc));
>  		srat_proc[0].id = ACPI_SRAT_TYPE_CPU_AFFINITY;
> @@ -512,6 +540,8 @@ int __init acpi_numa_init(void)
>  		srat_proc[2].handler = acpi_parse_gicc_affinity;
>  		srat_proc[3].id = ACPI_SRAT_TYPE_GENERIC_AFFINITY;
>  		srat_proc[3].handler = acpi_parse_gi_affinity;
> +		srat_proc[4].id = ACPI_SRAT_TYPE_RINTC_AFFINITY;
> +		srat_proc[4].handler = acpi_parse_rintc_affinity;
>  
>  		acpi_table_parse_entries_array(ACPI_SIG_SRAT,
>  					sizeof(struct acpi_table_srat),
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index b7165e52b3c6..a65273db55c6 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -269,6 +269,9 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
>  
>  int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
>  
> +static inline void
> +acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) { }
> +
I think this can be fit in single like as we can have upto 100
characters.

>  #ifndef PHYS_CPUID_INVALID
>  typedef u32 phys_cpuid_t;
>  #define PHYS_CPUID_INVALID (phys_cpuid_t)(-1)
> -- 
> 2.34.1
> 

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

* Re: [PATCH 0/4] Add ACPI NUMA support for RISC-V
  2024-01-31  2:31 [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
                   ` (4 preceding siblings ...)
  2024-03-05  2:30 ` [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
@ 2024-03-05  4:44 ` Sunil V L
  2024-03-05  7:42   ` Haibo Xu
  5 siblings, 1 reply; 20+ messages in thread
From: Sunil V L @ 2024-03-05  4:44 UTC (permalink / raw)
  To: Haibo Xu
  Cc: xiaobo55x, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Björn Töpel, Alexandre Ghiti, Greentime Hu,
	Anup Patel, Sami Tolvanen, Jisheng Zhang,
	Clément Léger, Baoquan He, Greg Kroah-Hartman,
	Chen Jiahao, Arnd Bergmann, James Morse, Evan Green,
	Samuel Holland, Yang Li, Tony Luck, Ard Biesheuvel, Yuntao Wang,
	Dan Williams, Dave Hansen, Alison Schofield, linux-riscv,
	linux-kernel, linux-acpi, acpica-devel

Hi Haibo,
On Wed, Jan 31, 2024 at 10:31:57AM +0800, Haibo Xu wrote:
> This patch series enable RISC-V ACPI NUMA support which was based on
> the recently approved ACPI ECR[1].
> 
> Patch 1/4 is generated from the acpica PR[2] and should be merged through
> the acpica project. Due to this dependency, other 3 patches can only be
> merged after the corresponding ACPICA patch was pulled into linux.
> 
> Patch 2/4 add the common SRAT RINTC affinity structure handler.
> Patch 3/4 add RISC-V specific acpi_numa.c file to parse NUMA information
> from SRAT and SLIT ACPI tables.
> Patch 4/4 add corresponding ACPI_NUMA config for RISC-V Kconfig. 
> 
> Based-on: https://github.com/linux-riscv/linux-riscv/tree/for-next
> 
> [1] https://mantis.uefi.org/mantis/view.php?id=2433

Please avoid providing mantis link. It is not useful for people who are
not UEFI members. Better to provide the link to the PDF version of the
ECR approved.

Thanks,
Sunil

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

* Re: [PATCH 3/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT
  2024-01-31  2:32 ` [PATCH 3/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT Haibo Xu
@ 2024-03-05  5:24   ` Sunil V L
  2024-03-05  9:54     ` Haibo Xu
  0 siblings, 1 reply; 20+ messages in thread
From: Sunil V L @ 2024-03-05  5:24 UTC (permalink / raw)
  To: Haibo Xu
  Cc: xiaobo55x, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Björn Töpel, Alexandre Ghiti, Greentime Hu,
	Baoquan He, Clément Léger, Sami Tolvanen,
	Jisheng Zhang, Greg Kroah-Hartman, Arnd Bergmann, Chen Jiahao,
	James Morse, Evan Green, Samuel Holland, Anup Patel,
	Ard Biesheuvel, Tony Luck, Yuntao Wang, Dan Williams,
	Alison Schofield, linux-riscv, linux-kernel, linux-acpi,
	acpica-devel

On Wed, Jan 31, 2024 at 10:32:00AM +0800, Haibo Xu wrote:
> Add acpi_numa.c file to enable parse NUMA information from
> ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and
> memory nodes to proximity domain mapping, while SLIT table
> provide the distance metrics between proximity domains.
> 
> Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> ---
>  arch/riscv/include/asm/acpi.h |  15 +++-
>  arch/riscv/kernel/Makefile    |   1 +
>  arch/riscv/kernel/acpi.c      |   5 --
>  arch/riscv/kernel/acpi_numa.c | 133 ++++++++++++++++++++++++++++++++++
>  arch/riscv/kernel/setup.c     |   4 +-
>  arch/riscv/kernel/smpboot.c   |   2 -
>  drivers/acpi/numa/srat.c      |   3 +-
>  include/linux/acpi.h          |   4 +
>  8 files changed, 156 insertions(+), 11 deletions(-)
>  create mode 100644 arch/riscv/kernel/acpi_numa.c
> 
> diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h
> index 7dad0cf9d701..e0a1f84404f3 100644
> --- a/arch/riscv/include/asm/acpi.h
> +++ b/arch/riscv/include/asm/acpi.h
> @@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }
>  
>  void acpi_init_rintc_map(void);
>  struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
> -u32 get_acpi_id_for_cpu(int cpu);
> +static inline u32 get_acpi_id_for_cpu(int cpu)
> +{
> +	return acpi_cpu_get_madt_rintc(cpu)->uid;
> +}
> +
>  int acpi_get_riscv_isa(struct acpi_table_header *table,
>  		       unsigned int cpu, const char **isa);
>  
> -static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
>  void acpi_get_cbo_block_size(struct acpi_table_header *table, u32 *cbom_size,
>  			     u32 *cboz_size, u32 *cbop_size);
>  #else
> @@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,
>  
>  #endif /* CONFIG_ACPI */
>  
> +#ifdef CONFIG_ACPI_NUMA
> +int acpi_numa_get_nid(unsigned int cpu);
> +void acpi_map_cpus_to_nodes(void);
> +#else
> +static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
> +static inline void acpi_map_cpus_to_nodes(void) { }
> +#endif /* CONFIG_ACPI_NUMA */
> +
>  #endif /*_ASM_ACPI_H*/
> diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
> index f71910718053..5d3e9cf89b76 100644
> --- a/arch/riscv/kernel/Makefile
> +++ b/arch/riscv/kernel/Makefile
> @@ -105,3 +105,4 @@ obj-$(CONFIG_COMPAT)		+= compat_vdso/
>  
>  obj-$(CONFIG_64BIT)		+= pi/
>  obj-$(CONFIG_ACPI)		+= acpi.o
> +obj-$(CONFIG_ACPI_NUMA)	+= acpi_numa.o
> diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c
> index e619edc8b0cc..040bdbfea2b4 100644
> --- a/arch/riscv/kernel/acpi.c
> +++ b/arch/riscv/kernel/acpi.c
> @@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
>  	return &cpu_madt_rintc[cpu];
>  }
>  
> -u32 get_acpi_id_for_cpu(int cpu)
> -{
> -	return acpi_cpu_get_madt_rintc(cpu)->uid;
> -}
> -
>  /*
>   * __acpi_map_table() will be called before paging_init(), so early_ioremap()
>   * or early_memremap() should be called here to for ACPI table mapping.
> diff --git a/arch/riscv/kernel/acpi_numa.c b/arch/riscv/kernel/acpi_numa.c
> new file mode 100644
> index 000000000000..493642a61457
> --- /dev/null
> +++ b/arch/riscv/kernel/acpi_numa.c
> @@ -0,0 +1,133 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * ACPI 6.6 based NUMA setup for RISCV
> + * Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c
> + *
> + * Copyright 2004 Andi Kleen, SuSE Labs.
> + * Copyright (C) 2013-2016, Linaro Ltd.
> + *		Author: Hanjun Guo <hanjun.guo@linaro.org>
> + * Copyright (C) 2024 Intel Corporation.
> + *
> + * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
> + *
> + * Called from acpi_numa_init while reading the SRAT and SLIT tables.
> + * Assumes all memory regions belonging to a single proximity domain
> + * are in one chunk. Holes between them will be included in the node.
> + */
> +
> +#define pr_fmt(fmt) "ACPI: NUMA: " fmt
> +
> +#include <linux/acpi.h>
> +#include <linux/bitmap.h>
> +#include <linux/kernel.h>
> +#include <linux/mm.h>
> +#include <linux/memblock.h>
> +#include <linux/mmzone.h>
> +#include <linux/module.h>
> +#include <linux/topology.h>
> +
> +#include <asm/numa.h>
> +
> +static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
> +
> +int __init acpi_numa_get_nid(unsigned int cpu)
> +{
> +	return acpi_early_node_map[cpu];
> +}
> +
> +static inline int get_cpu_for_acpi_id(u32 uid)
> +{
> +	int cpu;
> +
> +	for (cpu = 0; cpu < nr_cpu_ids; cpu++)
> +		if (uid == get_acpi_id_for_cpu(cpu))
> +			return cpu;
> +
> +	return -EINVAL;
> +}
> +
> +static int __init acpi_parse_rintc_pxm(union acpi_subtable_headers *header,
> +				      const unsigned long end)

Please check alignment.

> +{
> +	struct acpi_srat_rintc_affinity *pa;
> +	int cpu, pxm, node;
> +
> +	if (srat_disabled())
> +		return -EINVAL;
> +
> +	pa = (struct acpi_srat_rintc_affinity *)header;
> +	if (!pa)
> +		return -EINVAL;
> +
> +	if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
> +		return 0;
> +
> +	pxm = pa->proximity_domain;
> +	node = pxm_to_node(pxm);
> +
> +	/*
> +	 * If we can't map the UID to a logical cpu this
> +	 * means that the UID is not part of possible cpus
> +	 * so we do not need a NUMA mapping for it, skip
> +	 * the SRAT entry and keep parsing.
> +	 */
> +	cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid);
> +	if (cpu < 0)
> +		return 0;
> +
> +	acpi_early_node_map[cpu] = node;
> +	pr_info("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n", pxm,
> +		cpuid_to_hartid_map(cpu), node);
> +
> +	return 0;
> +}
> +
> +void __init acpi_map_cpus_to_nodes(void)
> +{
> +	int i;
> +
> +	/*
> +	 * In ACPI, SMP and CPU NUMA information is provided in separate
> +	 * static tables, namely the MADT and the SRAT.
> +	 *
> +	 * Thus, it is simpler to first create the cpu logical map through
> +	 * an MADT walk and then map the logical cpus to their node ids
> +	 * as separate steps.
> +	 */
> +	acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
> +					    ACPI_SRAT_TYPE_RINTC_AFFINITY,
> +					    acpi_parse_rintc_pxm, 0);
> +
Alignment here as well.

> +	for (i = 0; i < nr_cpu_ids; i++)
> +		early_map_cpu_to_node(i, acpi_numa_get_nid(i));
> +}
> +
> +/* Callback for Proximity Domain -> logical node ID mapping */
> +void __init acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa)
> +{
> +	int pxm, node;
> +
> +	if (srat_disabled())
> +		return;
> +
> +	if (pa->header.length < sizeof(struct acpi_srat_rintc_affinity)) {
> +		pr_err("SRAT: Invalid SRAT header length: %d\n",
> +			pa->header.length);
Can we merge these into single line?

> +		bad_srat();
> +		return;
> +	}
> +
> +	if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
> +		return;
> +
> +	pxm = pa->proximity_domain;
> +	node = acpi_map_pxm_to_node(pxm);
> +
> +	if (node == NUMA_NO_NODE) {
> +		pr_err("SRAT: Too many proximity domains %d\n", pxm);
> +		bad_srat();
> +		return;
> +	}
> +
> +	node_set(node, numa_nodes_parsed);
> +}
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 4f73c0ae44b2..a2cde65b69e9 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)
>  	setup_smp();
>  #endif
>  
> -	if (!acpi_disabled)
> +	if (!acpi_disabled) {
>  		acpi_init_rintc_map();
> +		acpi_map_cpus_to_nodes();
Is it not possible to fill up both in single parsing of MADT?

> +	}
>  
>  	riscv_init_cbo_blocksizes();
>  	riscv_fill_hwcap();
> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> index 519b6bd946e5..b188d83d1ec4 100644
> --- a/arch/riscv/kernel/smpboot.c
> +++ b/arch/riscv/kernel/smpboot.c
> @@ -101,7 +101,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
>  	if (hart == cpuid_to_hartid_map(0)) {
>  		BUG_ON(found_boot_cpu);
>  		found_boot_cpu = true;
> -		early_map_cpu_to_node(0, acpi_numa_get_nid(cpu_count));
>  		return 0;
>  	}
>  
> @@ -111,7 +110,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
>  	}
>  
>  	cpuid_to_hartid_map(cpu_count) = hart;
> -	early_map_cpu_to_node(cpu_count, acpi_numa_get_nid(cpu_count));
>  	cpu_count++;
>  
>  	return 0;
> diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> index 503abcf6125d..1f0462cef47c 100644
> --- a/drivers/acpi/numa/srat.c
> +++ b/drivers/acpi/numa/srat.c
> @@ -219,7 +219,8 @@ int __init srat_disabled(void)
>  	return acpi_numa < 0;
>  }
>  
> -#if defined(CONFIG_X86) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
> +#if defined(CONFIG_X86) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || \
> +	defined(CONFIG_RISCV)
Please check alignment. Or make it single line if fits in 100 chars.
Also, it looks it covers most of the architectures now. Is it possible
to simplify / remove the condition? I hope IA64 is removed now?

May be you need to update the comment at #endif too.

Thanks
Sunil

>  /*
>   * Callback for SLIT parsing.  pxm_to_node() returns NUMA_NO_NODE for
>   * I/O localities since SRAT does not list them.  I/O localities are
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index a65273db55c6..be78a9d28927 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -269,8 +269,12 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
>  
>  int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
>  
> +#ifdef CONFIG_RISCV
> +void acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa);
> +#else
>  static inline void
>  acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) { }
> +#endif
>  
>  #ifndef PHYS_CPUID_INVALID
>  typedef u32 phys_cpuid_t;
> -- 
> 2.34.1
> 

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

* Re: [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA
  2024-01-31  2:32 ` [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA Haibo Xu
  2024-01-31  9:33   ` Arnd Bergmann
@ 2024-03-05  5:26   ` Sunil V L
  2024-03-05  8:32     ` Haibo Xu
  1 sibling, 1 reply; 20+ messages in thread
From: Sunil V L @ 2024-03-05  5:26 UTC (permalink / raw)
  To: Haibo Xu
  Cc: xiaobo55x, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Anup Patel, Alexandre Ghiti, Greentime Hu,
	Sami Tolvanen, Jisheng Zhang, Clément Léger,
	Baoquan He, Greg Kroah-Hartman, Chen Jiahao, Arnd Bergmann,
	James Morse, Russell King (Oracle),
	Evan Green, Samuel Holland, Ard Biesheuvel, Tony Luck,
	Yuntao Wang, Dave Hansen, Dan Williams, Alison Schofield,
	linux-riscv, linux-kernel, linux-acpi, acpica-devel

On Wed, Jan 31, 2024 at 10:32:01AM +0800, Haibo Xu wrote:
> Enable ACPI based NUMA for RISCV in Kconfig.
> 
> Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> ---
>  arch/riscv/Kconfig        | 1 +
>  drivers/acpi/numa/Kconfig | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index bffbd869a068..e586ab959f34 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -438,6 +438,7 @@ config NUMA
>  	select HAVE_SETUP_PER_CPU_AREA
>  	select NEED_PER_CPU_EMBED_FIRST_CHUNK
>  	select NEED_PER_CPU_PAGE_FIRST_CHUNK
> +	select ACPI_NUMA if ACPI
>  	select OF_NUMA
>  	select USE_PERCPU_NUMA_NODE_ID
>  	help
> diff --git a/drivers/acpi/numa/Kconfig b/drivers/acpi/numa/Kconfig
> index 849c2bd820b9..525297c44250 100644
> --- a/drivers/acpi/numa/Kconfig
> +++ b/drivers/acpi/numa/Kconfig
> @@ -2,7 +2,7 @@
>  config ACPI_NUMA
>  	bool "NUMA support"
>  	depends on NUMA
> -	depends on (X86 || ARM64 || LOONGARCH)
> +	depends on (X86 || ARM64 || LOONGARCH || RISCV)
Is it possible to remove this if IA64 is removed now? 

Thanks,
Sunil
>  	default y if ARM64
>  
>  config ACPI_HMAT
> -- 
> 2.34.1
> 

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

* Re: [PATCH 0/4] Add ACPI NUMA support for RISC-V
  2024-03-05  4:44 ` Sunil V L
@ 2024-03-05  7:42   ` Haibo Xu
  0 siblings, 0 replies; 20+ messages in thread
From: Haibo Xu @ 2024-03-05  7:42 UTC (permalink / raw)
  To: Sunil V L
  Cc: Haibo Xu, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Björn Töpel, Alexandre Ghiti, Greentime Hu,
	Anup Patel, Sami Tolvanen, Jisheng Zhang,
	Clément Léger, Baoquan He, Greg Kroah-Hartman,
	Arnd Bergmann, James Morse, Evan Green, Samuel Holland, Yang Li,
	Tony Luck, Ard Biesheuvel, Yuntao Wang, Dan Williams,
	Dave Hansen, Alison Schofield, linux-riscv, linux-kernel,
	linux-acpi, acpica-devel

On Tue, Mar 5, 2024 at 12:44 PM Sunil V L <sunilvl@ventanamicro.com> wrote:
>
> Hi Haibo,
> On Wed, Jan 31, 2024 at 10:31:57AM +0800, Haibo Xu wrote:
> > This patch series enable RISC-V ACPI NUMA support which was based on
> > the recently approved ACPI ECR[1].
> >
> > Patch 1/4 is generated from the acpica PR[2] and should be merged through
> > the acpica project. Due to this dependency, other 3 patches can only be
> > merged after the corresponding ACPICA patch was pulled into linux.
> >
> > Patch 2/4 add the common SRAT RINTC affinity structure handler.
> > Patch 3/4 add RISC-V specific acpi_numa.c file to parse NUMA information
> > from SRAT and SLIT ACPI tables.
> > Patch 4/4 add corresponding ACPI_NUMA config for RISC-V Kconfig.
> >
> > Based-on: https://github.com/linux-riscv/linux-riscv/tree/for-next
> >
> > [1] https://mantis.uefi.org/mantis/view.php?id=2433
>
> Please avoid providing mantis link. It is not useful for people who are
> not UEFI members. Better to provide the link to the PDF version of the
> ECR approved.
>

Sure. Will update with a PDF link in v2.

Thanks,
Haibo

> Thanks,
> Sunil

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

* Re: [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA
  2024-03-05  5:26   ` Sunil V L
@ 2024-03-05  8:32     ` Haibo Xu
  0 siblings, 0 replies; 20+ messages in thread
From: Haibo Xu @ 2024-03-05  8:32 UTC (permalink / raw)
  To: Sunil V L
  Cc: Haibo Xu, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Anup Patel, Alexandre Ghiti, Greentime Hu,
	Sami Tolvanen, Jisheng Zhang, Clément Léger,
	Baoquan He, Greg Kroah-Hartman, Chen Jiahao, Arnd Bergmann,
	James Morse, Russell King (Oracle),
	Evan Green, Samuel Holland, Ard Biesheuvel, Tony Luck,
	Yuntao Wang, Dave Hansen, Dan Williams, Alison Schofield,
	linux-riscv, linux-kernel, linux-acpi, acpica-devel

On Tue, Mar 5, 2024 at 1:26 PM Sunil V L <sunilvl@ventanamicro.com> wrote:
>
> On Wed, Jan 31, 2024 at 10:32:01AM +0800, Haibo Xu wrote:
> > Enable ACPI based NUMA for RISCV in Kconfig.
> >
> > Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> > ---
> >  arch/riscv/Kconfig        | 1 +
> >  drivers/acpi/numa/Kconfig | 2 +-
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> > index bffbd869a068..e586ab959f34 100644
> > --- a/arch/riscv/Kconfig
> > +++ b/arch/riscv/Kconfig
> > @@ -438,6 +438,7 @@ config NUMA
> >       select HAVE_SETUP_PER_CPU_AREA
> >       select NEED_PER_CPU_EMBED_FIRST_CHUNK
> >       select NEED_PER_CPU_PAGE_FIRST_CHUNK
> > +     select ACPI_NUMA if ACPI
> >       select OF_NUMA
> >       select USE_PERCPU_NUMA_NODE_ID
> >       help
> > diff --git a/drivers/acpi/numa/Kconfig b/drivers/acpi/numa/Kconfig
> > index 849c2bd820b9..525297c44250 100644
> > --- a/drivers/acpi/numa/Kconfig
> > +++ b/drivers/acpi/numa/Kconfig
> > @@ -2,7 +2,7 @@
> >  config ACPI_NUMA
> >       bool "NUMA support"
> >       depends on NUMA
> > -     depends on (X86 || ARM64 || LOONGARCH)
> > +     depends on (X86 || ARM64 || LOONGARCH || RISCV)
> Is it possible to remove this if IA64 is removed now?
>

Yes. Arnd also suggest removing this totally.
Will update it in v2.

> Thanks,
> Sunil
> >       default y if ARM64
> >
> >  config ACPI_HMAT
> > --
> > 2.34.1
> >

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

* Re: [PATCH 2/4] ACPI: NUMA: Add handler for SRAT RINTC affinity structure
  2024-03-05  4:41   ` Sunil V L
@ 2024-03-05  8:42     ` Haibo Xu
  0 siblings, 0 replies; 20+ messages in thread
From: Haibo Xu @ 2024-03-05  8:42 UTC (permalink / raw)
  To: Sunil V L
  Cc: Haibo Xu, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Anup Patel, Alexandre Ghiti, Greentime Hu, Baoquan He,
	Jisheng Zhang, Sami Tolvanen, Clément Léger,
	Greg Kroah-Hartman, Arnd Bergmann, Chen Jiahao, James Morse,
	Evan Green, Samuel Holland, Ard Biesheuvel, Tony Luck,
	Yuntao Wang, Alison Schofield, Dave Hansen, linux-riscv,
	linux-kernel, linux-acpi, acpica-devel

On Tue, Mar 5, 2024 at 12:42 PM Sunil V L <sunilvl@ventanamicro.com> wrote:
>
> Hi Haibo,
>
> On Wed, Jan 31, 2024 at 10:31:59AM +0800, Haibo Xu wrote:
> > Add RINTC affinity structure handler during parsing SRAT table.
> > The ARCH specific implementation will be added in next patch.
> >
> > Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> > ---
> >  drivers/acpi/numa/srat.c | 32 +++++++++++++++++++++++++++++++-
> >  include/linux/acpi.h     |  3 +++
> >  2 files changed, 34 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> > index 0214518fc582..503abcf6125d 100644
> > --- a/drivers/acpi/numa/srat.c
> > +++ b/drivers/acpi/numa/srat.c
> > @@ -165,6 +165,19 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header)
> >               }
> >       }
> >       break;
> > +
> > +     case ACPI_SRAT_TYPE_RINTC_AFFINITY:
> > +             {
> > +                     struct acpi_srat_rintc_affinity *p =
> > +                         (struct acpi_srat_rintc_affinity *)header;
> > +                     pr_debug("SRAT Processor (acpi id[0x%04x]) in proximity domain %d %s\n",
> > +                              p->acpi_processor_uid,
> > +                              p->proximity_domain,
> > +                              (p->flags & ACPI_SRAT_RINTC_ENABLED) ?
> > +                              "enabled" : "disabled");
> > +             }
> > +             break;
> > +
> >       default:
> >               pr_warn("Found unsupported SRAT entry (type = 0x%x)\n",
> >                       header->type);
> > @@ -448,6 +461,21 @@ acpi_parse_gi_affinity(union acpi_subtable_headers *header,
> >  }
> >  #endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */
> >
> > +static int __init
> > +acpi_parse_rintc_affinity(union acpi_subtable_headers *header,
> > +                      const unsigned long end)
> Alignment doesn't look right. Could you please run checkpatch on all
> the patches?
>

Seems something is wrong with my vim configuration.
Will fix it in v2.

> > +{
> > +     struct acpi_srat_rintc_affinity *rintc_affinity;
> > +
> > +     rintc_affinity = (struct acpi_srat_rintc_affinity *)header;
> > +     acpi_table_print_srat_entry(&header->common);
> > +
> > +     /* let architecture-dependent part to do it */
> > +     acpi_numa_rintc_affinity_init(rintc_affinity);
> > +
> Is it required to have this commit first prior to architecture
> functionality? I am wondering whether it is logically better to
> implement the function first and then consume in next commit?
>

No dependency between this commit and the next commit.
Will change the order in v2.

> > +     return 0;
> > +}
> > +
> >  static int __initdata parsed_numa_memblks;
> >
> >  static int __init
> > @@ -501,7 +529,7 @@ int __init acpi_numa_init(void)
> >
> >       /* SRAT: System Resource Affinity Table */
> >       if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
> > -             struct acpi_subtable_proc srat_proc[4];
> > +             struct acpi_subtable_proc srat_proc[5];
> >
> >               memset(srat_proc, 0, sizeof(srat_proc));
> >               srat_proc[0].id = ACPI_SRAT_TYPE_CPU_AFFINITY;
> > @@ -512,6 +540,8 @@ int __init acpi_numa_init(void)
> >               srat_proc[2].handler = acpi_parse_gicc_affinity;
> >               srat_proc[3].id = ACPI_SRAT_TYPE_GENERIC_AFFINITY;
> >               srat_proc[3].handler = acpi_parse_gi_affinity;
> > +             srat_proc[4].id = ACPI_SRAT_TYPE_RINTC_AFFINITY;
> > +             srat_proc[4].handler = acpi_parse_rintc_affinity;
> >
> >               acpi_table_parse_entries_array(ACPI_SIG_SRAT,
> >                                       sizeof(struct acpi_table_srat),
> > diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> > index b7165e52b3c6..a65273db55c6 100644
> > --- a/include/linux/acpi.h
> > +++ b/include/linux/acpi.h
> > @@ -269,6 +269,9 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
> >
> >  int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
> >
> > +static inline void
> > +acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) { }
> > +
> I think this can be fit in single like as we can have upto 100
> characters.
>

Sure. will fix it in v2.

Thanks,
Haibo

> >  #ifndef PHYS_CPUID_INVALID
> >  typedef u32 phys_cpuid_t;
> >  #define PHYS_CPUID_INVALID (phys_cpuid_t)(-1)
> > --
> > 2.34.1
> >

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

* Re: [PATCH 3/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT
  2024-03-05  5:24   ` Sunil V L
@ 2024-03-05  9:54     ` Haibo Xu
  2024-03-05 10:06       ` Sunil V L
  0 siblings, 1 reply; 20+ messages in thread
From: Haibo Xu @ 2024-03-05  9:54 UTC (permalink / raw)
  To: Sunil V L
  Cc: Haibo Xu, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Björn Töpel, Alexandre Ghiti, Greentime Hu,
	Baoquan He, Clément Léger, Sami Tolvanen,
	Jisheng Zhang, Greg Kroah-Hartman, Arnd Bergmann, Chen Jiahao,
	James Morse, Evan Green, Samuel Holland, Anup Patel,
	Ard Biesheuvel, Tony Luck, Yuntao Wang, Dan Williams,
	Alison Schofield, linux-riscv, linux-kernel, linux-acpi,
	acpica-devel

On Tue, Mar 5, 2024 at 1:24 PM Sunil V L <sunilvl@ventanamicro.com> wrote:
>
> On Wed, Jan 31, 2024 at 10:32:00AM +0800, Haibo Xu wrote:
> > Add acpi_numa.c file to enable parse NUMA information from
> > ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and
> > memory nodes to proximity domain mapping, while SLIT table
> > provide the distance metrics between proximity domains.
> >
> > Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> > ---
> >  arch/riscv/include/asm/acpi.h |  15 +++-
> >  arch/riscv/kernel/Makefile    |   1 +
> >  arch/riscv/kernel/acpi.c      |   5 --
> >  arch/riscv/kernel/acpi_numa.c | 133 ++++++++++++++++++++++++++++++++++
> >  arch/riscv/kernel/setup.c     |   4 +-
> >  arch/riscv/kernel/smpboot.c   |   2 -
> >  drivers/acpi/numa/srat.c      |   3 +-
> >  include/linux/acpi.h          |   4 +
> >  8 files changed, 156 insertions(+), 11 deletions(-)
> >  create mode 100644 arch/riscv/kernel/acpi_numa.c
> >
> > diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h
> > index 7dad0cf9d701..e0a1f84404f3 100644
> > --- a/arch/riscv/include/asm/acpi.h
> > +++ b/arch/riscv/include/asm/acpi.h
> > @@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }
> >
> >  void acpi_init_rintc_map(void);
> >  struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
> > -u32 get_acpi_id_for_cpu(int cpu);
> > +static inline u32 get_acpi_id_for_cpu(int cpu)
> > +{
> > +     return acpi_cpu_get_madt_rintc(cpu)->uid;
> > +}
> > +
> >  int acpi_get_riscv_isa(struct acpi_table_header *table,
> >                      unsigned int cpu, const char **isa);
> >
> > -static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
> >  void acpi_get_cbo_block_size(struct acpi_table_header *table, u32 *cbom_size,
> >                            u32 *cboz_size, u32 *cbop_size);
> >  #else
> > @@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,
> >
> >  #endif /* CONFIG_ACPI */
> >
> > +#ifdef CONFIG_ACPI_NUMA
> > +int acpi_numa_get_nid(unsigned int cpu);
> > +void acpi_map_cpus_to_nodes(void);
> > +#else
> > +static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
> > +static inline void acpi_map_cpus_to_nodes(void) { }
> > +#endif /* CONFIG_ACPI_NUMA */
> > +
> >  #endif /*_ASM_ACPI_H*/
> > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
> > index f71910718053..5d3e9cf89b76 100644
> > --- a/arch/riscv/kernel/Makefile
> > +++ b/arch/riscv/kernel/Makefile
> > @@ -105,3 +105,4 @@ obj-$(CONFIG_COMPAT)              += compat_vdso/
> >
> >  obj-$(CONFIG_64BIT)          += pi/
> >  obj-$(CONFIG_ACPI)           += acpi.o
> > +obj-$(CONFIG_ACPI_NUMA)      += acpi_numa.o
> > diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c
> > index e619edc8b0cc..040bdbfea2b4 100644
> > --- a/arch/riscv/kernel/acpi.c
> > +++ b/arch/riscv/kernel/acpi.c
> > @@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
> >       return &cpu_madt_rintc[cpu];
> >  }
> >
> > -u32 get_acpi_id_for_cpu(int cpu)
> > -{
> > -     return acpi_cpu_get_madt_rintc(cpu)->uid;
> > -}
> > -
> >  /*
> >   * __acpi_map_table() will be called before paging_init(), so early_ioremap()
> >   * or early_memremap() should be called here to for ACPI table mapping.
> > diff --git a/arch/riscv/kernel/acpi_numa.c b/arch/riscv/kernel/acpi_numa.c
> > new file mode 100644
> > index 000000000000..493642a61457
> > --- /dev/null
> > +++ b/arch/riscv/kernel/acpi_numa.c
> > @@ -0,0 +1,133 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * ACPI 6.6 based NUMA setup for RISCV
> > + * Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c
> > + *
> > + * Copyright 2004 Andi Kleen, SuSE Labs.
> > + * Copyright (C) 2013-2016, Linaro Ltd.
> > + *           Author: Hanjun Guo <hanjun.guo@linaro.org>
> > + * Copyright (C) 2024 Intel Corporation.
> > + *
> > + * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
> > + *
> > + * Called from acpi_numa_init while reading the SRAT and SLIT tables.
> > + * Assumes all memory regions belonging to a single proximity domain
> > + * are in one chunk. Holes between them will be included in the node.
> > + */
> > +
> > +#define pr_fmt(fmt) "ACPI: NUMA: " fmt
> > +
> > +#include <linux/acpi.h>
> > +#include <linux/bitmap.h>
> > +#include <linux/kernel.h>
> > +#include <linux/mm.h>
> > +#include <linux/memblock.h>
> > +#include <linux/mmzone.h>
> > +#include <linux/module.h>
> > +#include <linux/topology.h>
> > +
> > +#include <asm/numa.h>
> > +
> > +static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
> > +
> > +int __init acpi_numa_get_nid(unsigned int cpu)
> > +{
> > +     return acpi_early_node_map[cpu];
> > +}
> > +
> > +static inline int get_cpu_for_acpi_id(u32 uid)
> > +{
> > +     int cpu;
> > +
> > +     for (cpu = 0; cpu < nr_cpu_ids; cpu++)
> > +             if (uid == get_acpi_id_for_cpu(cpu))
> > +                     return cpu;
> > +
> > +     return -EINVAL;
> > +}
> > +
> > +static int __init acpi_parse_rintc_pxm(union acpi_subtable_headers *header,
> > +                                   const unsigned long end)
>
> Please check alignment.
>

Sure.

> > +{
> > +     struct acpi_srat_rintc_affinity *pa;
> > +     int cpu, pxm, node;
> > +
> > +     if (srat_disabled())
> > +             return -EINVAL;
> > +
> > +     pa = (struct acpi_srat_rintc_affinity *)header;
> > +     if (!pa)
> > +             return -EINVAL;
> > +
> > +     if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
> > +             return 0;
> > +
> > +     pxm = pa->proximity_domain;
> > +     node = pxm_to_node(pxm);
> > +
> > +     /*
> > +      * If we can't map the UID to a logical cpu this
> > +      * means that the UID is not part of possible cpus
> > +      * so we do not need a NUMA mapping for it, skip
> > +      * the SRAT entry and keep parsing.
> > +      */
> > +     cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid);
> > +     if (cpu < 0)
> > +             return 0;
> > +
> > +     acpi_early_node_map[cpu] = node;
> > +     pr_info("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n", pxm,
> > +             cpuid_to_hartid_map(cpu), node);
> > +
> > +     return 0;
> > +}
> > +
> > +void __init acpi_map_cpus_to_nodes(void)
> > +{
> > +     int i;
> > +
> > +     /*
> > +      * In ACPI, SMP and CPU NUMA information is provided in separate
> > +      * static tables, namely the MADT and the SRAT.
> > +      *
> > +      * Thus, it is simpler to first create the cpu logical map through
> > +      * an MADT walk and then map the logical cpus to their node ids
> > +      * as separate steps.
> > +      */
> > +     acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
> > +                                         ACPI_SRAT_TYPE_RINTC_AFFINITY,
> > +                                         acpi_parse_rintc_pxm, 0);
> > +
> Alignment here as well.
>

Sure.

> > +     for (i = 0; i < nr_cpu_ids; i++)
> > +             early_map_cpu_to_node(i, acpi_numa_get_nid(i));
> > +}
> > +
> > +/* Callback for Proximity Domain -> logical node ID mapping */
> > +void __init acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa)
> > +{
> > +     int pxm, node;
> > +
> > +     if (srat_disabled())
> > +             return;
> > +
> > +     if (pa->header.length < sizeof(struct acpi_srat_rintc_affinity)) {
> > +             pr_err("SRAT: Invalid SRAT header length: %d\n",
> > +                     pa->header.length);
> Can we merge these into single line?
>
> > +             bad_srat();
> > +             return;
> > +     }
> > +
> > +     if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
> > +             return;
> > +
> > +     pxm = pa->proximity_domain;
> > +     node = acpi_map_pxm_to_node(pxm);
> > +
> > +     if (node == NUMA_NO_NODE) {
> > +             pr_err("SRAT: Too many proximity domains %d\n", pxm);
> > +             bad_srat();
> > +             return;
> > +     }
> > +
> > +     node_set(node, numa_nodes_parsed);
> > +}
> > diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> > index 4f73c0ae44b2..a2cde65b69e9 100644
> > --- a/arch/riscv/kernel/setup.c
> > +++ b/arch/riscv/kernel/setup.c
> > @@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)
> >       setup_smp();
> >  #endif
> >
> > -     if (!acpi_disabled)
> > +     if (!acpi_disabled) {
> >               acpi_init_rintc_map();
> > +             acpi_map_cpus_to_nodes();
> Is it not possible to fill up both in single parsing of MADT?
>

I think it's not possible to fill both in a single MADT parse since
the NUMA info is provided in a separate SRAT table.

For RISC-V, currently we parsed 2 times of the MADT.
FIrst one in setup_smp()->acpi_parse_and_init_cpus() call to build up
cpuid_to_hartid_map.
Second one in acpi_init_rintc_map call to build the cpu_madt_rintc[]
cache structure.

Since the first one depends on the CONFIG_SMP, I am not sure whether
it's possible to combine
these two parts into one.

> > +     }
> >
> >       riscv_init_cbo_blocksizes();
> >       riscv_fill_hwcap();
> > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> > index 519b6bd946e5..b188d83d1ec4 100644
> > --- a/arch/riscv/kernel/smpboot.c
> > +++ b/arch/riscv/kernel/smpboot.c
> > @@ -101,7 +101,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
> >       if (hart == cpuid_to_hartid_map(0)) {
> >               BUG_ON(found_boot_cpu);
> >               found_boot_cpu = true;
> > -             early_map_cpu_to_node(0, acpi_numa_get_nid(cpu_count));
> >               return 0;
> >       }
> >
> > @@ -111,7 +110,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
> >       }
> >
> >       cpuid_to_hartid_map(cpu_count) = hart;
> > -     early_map_cpu_to_node(cpu_count, acpi_numa_get_nid(cpu_count));
> >       cpu_count++;
> >
> >       return 0;
> > diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> > index 503abcf6125d..1f0462cef47c 100644
> > --- a/drivers/acpi/numa/srat.c
> > +++ b/drivers/acpi/numa/srat.c
> > @@ -219,7 +219,8 @@ int __init srat_disabled(void)
> >       return acpi_numa < 0;
> >  }
> >
> > -#if defined(CONFIG_X86) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
> > +#if defined(CONFIG_X86) || defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || \
> > +     defined(CONFIG_RISCV)
> Please check alignment. Or make it single line if fits in 100 chars.
> Also, it looks it covers most of the architectures now. Is it possible
> to simplify / remove the condition? I hope IA64 is removed now?
>

Good catch!

Since IA64 support was removed in commit
cf8e8658100d4(https://lwn.net/Articles/923376/).
I think it's possible to remove the condition. Will fix it in v2.

Thanks,
Haibo

> May be you need to update the comment at #endif too.
>
> Thanks
> Sunil
>
> >  /*
> >   * Callback for SLIT parsing.  pxm_to_node() returns NUMA_NO_NODE for
> >   * I/O localities since SRAT does not list them.  I/O localities are
> > diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> > index a65273db55c6..be78a9d28927 100644
> > --- a/include/linux/acpi.h
> > +++ b/include/linux/acpi.h
> > @@ -269,8 +269,12 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
> >
> >  int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
> >
> > +#ifdef CONFIG_RISCV
> > +void acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa);
> > +#else
> >  static inline void
> >  acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa) { }
> > +#endif
> >
> >  #ifndef PHYS_CPUID_INVALID
> >  typedef u32 phys_cpuid_t;
> > --
> > 2.34.1
> >

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

* Re: [PATCH 3/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT
  2024-03-05  9:54     ` Haibo Xu
@ 2024-03-05 10:06       ` Sunil V L
  0 siblings, 0 replies; 20+ messages in thread
From: Sunil V L @ 2024-03-05 10:06 UTC (permalink / raw)
  To: Haibo Xu
  Cc: Haibo Xu, ajones, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Rafael J. Wysocki, Len Brown, Robert Moore, Conor Dooley,
	Guo Ren, Björn Töpel, Alexandre Ghiti, Greentime Hu,
	Baoquan He, Clément Léger, Sami Tolvanen,
	Jisheng Zhang, Greg Kroah-Hartman, Arnd Bergmann, Chen Jiahao,
	James Morse, Evan Green, Samuel Holland, Anup Patel,
	Ard Biesheuvel, Tony Luck, Yuntao Wang, Dan Williams,
	Alison Schofield, linux-riscv, linux-kernel, linux-acpi,
	acpica-devel

On Tue, Mar 05, 2024 at 05:54:03PM +0800, Haibo Xu wrote:
> On Tue, Mar 5, 2024 at 1:24 PM Sunil V L <sunilvl@ventanamicro.com> wrote:
> >
> > On Wed, Jan 31, 2024 at 10:32:00AM +0800, Haibo Xu wrote:
> > > Add acpi_numa.c file to enable parse NUMA information from
> > > ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and
> > > memory nodes to proximity domain mapping, while SLIT table
> > > provide the distance metrics between proximity domains.
> > >
> > > Signed-off-by: Haibo Xu <haibo1.xu@intel.com>
> > > ---
> > >  arch/riscv/include/asm/acpi.h |  15 +++-
> > >  arch/riscv/kernel/Makefile    |   1 +
> > >  arch/riscv/kernel/acpi.c      |   5 --
> > >  arch/riscv/kernel/acpi_numa.c | 133 ++++++++++++++++++++++++++++++++++
> > >  arch/riscv/kernel/setup.c     |   4 +-
> > >  arch/riscv/kernel/smpboot.c   |   2 -
> > >  drivers/acpi/numa/srat.c      |   3 +-
> > >  include/linux/acpi.h          |   4 +
> > >  8 files changed, 156 insertions(+), 11 deletions(-)
> > >  create mode 100644 arch/riscv/kernel/acpi_numa.c
> > >
> > > diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h
> > > index 7dad0cf9d701..e0a1f84404f3 100644
> > > --- a/arch/riscv/include/asm/acpi.h
> > > +++ b/arch/riscv/include/asm/acpi.h
> > > @@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }
> > >
> > >  void acpi_init_rintc_map(void);
> > >  struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
> > > -u32 get_acpi_id_for_cpu(int cpu);
> > > +static inline u32 get_acpi_id_for_cpu(int cpu)
> > > +{
> > > +     return acpi_cpu_get_madt_rintc(cpu)->uid;
> > > +}
> > > +
> > >  int acpi_get_riscv_isa(struct acpi_table_header *table,
> > >                      unsigned int cpu, const char **isa);
> > >
> > > -static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
> > >  void acpi_get_cbo_block_size(struct acpi_table_header *table, u32 *cbom_size,
> > >                            u32 *cboz_size, u32 *cbop_size);
> > >  #else
> > > @@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,
> > >
> > >  #endif /* CONFIG_ACPI */
> > >
> > > +#ifdef CONFIG_ACPI_NUMA
> > > +int acpi_numa_get_nid(unsigned int cpu);
> > > +void acpi_map_cpus_to_nodes(void);
> > > +#else
> > > +static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
> > > +static inline void acpi_map_cpus_to_nodes(void) { }
> > > +#endif /* CONFIG_ACPI_NUMA */
> > > +
> > >  #endif /*_ASM_ACPI_H*/
> > > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
> > > index f71910718053..5d3e9cf89b76 100644
> > > --- a/arch/riscv/kernel/Makefile
> > > +++ b/arch/riscv/kernel/Makefile
> > > @@ -105,3 +105,4 @@ obj-$(CONFIG_COMPAT)              += compat_vdso/
> > >
> > >  obj-$(CONFIG_64BIT)          += pi/
> > >  obj-$(CONFIG_ACPI)           += acpi.o
> > > +obj-$(CONFIG_ACPI_NUMA)      += acpi_numa.o
> > > diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c
> > > index e619edc8b0cc..040bdbfea2b4 100644
> > > --- a/arch/riscv/kernel/acpi.c
> > > +++ b/arch/riscv/kernel/acpi.c
> > > @@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
> > >       return &cpu_madt_rintc[cpu];
> > >  }
> > >
> > > -u32 get_acpi_id_for_cpu(int cpu)
> > > -{
> > > -     return acpi_cpu_get_madt_rintc(cpu)->uid;
> > > -}
> > > -
> > >  /*
> > >   * __acpi_map_table() will be called before paging_init(), so early_ioremap()
> > >   * or early_memremap() should be called here to for ACPI table mapping.
> > > diff --git a/arch/riscv/kernel/acpi_numa.c b/arch/riscv/kernel/acpi_numa.c
> > > new file mode 100644
> > > index 000000000000..493642a61457
> > > --- /dev/null
> > > +++ b/arch/riscv/kernel/acpi_numa.c
> > > @@ -0,0 +1,133 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * ACPI 6.6 based NUMA setup for RISCV
> > > + * Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c
> > > + *
> > > + * Copyright 2004 Andi Kleen, SuSE Labs.
> > > + * Copyright (C) 2013-2016, Linaro Ltd.
> > > + *           Author: Hanjun Guo <hanjun.guo@linaro.org>
> > > + * Copyright (C) 2024 Intel Corporation.
> > > + *
> > > + * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
> > > + *
> > > + * Called from acpi_numa_init while reading the SRAT and SLIT tables.
> > > + * Assumes all memory regions belonging to a single proximity domain
> > > + * are in one chunk. Holes between them will be included in the node.
> > > + */
> > > +
> > > +#define pr_fmt(fmt) "ACPI: NUMA: " fmt
> > > +
> > > +#include <linux/acpi.h>
> > > +#include <linux/bitmap.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/mm.h>
> > > +#include <linux/memblock.h>
> > > +#include <linux/mmzone.h>
> > > +#include <linux/module.h>
> > > +#include <linux/topology.h>
> > > +
> > > +#include <asm/numa.h>
> > > +
> > > +static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
> > > +
> > > +int __init acpi_numa_get_nid(unsigned int cpu)
> > > +{
> > > +     return acpi_early_node_map[cpu];
> > > +}
> > > +
> > > +static inline int get_cpu_for_acpi_id(u32 uid)
> > > +{
> > > +     int cpu;
> > > +
> > > +     for (cpu = 0; cpu < nr_cpu_ids; cpu++)
> > > +             if (uid == get_acpi_id_for_cpu(cpu))
> > > +                     return cpu;
> > > +
> > > +     return -EINVAL;
> > > +}
> > > +
> > > +static int __init acpi_parse_rintc_pxm(union acpi_subtable_headers *header,
> > > +                                   const unsigned long end)
> >
> > Please check alignment.
> >
> 
> Sure.
> 
> > > +{
> > > +     struct acpi_srat_rintc_affinity *pa;
> > > +     int cpu, pxm, node;
> > > +
> > > +     if (srat_disabled())
> > > +             return -EINVAL;
> > > +
> > > +     pa = (struct acpi_srat_rintc_affinity *)header;
> > > +     if (!pa)
> > > +             return -EINVAL;
> > > +
> > > +     if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
> > > +             return 0;
> > > +
> > > +     pxm = pa->proximity_domain;
> > > +     node = pxm_to_node(pxm);
> > > +
> > > +     /*
> > > +      * If we can't map the UID to a logical cpu this
> > > +      * means that the UID is not part of possible cpus
> > > +      * so we do not need a NUMA mapping for it, skip
> > > +      * the SRAT entry and keep parsing.
> > > +      */
> > > +     cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid);
> > > +     if (cpu < 0)
> > > +             return 0;
> > > +
> > > +     acpi_early_node_map[cpu] = node;
> > > +     pr_info("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n", pxm,
> > > +             cpuid_to_hartid_map(cpu), node);
> > > +
> > > +     return 0;
> > > +}
> > > +
> > > +void __init acpi_map_cpus_to_nodes(void)
> > > +{
> > > +     int i;
> > > +
> > > +     /*
> > > +      * In ACPI, SMP and CPU NUMA information is provided in separate
> > > +      * static tables, namely the MADT and the SRAT.
> > > +      *
> > > +      * Thus, it is simpler to first create the cpu logical map through
> > > +      * an MADT walk and then map the logical cpus to their node ids
> > > +      * as separate steps.
> > > +      */
> > > +     acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
> > > +                                         ACPI_SRAT_TYPE_RINTC_AFFINITY,
> > > +                                         acpi_parse_rintc_pxm, 0);
> > > +
> > Alignment here as well.
> >
> 
> Sure.
> 
> > > +     for (i = 0; i < nr_cpu_ids; i++)
> > > +             early_map_cpu_to_node(i, acpi_numa_get_nid(i));
> > > +}
> > > +
> > > +/* Callback for Proximity Domain -> logical node ID mapping */
> > > +void __init acpi_numa_rintc_affinity_init(struct acpi_srat_rintc_affinity *pa)
> > > +{
> > > +     int pxm, node;
> > > +
> > > +     if (srat_disabled())
> > > +             return;
> > > +
> > > +     if (pa->header.length < sizeof(struct acpi_srat_rintc_affinity)) {
> > > +             pr_err("SRAT: Invalid SRAT header length: %d\n",
> > > +                     pa->header.length);
> > Can we merge these into single line?
> >
> > > +             bad_srat();
> > > +             return;
> > > +     }
> > > +
> > > +     if (!(pa->flags & ACPI_SRAT_RINTC_ENABLED))
> > > +             return;
> > > +
> > > +     pxm = pa->proximity_domain;
> > > +     node = acpi_map_pxm_to_node(pxm);
> > > +
> > > +     if (node == NUMA_NO_NODE) {
> > > +             pr_err("SRAT: Too many proximity domains %d\n", pxm);
> > > +             bad_srat();
> > > +             return;
> > > +     }
> > > +
> > > +     node_set(node, numa_nodes_parsed);
> > > +}
> > > diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> > > index 4f73c0ae44b2..a2cde65b69e9 100644
> > > --- a/arch/riscv/kernel/setup.c
> > > +++ b/arch/riscv/kernel/setup.c
> > > @@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)
> > >       setup_smp();
> > >  #endif
> > >
> > > -     if (!acpi_disabled)
> > > +     if (!acpi_disabled) {
> > >               acpi_init_rintc_map();
> > > +             acpi_map_cpus_to_nodes();
> > Is it not possible to fill up both in single parsing of MADT?
> >
> 
> I think it's not possible to fill both in a single MADT parse since
> the NUMA info is provided in a separate SRAT table.
> 
Ahh, yes. My mistake. This looks good to me.

Thanks,
Sunil

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

end of thread, other threads:[~2024-03-05 10:06 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-31  2:31 [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
2024-01-31  2:31 ` [PATCH 1/4] ACPICA: SRAT: Add RISC-V RINTC affinity structure Haibo Xu
2024-02-12 13:31   ` Rafael J. Wysocki
2024-02-18  7:18     ` Haibo Xu
2024-01-31  2:31 ` [PATCH 2/4] ACPI: NUMA: Add handler for SRAT " Haibo Xu
2024-03-05  4:41   ` Sunil V L
2024-03-05  8:42     ` Haibo Xu
2024-01-31  2:32 ` [PATCH 3/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT Haibo Xu
2024-03-05  5:24   ` Sunil V L
2024-03-05  9:54     ` Haibo Xu
2024-03-05 10:06       ` Sunil V L
2024-01-31  2:32 ` [PATCH 4/4] ACPI: RISCV: Enable ACPI based NUMA Haibo Xu
2024-01-31  9:33   ` Arnd Bergmann
2024-02-01  2:58     ` Haibo Xu
2024-02-01  5:52       ` Arnd Bergmann
2024-03-05  5:26   ` Sunil V L
2024-03-05  8:32     ` Haibo Xu
2024-03-05  2:30 ` [PATCH 0/4] Add ACPI NUMA support for RISC-V Haibo Xu
2024-03-05  4:44 ` Sunil V L
2024-03-05  7:42   ` Haibo Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).