hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/arch/arm64/kernel/setup.c
....@@ -1,20 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Based on arch/arm/kernel/setup.c
34 *
45 * Copyright (C) 1995-2001 Russell King
56 * Copyright (C) 2012 ARM Ltd.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
187 */
198
209 #include <linux/acpi.h>
....@@ -26,7 +15,6 @@
2615 #include <linux/initrd.h>
2716 #include <linux/console.h>
2817 #include <linux/cache.h>
29
-#include <linux/bootmem.h>
3018 #include <linux/screen_info.h>
3119 #include <linux/init.h>
3220 #include <linux/kexec.h>
....@@ -59,7 +47,6 @@
5947 #include <asm/cacheflush.h>
6048 #include <asm/tlbflush.h>
6149 #include <asm/traps.h>
62
-#include <asm/memblock.h>
6350 #include <asm/efi.h>
6451 #include <asm/xen/hypervisor.h>
6552 #include <asm/mmu_context.h>
....@@ -68,14 +55,6 @@
6855 static struct resource *standard_resources;
6956
7057 phys_addr_t __fdt_pointer __initdata;
71
-
72
-/* Vendor stub */
73
-unsigned int boot_reason;
74
-EXPORT_SYMBOL_GPL(boot_reason);
75
-
76
-/* Vendor stub */
77
-unsigned int cold_boot;
78
-EXPORT_SYMBOL_GPL(cold_boot);
7958
8059 /*
8160 * Standard memory resources
....@@ -106,7 +85,7 @@
10685 void __init smp_setup_processor_id(void)
10786 {
10887 u64 mpidr = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
109
- cpu_logical_map(0) = mpidr;
88
+ set_cpu_logical_map(0, mpidr);
11089
11190 /*
11291 * clear __my_cpu_offset on boot CPU to avoid hang caused by
....@@ -189,6 +168,21 @@
189168 pr_warn("Large number of MPIDR hash buckets detected\n");
190169 }
191170
171
+static void *early_fdt_ptr __initdata;
172
+
173
+void __init *get_early_fdt_ptr(void)
174
+{
175
+ return early_fdt_ptr;
176
+}
177
+
178
+asmlinkage void __init early_fdt_map(u64 dt_phys)
179
+{
180
+ int fdt_size;
181
+
182
+ early_fixmap_init();
183
+ early_fdt_ptr = fixmap_remap_fdt(dt_phys, &fdt_size, PAGE_KERNEL);
184
+}
185
+
192186 static void __init setup_machine_fdt(phys_addr_t dt_phys)
193187 {
194188 int size;
....@@ -225,6 +219,7 @@
225219 struct memblock_region *region;
226220 struct resource *res;
227221 unsigned long i = 0;
222
+ size_t res_size;
228223
229224 kernel_code.start = __pa_symbol(_text);
230225 kernel_code.end = __pa_symbol(__init_begin - 1);
....@@ -232,10 +227,12 @@
232227 kernel_data.end = __pa_symbol(_end - 1);
233228
234229 num_standard_resources = memblock.memory.cnt;
235
- standard_resources = alloc_bootmem_low(num_standard_resources *
236
- sizeof(*standard_resources));
230
+ res_size = num_standard_resources * sizeof(*standard_resources);
231
+ standard_resources = memblock_alloc(res_size, SMP_CACHE_BYTES);
232
+ if (!standard_resources)
233
+ panic("%s: Failed to allocate %zu bytes\n", __func__, res_size);
237234
238
- for_each_memblock(memory, region) {
235
+ for_each_mem_region(region) {
239236 res = &standard_resources[i++];
240237 if (memblock_is_nomap(region)) {
241238 res->name = "reserved";
....@@ -275,7 +272,7 @@
275272 if (!memblock_is_region_reserved(mem->start, mem_size))
276273 continue;
277274
278
- for_each_reserved_mem_region(j, &r_start, &r_end) {
275
+ for_each_reserved_mem_range(j, &r_start, &r_end) {
279276 resource_size_t start, end;
280277
281278 start = max(PFN_PHYS(PFN_DOWN(r_start)), mem->start);
....@@ -294,7 +291,12 @@
294291
295292 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
296293
297
-void __init setup_arch(char **cmdline_p)
294
+u64 cpu_logical_map(unsigned int cpu)
295
+{
296
+ return __cpu_logical_map[cpu];
297
+}
298
+
299
+void __init __no_sanitize_address setup_arch(char **cmdline_p)
298300 {
299301 init_mm.start_code = (unsigned long) _text;
300302 init_mm.end_code = (unsigned long) _etext;
....@@ -302,6 +304,13 @@
302304 init_mm.brk = (unsigned long) _end;
303305
304306 *cmdline_p = boot_command_line;
307
+
308
+ /*
309
+ * If know now we are going to need KPTI then use non-global
310
+ * mappings from the start, avoiding the cost of rewriting
311
+ * everything later.
312
+ */
313
+ arm64_use_ng_mappings = kaslr_requires_kpti();
305314
306315 early_fixmap_init();
307316 early_ioremap_init();
....@@ -330,6 +339,10 @@
330339
331340 xen_early_init();
332341 efi_init();
342
+
343
+ if (!efi_enabled(EFI_BOOT) && ((u64)_text % MIN_KIMG_ALIGN) != 0)
344
+ pr_warn(FW_BUG "Kernel image misaligned at boot, please fix your bootloader!");
345
+
333346 arm64_memblock_init();
334347
335348 paging_init();
....@@ -355,12 +368,12 @@
355368 else
356369 psci_acpi_init();
357370
358
- cpu_read_bootcpu_ops();
371
+ init_bootcpu_ops();
359372 smp_init_cpus();
360373 smp_build_mpidr_hash();
361374
362375 /* Init percpu seeds for random tags after cpus are set up. */
363
- kasan_init_tags();
376
+ kasan_init_sw_tags();
364377
365378 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
366379 /*
....@@ -368,22 +381,26 @@
368381 * faults in case uaccess_enable() is inadvertently called by the init
369382 * thread.
370383 */
371
- init_task.thread_info.ttbr0 = __pa_symbol(empty_zero_page);
384
+ init_task.thread_info.ttbr0 = phys_to_ttbr(__pa_symbol(reserved_pg_dir));
372385 #endif
373386
374
-#ifdef CONFIG_VT
375
-#if defined(CONFIG_VGA_CONSOLE)
376
- conswitchp = &vga_con;
377
-#elif defined(CONFIG_DUMMY_CONSOLE)
378
- conswitchp = &dummy_con;
379
-#endif
380
-#endif
381387 if (boot_args[1] || boot_args[2] || boot_args[3]) {
382388 pr_err("WARNING: x1-x3 nonzero in violation of boot protocol:\n"
383389 "\tx1: %016llx\n\tx2: %016llx\n\tx3: %016llx\n"
384390 "This indicates a broken bootloader or old kernel\n",
385391 boot_args[1], boot_args[2], boot_args[3]);
386392 }
393
+}
394
+
395
+static inline bool cpu_can_disable(unsigned int cpu)
396
+{
397
+#ifdef CONFIG_HOTPLUG_CPU
398
+ const struct cpu_operations *ops = get_cpu_ops(cpu);
399
+
400
+ if (ops && ops->cpu_can_disable)
401
+ return ops->cpu_can_disable(cpu);
402
+#endif
403
+ return false;
387404 }
388405
389406 static int __init topology_init(void)
....@@ -395,7 +412,7 @@
395412
396413 for_each_possible_cpu(i) {
397414 struct cpu *cpu = &per_cpu(cpu_data.cpu, i);
398
- cpu->hotpluggable = 1;
415
+ cpu->hotpluggable = cpu_can_disable(i);
399416 register_cpu(cpu, i);
400417 }
401418
....@@ -403,31 +420,36 @@
403420 }
404421 subsys_initcall(topology_init);
405422
406
-/*
407
- * Dump out kernel offset information on panic.
408
- */
409
-static int dump_kernel_offset(struct notifier_block *self, unsigned long v,
410
- void *p)
423
+static void dump_kernel_offset(void)
411424 {
412425 const unsigned long offset = kaslr_offset();
413426
414427 if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && offset > 0) {
415428 pr_emerg("Kernel Offset: 0x%lx from 0x%lx\n",
416429 offset, KIMAGE_VADDR);
430
+ pr_emerg("PHYS_OFFSET: 0x%llx\n", PHYS_OFFSET);
417431 } else {
418432 pr_emerg("Kernel Offset: disabled\n");
419433 }
434
+}
435
+
436
+static int arm64_panic_block_dump(struct notifier_block *self,
437
+ unsigned long v, void *p)
438
+{
439
+ dump_kernel_offset();
440
+ dump_cpu_features();
441
+ dump_mem_limit();
420442 return 0;
421443 }
422444
423
-static struct notifier_block kernel_offset_notifier = {
424
- .notifier_call = dump_kernel_offset
445
+static struct notifier_block arm64_panic_block = {
446
+ .notifier_call = arm64_panic_block_dump
425447 };
426448
427
-static int __init register_kernel_offset_dumper(void)
449
+static int __init register_arm64_panic_block(void)
428450 {
429451 atomic_notifier_chain_register(&panic_notifier_list,
430
- &kernel_offset_notifier);
452
+ &arm64_panic_block);
431453 return 0;
432454 }
433
-__initcall(register_kernel_offset_dumper);
455
+device_initcall(register_arm64_panic_block);