2019-06-03 07:44:50 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-04-08 15:50:27 -07:00
|
|
|
/*
|
|
|
|
* NUMA support, based on the x86 implementation.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Cavium Inc.
|
|
|
|
* Author: Ganapatrao Kulkarni <gkulkarni@cavium.com>
|
|
|
|
*/
|
|
|
|
|
2016-09-01 14:54:59 +08:00
|
|
|
#define pr_fmt(fmt) "NUMA: " fmt
|
|
|
|
|
2016-05-24 15:35:44 -07:00
|
|
|
#include <linux/acpi.h>
|
2016-04-08 15:50:27 -07:00
|
|
|
#include <linux/memblock.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
2024-08-07 09:41:08 +03:00
|
|
|
#include <linux/numa_memblks.h>
|
2016-04-08 15:50:27 -07:00
|
|
|
|
2016-09-01 14:55:00 +08:00
|
|
|
#include <asm/sections.h>
|
2016-08-15 16:33:10 +01:00
|
|
|
|
2016-04-08 15:50:27 -07:00
|
|
|
static int cpu_to_node_map[NR_CPUS] = { [0 ... NR_CPUS-1] = NUMA_NO_NODE };
|
|
|
|
|
2016-12-12 23:18:29 -05:00
|
|
|
bool numa_off;
|
2016-04-08 15:50:27 -07:00
|
|
|
|
|
|
|
static __init int numa_parse_early_param(char *opt)
|
|
|
|
{
|
|
|
|
if (!opt)
|
|
|
|
return -EINVAL;
|
2019-07-30 10:44:15 +08:00
|
|
|
if (str_has_prefix(opt, "off"))
|
2016-05-24 15:35:37 -07:00
|
|
|
numa_off = true;
|
2024-08-07 09:41:08 +03:00
|
|
|
if (!strncmp(opt, "fake=", 5))
|
|
|
|
return numa_emu_cmdline(opt + 5);
|
2016-09-01 14:54:59 +08:00
|
|
|
|
2016-04-08 15:50:27 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("numa", numa_parse_early_param);
|
|
|
|
|
|
|
|
cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
|
|
|
|
EXPORT_SYMBOL(node_to_cpumask_map);
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_PER_CPU_MAPS
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a pointer to the bitmask of CPUs on Node 'node'.
|
|
|
|
*/
|
|
|
|
const struct cpumask *cpumask_of_node(int node)
|
|
|
|
{
|
2020-09-21 10:39:36 +08:00
|
|
|
|
|
|
|
if (node == NUMA_NO_NODE)
|
|
|
|
return cpu_all_mask;
|
|
|
|
|
|
|
|
if (WARN_ON(node < 0 || node >= nr_node_ids))
|
2016-04-08 15:50:27 -07:00
|
|
|
return cpu_none_mask;
|
|
|
|
|
|
|
|
if (WARN_ON(node_to_cpumask_map[node] == NULL))
|
|
|
|
return cpu_online_mask;
|
|
|
|
|
|
|
|
return node_to_cpumask_map[node];
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cpumask_of_node);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2024-08-07 09:41:08 +03:00
|
|
|
#ifndef CONFIG_NUMA_EMU
|
2018-07-06 12:02:43 +01:00
|
|
|
static void numa_update_cpu(unsigned int cpu, bool remove)
|
2016-04-08 15:50:27 -07:00
|
|
|
{
|
2018-07-06 12:02:43 +01:00
|
|
|
int nid = cpu_to_node(cpu);
|
|
|
|
|
|
|
|
if (nid == NUMA_NO_NODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (remove)
|
|
|
|
cpumask_clear_cpu(cpu, node_to_cpumask_map[nid]);
|
|
|
|
else
|
2016-04-08 15:50:27 -07:00
|
|
|
cpumask_set_cpu(cpu, node_to_cpumask_map[nid]);
|
|
|
|
}
|
|
|
|
|
2018-07-06 12:02:43 +01:00
|
|
|
void numa_add_cpu(unsigned int cpu)
|
2016-04-08 15:50:27 -07:00
|
|
|
{
|
2018-07-06 12:02:43 +01:00
|
|
|
numa_update_cpu(cpu, false);
|
|
|
|
}
|
2016-04-08 15:50:27 -07:00
|
|
|
|
2018-07-06 12:02:43 +01:00
|
|
|
void numa_remove_cpu(unsigned int cpu)
|
|
|
|
{
|
|
|
|
numa_update_cpu(cpu, true);
|
|
|
|
}
|
2024-08-07 09:41:08 +03:00
|
|
|
#endif
|
2018-07-06 12:02:43 +01:00
|
|
|
|
|
|
|
void numa_clear_node(unsigned int cpu)
|
|
|
|
{
|
|
|
|
numa_remove_cpu(cpu);
|
2016-04-08 15:50:27 -07:00
|
|
|
set_cpu_numa_node(cpu, NUMA_NO_NODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate node_to_cpumask_map based on number of available nodes
|
|
|
|
* Requires node_possible_map to be valid.
|
|
|
|
*
|
|
|
|
* Note: cpumask_of_node() is not valid until after this is done.
|
|
|
|
* (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
|
|
|
|
*/
|
|
|
|
static void __init setup_node_to_cpumask_map(void)
|
|
|
|
{
|
|
|
|
int node;
|
|
|
|
|
|
|
|
/* setup nr_node_ids if not done yet */
|
|
|
|
if (nr_node_ids == MAX_NUMNODES)
|
|
|
|
setup_nr_node_ids();
|
|
|
|
|
|
|
|
/* allocate and clear the mapping */
|
|
|
|
for (node = 0; node < nr_node_ids; node++) {
|
|
|
|
alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
|
|
|
|
cpumask_clear(node_to_cpumask_map[node]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cpumask_of_node() will now work */
|
2019-03-05 15:48:26 -08:00
|
|
|
pr_debug("Node to cpumask map for %u nodes\n", nr_node_ids);
|
2016-04-08 15:50:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-03-14 12:16:19 -04:00
|
|
|
* Set the cpu to node and mem mapping
|
2016-04-08 15:50:27 -07:00
|
|
|
*/
|
|
|
|
void numa_store_cpu_info(unsigned int cpu)
|
|
|
|
{
|
2018-07-06 12:02:43 +01:00
|
|
|
set_cpu_numa_node(cpu, cpu_to_node_map[cpu]);
|
2016-04-08 15:50:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init early_map_cpu_to_node(unsigned int cpu, int nid)
|
|
|
|
{
|
|
|
|
/* fallback to node 0 */
|
2016-09-01 14:55:04 +08:00
|
|
|
if (nid < 0 || nid >= MAX_NUMNODES || numa_off)
|
2016-04-08 15:50:27 -07:00
|
|
|
nid = 0;
|
|
|
|
|
|
|
|
cpu_to_node_map[cpu] = nid;
|
2016-09-01 14:55:04 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We should set the numa node of cpu0 as soon as possible, because it
|
|
|
|
* has already been set up online before. cpu_to_node(0) will soon be
|
|
|
|
* called.
|
|
|
|
*/
|
|
|
|
if (!cpu)
|
|
|
|
set_cpu_numa_node(cpu, nid);
|
2016-04-08 15:50:27 -07:00
|
|
|
}
|
|
|
|
|
2016-09-01 14:55:00 +08:00
|
|
|
#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
|
|
|
|
unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
|
|
|
|
EXPORT_SYMBOL(__per_cpu_offset);
|
|
|
|
|
2024-08-07 09:41:08 +03:00
|
|
|
int early_cpu_to_node(int cpu)
|
2016-09-01 14:55:00 +08:00
|
|
|
{
|
|
|
|
return cpu_to_node_map[cpu];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
|
|
|
|
{
|
arm64/numa: fix pcpu_cpu_distance() to get correct CPU proximity
The pcpu_build_alloc_info() function group CPUs according to their
proximity, by call callback function @cpu_distance_fn from different
ARCHs.
For arm64 the callback of @cpu_distance_fn is
pcpu_cpu_distance(from, to)
-> node_distance(from, to)
The @from and @to for function node_distance() should be nid.
However, pcpu_cpu_distance() in arch/arm64/mm/numa.c just past the
cpu id for @from and @to, and didn't convert to numa node id.
For this incorrect cpu proximity get from ARCH, it may cause each CPU
in one group and make group_cnt out of bound:
setup_per_cpu_areas()
pcpu_embed_first_chunk()
pcpu_build_alloc_info()
in pcpu_build_alloc_info, since cpu_distance_fn will return
REMOTE_DISTANCE if we pass cpu ids (0,1,2...), so
cpu_distance_fn(cpu, tcpu) > LOCAL_DISTANCE will wrongly be ture.
This may results in triggering the BUG_ON(unit != nr_units) later:
[ 0.000000] kernel BUG at mm/percpu.c:1916!
[ 0.000000] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
[ 0.000000] Modules linked in:
[ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.9.0-rc1-00003-g14155ca-dirty #26
[ 0.000000] Hardware name: Hisilicon Hi1616 Evaluation Board (DT)
[ 0.000000] task: ffff000008d6e900 task.stack: ffff000008d60000
[ 0.000000] PC is at pcpu_embed_first_chunk+0x420/0x704
[ 0.000000] LR is at pcpu_embed_first_chunk+0x3bc/0x704
[ 0.000000] pc : [<ffff000008c754f4>] lr : [<ffff000008c75490>] pstate: 800000c5
[ 0.000000] sp : ffff000008d63eb0
[ 0.000000] x29: ffff000008d63eb0 [ 0.000000] x28: 0000000000000000
[ 0.000000] x27: 0000000000000040 [ 0.000000] x26: ffff8413fbfcef00
[ 0.000000] x25: 0000000000000042 [ 0.000000] x24: 0000000000000042
[ 0.000000] x23: 0000000000001000 [ 0.000000] x22: 0000000000000046
[ 0.000000] x21: 0000000000000001 [ 0.000000] x20: ffff000008cb3bc8
[ 0.000000] x19: ffff8413fbfcf570 [ 0.000000] x18: 0000000000000000
[ 0.000000] x17: ffff000008e49ae0 [ 0.000000] x16: 0000000000000003
[ 0.000000] x15: 000000000000001e [ 0.000000] x14: 0000000000000004
[ 0.000000] x13: 0000000000000000 [ 0.000000] x12: 000000000000006f
[ 0.000000] x11: 00000413fbffff00 [ 0.000000] x10: 0000000000000004
[ 0.000000] x9 : 0000000000000000 [ 0.000000] x8 : 0000000000000001
[ 0.000000] x7 : ffff8413fbfcf63c [ 0.000000] x6 : ffff000008d65d28
[ 0.000000] x5 : ffff000008d65e50 [ 0.000000] x4 : 0000000000000000
[ 0.000000] x3 : ffff000008cb3cc8 [ 0.000000] x2 : 0000000000000040
[ 0.000000] x1 : 0000000000000040 [ 0.000000] x0 : 0000000000000000
[...]
[ 0.000000] Call trace:
[ 0.000000] Exception stack(0xffff000008d63ce0 to 0xffff000008d63e10)
[ 0.000000] 3ce0: ffff8413fbfcf570 0001000000000000 ffff000008d63eb0 ffff000008c754f4
[ 0.000000] 3d00: ffff000008d63d50 ffff0000081af210 00000413fbfff010 0000000000001000
[ 0.000000] 3d20: ffff000008d63d50 ffff0000081af220 00000413fbfff010 0000000000001000
[ 0.000000] 3d40: 00000413fbfcef00 0000000000000004 ffff000008d63db0 ffff0000081af390
[ 0.000000] 3d60: 00000413fbfcef00 0000000000001000 0000000000000000 0000000000001000
[ 0.000000] 3d80: 0000000000000000 0000000000000040 0000000000000040 ffff000008cb3cc8
[ 0.000000] 3da0: 0000000000000000 ffff000008d65e50 ffff000008d65d28 ffff8413fbfcf63c
[ 0.000000] 3dc0: 0000000000000001 0000000000000000 0000000000000004 00000413fbffff00
[ 0.000000] 3de0: 000000000000006f 0000000000000000 0000000000000004 000000000000001e
[ 0.000000] 3e00: 0000000000000003 ffff000008e49ae0
[ 0.000000] [<ffff000008c754f4>] pcpu_embed_first_chunk+0x420/0x704
[ 0.000000] [<ffff000008c6658c>] setup_per_cpu_areas+0x38/0xc8
[ 0.000000] [<ffff000008c608d8>] start_kernel+0x10c/0x390
[ 0.000000] [<ffff000008c601d8>] __primary_switched+0x5c/0x64
[ 0.000000] Code: b8018660 17ffffd7 6b16037f 54000080 (d4210000)
[ 0.000000] ---[ end trace 0000000000000000 ]---
[ 0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
Fix by getting cpu's node id with early_cpu_to_node() then pass it
to node_distance() as the original intention.
Fixes: 7af3a0a99252 ("arm64/numa: support HAVE_SETUP_PER_CPU_AREA")
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2016-10-21 16:13:55 +08:00
|
|
|
return node_distance(early_cpu_to_node(from), early_cpu_to_node(to));
|
2016-09-01 14:55:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init setup_per_cpu_areas(void)
|
|
|
|
{
|
|
|
|
unsigned long delta;
|
|
|
|
unsigned int cpu;
|
2021-11-05 13:39:44 -07:00
|
|
|
int rc = -EINVAL;
|
|
|
|
|
|
|
|
if (pcpu_chosen_fc != PCPU_FC_PAGE) {
|
|
|
|
/*
|
|
|
|
* Always reserve area for module percpu variables. That's
|
|
|
|
* what the legacy allocator did.
|
|
|
|
*/
|
|
|
|
rc = pcpu_embed_first_chunk(PERCPU_MODULE_RESERVE,
|
|
|
|
PERCPU_DYNAMIC_RESERVE, PAGE_SIZE,
|
|
|
|
pcpu_cpu_distance,
|
2022-01-19 18:07:49 -08:00
|
|
|
early_cpu_to_node);
|
2021-11-05 13:39:44 -07:00
|
|
|
#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
|
|
|
|
if (rc < 0)
|
|
|
|
pr_warn("PERCPU: %s allocator failed (%d), falling back to page size\n",
|
|
|
|
pcpu_fc_names[pcpu_chosen_fc], rc);
|
|
|
|
#endif
|
|
|
|
}
|
2016-09-01 14:55:00 +08:00
|
|
|
|
2021-11-05 13:39:44 -07:00
|
|
|
#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
|
|
|
|
if (rc < 0)
|
2022-01-19 18:07:53 -08:00
|
|
|
rc = pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, early_cpu_to_node);
|
2021-11-05 13:39:44 -07:00
|
|
|
#endif
|
2016-09-01 14:55:00 +08:00
|
|
|
if (rc < 0)
|
2021-11-05 13:39:44 -07:00
|
|
|
panic("Failed to initialize percpu areas (err=%d).", rc);
|
2016-09-01 14:55:00 +08:00
|
|
|
|
|
|
|
delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
|
|
|
|
for_each_possible_cpu(cpu)
|
|
|
|
__per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-03-14 12:16:19 -04:00
|
|
|
/*
|
2016-04-08 15:50:27 -07:00
|
|
|
* Initialize NODE_DATA for a node on the local memory
|
|
|
|
*/
|
|
|
|
static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn)
|
|
|
|
{
|
2017-07-20 12:03:59 +01:00
|
|
|
if (start_pfn >= end_pfn)
|
2016-10-21 16:13:56 +08:00
|
|
|
pr_info("Initmem setup node %d [<memory-less node>]\n", nid);
|
2016-04-08 15:50:27 -07:00
|
|
|
|
2024-08-07 09:40:53 +03:00
|
|
|
alloc_node_data(nid);
|
2016-04-08 15:50:27 -07:00
|
|
|
|
|
|
|
NODE_DATA(nid)->node_id = nid;
|
|
|
|
NODE_DATA(nid)->node_start_pfn = start_pfn;
|
|
|
|
NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init numa_register_nodes(void)
|
|
|
|
{
|
|
|
|
int nid;
|
|
|
|
|
arch_numa: Restore nid checks before registering a memblock with a node
Commit 767507654c22 ("arch_numa: switch over to numa_memblks")
significantly cleaned up the NUMA registration code, but also
dropped a significant check that was refusing to accept to
configure a memblock with an invalid nid.
On "quality hardware" such as my ThunderX machine, this results
in a kernel that dies immediately:
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x431f0a10]
[ 0.000000] Linux version 6.12.0-00013-g8920d74cf8db (maz@valley-girl) (gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #3872 SMP PREEMPT Wed Nov 27 15:25:49 GMT 2024
[ 0.000000] KASLR disabled due to lack of seed
[ 0.000000] Machine model: Cavium ThunderX CN88XX board
[ 0.000000] efi: EFI v2.4 by American Megatrends
[ 0.000000] efi: ESRT=0xffce0ff18 SMBIOS 3.0=0xfffb0000 ACPI 2.0=0xffec60000 MEMRESERVE=0xffc905d98
[ 0.000000] esrt: Reserving ESRT space from 0x0000000ffce0ff18 to 0x0000000ffce0ff50.
[ 0.000000] earlycon: pl11 at MMIO 0x000087e024000000 (options '115200n8')
[ 0.000000] printk: legacy bootconsole [pl11] enabled
[ 0.000000] NODE_DATA(0) allocated [mem 0xff6754580-0xff67566bf]
[ 0.000000] Unable to handle kernel paging request at virtual address 0000000000001d40
[ 0.000000] Mem abort info:
[ 0.000000] ESR = 0x0000000096000004
[ 0.000000] EC = 0x25: DABT (current EL), IL = 32 bits
[ 0.000000] SET = 0, FnV = 0
[ 0.000000] EA = 0, S1PTW = 0
[ 0.000000] FSC = 0x04: level 0 translation fault
[ 0.000000] Data abort info:
[ 0.000000] ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000
[ 0.000000] CM = 0, WnR = 0, TnD = 0, TagAccess = 0
[ 0.000000] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[ 0.000000] [0000000000001d40] user address but active_mm is swapper
[ 0.000000] Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
[ 0.000000] Modules linked in:
[ 0.000000] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.12.0-00013-g8920d74cf8db #3872
[ 0.000000] Hardware name: Cavium ThunderX CN88XX board (DT)
[ 0.000000] pstate: a00000c5 (NzCv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[ 0.000000] pc : sparse_init_nid+0x54/0x428
[ 0.000000] lr : sparse_init+0x118/0x240
[ 0.000000] sp : ffff800081da3cb0
[ 0.000000] x29: ffff800081da3cb0 x28: 0000000fedbab10c x27: 0000000000000001
[ 0.000000] x26: 0000000ffee250f8 x25: 0000000000000001 x24: ffff800082102cd0
[ 0.000000] x23: 0000000000000001 x22: 0000000000000000 x21: 00000000001fffff
[ 0.000000] x20: 0000000000000001 x19: 0000000000000000 x18: ffffffffffffffff
[ 0.000000] x17: 0000000001b00000 x16: 0000000ffd130000 x15: 0000000000000000
[ 0.000000] x14: 00000000003e0000 x13: 00000000000001c8 x12: 0000000000000014
[ 0.000000] x11: ffff800081e82860 x10: ffff8000820fb2c8 x9 : ffff8000820fb490
[ 0.000000] x8 : 0000000000ffed20 x7 : 0000000000000014 x6 : 00000000001fffff
[ 0.000000] x5 : 00000000ffffffff x4 : 0000000000000000 x3 : 0000000000000000
[ 0.000000] x2 : 0000000000000000 x1 : 0000000000000040 x0 : 0000000000000007
[ 0.000000] Call trace:
[ 0.000000] sparse_init_nid+0x54/0x428
[ 0.000000] sparse_init+0x118/0x240
[ 0.000000] bootmem_init+0x70/0x1c8
[ 0.000000] setup_arch+0x184/0x270
[ 0.000000] start_kernel+0x74/0x670
[ 0.000000] __primary_switched+0x80/0x90
[ 0.000000] Code: f865d804 d37df060 cb030000 d2800003 (b95d4084)
[ 0.000000] ---[ end trace 0000000000000000 ]---
[ 0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[ 0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
while previous kernel versions were able to recognise how brain-damaged
the machine is, and only build a fake node.
Use the memblock_validate_numa_coverage() helper to restore some sanity
and a "working" system.
Fixes: 767507654c22 ("arch_numa: switch over to numa_memblks")
Suggested-by: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20241201092702.3792845-1-maz@kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
2024-12-01 09:27:02 +00:00
|
|
|
/* Check the validity of the memblock/node mapping */
|
|
|
|
if (!memblock_validate_numa_coverage(0))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-04-08 15:50:27 -07:00
|
|
|
/* Finally register nodes. */
|
|
|
|
for_each_node_mask(nid, numa_nodes_parsed) {
|
|
|
|
unsigned long start_pfn, end_pfn;
|
|
|
|
|
|
|
|
get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
|
|
|
|
setup_node_data(nid, start_pfn, end_pfn);
|
|
|
|
node_set_online(nid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup online nodes to actual nodes*/
|
|
|
|
node_possible_map = numa_nodes_parsed;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init numa_init(int (*init_func)(void))
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
nodes_clear(numa_nodes_parsed);
|
|
|
|
nodes_clear(node_possible_map);
|
|
|
|
nodes_clear(node_online_map);
|
|
|
|
|
2024-08-07 09:41:08 +03:00
|
|
|
ret = numa_memblks_init(init_func, /* memblock_force_top_down */ false);
|
2016-04-08 15:50:27 -07:00
|
|
|
if (ret < 0)
|
2018-09-22 21:09:56 +05:30
|
|
|
goto out_free_distance;
|
2016-04-08 15:50:27 -07:00
|
|
|
|
2016-09-01 14:54:56 +08:00
|
|
|
if (nodes_empty(numa_nodes_parsed)) {
|
|
|
|
pr_info("No NUMA configuration found\n");
|
2018-09-22 21:09:56 +05:30
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_free_distance;
|
2016-09-01 14:54:56 +08:00
|
|
|
}
|
2016-04-08 15:50:27 -07:00
|
|
|
|
|
|
|
ret = numa_register_nodes();
|
|
|
|
if (ret < 0)
|
2018-09-22 21:09:56 +05:30
|
|
|
goto out_free_distance;
|
2016-04-08 15:50:27 -07:00
|
|
|
|
|
|
|
setup_node_to_cpumask_map();
|
|
|
|
|
|
|
|
return 0;
|
2018-09-22 21:09:56 +05:30
|
|
|
out_free_distance:
|
2024-08-07 09:41:08 +03:00
|
|
|
numa_reset_distance();
|
2018-09-22 21:09:56 +05:30
|
|
|
return ret;
|
2016-04-08 15:50:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-14 12:16:19 -04:00
|
|
|
* dummy_numa_init() - Fallback dummy NUMA init
|
2016-04-08 15:50:27 -07:00
|
|
|
*
|
|
|
|
* Used if there's no underlying NUMA architecture, NUMA initialization
|
|
|
|
* fails, or NUMA is disabled on the command line.
|
|
|
|
*
|
|
|
|
* Must online at least one node (node 0) and add memory blocks that cover all
|
|
|
|
* allowed memory. It is unlikely that this function fails.
|
2019-03-14 12:16:19 -04:00
|
|
|
*
|
|
|
|
* Return: 0 on success, -errno on failure.
|
2016-04-08 15:50:27 -07:00
|
|
|
*/
|
|
|
|
static int __init dummy_numa_init(void)
|
|
|
|
{
|
2020-10-13 16:57:31 -07:00
|
|
|
phys_addr_t start = memblock_start_of_DRAM();
|
2021-01-27 19:55:33 -08:00
|
|
|
phys_addr_t end = memblock_end_of_DRAM() - 1;
|
2016-04-08 15:50:27 -07:00
|
|
|
int ret;
|
|
|
|
|
2016-05-24 15:35:37 -07:00
|
|
|
if (numa_off)
|
|
|
|
pr_info("NUMA disabled\n"); /* Forced off on command line. */
|
2021-01-27 19:55:33 -08:00
|
|
|
pr_info("Faking a node at [mem %pap-%pap]\n", &start, &end);
|
2016-04-08 15:50:27 -07:00
|
|
|
|
2021-01-27 19:55:33 -08:00
|
|
|
ret = numa_add_memblk(0, start, end + 1);
|
2020-10-13 16:57:31 -07:00
|
|
|
if (ret) {
|
2016-04-08 15:50:27 -07:00
|
|
|
pr_err("NUMA init failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2024-08-07 09:41:08 +03:00
|
|
|
node_set(0, numa_nodes_parsed);
|
2016-04-08 15:50:27 -07:00
|
|
|
|
2016-05-24 15:35:37 -07:00
|
|
|
numa_off = true;
|
2016-04-08 15:50:27 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:38:25 -08:00
|
|
|
#ifdef CONFIG_ACPI_NUMA
|
|
|
|
static int __init arch_acpi_numa_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = acpi_numa_init();
|
|
|
|
if (ret) {
|
2024-06-13 16:54:36 +08:00
|
|
|
pr_debug("Failed to initialise from firmware\n");
|
2020-11-18 16:38:25 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return srat_disabled() ? -EINVAL : 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int __init arch_acpi_numa_init(void)
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-08 15:50:27 -07:00
|
|
|
/**
|
2020-11-18 16:38:25 -08:00
|
|
|
* arch_numa_init() - Initialize NUMA
|
2016-04-08 15:50:27 -07:00
|
|
|
*
|
2019-03-14 12:16:19 -04:00
|
|
|
* Try each configured NUMA initialization method until one succeeds. The
|
2020-09-01 17:11:54 +08:00
|
|
|
* last fallback is dummy single node config encompassing whole memory.
|
2016-04-08 15:50:27 -07:00
|
|
|
*/
|
2020-11-18 16:38:25 -08:00
|
|
|
void __init arch_numa_init(void)
|
2016-04-08 15:50:27 -07:00
|
|
|
{
|
|
|
|
if (!numa_off) {
|
2020-11-18 16:38:25 -08:00
|
|
|
if (!acpi_disabled && !numa_init(arch_acpi_numa_init))
|
2016-05-24 15:35:44 -07:00
|
|
|
return;
|
|
|
|
if (acpi_disabled && !numa_init(of_numa_init))
|
2016-04-08 15:50:27 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
numa_init(dummy_numa_init);
|
|
|
|
}
|
2024-08-07 09:41:08 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_NUMA_EMU
|
|
|
|
void __init numa_emu_update_cpu_to_node(int *emu_nid_to_phys,
|
|
|
|
unsigned int nr_emu_nids)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transform cpu_to_node_map table to use emulated nids by
|
|
|
|
* reverse-mapping phys_nid. The maps should always exist but fall
|
|
|
|
* back to zero just in case.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ARRAY_SIZE(cpu_to_node_map); i++) {
|
|
|
|
if (cpu_to_node_map[i] == NUMA_NO_NODE)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < nr_emu_nids; j++)
|
|
|
|
if (cpu_to_node_map[i] == emu_nid_to_phys[j])
|
|
|
|
break;
|
|
|
|
cpu_to_node_map[i] = j < nr_emu_nids ? j : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 __init numa_emu_dma_end(void)
|
|
|
|
{
|
|
|
|
return memblock_start_of_DRAM() + SZ_4G;
|
|
|
|
}
|
|
|
|
|
|
|
|
void debug_cpumask_set_cpu(unsigned int cpu, int node, bool enable)
|
|
|
|
{
|
|
|
|
struct cpumask *mask;
|
|
|
|
|
|
|
|
if (node == NUMA_NO_NODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mask = node_to_cpumask_map[node];
|
|
|
|
if (!cpumask_available(mask)) {
|
|
|
|
pr_err("node_to_cpumask_map[%i] NULL\n", node);
|
|
|
|
dump_stack();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
cpumask_set_cpu(cpu, mask);
|
|
|
|
else
|
|
|
|
cpumask_clear_cpu(cpu, mask);
|
|
|
|
|
|
|
|
pr_debug("%s cpu %d node %d: mask now %*pbl\n",
|
|
|
|
enable ? "numa_add_cpu" : "numa_remove_cpu",
|
|
|
|
cpu, node, cpumask_pr_args(mask));
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NUMA_EMU */
|