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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  linux/init/main.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Copyright (C) 1991, 1992  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *  GK 2/5/95  -  Changed to support mounting root fs via NFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *  Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *  Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *  Simplified starting of init:  Michael A. Griffith <grif@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #define DEBUG		/* Enable initcall_debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/binfmts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/stackprotector.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/bootconfig.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/kprobes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/start_kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/profile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/kfence.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/cpuset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/cgroup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/tick.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/sched/isolation.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/taskstats_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/delayacct.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <linux/rmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <linux/mempolicy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <linux/key.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include <linux/page_ext.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <linux/debug_locks.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include <linux/debugobjects.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <linux/lockdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include <linux/kmemleak.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #include <linux/padata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #include <linux/pid_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #include <linux/device/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #include <linux/sched/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #include <linux/kgdb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #include <linux/ftrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #include <linux/async.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #include <linux/sfi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #include <linux/shmem_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #include <linux/pti.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #include <linux/elevator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #include <linux/sched/clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #include <linux/context_tracking.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #include <linux/integrity.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #include <linux/proc_ns.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) #include <linux/rodata_test.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) #include <linux/jump_label.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) #include <linux/mem_encrypt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) #include <linux/kcsan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #include <linux/init_syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #include <linux/stackdepot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #include <asm/bugs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) #include <trace/events/initcall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) #include <kunit/test.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static int kernel_init(void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) extern void init_IRQ(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) extern void radix_tree_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121)  * Debug helper: via this flag we know that we are in 'early bootup code'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)  * where only the boot processor is running with IRQ disabled.  This means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)  * two things - IRQ must not be enabled before the flag is cleared and some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)  * operations which are not allowed with IRQ disabled are allowed while the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)  * flag is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) bool early_boot_irqs_disabled __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) enum system_states system_state __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) EXPORT_SYMBOL(system_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)  * Boot command-line arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) extern void time_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) /* Default late time init is NULL. archs can override this later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) void (*__initdata late_time_init)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) /* Untouched command line saved by arch-specific code. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) char __initdata boot_command_line[COMMAND_LINE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) /* Untouched saved command line (eg. for /proc) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) char *saved_command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) /* Command line for parameter parsing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static char *static_command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) /* Untouched extra command line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) static char *extra_command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) /* Extra init arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) static char *extra_init_args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) #ifdef CONFIG_BOOT_CONFIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) /* Is bootconfig on command line? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) static bool bootconfig_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static bool initargs_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) # define bootconfig_found false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) # define initargs_found false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) static char *execute_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) static char *ramdisk_execute_command = "/init";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  * Used to generate warnings if static_key manipulation functions are used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  * before jump_label_init is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) bool static_key_initialized __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) EXPORT_SYMBOL_GPL(static_key_initialized);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)  * If set, this is an indication to the drivers that reset the underlying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)  * device before going ahead with the initialization otherwise driver might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175)  * rely on the BIOS and skip the reset operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177)  * This is useful if kernel is booting in an unreliable environment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178)  * For ex. kdump situation where previous kernel has crashed, BIOS has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179)  * skipped and devices will be in unknown state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) unsigned int reset_devices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) EXPORT_SYMBOL(reset_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) static int __init set_reset_devices(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	reset_devices = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) __setup("reset_devices", set_reset_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) static const char *panic_later, *panic_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) extern const struct obs_kernel_param __setup_start[], __setup_end[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) static bool __init obsolete_checksetup(char *line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	const struct obs_kernel_param *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	bool had_early_param = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	p = __setup_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		int n = strlen(p->str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		if (parameqn(line, p->str, n)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 			if (p->early) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 				/* Already done in parse_early_param?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 				 * (Needs exact match on param part).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 				 * Keep iterating, as we can have early
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 				 * params and __setups of same names 8( */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 				if (line[n] == '\0' || line[n] == '=')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 					had_early_param = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 			} else if (!p->setup_func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 				pr_warn("Parameter %s is obsolete, ignored\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 					p->str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 				return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 			} else if (p->setup_func(line + n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 				return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	} while (p < __setup_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	return had_early_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)  * This should be approx 2 Bo*oMips to start (note initial shift), and will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229)  * still work even if initially too large, it will just take slightly longer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) unsigned long loops_per_jiffy = (1<<12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) EXPORT_SYMBOL(loops_per_jiffy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) static int __init debug_kernel(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	console_loglevel = CONSOLE_LOGLEVEL_DEBUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) static int __init quiet_kernel(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	console_loglevel = CONSOLE_LOGLEVEL_QUIET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) early_param("debug", debug_kernel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) early_param("quiet", quiet_kernel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) static int __init loglevel(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	int newlevel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	 * Only update loglevel value when a correct setting was passed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	 * to prevent blind crashes (when loglevel being set to 0) that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	 * are quite hard to debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	if (get_option(&str, &newlevel)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		console_loglevel = newlevel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) early_param("loglevel", loglevel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	u32 size, csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	u32 *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	if (!initrd_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	 * Since Grub may align the size of initrd to 4, we must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	 * check the preceding 3 bytes as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		if (!memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 			goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		data--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	hdr = (u32 *)(data - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	size = le32_to_cpu(hdr[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	csum = le32_to_cpu(hdr[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	data = ((void *)hdr) - size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	if ((unsigned long)data < initrd_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		pr_err("bootconfig size %d is greater than initrd size %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 			size, initrd_end - initrd_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	/* Remove bootconfig from initramfs/initrd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	initrd_end = (unsigned long)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	if (_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		*_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	if (_csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		*_csum = csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) #ifdef CONFIG_BOOT_CONFIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) static char xbc_namebuf[XBC_KEYLEN_MAX] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) static int __init xbc_snprint_cmdline(char *buf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 				      struct xbc_node *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	struct xbc_node *knode, *vnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	char *end = buf + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	const char *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	xbc_node_for_each_key_value(root, knode, val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		ret = xbc_node_compose_key_after(root, knode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 					xbc_namebuf, XBC_KEYLEN_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		vnode = xbc_node_get_child(knode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		if (!vnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 			ret = snprintf(buf, rest(buf, end), "%s ", xbc_namebuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 			buf += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		xbc_array_for_each_value(vnode, val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			ret = snprintf(buf, rest(buf, end), "%s=\"%s\" ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 				       xbc_namebuf, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			buf += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	return buf - (end - size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) #undef rest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) /* Make an extra command line under given key word */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) static char * __init xbc_make_cmdline(const char *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	struct xbc_node *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	char *new_cmdline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	int ret, len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	root = xbc_find_node(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	/* Count required buffer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	len = xbc_snprint_cmdline(NULL, 0, root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	new_cmdline = memblock_alloc(len + 1, SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	if (!new_cmdline) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		pr_err("Failed to allocate memory for extra kernel cmdline.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	ret = xbc_snprint_cmdline(new_cmdline, len + 1, root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	if (ret < 0 || ret > len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		pr_err("Failed to print extra kernel cmdline.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		memblock_free(__pa(new_cmdline), len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	return new_cmdline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) static int __init bootconfig_params(char *param, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 				    const char *unused, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	if (strcmp(param, "bootconfig") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		bootconfig_found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) static void __init setup_boot_config(const char *cmdline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	const char *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	int pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	u32 size, csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	char *data, *copy, *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	/* Cut out the bootconfig data even if we have no bootconfig option */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	data = get_boot_config_from_initrd(&size, &csum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			 bootconfig_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	if (IS_ERR(err) || !bootconfig_found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	/* parse_args() stops at '--' and returns an address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		initargs_found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		pr_err("'bootconfig' found on command line, but no bootconfig found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	if (size >= XBC_DATA_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		pr_err("bootconfig size %d greater than max size %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 			size, XBC_DATA_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	if (xbc_calc_checksum(data, size) != csum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		pr_err("bootconfig checksum failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	copy = memblock_alloc(size + 1, SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	if (!copy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		pr_err("Failed to allocate memory for bootconfig\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	memcpy(copy, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	copy[size] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	ret = xbc_init(copy, &msg, &pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		if (pos < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 			pr_err("Failed to init bootconfig: %s.\n", msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			pr_err("Failed to parse bootconfig: %s at %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 				msg, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		/* keys starting with "kernel." are passed via cmdline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		extra_command_line = xbc_make_cmdline("kernel");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		/* Also, "init." keys are init arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		extra_init_args = xbc_make_cmdline("init");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) static void __init setup_boot_config(const char *cmdline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	/* Remove bootconfig data from initrd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	get_boot_config_from_initrd(NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) static int __init warn_bootconfig(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	pr_warn("WARNING: 'bootconfig' found on the kernel command line but CONFIG_BOOT_CONFIG is not set.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) early_param("bootconfig", warn_bootconfig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) /* Change NUL term back to "=", to make "param" the whole string. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) static void __init repair_env_string(char *param, char *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	if (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		/* param=val or param="val"? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		if (val == param+strlen(param)+1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			val[-1] = '=';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		else if (val == param+strlen(param)+2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			val[-2] = '=';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			memmove(val-1, val, strlen(val)+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) /* Anything after -- gets handed straight to init. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) static int __init set_init_arg(char *param, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			       const char *unused, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	if (panic_later)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	repair_env_string(param, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	for (i = 0; argv_init[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		if (i == MAX_INIT_ARGS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			panic_later = "init";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 			panic_param = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	argv_init[i] = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521)  * Unknown boot options get handed to init, unless they look like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522)  * unused parameters (modprobe will find them in /proc/cmdline).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) static int __init unknown_bootoption(char *param, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 				     const char *unused, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	size_t len = strlen(param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	repair_env_string(param, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	/* Handle obsolete-style parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	if (obsolete_checksetup(param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	/* Unused module parameter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	if (strnchr(param, len, '.'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	if (panic_later)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	if (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		/* Environment option */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		for (i = 0; envp_init[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 			if (i == MAX_INIT_ENVS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 				panic_later = "env";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 				panic_param = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 			if (!strncmp(param, envp_init[i], len+1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		envp_init[i] = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		/* Command line option */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		for (i = 0; argv_init[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 			if (i == MAX_INIT_ARGS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 				panic_later = "init";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 				panic_param = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		argv_init[i] = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) static int __init init_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	execute_command = str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	 * In case LILO is going to boot us with default command line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	 * it prepends "auto" before the whole cmdline which makes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	 * the shell think it should execute a script with such name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	 * So we ignore all arguments entered _before_ init=... [MJ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	for (i = 1; i < MAX_INIT_ARGS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		argv_init[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) __setup("init=", init_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) static int __init rdinit_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	ramdisk_execute_command = str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	/* See "auto" comment in init_setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	for (i = 1; i < MAX_INIT_ARGS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		argv_init[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) __setup("rdinit=", rdinit_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) static const unsigned int setup_max_cpus = NR_CPUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) static inline void setup_nr_cpu_ids(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) static inline void smp_prepare_cpus(unsigned int maxcpus) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604)  * We need to store the untouched command line for future reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605)  * We also need to store the touched command line since the parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606)  * parsing is performed in place, and we should allow a component to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607)  * store reference of name/value for future reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) static void __init setup_command_line(char *command_line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	size_t len, xlen = 0, ilen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	if (extra_command_line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		xlen = strlen(extra_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	if (extra_init_args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		ilen = strlen(extra_init_args) + 4; /* for " -- " */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	len = xlen + strlen(boot_command_line) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	saved_command_line = memblock_alloc(len + ilen, SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	if (!saved_command_line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	static_command_line = memblock_alloc(len, SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	if (!static_command_line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		panic("%s: Failed to allocate %zu bytes\n", __func__, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	if (xlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		 * We have to put extra_command_line before boot command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		 * lines because there could be dashes (separator of init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		 * command line) in the command lines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		strcpy(saved_command_line, extra_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		strcpy(static_command_line, extra_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	strcpy(saved_command_line + xlen, boot_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	strcpy(static_command_line + xlen, command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	if (ilen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		 * Append supplemental init boot args to saved_command_line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		 * so that user can check what command line options passed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		 * to init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		len = strlen(saved_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		if (initargs_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			saved_command_line[len++] = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			strcpy(saved_command_line + len, " -- ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 			len += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		strcpy(saved_command_line + len, extra_init_args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)  * We need to finalize in a non-__init function or else race conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660)  * between the root thread and the init thread may cause start_kernel to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661)  * be reaped by free_initmem before the root thread has proceeded to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662)  * cpu_idle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664)  * gcc-3.4 accidentally inlines this function, so use noinline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) static __initdata DECLARE_COMPLETION(kthreadd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) noinline void __ref rest_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	struct task_struct *tsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	int pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	rcu_scheduler_starting();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	 * We need to spawn init first so that it obtains pid 1, however
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	 * the init task will end up wanting to create kthreads, which, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	 * we schedule it before we create kthreadd, will OOPS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	pid = kernel_thread(kernel_init, NULL, CLONE_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	 * Pin init on the boot CPU. Task migration is not properly working
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	 * until sched_init_smp() has been run. It will set the allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	 * CPUs for init to the non isolated CPUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	tsk = find_task_by_pid_ns(pid, &init_pid_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	set_cpus_allowed_ptr(tsk, cpumask_of(smp_processor_id()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	numa_default_policy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	 * Enable might_sleep() and smp_processor_id() checks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	 * They cannot be enabled earlier because with CONFIG_PREEMPTION=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	 * kernel_thread() would trigger might_sleep() splats. With
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	 * CONFIG_PREEMPT_VOLUNTARY=y the init task might have scheduled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	 * already, but it's stuck on the kthreadd_done completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	system_state = SYSTEM_SCHEDULING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	complete(&kthreadd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	 * The boot idle thread must execute schedule()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	 * at least once to get things moving:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	schedule_preempt_disabled();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	/* Call into cpu_idle with preempt disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	cpu_startup_entry(CPUHP_ONLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) /* Check for early params. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) static int __init do_early_param(char *param, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 				 const char *unused, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	const struct obs_kernel_param *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	for (p = __setup_start; p < __setup_end; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		if ((p->early && parameq(param, p->str)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		    (strcmp(param, "console") == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		     strcmp(p->str, "earlycon") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			if (p->setup_func(val) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 				pr_warn("Malformed early option '%s'\n", param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	/* We accept everything at this stage. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) void __init parse_early_options(char *cmdline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	parse_args("early options", cmdline, NULL, 0, 0, 0, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		   do_early_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) /* Arch code calls this early on, or if not, just before other parsing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) void __init parse_early_param(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	static int done __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	/* All fall through to do_early_param. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	parse_early_options(tmp_cmdline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) void __init __weak arch_post_acpi_subsys_init(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) void __init __weak smp_setup_processor_id(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) # if THREAD_SIZE >= PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) void __init __weak thread_stack_cache_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) void __init __weak mem_encrypt_init(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) void __init __weak poking_init(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) void __init __weak pgtable_cache_init(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) bool initcall_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) core_param(initcall_debug, initcall_debug, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) #ifdef TRACEPOINTS_ENABLED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) static void __init initcall_debug_enable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) static inline void initcall_debug_enable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) /* Report memory auto-initialization states for this boot. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) static void __init report_meminit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	const char *stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (IS_ENABLED(CONFIG_INIT_STACK_ALL_PATTERN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		stack = "all(pattern)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	else if (IS_ENABLED(CONFIG_INIT_STACK_ALL_ZERO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		stack = "all(zero)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		stack = "byref_all(zero)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		stack = "byref(zero)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_USER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		stack = "__user(zero)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		stack = "off";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	pr_info("mem auto-init: stack:%s, heap alloc:%s, heap free:%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		stack, want_init_on_alloc(GFP_KERNEL) ? "on" : "off",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		want_init_on_free() ? "on" : "off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	if (want_init_on_free())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		pr_info("mem auto-init: clearing system memory may take some time...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)  * Set up kernel memory allocators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) static void __init mm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	 * page_ext requires contiguous pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	 * bigger than MAX_ORDER unless SPARSEMEM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	page_ext_init_flatmem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	init_mem_debugging_and_hardening();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	kfence_alloc_pool();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	report_meminit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	stack_depot_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	mem_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	/* page_owner must be initialized after buddy is ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	page_ext_init_flatmem_late();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	kmem_cache_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	kmemleak_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	pgtable_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	debug_objects_mem_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	vmalloc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	ioremap_huge_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	/* Should be run before the first non-init thread is created */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	init_espfix_bsp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	/* Should be run after espfix64 is set up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	pti_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) void __init __weak arch_call_rest_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	rest_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	char *command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	char *after_dashes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	set_task_stack_end_magic(&init_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	smp_setup_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	debug_objects_early_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	cgroup_init_early();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	early_boot_irqs_disabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	 * Interrupts are still disabled. Do necessary setups, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	 * enable them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	boot_cpu_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	page_address_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	pr_notice("%s", linux_banner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	early_security_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	setup_arch(&command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	setup_boot_config(command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	setup_command_line(command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	setup_nr_cpu_ids();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	setup_per_cpu_areas();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	smp_prepare_boot_cpu();	/* arch-specific boot-cpu hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	boot_cpu_hotplug_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	build_all_zonelists(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	page_alloc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) #ifdef CONFIG_ARCH_ROCKCHIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		const char *s = saved_command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		const char *e = &saved_command_line[strlen(saved_command_line)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		int n =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		    pr_notice("Kernel command line: %s\n", saved_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		n -= strlen("Kernel command line: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		s += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		/* command line maybe too long to print one time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		while (n > 0 && s < e) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 			n = pr_cont("%s\n", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			s += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	pr_notice("Kernel command line: %s\n", saved_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	/* parameters may set static keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	jump_label_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	parse_early_param();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	after_dashes = parse_args("Booting kernel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 				  static_command_line, __start___param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 				  __stop___param - __start___param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 				  -1, -1, NULL, &unknown_bootoption);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	if (!IS_ERR_OR_NULL(after_dashes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 			   NULL, set_init_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	if (extra_init_args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		parse_args("Setting extra init args", extra_init_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 			   NULL, 0, -1, -1, NULL, set_init_arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	 * These use large bootmem allocations and must precede
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	 * kmem_cache_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	setup_log_buf(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	vfs_caches_init_early();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	sort_main_extable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	trap_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	mm_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	ftrace_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	/* trace_printk can be enabled here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	early_trace_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	 * Set up the scheduler prior starting any interrupts (such as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	 * timer interrupt). Full topology setup happens at smp_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	 * time - but meanwhile we still have a functioning scheduler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	sched_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	if (WARN(!irqs_disabled(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		 "Interrupts were enabled *very* early, fixing it\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	radix_tree_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	 * Set up housekeeping before setting up workqueues to allow the unbound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	 * workqueue to take non-housekeeping into account.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	housekeeping_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	 * Allow workqueue creation and work item queueing/cancelling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	 * early.  Work item execution depends on kthreads and starts after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	 * workqueue_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	workqueue_init_early();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	rcu_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	/* Trace events are available after this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	trace_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	if (initcall_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		initcall_debug_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	context_tracking_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	/* init some links before init_ISA_irqs() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	early_irq_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	init_IRQ();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	tick_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	rcu_init_nohz();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	init_timers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	hrtimers_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	softirq_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	timekeeping_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	kfence_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	 * For best initial stack canary entropy, prepare it after:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	 * - setup_arch() for any UEFI RNG entropy and boot cmdline access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	 * - timekeeping_init() for ktime entropy used in rand_initialize()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	 * - rand_initialize() to get any arch-specific entropy like RDRAND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	 * - add_latent_entropy() to get any latent entropy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	 * - adding command line entropy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	rand_initialize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	add_latent_entropy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	add_device_randomness(command_line, strlen(command_line));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	boot_init_stack_canary();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	time_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	perf_event_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	profile_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	call_function_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	WARN(!irqs_disabled(), "Interrupts were enabled early\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	early_boot_irqs_disabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	kmem_cache_init_late();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	 * HACK ALERT! This is early. We're enabling the console before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	 * we've done PCI setups etc, and console_init() must be aware of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	 * this. But we do want output early, in case something goes wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	console_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	if (panic_later)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		panic("Too many boot %s vars at `%s'", panic_later,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		      panic_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	lockdep_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	 * Need to run this when irqs are enabled, because it wants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	 * to self-test [hard/soft]-irqs on/off lock inversion bugs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	 * too:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	locking_selftest();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	 * This needs to be called before any devices perform DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	 * operations that might use the SWIOTLB bounce buffers. It will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	 * mark the bounce buffers as decrypted so that their usage will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	 * not cause "plain-text" data to be decrypted when accessed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	mem_encrypt_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	if (initrd_start && !initrd_below_start_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	    page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		pr_crit("initrd overwritten (0x%08lx < 0x%08lx) - disabling it.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		    page_to_pfn(virt_to_page((void *)initrd_start)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		    min_low_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		initrd_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	setup_per_cpu_pageset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	numa_policy_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	acpi_early_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	if (late_time_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		late_time_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	sched_clock_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	calibrate_delay();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	pid_idr_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	anon_vma_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	if (efi_enabled(EFI_RUNTIME_SERVICES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		efi_enter_virtual_mode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	thread_stack_cache_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	cred_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	fork_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	proc_caches_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	uts_ns_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	buffer_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	key_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	security_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	dbg_late_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	vfs_caches_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	pagecache_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	signals_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	seq_file_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	proc_root_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	nsfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	cpuset_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	cgroup_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	taskstats_init_early();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	delayacct_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	poking_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	check_bugs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	acpi_subsystem_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	arch_post_acpi_subsys_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	sfi_init_late();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	kcsan_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	/* Do the rest non-__init'ed, we're now alive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	arch_call_rest_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	prevent_tail_call_optimization();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) /* Call all constructor functions linked into the kernel. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) static void __init do_ctors(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) #ifdef CONFIG_CONSTRUCTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	for (; fn < (ctor_fn_t *) __ctors_end; fn++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		(*fn)();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) #ifdef CONFIG_KALLSYMS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) struct blacklist_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	struct list_head next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static __initdata_or_module LIST_HEAD(blacklisted_initcalls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static int __init initcall_blacklist(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	char *str_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	struct blacklist_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	/* str argument is a comma-separated list of functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		str_entry = strsep(&str, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		if (str_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			pr_debug("blacklisting initcall %s\n", str_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			entry = memblock_alloc(sizeof(*entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 					       SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 				panic("%s: Failed to allocate %zu bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 				      __func__, sizeof(*entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 			entry->buf = memblock_alloc(strlen(str_entry) + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 						    SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			if (!entry->buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 				panic("%s: Failed to allocate %zu bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 				      __func__, strlen(str_entry) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			strcpy(entry->buf, str_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 			list_add(&entry->next, &blacklisted_initcalls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	} while (str_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) static bool __init_or_module initcall_blacklisted(initcall_t fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	struct blacklist_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	char fn_name[KSYM_SYMBOL_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	if (list_empty(&blacklisted_initcalls))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	addr = (unsigned long) dereference_function_descriptor(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	sprint_symbol_no_offset(fn_name, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	 * fn will be "function_name [module_name]" where [module_name] is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	 * displayed for built-in init functions.  Strip off the [module_name].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	strreplace(fn_name, ' ', '\0');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	list_for_each_entry(entry, &blacklisted_initcalls, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		if (!strcmp(fn_name, entry->buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 			pr_debug("initcall %s blacklisted\n", fn_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) static int __init initcall_blacklist(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	pr_warn("initcall_blacklist requires CONFIG_KALLSYMS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) static bool __init_or_module initcall_blacklisted(initcall_t fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) __setup("initcall_blacklist=", initcall_blacklist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) static __init_or_module void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) trace_initcall_start_cb(void *data, initcall_t fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	ktime_t *calltime = (ktime_t *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	printk(KERN_DEBUG "calling  %pS @ %i\n", fn, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	*calltime = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) static __init_or_module void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) trace_initcall_finish_cb(void *data, initcall_t fn, int ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	ktime_t *calltime = (ktime_t *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	ktime_t delta, rettime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	unsigned long long duration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	rettime = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	delta = ktime_sub(rettime, *calltime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	duration = (unsigned long long) ktime_to_ns(delta) >> 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	printk(KERN_DEBUG "initcall %pS returned %d after %lld usecs\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		 fn, ret, duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) static ktime_t initcall_calltime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) #ifdef TRACEPOINTS_ENABLED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) static void __init initcall_debug_enable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	ret = register_trace_initcall_start(trace_initcall_start_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 					    &initcall_calltime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	ret |= register_trace_initcall_finish(trace_initcall_finish_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 					      &initcall_calltime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	WARN(ret, "Failed to register initcall tracepoints\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) # define do_trace_initcall_start	trace_initcall_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) # define do_trace_initcall_finish	trace_initcall_finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) static inline void do_trace_initcall_start(initcall_t fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	if (!initcall_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	trace_initcall_start_cb(&initcall_calltime, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) static inline void do_trace_initcall_finish(initcall_t fn, int ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	if (!initcall_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	trace_initcall_finish_cb(&initcall_calltime, fn, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) #endif /* !TRACEPOINTS_ENABLED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) int __init_or_module do_one_initcall(initcall_t fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	int count = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	char msgbuf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	if (initcall_blacklisted(fn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	do_trace_initcall_start(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	ret = fn();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	do_trace_initcall_finish(fn, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	msgbuf[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	if (preempt_count() != count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		sprintf(msgbuf, "preemption imbalance ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		preempt_count_set(count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	if (irqs_disabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	WARN(msgbuf[0], "initcall %pS returned with %s\n", fn, msgbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	add_latent_entropy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) extern initcall_entry_t __initcall_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) extern initcall_entry_t __initcall0_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) extern initcall_entry_t __initcall1_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) extern initcall_entry_t __initcall2_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) extern initcall_entry_t __initcall3_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) extern initcall_entry_t __initcall4_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) extern initcall_entry_t __initcall5_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) extern initcall_entry_t __initcall6_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) extern initcall_entry_t __initcall7_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) extern initcall_entry_t __initcall_end[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) static initcall_entry_t *initcall_levels[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	__initcall0_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	__initcall1_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	__initcall2_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	__initcall3_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	__initcall4_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	__initcall5_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	__initcall6_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	__initcall7_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	__initcall_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) /* Keep these in sync with initcalls in include/linux/init.h */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) static const char *initcall_level_names[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	"pure",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	"core",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	"postcore",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	"arch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	"subsys",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	"fs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	"device",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	"late",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) static int __init ignore_unknown_bootoption(char *param, char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 			       const char *unused, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) #ifdef CONFIG_INITCALL_ASYNC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) extern initcall_entry_t __initcall0s_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) extern initcall_entry_t __initcall1s_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) extern initcall_entry_t __initcall2s_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) extern initcall_entry_t __initcall3s_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) extern initcall_entry_t __initcall4s_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) extern initcall_entry_t __initcall5s_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) extern initcall_entry_t __initcall6s_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) extern initcall_entry_t __initcall7s_start[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) static initcall_entry_t *initcall_sync_levels[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	__initcall0s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	__initcall1s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	__initcall2s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	__initcall3s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	__initcall4s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	__initcall5s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	__initcall6s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	__initcall7s_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	__initcall_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) struct initcall_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	struct kthread_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	initcall_t call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) struct initcall_worker {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	struct kthread_worker *worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	bool queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) static struct initcall_worker *initcall_workers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) static int initcall_nr_workers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) static int __init setup_initcall_nr_threads(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	get_option(&str, &initcall_nr_workers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) __setup("initcall_nr_threads=", setup_initcall_nr_threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) static void __init initcall_work_func(struct kthread_work *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	struct initcall_work *iwork =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		container_of(work, struct initcall_work, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	do_one_initcall(iwork->call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) static void __init initcall_queue_work(struct initcall_worker *iworker,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 				       struct initcall_work *iwork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	kthread_queue_work(iworker->worker, &iwork->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	iworker->queued = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) static void __init initcall_flush_worker(int level, bool sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	struct initcall_worker *iworker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	for (i = 0; i < initcall_nr_workers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		iworker = &initcall_workers[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		if (iworker->queued) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 			kthread_flush_worker(iworker->worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 			iworker->queued = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) static int __init do_initcall_level_threaded(int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	initcall_entry_t *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	size_t i = 0, w = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	size_t n = initcall_levels[level + 1] - initcall_levels[level];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	struct initcall_work *iwork, *iworks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	ktime_t start = 0, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	if (!n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	iworks = kmalloc_array(n, sizeof(*iworks), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	if (!iworks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	if (initcall_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		start = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	for (fn = initcall_levels[level]; fn < initcall_sync_levels[level];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	     fn++, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 		iwork = &iworks[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 		iwork->call = initcall_from_entry(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		kthread_init_work(&iwork->work, initcall_work_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		initcall_queue_work(&initcall_workers[w], iwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		if (++w >= initcall_nr_workers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 			w = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	if (initcall_sync_levels[level] > initcall_levels[level]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		initcall_flush_worker(level, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		if (initcall_debug) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 			end = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 			printk(KERN_DEBUG "initcall level %s %lld usecs\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 			       initcall_level_names[level],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 			       ktime_us_delta(end, start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 			start = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	for (fn = initcall_sync_levels[level]; fn < initcall_levels[level + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	     fn++, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		iwork = &iworks[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		iwork->call = initcall_from_entry(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		kthread_init_work(&iwork->work, initcall_work_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		initcall_queue_work(&initcall_workers[w], iwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		if (++w >= initcall_nr_workers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 			w = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	if (initcall_levels[level + 1] > initcall_sync_levels[level]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		initcall_flush_worker(level, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		if (initcall_debug) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 			end = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 			printk(KERN_DEBUG "initcall level %s_sync %lld usecs\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 			       initcall_level_names[level],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 			       ktime_us_delta(end, start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	kfree(iworks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) static void __init initcall_init_workers(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	if (initcall_nr_workers < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		initcall_nr_workers = num_online_cpus() * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	if (!initcall_nr_workers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	initcall_workers =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		kcalloc(initcall_nr_workers, sizeof(*initcall_workers),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 			GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	if (!initcall_workers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		initcall_nr_workers = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	for (i = 0; i < initcall_nr_workers; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 		struct kthread_worker *worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		worker = kthread_create_worker(0, "init/%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		if (IS_ERR(worker)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 			i--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			initcall_nr_workers = (i >= 0 ? i : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		initcall_workers[i].worker = worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) static void __init initcall_free_works(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	for (i = 0; i < initcall_nr_workers; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 		if (initcall_workers[i].worker)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			kthread_destroy_worker(initcall_workers[i].worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	kfree(initcall_workers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) #endif /* CONFIG_INITCALL_ASYNC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) static void __init do_initcall_level(int level, char *command_line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	initcall_entry_t *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	parse_args(initcall_level_names[level],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 		   command_line, __start___param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		   __stop___param - __start___param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		   level, level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 		   NULL, ignore_unknown_bootoption);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	trace_initcall_level(initcall_level_names[level]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) #ifdef CONFIG_INITCALL_ASYNC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	if (initcall_nr_workers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		if (do_initcall_level_threaded(level) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		do_one_initcall(initcall_from_entry(fn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) static void __init do_initcalls(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	size_t len = strlen(saved_command_line) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	char *command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) #ifdef CONFIG_INITCALL_ASYNC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	initcall_init_workers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	command_line = kzalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	if (!command_line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		panic("%s: Failed to allocate %zu bytes\n", __func__, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		/* Parser modifies command_line, restore it each time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		strcpy(command_line, saved_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 		do_initcall_level(level, command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	kfree(command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) #ifdef CONFIG_INITCALL_ASYNC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	initcall_free_works();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)  * Ok, the machine is now initialized. None of the devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)  * have been touched yet, but the CPU subsystem is up and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)  * running, and memory and process management works.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)  * Now we can finally start doing some real work..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) static void __init do_basic_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	cpuset_init_smp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	driver_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	init_irq_proc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	do_ctors();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	usermodehelper_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	do_initcalls();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) static void __init do_pre_smp_initcalls(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	initcall_entry_t *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	trace_initcall_level("early");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	for (fn = __initcall_start; fn < __initcall0_start; fn++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 		do_one_initcall(initcall_from_entry(fn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) static int run_init_process(const char *init_filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	const char *const *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	argv_init[0] = init_filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	pr_info("Run %s as init process\n", init_filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	pr_debug("  with arguments:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	for (p = argv_init; *p; p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		pr_debug("    %s\n", *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	pr_debug("  with environment:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	for (p = envp_init; *p; p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		pr_debug("    %s\n", *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	return kernel_execve(init_filename, argv_init, envp_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) static int try_to_run_init_process(const char *init_filename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	ret = run_init_process(init_filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	if (ret && ret != -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		pr_err("Starting init: %s exists but couldn't execute it (error %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 		       init_filename, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) static noinline void __init kernel_init_freeable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) bool rodata_enabled __ro_after_init = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) static int __init set_debug_rodata(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	return strtobool(str, &rodata_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) __setup("rodata=", set_debug_rodata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) #ifdef CONFIG_STRICT_KERNEL_RWX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) static void mark_readonly(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	if (rodata_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		 * load_module() results in W+X mappings, which are cleaned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 		 * up with call_rcu().  Let's make sure that queued work is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		 * flushed so that we don't hit false positives looking for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 		 * insecure pages which are W+X.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		mark_rodata_ro();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 		rodata_test();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		pr_info("Kernel memory protection disabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) #elif defined(CONFIG_ARCH_HAS_STRICT_KERNEL_RWX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) static inline void mark_readonly(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	pr_warn("Kernel memory protection not selected by kernel config.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) static inline void mark_readonly(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	pr_warn("This architecture does not have kernel memory protection.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) void __weak free_initmem(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	free_initmem_default(POISON_FREE_INITMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) static int __ref kernel_init(void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	kernel_init_freeable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	/* need to finish all async __init code before freeing the memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	async_synchronize_full();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	kprobe_free_init_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	ftrace_free_init_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	kgdb_free_init_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	free_initmem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	mark_readonly();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	 * Kernel mappings are now finalized - update the userspace page-table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	 * to finalize PTI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	pti_finalize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	system_state = SYSTEM_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	numa_default_policy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	rcu_end_inkernel_boot();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	do_sysctl_args();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	if (ramdisk_execute_command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 		ret = run_init_process(ramdisk_execute_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 		pr_err("Failed to execute %s (error %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 		       ramdisk_execute_command, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	 * We try each of these until one succeeds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	 * The Bourne shell can be used instead of init if we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	 * trying to recover a really broken machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	if (execute_command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		ret = run_init_process(execute_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		panic("Requested init %s failed (error %d).",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		      execute_command, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	if (CONFIG_DEFAULT_INIT[0] != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 		ret = run_init_process(CONFIG_DEFAULT_INIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 			pr_err("Default init %s failed (error %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 			       CONFIG_DEFAULT_INIT, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	if (!try_to_run_init_process("/sbin/init") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	    !try_to_run_init_process("/etc/init") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	    !try_to_run_init_process("/bin/init") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	    !try_to_run_init_process("/bin/sh"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	panic("No working init found.  Try passing init= option to kernel. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	      "See Linux Documentation/admin-guide/init.rst for guidance.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) /* Open /dev/console, for stdin/stdout/stderr, this should never fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) void __init console_on_rootfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	struct file *file = filp_open("/dev/console", O_RDWR, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	if (IS_ERR(file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		pr_err("Warning: unable to open an initial console.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	init_dup(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	init_dup(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	init_dup(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	fput(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) static noinline void __init kernel_init_freeable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	 * Wait until kthreadd is all set-up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	wait_for_completion(&kthreadd_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	/* Now the scheduler is fully set up and can do blocking allocations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	gfp_allowed_mask = __GFP_BITS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	 * init can allocate pages on any node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	set_mems_allowed(node_states[N_MEMORY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	cad_pid = get_pid(task_pid(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	smp_prepare_cpus(setup_max_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	workqueue_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	init_mm_internals();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	rcu_init_tasks_generic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	do_pre_smp_initcalls();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	lockup_detector_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	smp_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	sched_init_smp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) #if defined(CONFIG_ROCKCHIP_THUNDER_BOOT) && defined(CONFIG_SMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	kthread_run(defer_free_memblock, NULL, "defer_mem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	padata_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	page_alloc_init_late();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	/* Initialize page ext after all struct pages are initialized. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	page_ext_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	do_basic_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	kunit_run_all_tests();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) #if IS_BUILTIN(CONFIG_INITRD_ASYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	async_synchronize_full();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	console_on_rootfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	 * check if there is an early userspace init.  If yes, let it do all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	 * the work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	if (init_eaccess(ramdisk_execute_command) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		ramdisk_execute_command = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 		prepare_namespace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	 * Ok, we have completed the initial bootup, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	 * we're essentially up and running. Get rid of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	 * initmem segments and start the user-mode stuff..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	 * rootfs is available now, try loading the public keys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	 * and default modules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	integrity_load_keys();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) }