[PATCH] MIPS: Add set_memory_node()

From: Jinyang He
Date: Mon Oct 12 2020 - 23:20:03 EST


Commit e7ae8d174eec ("MIPS: replace add_memory_region with memblock")
replaced add_memory_region(, , BOOT_MEM_RAM) with memblock_add(). But
it doesn't work well on some platforms which have NUMA like Loongson64.
Because memblock_add() calls memblock_add_range() and sets memory at
MAX_NUMNODES. As mm/memblock.c says, assign the region to a NUMA node
later by using memblock_set_node(). This patch provides a NUMA port
set_memory_node() and provides Loongson64 specific function.

The one of examples as follows,
cmdline + "mem=220M@2M"

arch/mips/kernel/setup.c:
parse_early_param();
+ __memblock_dump_all();
if (usermem)

Without this patch:
...
[ 0.000000] MEMBLOCK configuration:
[ 0.000000] memory size = 0x000000000dc00000 reserved size = 0x0000000003d74000
[ 0.000000] memory.cnt = 0x1
[ 0.000000] memory[0x0] [0x0000000000200000-0x000000000ddfffff], 0x000000000dc00000 bytes flags: 0x0
...
and stopped starting.

With this patch:
...
[ 0.000000] MEMBLOCK configuration:
[ 0.000000] memory size = 0x000000000dc00000 reserved size = 0x0000000003d74000
[ 0.000000] memory.cnt = 0x1
[ 0.000000] memory[0x0] [0x0000000000200000-0x000000000ddfffff], 0x000000000dc00000 bytes on node 0 flags: 0x0
...
and started well.

Signed-off-by: Jinyang He <hejinyang@xxxxxxxxxxx>
---
arch/mips/include/asm/bootinfo.h | 4 ++++
arch/mips/kernel/setup.c | 12 ++++++++++++
arch/mips/loongson64/numa.c | 8 ++++++++
arch/mips/sgi-ip27/ip27-memory.c | 5 +++++
4 files changed, 29 insertions(+)

diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h
index aa03b12..29e2d9c 100644
--- a/arch/mips/include/asm/bootinfo.h
+++ b/arch/mips/include/asm/bootinfo.h
@@ -92,6 +92,10 @@ extern unsigned long mips_machtype;

extern void detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max);

+#ifdef CONFIG_NUMA
+extern void set_memory_node(phys_addr_t start, phys_addr_t size);
+#endif
+
extern void prom_init(void);
extern void prom_free_prom_memory(void);
extern void prom_cleanup(void);
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index fb05b66..c1e282d 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -362,6 +362,9 @@ static int __init early_parse_mem(char *p)
start = memparse(p + 1, &p);

memblock_add(start, size);
+#ifdef CONFIG_NUMA
+ set_memory_node(start, size);
+#endif

return 0;
}
@@ -388,12 +391,18 @@ static int __init early_parse_memmap(char *p)
if (*p == '@') {
start_at = memparse(p+1, &p);
memblock_add(start_at, mem_size);
+#ifdef CONFIG_NUMA
+ set_memory_node(start_at, mem_size);
+#endif
} else if (*p == '#') {
pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
return -EINVAL;
} else if (*p == '$') {
start_at = memparse(p+1, &p);
memblock_add(start_at, mem_size);
+#ifdef CONFIG_NUMA
+ set_memory_node(start_at, mem_size);
+#endif
memblock_reserve(start_at, mem_size);
} else {
pr_err("\"memmap\" invalid format!\n");
@@ -509,6 +518,9 @@ static void __init check_kernel_sections_mem(void)
if (!memblock_is_region_memory(start, size)) {
pr_info("Kernel sections are not in the memory maps\n");
memblock_add(start, size);
+#ifdef CONFIG_NUMA
+ set_memory_node(start, size);
+#endif
}
}

diff --git a/arch/mips/loongson64/numa.c b/arch/mips/loongson64/numa.c
index cf9459f..d428058 100644
--- a/arch/mips/loongson64/numa.c
+++ b/arch/mips/loongson64/numa.c
@@ -234,6 +234,14 @@ void __init mem_init(void)
mem_init_print_info(NULL);
}

+void __init set_memory_node(phys_addr_t start, phys_addr_t size)
+{
+ u64 node_id;
+
+ node_id = (start >> 44) & 3;
+ memblock_set_node(start, size, &memblock.memory, node_id);
+}
+
/* All PCI device belongs to logical Node-0 */
int pcibus_to_node(struct pci_bus *bus)
{
diff --git a/arch/mips/sgi-ip27/ip27-memory.c b/arch/mips/sgi-ip27/ip27-memory.c
index d411e0a..f0ed2d4 100644
--- a/arch/mips/sgi-ip27/ip27-memory.c
+++ b/arch/mips/sgi-ip27/ip27-memory.c
@@ -427,3 +427,8 @@ void __init mem_init(void)
setup_zero_pages(); /* This comes from node 0 */
mem_init_print_info(NULL);
}
+
+void __init set_memory_node(phys_addr_t start, phys_addr_t size)
+{
+
+}
--
2.1.0