Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/crash_dump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/pfn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/desc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/mpspec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/apicdef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/proto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/stackprotector.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) EXPORT_PER_CPU_SYMBOL(cpu_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define BOOT_PERCPU_OFFSET 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) DEFINE_PER_CPU_READ_MOSTLY(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) EXPORT_PER_CPU_SYMBOL(this_cpu_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) unsigned long __per_cpu_offset[NR_CPUS] __ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	[0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) EXPORT_SYMBOL(__per_cpu_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * On x86_64 symbols referenced from code should be reachable using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * 32bit relocations.  Reserve space for static percpu variables in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * modules so that they are always served from the first chunk which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * is located at the percpu segment base.  On x86_32, anything can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * address anywhere.  No need to reserve space in the first chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define PERCPU_FIRST_CHUNK_RESERVE	PERCPU_MODULE_RESERVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define PERCPU_FIRST_CHUNK_RESERVE	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * pcpu_need_numa - determine percpu allocation needs to consider NUMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * If NUMA is not configured or there is only one NUMA node available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * there is no reason to consider NUMA.  This function determines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * whether percpu allocation should consider NUMA or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * true if NUMA should be considered; otherwise, false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static bool __init pcpu_need_numa(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #ifdef CONFIG_NEED_MULTIPLE_NODES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	pg_data_t *last = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		int node = early_cpu_to_node(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (node_online(node) && NODE_DATA(node) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		    last && last != NODE_DATA(node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		last = NODE_DATA(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * pcpu_alloc_bootmem - NUMA friendly alloc_bootmem wrapper for percpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * @cpu: cpu to allocate for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * @size: size allocation in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * @align: alignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * Allocate @size bytes aligned at @align for cpu @cpu.  This wrapper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * does the right thing for NUMA regardless of the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * Pointer to the allocated area on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 					unsigned long align)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	const unsigned long goal = __pa(MAX_DMA_ADDRESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #ifdef CONFIG_NEED_MULTIPLE_NODES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int node = early_cpu_to_node(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	void *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (!node_online(node) || !NODE_DATA(node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		ptr = memblock_alloc_from(size, align, goal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		pr_info("cpu %d has no node %d or node-local memory\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			cpu, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		pr_debug("per cpu data for cpu%d %lu bytes at %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			 cpu, size, __pa(ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		ptr = memblock_alloc_try_nid(size, align, goal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 					     MEMBLOCK_ALLOC_ACCESSIBLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 					     node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		pr_debug("per cpu data for cpu%d %lu bytes on node%d at %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			 cpu, size, node, __pa(ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return memblock_alloc_from(size, align, goal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * Helpers for first chunk memory allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return pcpu_alloc_bootmem(cpu, size, align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static void __init pcpu_fc_free(void *ptr, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	memblock_free(__pa(ptr), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #ifdef CONFIG_NEED_MULTIPLE_NODES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (early_cpu_to_node(from) == early_cpu_to_node(to))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return LOCAL_DISTANCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return REMOTE_DISTANCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	return LOCAL_DISTANCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static void __init pcpup_populate_pte(unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	populate_extra_pte(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static inline void setup_percpu_segment(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct desc_struct d = GDT_ENTRY_INIT(0x8092, per_cpu_offset(cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 					      0xFFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_PERCPU, &d, DESCTYPE_S);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void __init setup_per_cpu_areas(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	unsigned long delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	pr_info("NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%u nr_node_ids:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		NR_CPUS, nr_cpumask_bits, nr_cpu_ids, nr_node_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	 * Allocate percpu area.  Embedding allocator is our favorite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	 * however, on NUMA configurations, it can result in very
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 * sparse unit mapping and vmalloc area isn't spacious enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * on 32bit.  Use page in that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (pcpu_chosen_fc == PCPU_FC_AUTO && pcpu_need_numa())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		pcpu_chosen_fc = PCPU_FC_PAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (pcpu_chosen_fc != PCPU_FC_PAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		const size_t dyn_size = PERCPU_MODULE_RESERVE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			PERCPU_DYNAMIC_RESERVE - PERCPU_FIRST_CHUNK_RESERVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		size_t atom_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		 * On 64bit, use PMD_SIZE for atom_size so that embedded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		 * percpu areas are aligned to PMD.  This, in the future,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		 * can also allow using PMD mappings in vmalloc area.  Use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		 * PAGE_SIZE on 32bit as vmalloc space is highly contended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		 * and large vmalloc area allocs can easily fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		atom_size = PMD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		atom_size = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		rc = pcpu_embed_first_chunk(PERCPU_FIRST_CHUNK_RESERVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 					    dyn_size, atom_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 					    pcpu_cpu_distance,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 					    pcpu_fc_alloc, pcpu_fc_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			pr_warn("%s allocator failed (%d), falling back to page size\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				pcpu_fc_names[pcpu_chosen_fc], rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		rc = pcpu_page_first_chunk(PERCPU_FIRST_CHUNK_RESERVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 					   pcpu_fc_alloc, pcpu_fc_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 					   pcpup_populate_pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		panic("cannot initialize percpu area (err=%d)", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	/* alrighty, percpu areas up and running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		per_cpu(cpu_number, cpu) = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		setup_percpu_segment(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		setup_stack_canary_segment(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		 * Copy data used in early init routines from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		 * initial arrays to the per cpu data areas.  These
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		 * arrays then become expendable and the *_early_ptr's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		 * are zeroed indicating that the static arrays are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		 * gone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #ifdef CONFIG_X86_LOCAL_APIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		per_cpu(x86_cpu_to_apicid, cpu) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			early_per_cpu_map(x86_cpu_to_apicid, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		per_cpu(x86_bios_cpu_apicid, cpu) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			early_per_cpu_map(x86_bios_cpu_apicid, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		per_cpu(x86_cpu_to_acpiid, cpu) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			early_per_cpu_map(x86_cpu_to_acpiid, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		per_cpu(x86_cpu_to_logical_apicid, cpu) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			early_per_cpu_map(x86_cpu_to_logical_apicid, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #ifdef CONFIG_NUMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		per_cpu(x86_cpu_to_node_map, cpu) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			early_per_cpu_map(x86_cpu_to_node_map, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		 * Ensure that the boot cpu numa_node is correct when the boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		 * cpu is on a node that doesn't have memory installed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		 * Also cpu_up() will call cpu_to_node() for APs when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		 * MEMORY_HOTPLUG is defined, before per_cpu(numa_node) is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		 * up later with c_init aka intel_init/amd_init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		 * So set them all (boot cpu and all APs).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		 * Up to this point, the boot CPU has been using .init.data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		 * area.  Reload any changed state for the boot CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		if (!cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			switch_to_new_gdt(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* indicate the early static arrays will soon be gone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #ifdef CONFIG_X86_LOCAL_APIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	early_per_cpu_ptr(x86_cpu_to_apicid) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	early_per_cpu_ptr(x86_cpu_to_acpiid) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	early_per_cpu_ptr(x86_cpu_to_logical_apicid) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #ifdef CONFIG_NUMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	early_per_cpu_ptr(x86_cpu_to_node_map) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* Setup node to cpumask map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	setup_node_to_cpumask_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	/* Setup cpu initialized, callin, callout masks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	setup_cpu_local_masks();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	 * Sync back kernel address range again.  We already did this in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	 * setup_arch(), but percpu data also needs to be available in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * the smpboot asm and arch_sync_kernel_mappings() doesn't sync to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 * swapper_pg_dir on 32-bit. The per-cpu mappings need to be available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	 * there too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	 * FIXME: Can the later sync in setup_cpu_entry_areas() replace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 * this call?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	sync_initial_page_table();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }