1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3 #include <linux/kernel.h>
4 #include <linux/module.h>
8 #include <linux/kexec.h>
13 #include <asm/sections.h>
14 #include <asm/processor.h>
15 #include <asm/setup.h>
18 #include <asm/highmem.h>
22 #include <asm/stackprotector.h>
28 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
30 #define BOOT_PERCPU_OFFSET 0
49 #define PERCPU_FIRST_CHUNK_RESERVE PERCPU_MODULE_RESERVE
51 #define PERCPU_FIRST_CHUNK_RESERVE 0
65 static bool __init pcpu_need_numa(
void)
67 #ifdef CONFIG_NEED_MULTIPLE_NODES
72 int node = early_cpu_to_node(cpu);
98 static void *
__init pcpu_alloc_bootmem(
unsigned int cpu,
unsigned long size,
102 #ifdef CONFIG_NEED_MULTIPLE_NODES
103 int node = early_cpu_to_node(cpu);
108 pr_info(
"cpu %d has no node %d or node-local memory\n",
110 pr_debug(
"per cpu data for cpu%d %lu bytes at %016lx\n",
111 cpu, size,
__pa(ptr));
115 pr_debug(
"per cpu data for cpu%d %lu bytes on node%d at %016lx\n",
116 cpu, size, node,
__pa(ptr));
127 static void *
__init pcpu_fc_alloc(
unsigned int cpu,
size_t size,
size_t align)
129 return pcpu_alloc_bootmem(cpu, size, align);
132 static void __init pcpu_fc_free(
void *ptr,
size_t size)
137 static int __init pcpu_cpu_distance(
unsigned int from,
unsigned int to)
139 #ifdef CONFIG_NEED_MULTIPLE_NODES
140 if (early_cpu_to_node(from) == early_cpu_to_node(to))
149 static void __init pcpup_populate_pte(
unsigned long addr)
154 static inline void setup_percpu_segment(
int cpu)
159 pack_descriptor(&
gdt, per_cpu_offset(cpu), 0xFFFFF,
173 pr_info(
"NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%d nr_node_ids:%d\n",
204 rc = pcpu_embed_first_chunk(PERCPU_FIRST_CHUNK_RESERVE,
207 pcpu_fc_alloc, pcpu_fc_free);
209 pr_warning(
"%s allocator failed (%d), falling back to page size\n",
214 pcpu_fc_alloc, pcpu_fc_free,
217 panic(
"cannot initialize percpu area (err=%d)", rc);
223 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
225 setup_percpu_segment(cpu);
226 setup_stack_canary_segment(cpu);
234 #ifdef CONFIG_X86_LOCAL_APIC
235 per_cpu(x86_cpu_to_apicid, cpu) =
236 early_per_cpu_map(x86_cpu_to_apicid, cpu);
237 per_cpu(x86_bios_cpu_apicid, cpu) =
238 early_per_cpu_map(x86_bios_cpu_apicid, cpu);
241 per_cpu(x86_cpu_to_logical_apicid, cpu) =
242 early_per_cpu_map(x86_cpu_to_logical_apicid, cpu);
246 per_cpu(irq_stack_union.irq_stack, cpu) +
250 per_cpu(x86_cpu_to_node_map, cpu) =
251 early_per_cpu_map(x86_cpu_to_node_map, cpu);
271 #ifdef CONFIG_X86_LOCAL_APIC