1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * linux/init/main.c 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * GK 2/5/95 - Changed to support mounting root fs via NFS 81da177e4SLinus Torvalds * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96 91da177e4SLinus Torvalds * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96 101da177e4SLinus Torvalds * Simplified starting of init: Michael A. Griffith <[email protected]> 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 13ea676e84SAndrew Morton #define DEBUG /* Enable initcall_debug */ 14ea676e84SAndrew Morton 151da177e4SLinus Torvalds #include <linux/types.h> 168a293be0SPaul Gortmaker #include <linux/extable.h> 171da177e4SLinus Torvalds #include <linux/module.h> 181da177e4SLinus Torvalds #include <linux/proc_fs.h> 195c2c5c55SIngo Molnar #include <linux/binfmts.h> 201da177e4SLinus Torvalds #include <linux/kernel.h> 211da177e4SLinus Torvalds #include <linux/syscalls.h> 229b5609fdSIngo Molnar #include <linux/stackprotector.h> 231da177e4SLinus Torvalds #include <linux/string.h> 241da177e4SLinus Torvalds #include <linux/ctype.h> 251da177e4SLinus Torvalds #include <linux/delay.h> 261da177e4SLinus Torvalds #include <linux/ioport.h> 271da177e4SLinus Torvalds #include <linux/init.h> 281da177e4SLinus Torvalds #include <linux/initrd.h> 2957c8a661SMike Rapoport #include <linux/memblock.h> 304a7a16dcSLen Brown #include <linux/acpi.h> 317684b858SMasami Hiramatsu #include <linux/bootconfig.h> 320c688614SNicolas Pitre #include <linux/console.h> 3338b8d208SIngo Molnar #include <linux/nmi.h> 341da177e4SLinus Torvalds #include <linux/percpu.h> 351da177e4SLinus Torvalds #include <linux/kmod.h> 3682d083abSMasami Hiramatsu #include <linux/kprobes.h> 37db64fe02SNick Piggin #include <linux/vmalloc.h> 381da177e4SLinus Torvalds #include <linux/kernel_stat.h> 39d7cd5611SRusty Russell #include <linux/start_kernel.h> 401da177e4SLinus Torvalds #include <linux/security.h> 413d442233SJens Axboe #include <linux/smp.h> 421da177e4SLinus Torvalds #include <linux/profile.h> 430ce20dd8SAlexander Potapenko #include <linux/kfence.h> 441da177e4SLinus Torvalds #include <linux/rcupdate.h> 451da177e4SLinus Torvalds #include <linux/moduleparam.h> 461da177e4SLinus Torvalds #include <linux/kallsyms.h> 471da177e4SLinus Torvalds #include <linux/writeback.h> 481da177e4SLinus Torvalds #include <linux/cpu.h> 491da177e4SLinus Torvalds #include <linux/cpuset.h> 50ddbcc7e8SPaul Menage #include <linux/cgroup.h> 511da177e4SLinus Torvalds #include <linux/efi.h> 52906568c9SThomas Gleixner #include <linux/tick.h> 5378634061SFrederic Weisbecker #include <linux/sched/isolation.h> 546168a702SAndrew Morton #include <linux/interrupt.h> 55c757249aSShailabh Nagar #include <linux/taskstats_kern.h> 56ca74e92bSShailabh Nagar #include <linux/delayacct.h> 571da177e4SLinus Torvalds #include <linux/unistd.h> 583ea056c5SAlexey Dobriyan #include <linux/utsname.h> 591da177e4SLinus Torvalds #include <linux/rmap.h> 601da177e4SLinus Torvalds #include <linux/mempolicy.h> 611da177e4SLinus Torvalds #include <linux/key.h> 62eefa864bSJoonsoo Kim #include <linux/page_ext.h> 639a11b49aSIngo Molnar #include <linux/debug_locks.h> 643ac7fe5aSThomas Gleixner #include <linux/debugobjects.h> 65fbb9ce95SIngo Molnar #include <linux/lockdep.h> 663c7b4e6bSCatalin Marinas #include <linux/kmemleak.h> 67f1b192b1SDaniel Jordan #include <linux/padata.h> 6884d73786SSukadev Bhattiprolu #include <linux/pid_namespace.h> 694c002c97SGreg Kroah-Hartman #include <linux/device/driver.h> 7073c27992SEric W. Biederman #include <linux/kthread.h> 71e6fe6649SAdrian Bunk #include <linux/sched.h> 721777e463SIngo Molnar #include <linux/sched/init.h> 73a1c9eea9SAdrian Bunk #include <linux/signal.h> 74199f0ca5SAkinobu Mita #include <linux/idr.h> 750b4b3827SJason Wessel #include <linux/kgdb.h> 7668bf21aaSSteven Rostedt #include <linux/ftrace.h> 7722a9d645SArjan van de Ven #include <linux/async.h> 782b2af54aSKay Sievers #include <linux/shmem_fs.h> 795a0e3ad6STejun Heo #include <linux/slab.h> 8024a24bb6SPeter Zijlstra #include <linux/perf_event.h> 81a74fb73cSAl Viro #include <linux/ptrace.h> 82aa8c6248SThomas Gleixner #include <linux/pti.h> 83bb813f4cSTejun Heo #include <linux/blkdev.h> 84bb813f4cSTejun Heo #include <linux/elevator.h> 855d2a4e91SPavel Tatashin #include <linux/sched/clock.h> 8629930025SIngo Molnar #include <linux/sched/task.h> 8768db0cf1SIngo Molnar #include <linux/sched/task_stack.h> 8865f382fdSFrederic Weisbecker #include <linux/context_tracking.h> 8947d06e53STheodore Ts'o #include <linux/random.h> 907b0b73d7SPrarit Bhargava #include <linux/list.h> 91c9cd2ce2SDmitry Kasatkin #include <linux/integrity.h> 92e149ed2bSAl Viro #include <linux/proc_ns.h> 930ddab1d2SToshi Kani #include <linux/io.h> 9439290b38SAKASHI Takahiro #include <linux/cache.h> 952959a5f7SJinbum Park #include <linux/rodata_test.h> 9633352244SJosh Poimboeuf #include <linux/jump_label.h> 97ae67d58dSMathieu Malaterre #include <linux/mem_encrypt.h> 98dfd402a4SMarco Elver #include <linux/kcsan.h> 99eb9d7d39SChristoph Hellwig #include <linux/init_syscalls.h> 100e1fdc403SVijayanand Jitta #include <linux/stackdepot.h> 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds #include <asm/io.h> 1031da177e4SLinus Torvalds #include <asm/bugs.h> 1041da177e4SLinus Torvalds #include <asm/setup.h> 105a940199fSAndi Kleen #include <asm/sections.h> 10637b73c82SArjan van de Ven #include <asm/cacheflush.h> 1071da177e4SLinus Torvalds 1084ee7c60dSSteven Rostedt (VMware) #define CREATE_TRACE_POINTS 1094ee7c60dSSteven Rostedt (VMware) #include <trace/events/initcall.h> 1104ee7c60dSSteven Rostedt (VMware) 1118c0d8849SBrendan Higgins #include <kunit/test.h> 1128c0d8849SBrendan Higgins 113aae5f662SSam Ravnborg static int kernel_init(void *); 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds extern void init_IRQ(void); 1161da177e4SLinus Torvalds extern void radix_tree_init(void); 1171da177e4SLinus Torvalds 1182ce802f6STejun Heo /* 1192ce802f6STejun Heo * Debug helper: via this flag we know that we are in 'early bootup code' 1202ce802f6STejun Heo * where only the boot processor is running with IRQ disabled. This means 1212ce802f6STejun Heo * two things - IRQ must not be enabled before the flag is cleared and some 1222ce802f6STejun Heo * operations which are not allowed with IRQ disabled are allowed while the 1232ce802f6STejun Heo * flag is set. 1242ce802f6STejun Heo */ 1252ce802f6STejun Heo bool early_boot_irqs_disabled __read_mostly; 1262ce802f6STejun Heo 127a6826048SPaul E. McKenney enum system_states system_state __read_mostly; 1281da177e4SLinus Torvalds EXPORT_SYMBOL(system_state); 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds /* 1311da177e4SLinus Torvalds * Boot command-line arguments 1321da177e4SLinus Torvalds */ 1331da177e4SLinus Torvalds #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT 1341da177e4SLinus Torvalds #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds extern void time_init(void); 1371da177e4SLinus Torvalds /* Default late time init is NULL. archs can override this later. */ 138d2e3192bSJan Beulich void (*__initdata late_time_init)(void); 1391da177e4SLinus Torvalds 14030d7e0d4SAlon Bar-Lev /* Untouched command line saved by arch-specific code. */ 14130d7e0d4SAlon Bar-Lev char __initdata boot_command_line[COMMAND_LINE_SIZE]; 14230d7e0d4SAlon Bar-Lev /* Untouched saved command line (eg. for /proc) */ 14330d7e0d4SAlon Bar-Lev char *saved_command_line; 14430d7e0d4SAlon Bar-Lev /* Command line for parameter parsing */ 14530d7e0d4SAlon Bar-Lev static char *static_command_line; 14651887d03SMasami Hiramatsu /* Untouched extra command line */ 14751887d03SMasami Hiramatsu static char *extra_command_line; 14813199162SMasami Hiramatsu /* Extra init arguments */ 14913199162SMasami Hiramatsu static char *extra_init_args; 1501da177e4SLinus Torvalds 151f61872bbSSteven Rostedt (VMware) #ifdef CONFIG_BOOT_CONFIG 152f61872bbSSteven Rostedt (VMware) /* Is bootconfig on command line? */ 153f61872bbSSteven Rostedt (VMware) static bool bootconfig_found; 154f61872bbSSteven Rostedt (VMware) static bool initargs_found; 155f61872bbSSteven Rostedt (VMware) #else 156f61872bbSSteven Rostedt (VMware) # define bootconfig_found false 157f61872bbSSteven Rostedt (VMware) # define initargs_found false 158f61872bbSSteven Rostedt (VMware) #endif 159f61872bbSSteven Rostedt (VMware) 1601da177e4SLinus Torvalds static char *execute_command; 161916db733SChristoph Hellwig static char *ramdisk_execute_command = "/init"; 1621da177e4SLinus Torvalds 1638b3b2955SJan Beulich /* 164c4b2c0c5SHannes Frederic Sowa * Used to generate warnings if static_key manipulation functions are used 165c4b2c0c5SHannes Frederic Sowa * before jump_label_init is called. 166c4b2c0c5SHannes Frederic Sowa */ 167dd4d9fecSFabian Frederick bool static_key_initialized __read_mostly; 168c4b2c0c5SHannes Frederic Sowa EXPORT_SYMBOL_GPL(static_key_initialized); 169c4b2c0c5SHannes Frederic Sowa 170c4b2c0c5SHannes Frederic Sowa /* 1718b3b2955SJan Beulich * If set, this is an indication to the drivers that reset the underlying 1728b3b2955SJan Beulich * device before going ahead with the initialization otherwise driver might 1738b3b2955SJan Beulich * rely on the BIOS and skip the reset operation. 1748b3b2955SJan Beulich * 1758b3b2955SJan Beulich * This is useful if kernel is booting in an unreliable environment. 176fc454fdcSFrans Klaver * For ex. kdump situation where previous kernel has crashed, BIOS has been 1778b3b2955SJan Beulich * skipped and devices will be in unknown state. 1788b3b2955SJan Beulich */ 1798b3b2955SJan Beulich unsigned int reset_devices; 1808b3b2955SJan Beulich EXPORT_SYMBOL(reset_devices); 1811da177e4SLinus Torvalds 1827e96287dSVivek Goyal static int __init set_reset_devices(char *str) 1837e96287dSVivek Goyal { 1847e96287dSVivek Goyal reset_devices = 1; 1857e96287dSVivek Goyal return 1; 1867e96287dSVivek Goyal } 1877e96287dSVivek Goyal 1887e96287dSVivek Goyal __setup("reset_devices", set_reset_devices); 1897e96287dSVivek Goyal 190d7627467SDavid Howells static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, }; 191d7627467SDavid Howells const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; 1921da177e4SLinus Torvalds static const char *panic_later, *panic_param; 1931da177e4SLinus Torvalds 194914dcaa8SRusty Russell extern const struct obs_kernel_param __setup_start[], __setup_end[]; 1951da177e4SLinus Torvalds 19631c025b5SYaowei Bai static bool __init obsolete_checksetup(char *line) 1971da177e4SLinus Torvalds { 198914dcaa8SRusty Russell const struct obs_kernel_param *p; 19931c025b5SYaowei Bai bool had_early_param = false; 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds p = __setup_start; 2021da177e4SLinus Torvalds do { 2031da177e4SLinus Torvalds int n = strlen(p->str); 204b1e4d20cSMichal Schmidt if (parameqn(line, p->str, n)) { 2051da177e4SLinus Torvalds if (p->early) { 20633df0d19SRusty Russell /* Already done in parse_early_param? 20733df0d19SRusty Russell * (Needs exact match on param part). 20833df0d19SRusty Russell * Keep iterating, as we can have early 20933df0d19SRusty Russell * params and __setups of same names 8( */ 2101da177e4SLinus Torvalds if (line[n] == '\0' || line[n] == '=') 21131c025b5SYaowei Bai had_early_param = true; 2121da177e4SLinus Torvalds } else if (!p->setup_func) { 213ea676e84SAndrew Morton pr_warn("Parameter %s is obsolete, ignored\n", 214ea676e84SAndrew Morton p->str); 21531c025b5SYaowei Bai return true; 2161da177e4SLinus Torvalds } else if (p->setup_func(line + n)) 21731c025b5SYaowei Bai return true; 2181da177e4SLinus Torvalds } 2191da177e4SLinus Torvalds p++; 2201da177e4SLinus Torvalds } while (p < __setup_end); 22133df0d19SRusty Russell 22233df0d19SRusty Russell return had_early_param; 2231da177e4SLinus Torvalds } 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds /* 2261da177e4SLinus Torvalds * This should be approx 2 Bo*oMips to start (note initial shift), and will 2271da177e4SLinus Torvalds * still work even if initially too large, it will just take slightly longer 2281da177e4SLinus Torvalds */ 2291da177e4SLinus Torvalds unsigned long loops_per_jiffy = (1<<12); 2301da177e4SLinus Torvalds EXPORT_SYMBOL(loops_per_jiffy); 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds static int __init debug_kernel(char *str) 2331da177e4SLinus Torvalds { 234a8fe19ebSBorislav Petkov console_loglevel = CONSOLE_LOGLEVEL_DEBUG; 235f6f21c81SYinghai Lu return 0; 2361da177e4SLinus Torvalds } 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds static int __init quiet_kernel(char *str) 2391da177e4SLinus Torvalds { 240a8fe19ebSBorislav Petkov console_loglevel = CONSOLE_LOGLEVEL_QUIET; 241f6f21c81SYinghai Lu return 0; 2421da177e4SLinus Torvalds } 2431da177e4SLinus Torvalds 244f6f21c81SYinghai Lu early_param("debug", debug_kernel); 245f6f21c81SYinghai Lu early_param("quiet", quiet_kernel); 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds static int __init loglevel(char *str) 2481da177e4SLinus Torvalds { 249808bf29bSAlexander Sverdlin int newlevel; 250808bf29bSAlexander Sverdlin 251808bf29bSAlexander Sverdlin /* 252808bf29bSAlexander Sverdlin * Only update loglevel value when a correct setting was passed, 253808bf29bSAlexander Sverdlin * to prevent blind crashes (when loglevel being set to 0) that 254808bf29bSAlexander Sverdlin * are quite hard to debug 255808bf29bSAlexander Sverdlin */ 256808bf29bSAlexander Sverdlin if (get_option(&str, &newlevel)) { 257808bf29bSAlexander Sverdlin console_loglevel = newlevel; 258d9d4fcfeSAlex Riesen return 0; 2591da177e4SLinus Torvalds } 2601da177e4SLinus Torvalds 261808bf29bSAlexander Sverdlin return -EINVAL; 262808bf29bSAlexander Sverdlin } 263808bf29bSAlexander Sverdlin 264f6f21c81SYinghai Lu early_param("loglevel", loglevel); 2651da177e4SLinus Torvalds 266de462e5fSMasami Hiramatsu #ifdef CONFIG_BLK_DEV_INITRD 267de462e5fSMasami Hiramatsu static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum) 268de462e5fSMasami Hiramatsu { 269de462e5fSMasami Hiramatsu u32 size, csum; 270de462e5fSMasami Hiramatsu char *data; 271de462e5fSMasami Hiramatsu u32 *hdr; 27250b8a742SMasami Hiramatsu int i; 273de462e5fSMasami Hiramatsu 274de462e5fSMasami Hiramatsu if (!initrd_end) 275de462e5fSMasami Hiramatsu return NULL; 276de462e5fSMasami Hiramatsu 277de462e5fSMasami Hiramatsu data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN; 27850b8a742SMasami Hiramatsu /* 27950b8a742SMasami Hiramatsu * Since Grub may align the size of initrd to 4, we must 28050b8a742SMasami Hiramatsu * check the preceding 3 bytes as well. 28150b8a742SMasami Hiramatsu */ 28250b8a742SMasami Hiramatsu for (i = 0; i < 4; i++) { 28350b8a742SMasami Hiramatsu if (!memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN)) 28450b8a742SMasami Hiramatsu goto found; 28550b8a742SMasami Hiramatsu data--; 28650b8a742SMasami Hiramatsu } 287de462e5fSMasami Hiramatsu return NULL; 288de462e5fSMasami Hiramatsu 28950b8a742SMasami Hiramatsu found: 290de462e5fSMasami Hiramatsu hdr = (u32 *)(data - 8); 29124aed094SMasami Hiramatsu size = le32_to_cpu(hdr[0]); 29224aed094SMasami Hiramatsu csum = le32_to_cpu(hdr[1]); 293de462e5fSMasami Hiramatsu 294de462e5fSMasami Hiramatsu data = ((void *)hdr) - size; 295de462e5fSMasami Hiramatsu if ((unsigned long)data < initrd_start) { 296de462e5fSMasami Hiramatsu pr_err("bootconfig size %d is greater than initrd size %ld\n", 297de462e5fSMasami Hiramatsu size, initrd_end - initrd_start); 298de462e5fSMasami Hiramatsu return NULL; 299de462e5fSMasami Hiramatsu } 300de462e5fSMasami Hiramatsu 301de462e5fSMasami Hiramatsu /* Remove bootconfig from initramfs/initrd */ 302de462e5fSMasami Hiramatsu initrd_end = (unsigned long)data; 303de462e5fSMasami Hiramatsu if (_size) 304de462e5fSMasami Hiramatsu *_size = size; 305de462e5fSMasami Hiramatsu if (_csum) 306de462e5fSMasami Hiramatsu *_csum = csum; 307de462e5fSMasami Hiramatsu 308de462e5fSMasami Hiramatsu return data; 309de462e5fSMasami Hiramatsu } 310de462e5fSMasami Hiramatsu #else 311de462e5fSMasami Hiramatsu static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum) 312de462e5fSMasami Hiramatsu { 313de462e5fSMasami Hiramatsu return NULL; 314de462e5fSMasami Hiramatsu } 315de462e5fSMasami Hiramatsu #endif 316de462e5fSMasami Hiramatsu 3177684b858SMasami Hiramatsu #ifdef CONFIG_BOOT_CONFIG 31851887d03SMasami Hiramatsu 319a27026e9SJason Yan static char xbc_namebuf[XBC_KEYLEN_MAX] __initdata; 32051887d03SMasami Hiramatsu 32151887d03SMasami Hiramatsu #define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0) 32251887d03SMasami Hiramatsu 32351887d03SMasami Hiramatsu static int __init xbc_snprint_cmdline(char *buf, size_t size, 32451887d03SMasami Hiramatsu struct xbc_node *root) 32551887d03SMasami Hiramatsu { 32651887d03SMasami Hiramatsu struct xbc_node *knode, *vnode; 32751887d03SMasami Hiramatsu char *end = buf + size; 32851887d03SMasami Hiramatsu const char *val; 32951887d03SMasami Hiramatsu int ret; 33051887d03SMasami Hiramatsu 33151887d03SMasami Hiramatsu xbc_node_for_each_key_value(root, knode, val) { 33251887d03SMasami Hiramatsu ret = xbc_node_compose_key_after(root, knode, 33351887d03SMasami Hiramatsu xbc_namebuf, XBC_KEYLEN_MAX); 33451887d03SMasami Hiramatsu if (ret < 0) 33551887d03SMasami Hiramatsu return ret; 33651887d03SMasami Hiramatsu 33751887d03SMasami Hiramatsu vnode = xbc_node_get_child(knode); 33888b91371SMasami Hiramatsu if (!vnode) { 33988b91371SMasami Hiramatsu ret = snprintf(buf, rest(buf, end), "%s ", xbc_namebuf); 34051887d03SMasami Hiramatsu if (ret < 0) 34151887d03SMasami Hiramatsu return ret; 34251887d03SMasami Hiramatsu buf += ret; 34351887d03SMasami Hiramatsu continue; 34488b91371SMasami Hiramatsu } 34551887d03SMasami Hiramatsu xbc_array_for_each_value(vnode, val) { 34688b91371SMasami Hiramatsu ret = snprintf(buf, rest(buf, end), "%s=\"%s\" ", 34788b91371SMasami Hiramatsu xbc_namebuf, val); 34851887d03SMasami Hiramatsu if (ret < 0) 34951887d03SMasami Hiramatsu return ret; 35051887d03SMasami Hiramatsu buf += ret; 35151887d03SMasami Hiramatsu } 35251887d03SMasami Hiramatsu } 35351887d03SMasami Hiramatsu 35451887d03SMasami Hiramatsu return buf - (end - size); 35551887d03SMasami Hiramatsu } 35651887d03SMasami Hiramatsu #undef rest 35751887d03SMasami Hiramatsu 35851887d03SMasami Hiramatsu /* Make an extra command line under given key word */ 35951887d03SMasami Hiramatsu static char * __init xbc_make_cmdline(const char *key) 36051887d03SMasami Hiramatsu { 36151887d03SMasami Hiramatsu struct xbc_node *root; 36251887d03SMasami Hiramatsu char *new_cmdline; 36351887d03SMasami Hiramatsu int ret, len = 0; 36451887d03SMasami Hiramatsu 36551887d03SMasami Hiramatsu root = xbc_find_node(key); 36651887d03SMasami Hiramatsu if (!root) 36751887d03SMasami Hiramatsu return NULL; 36851887d03SMasami Hiramatsu 36951887d03SMasami Hiramatsu /* Count required buffer size */ 37051887d03SMasami Hiramatsu len = xbc_snprint_cmdline(NULL, 0, root); 37151887d03SMasami Hiramatsu if (len <= 0) 37251887d03SMasami Hiramatsu return NULL; 37351887d03SMasami Hiramatsu 37451887d03SMasami Hiramatsu new_cmdline = memblock_alloc(len + 1, SMP_CACHE_BYTES); 37551887d03SMasami Hiramatsu if (!new_cmdline) { 37651887d03SMasami Hiramatsu pr_err("Failed to allocate memory for extra kernel cmdline.\n"); 37751887d03SMasami Hiramatsu return NULL; 37851887d03SMasami Hiramatsu } 37951887d03SMasami Hiramatsu 38051887d03SMasami Hiramatsu ret = xbc_snprint_cmdline(new_cmdline, len + 1, root); 38151887d03SMasami Hiramatsu if (ret < 0 || ret > len) { 38251887d03SMasami Hiramatsu pr_err("Failed to print extra kernel cmdline.\n"); 38351887d03SMasami Hiramatsu return NULL; 38451887d03SMasami Hiramatsu } 38551887d03SMasami Hiramatsu 38651887d03SMasami Hiramatsu return new_cmdline; 38751887d03SMasami Hiramatsu } 38851887d03SMasami Hiramatsu 38908d9e686SQiujun Huang static u32 boot_config_checksum(unsigned char *p, u32 size) 3907684b858SMasami Hiramatsu { 3917684b858SMasami Hiramatsu u32 ret = 0; 3927684b858SMasami Hiramatsu 3937684b858SMasami Hiramatsu while (size--) 3947684b858SMasami Hiramatsu ret += *p++; 3957684b858SMasami Hiramatsu 3967684b858SMasami Hiramatsu return ret; 3977684b858SMasami Hiramatsu } 3987684b858SMasami Hiramatsu 399f61872bbSSteven Rostedt (VMware) static int __init bootconfig_params(char *param, char *val, 400f61872bbSSteven Rostedt (VMware) const char *unused, void *arg) 401f61872bbSSteven Rostedt (VMware) { 402f61872bbSSteven Rostedt (VMware) if (strcmp(param, "bootconfig") == 0) { 403f61872bbSSteven Rostedt (VMware) bootconfig_found = true; 404f61872bbSSteven Rostedt (VMware) } 405f61872bbSSteven Rostedt (VMware) return 0; 406f61872bbSSteven Rostedt (VMware) } 407f61872bbSSteven Rostedt (VMware) 408*2b7d2fe7SCao jin static void __init setup_boot_config(void) 4097684b858SMasami Hiramatsu { 410f61872bbSSteven Rostedt (VMware) static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata; 41189b74cacSMasami Hiramatsu const char *msg; 41289b74cacSMasami Hiramatsu int pos; 4137684b858SMasami Hiramatsu u32 size, csum; 414477d0847SMasami Hiramatsu char *data, *copy, *err; 415a0057403SMasami Hiramatsu int ret; 4167684b858SMasami Hiramatsu 417611d0a95SMasami Hiramatsu /* Cut out the bootconfig data even if we have no bootconfig option */ 418de462e5fSMasami Hiramatsu data = get_boot_config_from_initrd(&size, &csum); 419de462e5fSMasami Hiramatsu 420f61872bbSSteven Rostedt (VMware) strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); 421477d0847SMasami Hiramatsu err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL, 422f61872bbSSteven Rostedt (VMware) bootconfig_params); 423f61872bbSSteven Rostedt (VMware) 424477d0847SMasami Hiramatsu if (IS_ERR(err) || !bootconfig_found) 4257684b858SMasami Hiramatsu return; 4267684b858SMasami Hiramatsu 427477d0847SMasami Hiramatsu /* parse_args() stops at '--' and returns an address */ 428477d0847SMasami Hiramatsu if (err) 429477d0847SMasami Hiramatsu initargs_found = true; 430477d0847SMasami Hiramatsu 431611d0a95SMasami Hiramatsu if (!data) { 432611d0a95SMasami Hiramatsu pr_err("'bootconfig' found on command line, but no bootconfig found\n"); 433611d0a95SMasami Hiramatsu return; 434611d0a95SMasami Hiramatsu } 435611d0a95SMasami Hiramatsu 4367495e092SSteven Rostedt (VMware) if (size >= XBC_DATA_MAX) { 4377495e092SSteven Rostedt (VMware) pr_err("bootconfig size %d greater than max size %d\n", 4387495e092SSteven Rostedt (VMware) size, XBC_DATA_MAX); 4397684b858SMasami Hiramatsu return; 4407495e092SSteven Rostedt (VMware) } 4417684b858SMasami Hiramatsu 4427495e092SSteven Rostedt (VMware) if (boot_config_checksum((unsigned char *)data, size) != csum) { 4437495e092SSteven Rostedt (VMware) pr_err("bootconfig checksum failed\n"); 4447684b858SMasami Hiramatsu return; 4457495e092SSteven Rostedt (VMware) } 4467684b858SMasami Hiramatsu 4477684b858SMasami Hiramatsu copy = memblock_alloc(size + 1, SMP_CACHE_BYTES); 4487684b858SMasami Hiramatsu if (!copy) { 4497684b858SMasami Hiramatsu pr_err("Failed to allocate memory for bootconfig\n"); 4507684b858SMasami Hiramatsu return; 4517684b858SMasami Hiramatsu } 4527684b858SMasami Hiramatsu 4537684b858SMasami Hiramatsu memcpy(copy, data, size); 4547684b858SMasami Hiramatsu copy[size] = '\0'; 4557684b858SMasami Hiramatsu 45689b74cacSMasami Hiramatsu ret = xbc_init(copy, &msg, &pos); 45789b74cacSMasami Hiramatsu if (ret < 0) { 45889b74cacSMasami Hiramatsu if (pos < 0) 45989b74cacSMasami Hiramatsu pr_err("Failed to init bootconfig: %s.\n", msg); 46089b74cacSMasami Hiramatsu else 46189b74cacSMasami Hiramatsu pr_err("Failed to parse bootconfig: %s at %d.\n", 46289b74cacSMasami Hiramatsu msg, pos); 46389b74cacSMasami Hiramatsu } else { 464a0057403SMasami Hiramatsu pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret); 46551887d03SMasami Hiramatsu /* keys starting with "kernel." are passed via cmdline */ 46651887d03SMasami Hiramatsu extra_command_line = xbc_make_cmdline("kernel"); 46713199162SMasami Hiramatsu /* Also, "init." keys are init arguments */ 46813199162SMasami Hiramatsu extra_init_args = xbc_make_cmdline("init"); 46951887d03SMasami Hiramatsu } 4707495e092SSteven Rostedt (VMware) return; 4717684b858SMasami Hiramatsu } 472de462e5fSMasami Hiramatsu 4737684b858SMasami Hiramatsu #else 474de462e5fSMasami Hiramatsu 475*2b7d2fe7SCao jin static void __init setup_boot_config(void) 476de462e5fSMasami Hiramatsu { 477de462e5fSMasami Hiramatsu /* Remove bootconfig data from initrd */ 478de462e5fSMasami Hiramatsu get_boot_config_from_initrd(NULL, NULL); 479de462e5fSMasami Hiramatsu } 480d8a953ddSMasami Hiramatsu 481d8a953ddSMasami Hiramatsu static int __init warn_bootconfig(char *str) 482d8a953ddSMasami Hiramatsu { 48336c6aa26SShaokun Zhang pr_warn("WARNING: 'bootconfig' found on the kernel command line but CONFIG_BOOT_CONFIG is not set.\n"); 484d8a953ddSMasami Hiramatsu return 0; 485d8a953ddSMasami Hiramatsu } 486d8a953ddSMasami Hiramatsu early_param("bootconfig", warn_bootconfig); 487d8a953ddSMasami Hiramatsu 4887684b858SMasami Hiramatsu #endif 4897684b858SMasami Hiramatsu 4901da177e4SLinus Torvalds /* Change NUL term back to "=", to make "param" the whole string. */ 4917e2762e1SArvind Sankar static void __init repair_env_string(char *param, char *val) 492a99cd112SChris Metcalf { 4931da177e4SLinus Torvalds if (val) { 4941da177e4SLinus Torvalds /* param=val or param="val"? */ 4951da177e4SLinus Torvalds if (val == param+strlen(param)+1) 4961da177e4SLinus Torvalds val[-1] = '='; 4971da177e4SLinus Torvalds else if (val == param+strlen(param)+2) { 4981da177e4SLinus Torvalds val[-2] = '='; 4991da177e4SLinus Torvalds memmove(val-1, val, strlen(val)+1); 5001da177e4SLinus Torvalds } else 5011da177e4SLinus Torvalds BUG(); 5021da177e4SLinus Torvalds } 503a99cd112SChris Metcalf } 504a99cd112SChris Metcalf 50551e158c1SRusty Russell /* Anything after -- gets handed straight to init. */ 506ecc86170SLuis R. Rodriguez static int __init set_init_arg(char *param, char *val, 507ecc86170SLuis R. Rodriguez const char *unused, void *arg) 50851e158c1SRusty Russell { 50951e158c1SRusty Russell unsigned int i; 51051e158c1SRusty Russell 51151e158c1SRusty Russell if (panic_later) 51251e158c1SRusty Russell return 0; 51351e158c1SRusty Russell 5147e2762e1SArvind Sankar repair_env_string(param, val); 51551e158c1SRusty Russell 51651e158c1SRusty Russell for (i = 0; argv_init[i]; i++) { 51751e158c1SRusty Russell if (i == MAX_INIT_ARGS) { 51851e158c1SRusty Russell panic_later = "init"; 51951e158c1SRusty Russell panic_param = param; 52051e158c1SRusty Russell return 0; 52151e158c1SRusty Russell } 52251e158c1SRusty Russell } 52351e158c1SRusty Russell argv_init[i] = param; 52451e158c1SRusty Russell return 0; 52551e158c1SRusty Russell } 52651e158c1SRusty Russell 527a99cd112SChris Metcalf /* 528a99cd112SChris Metcalf * Unknown boot options get handed to init, unless they look like 529a99cd112SChris Metcalf * unused parameters (modprobe will find them in /proc/cmdline). 530a99cd112SChris Metcalf */ 531ecc86170SLuis R. Rodriguez static int __init unknown_bootoption(char *param, char *val, 532ecc86170SLuis R. Rodriguez const char *unused, void *arg) 533a99cd112SChris Metcalf { 534283900e8SArvind Sankar size_t len = strlen(param); 535283900e8SArvind Sankar 5367e2762e1SArvind Sankar repair_env_string(param, val); 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds /* Handle obsolete-style parameters */ 5391da177e4SLinus Torvalds if (obsolete_checksetup(param)) 5401da177e4SLinus Torvalds return 0; 5411da177e4SLinus Torvalds 542f066a4f6SRusty Russell /* Unused module parameter. */ 543283900e8SArvind Sankar if (strnchr(param, len, '.')) 5441da177e4SLinus Torvalds return 0; 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds if (panic_later) 5471da177e4SLinus Torvalds return 0; 5481da177e4SLinus Torvalds 5491da177e4SLinus Torvalds if (val) { 5501da177e4SLinus Torvalds /* Environment option */ 5511da177e4SLinus Torvalds unsigned int i; 5521da177e4SLinus Torvalds for (i = 0; envp_init[i]; i++) { 5531da177e4SLinus Torvalds if (i == MAX_INIT_ENVS) { 554499a4584STetsuo Handa panic_later = "env"; 5551da177e4SLinus Torvalds panic_param = param; 5561da177e4SLinus Torvalds } 557283900e8SArvind Sankar if (!strncmp(param, envp_init[i], len+1)) 5581da177e4SLinus Torvalds break; 5591da177e4SLinus Torvalds } 5601da177e4SLinus Torvalds envp_init[i] = param; 5611da177e4SLinus Torvalds } else { 5621da177e4SLinus Torvalds /* Command line option */ 5631da177e4SLinus Torvalds unsigned int i; 5641da177e4SLinus Torvalds for (i = 0; argv_init[i]; i++) { 5651da177e4SLinus Torvalds if (i == MAX_INIT_ARGS) { 566499a4584STetsuo Handa panic_later = "init"; 5671da177e4SLinus Torvalds panic_param = param; 5681da177e4SLinus Torvalds } 5691da177e4SLinus Torvalds } 5701da177e4SLinus Torvalds argv_init[i] = param; 5711da177e4SLinus Torvalds } 5721da177e4SLinus Torvalds return 0; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds static int __init init_setup(char *str) 5761da177e4SLinus Torvalds { 5771da177e4SLinus Torvalds unsigned int i; 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds execute_command = str; 5801da177e4SLinus Torvalds /* 5811da177e4SLinus Torvalds * In case LILO is going to boot us with default command line, 5821da177e4SLinus Torvalds * it prepends "auto" before the whole cmdline which makes 5831da177e4SLinus Torvalds * the shell think it should execute a script with such name. 5841da177e4SLinus Torvalds * So we ignore all arguments entered _before_ init=... [MJ] 5851da177e4SLinus Torvalds */ 5861da177e4SLinus Torvalds for (i = 1; i < MAX_INIT_ARGS; i++) 5871da177e4SLinus Torvalds argv_init[i] = NULL; 5881da177e4SLinus Torvalds return 1; 5891da177e4SLinus Torvalds } 5901da177e4SLinus Torvalds __setup("init=", init_setup); 5911da177e4SLinus Torvalds 592ffdfc409SOlof Johansson static int __init rdinit_setup(char *str) 593ffdfc409SOlof Johansson { 594ffdfc409SOlof Johansson unsigned int i; 595ffdfc409SOlof Johansson 596ffdfc409SOlof Johansson ramdisk_execute_command = str; 597ffdfc409SOlof Johansson /* See "auto" comment in init_setup */ 598ffdfc409SOlof Johansson for (i = 1; i < MAX_INIT_ARGS; i++) 599ffdfc409SOlof Johansson argv_init[i] = NULL; 600ffdfc409SOlof Johansson return 1; 601ffdfc409SOlof Johansson } 602ffdfc409SOlof Johansson __setup("rdinit=", rdinit_setup); 603ffdfc409SOlof Johansson 6041da177e4SLinus Torvalds #ifndef CONFIG_SMP 60534db18a0SAmerigo Wang static const unsigned int setup_max_cpus = NR_CPUS; 606e0982e90SMike Travis static inline void setup_nr_cpu_ids(void) { } 6071da177e4SLinus Torvalds static inline void smp_prepare_cpus(unsigned int maxcpus) { } 6081da177e4SLinus Torvalds #endif 6091da177e4SLinus Torvalds 6101da177e4SLinus Torvalds /* 61130d7e0d4SAlon Bar-Lev * We need to store the untouched command line for future reference. 61230d7e0d4SAlon Bar-Lev * We also need to store the touched command line since the parameter 61330d7e0d4SAlon Bar-Lev * parsing is performed in place, and we should allow a component to 61430d7e0d4SAlon Bar-Lev * store reference of name/value for future reference. 61530d7e0d4SAlon Bar-Lev */ 61630d7e0d4SAlon Bar-Lev static void __init setup_command_line(char *command_line) 61730d7e0d4SAlon Bar-Lev { 61813199162SMasami Hiramatsu size_t len, xlen = 0, ilen = 0; 619f5c7310aSMike Rapoport 62051887d03SMasami Hiramatsu if (extra_command_line) 62151887d03SMasami Hiramatsu xlen = strlen(extra_command_line); 62213199162SMasami Hiramatsu if (extra_init_args) 62313199162SMasami Hiramatsu ilen = strlen(extra_init_args) + 4; /* for " -- " */ 62451887d03SMasami Hiramatsu 62551887d03SMasami Hiramatsu len = xlen + strlen(boot_command_line) + 1; 626f5c7310aSMike Rapoport 62713199162SMasami Hiramatsu saved_command_line = memblock_alloc(len + ilen, SMP_CACHE_BYTES); 628f5c7310aSMike Rapoport if (!saved_command_line) 62913199162SMasami Hiramatsu panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen); 630f5c7310aSMike Rapoport 631f5c7310aSMike Rapoport static_command_line = memblock_alloc(len, SMP_CACHE_BYTES); 632f5c7310aSMike Rapoport if (!static_command_line) 633f5c7310aSMike Rapoport panic("%s: Failed to allocate %zu bytes\n", __func__, len); 634f5c7310aSMike Rapoport 63551887d03SMasami Hiramatsu if (xlen) { 63651887d03SMasami Hiramatsu /* 63751887d03SMasami Hiramatsu * We have to put extra_command_line before boot command 63851887d03SMasami Hiramatsu * lines because there could be dashes (separator of init 63951887d03SMasami Hiramatsu * command line) in the command lines. 64051887d03SMasami Hiramatsu */ 64151887d03SMasami Hiramatsu strcpy(saved_command_line, extra_command_line); 64251887d03SMasami Hiramatsu strcpy(static_command_line, extra_command_line); 64351887d03SMasami Hiramatsu } 64451887d03SMasami Hiramatsu strcpy(saved_command_line + xlen, boot_command_line); 64551887d03SMasami Hiramatsu strcpy(static_command_line + xlen, command_line); 64613199162SMasami Hiramatsu 64713199162SMasami Hiramatsu if (ilen) { 64813199162SMasami Hiramatsu /* 64913199162SMasami Hiramatsu * Append supplemental init boot args to saved_command_line 65013199162SMasami Hiramatsu * so that user can check what command line options passed 65113199162SMasami Hiramatsu * to init. 65213199162SMasami Hiramatsu */ 65313199162SMasami Hiramatsu len = strlen(saved_command_line); 654f61872bbSSteven Rostedt (VMware) if (initargs_found) { 655f61872bbSSteven Rostedt (VMware) saved_command_line[len++] = ' '; 656f61872bbSSteven Rostedt (VMware) } else { 65713199162SMasami Hiramatsu strcpy(saved_command_line + len, " -- "); 65813199162SMasami Hiramatsu len += 4; 659f61872bbSSteven Rostedt (VMware) } 66013199162SMasami Hiramatsu 66113199162SMasami Hiramatsu strcpy(saved_command_line + len, extra_init_args); 66213199162SMasami Hiramatsu } 66330d7e0d4SAlon Bar-Lev } 66430d7e0d4SAlon Bar-Lev 66530d7e0d4SAlon Bar-Lev /* 6661da177e4SLinus Torvalds * We need to finalize in a non-__init function or else race conditions 6671da177e4SLinus Torvalds * between the root thread and the init thread may cause start_kernel to 6681da177e4SLinus Torvalds * be reaped by free_initmem before the root thread has proceeded to 6691da177e4SLinus Torvalds * cpu_idle. 6701da177e4SLinus Torvalds * 6711da177e4SLinus Torvalds * gcc-3.4 accidentally inlines this function, so use noinline. 6721da177e4SLinus Torvalds */ 6731da177e4SLinus Torvalds 674b433c3d4SPeter Zijlstra static __initdata DECLARE_COMPLETION(kthreadd_done); 675b433c3d4SPeter Zijlstra 67653c99bd6SMartin Schwidefsky noinline void __ref rest_init(void) 6771da177e4SLinus Torvalds { 6788fb12156SThomas Gleixner struct task_struct *tsk; 67973c27992SEric W. Biederman int pid; 68073c27992SEric W. Biederman 6817db905e6SPaul E. McKenney rcu_scheduler_starting(); 682b433c3d4SPeter Zijlstra /* 68397158569SPeter Zijlstra * We need to spawn init first so that it obtains pid 1, however 684b433c3d4SPeter Zijlstra * the init task will end up wanting to create kthreads, which, if 685b433c3d4SPeter Zijlstra * we schedule it before we create kthreadd, will OOPS. 686b433c3d4SPeter Zijlstra */ 6878fb12156SThomas Gleixner pid = kernel_thread(kernel_init, NULL, CLONE_FS); 6888fb12156SThomas Gleixner /* 6898fb12156SThomas Gleixner * Pin init on the boot CPU. Task migration is not properly working 6908fb12156SThomas Gleixner * until sched_init_smp() has been run. It will set the allowed 6918fb12156SThomas Gleixner * CPUs for init to the non isolated CPUs. 6928fb12156SThomas Gleixner */ 6938fb12156SThomas Gleixner rcu_read_lock(); 6948fb12156SThomas Gleixner tsk = find_task_by_pid_ns(pid, &init_pid_ns); 6958fb12156SThomas Gleixner set_cpus_allowed_ptr(tsk, cpumask_of(smp_processor_id())); 6968fb12156SThomas Gleixner rcu_read_unlock(); 6978fb12156SThomas Gleixner 6981da177e4SLinus Torvalds numa_default_policy(); 69973c27992SEric W. Biederman pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES); 700d11c563dSPaul E. McKenney rcu_read_lock(); 7015cd20455SPavel Emelyanov kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns); 702d11c563dSPaul E. McKenney rcu_read_unlock(); 7031c3c5eabSThomas Gleixner 7041c3c5eabSThomas Gleixner /* 7051c3c5eabSThomas Gleixner * Enable might_sleep() and smp_processor_id() checks. 706c1a280b6SThomas Gleixner * They cannot be enabled earlier because with CONFIG_PREEMPTION=y 7071c3c5eabSThomas Gleixner * kernel_thread() would trigger might_sleep() splats. With 7081c3c5eabSThomas Gleixner * CONFIG_PREEMPT_VOLUNTARY=y the init task might have scheduled 7091c3c5eabSThomas Gleixner * already, but it's stuck on the kthreadd_done completion. 7101c3c5eabSThomas Gleixner */ 7111c3c5eabSThomas Gleixner system_state = SYSTEM_SCHEDULING; 7121c3c5eabSThomas Gleixner 713b433c3d4SPeter Zijlstra complete(&kthreadd_done); 714f340c0d1SIngo Molnar 715f340c0d1SIngo Molnar /* 716f340c0d1SIngo Molnar * The boot idle thread must execute schedule() 7171df21055SIngo Molnar * at least once to get things moving: 718f340c0d1SIngo Molnar */ 719bd2f5536SThomas Gleixner schedule_preempt_disabled(); 7205bfb5d69SNick Piggin /* Call into cpu_idle with preempt disabled */ 721a1a04ec3SThomas Gleixner cpu_startup_entry(CPUHP_ONLINE); 7221da177e4SLinus Torvalds } 7231da177e4SLinus Torvalds 7241da177e4SLinus Torvalds /* Check for early params. */ 725ecc86170SLuis R. Rodriguez static int __init do_early_param(char *param, char *val, 726ecc86170SLuis R. Rodriguez const char *unused, void *arg) 7271da177e4SLinus Torvalds { 728914dcaa8SRusty Russell const struct obs_kernel_param *p; 7291da177e4SLinus Torvalds 7301da177e4SLinus Torvalds for (p = __setup_start; p < __setup_end; p++) { 731b1e4d20cSMichal Schmidt if ((p->early && parameq(param, p->str)) || 73218a8bd94SYinghai Lu (strcmp(param, "console") == 0 && 73318a8bd94SYinghai Lu strcmp(p->str, "earlycon") == 0) 73418a8bd94SYinghai Lu ) { 7351da177e4SLinus Torvalds if (p->setup_func(val) != 0) 736ea676e84SAndrew Morton pr_warn("Malformed early option '%s'\n", param); 7371da177e4SLinus Torvalds } 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds /* We accept everything at this stage. */ 7401da177e4SLinus Torvalds return 0; 7411da177e4SLinus Torvalds } 7421da177e4SLinus Torvalds 74313977091SMagnus Damm void __init parse_early_options(char *cmdline) 74413977091SMagnus Damm { 745ecc86170SLuis R. Rodriguez parse_args("early options", cmdline, NULL, 0, 0, 0, NULL, 746ecc86170SLuis R. Rodriguez do_early_param); 74713977091SMagnus Damm } 74813977091SMagnus Damm 7491da177e4SLinus Torvalds /* Arch code calls this early on, or if not, just before other parsing. */ 7501da177e4SLinus Torvalds void __init parse_early_param(void) 7511da177e4SLinus Torvalds { 752dd4d9fecSFabian Frederick static int done __initdata; 753dd4d9fecSFabian Frederick static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata; 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds if (done) 7561da177e4SLinus Torvalds return; 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds /* All fall through to do_early_param. */ 75930d7e0d4SAlon Bar-Lev strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); 76013977091SMagnus Damm parse_early_options(tmp_cmdline); 7611da177e4SLinus Torvalds done = 1; 7621da177e4SLinus Torvalds } 7631da177e4SLinus Torvalds 764e7ff3a47SThomas Gleixner void __init __weak arch_post_acpi_subsys_init(void) { } 765e7ff3a47SThomas Gleixner 766839ad62eSBenjamin Herrenschmidt void __init __weak smp_setup_processor_id(void) 767033ab7f8SAndrew Morton { 768033ab7f8SAndrew Morton } 769033ab7f8SAndrew Morton 770eded09ccSDavid Howells # if THREAD_SIZE >= PAGE_SIZE 771b235beeaSLinus Torvalds void __init __weak thread_stack_cache_init(void) 7728c9843e5SBenjamin Herrenschmidt { 7738c9843e5SBenjamin Herrenschmidt } 774eded09ccSDavid Howells #endif 7758c9843e5SBenjamin Herrenschmidt 776c7753208STom Lendacky void __init __weak mem_encrypt_init(void) { } 777c7753208STom Lendacky 7784fc19708SNadav Amit void __init __weak poking_init(void) { } 7794fc19708SNadav Amit 780782de70cSMike Rapoport void __init __weak pgtable_cache_init(void) { } 781caa84136SNadav Amit 7824e37958dSSteven Rostedt (VMware) bool initcall_debug; 7834e37958dSSteven Rostedt (VMware) core_param(initcall_debug, initcall_debug, bool, 0644); 784b0dc52f1SSteven Rostedt (VMware) 785b0dc52f1SSteven Rostedt (VMware) #ifdef TRACEPOINTS_ENABLED 7864e37958dSSteven Rostedt (VMware) static void __init initcall_debug_enable(void); 787b0dc52f1SSteven Rostedt (VMware) #else 788b0dc52f1SSteven Rostedt (VMware) static inline void initcall_debug_enable(void) 789b0dc52f1SSteven Rostedt (VMware) { 790b0dc52f1SSteven Rostedt (VMware) } 791b0dc52f1SSteven Rostedt (VMware) #endif 7924e37958dSSteven Rostedt (VMware) 79323a5c8cbSAlexander Potapenko /* Report memory auto-initialization states for this boot. */ 79423a5c8cbSAlexander Potapenko static void __init report_meminit(void) 79523a5c8cbSAlexander Potapenko { 79623a5c8cbSAlexander Potapenko const char *stack; 79723a5c8cbSAlexander Potapenko 798f0fe00d4S[email protected] if (IS_ENABLED(CONFIG_INIT_STACK_ALL_PATTERN)) 799f0fe00d4S[email protected] stack = "all(pattern)"; 800f0fe00d4S[email protected] else if (IS_ENABLED(CONFIG_INIT_STACK_ALL_ZERO)) 801f0fe00d4S[email protected] stack = "all(zero)"; 80223a5c8cbSAlexander Potapenko else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL)) 803f0fe00d4S[email protected] stack = "byref_all(zero)"; 80423a5c8cbSAlexander Potapenko else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF)) 805f0fe00d4S[email protected] stack = "byref(zero)"; 80623a5c8cbSAlexander Potapenko else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_USER)) 807f0fe00d4S[email protected] stack = "__user(zero)"; 80823a5c8cbSAlexander Potapenko else 80923a5c8cbSAlexander Potapenko stack = "off"; 81023a5c8cbSAlexander Potapenko 81123a5c8cbSAlexander Potapenko pr_info("mem auto-init: stack:%s, heap alloc:%s, heap free:%s\n", 81223a5c8cbSAlexander Potapenko stack, want_init_on_alloc(GFP_KERNEL) ? "on" : "off", 81323a5c8cbSAlexander Potapenko want_init_on_free() ? "on" : "off"); 81423a5c8cbSAlexander Potapenko if (want_init_on_free()) 81523a5c8cbSAlexander Potapenko pr_info("mem auto-init: clearing system memory may take some time...\n"); 81623a5c8cbSAlexander Potapenko } 81723a5c8cbSAlexander Potapenko 818444f478fSPekka Enberg /* 819444f478fSPekka Enberg * Set up kernel memory allocators 820444f478fSPekka Enberg */ 821444f478fSPekka Enberg static void __init mm_init(void) 822444f478fSPekka Enberg { 823eefa864bSJoonsoo Kim /* 824eefa864bSJoonsoo Kim * page_ext requires contiguous pages, 825eefa864bSJoonsoo Kim * bigger than MAX_ORDER unless SPARSEMEM. 826eefa864bSJoonsoo Kim */ 827eefa864bSJoonsoo Kim page_ext_init_flatmem(); 82804013513SVlastimil Babka init_mem_debugging_and_hardening(); 8290ce20dd8SAlexander Potapenko kfence_alloc_pool(); 83023a5c8cbSAlexander Potapenko report_meminit(); 831e1fdc403SVijayanand Jitta stack_depot_init(); 832444f478fSPekka Enberg mem_init(); 8337fb7ab6dSZhenhua Huang /* page_owner must be initialized after buddy is ready */ 8347fb7ab6dSZhenhua Huang page_ext_init_flatmem_late(); 835444f478fSPekka Enberg kmem_cache_init(); 836c5665868SCatalin Marinas kmemleak_init(); 837b35f1819SKirill A. Shutemov pgtable_init(); 838a9ee3a63SQian Cai debug_objects_mem_init(); 839444f478fSPekka Enberg vmalloc_init(); 8400ddab1d2SToshi Kani ioremap_huge_init(); 841613e396bSThomas Gleixner /* Should be run before the first non-init thread is created */ 842613e396bSThomas Gleixner init_espfix_bsp(); 843aa8c6248SThomas Gleixner /* Should be run after espfix64 is set up. */ 844aa8c6248SThomas Gleixner pti_init(); 845444f478fSPekka Enberg } 846444f478fSPekka Enberg 84753c99bd6SMartin Schwidefsky void __init __weak arch_call_rest_init(void) 84853c99bd6SMartin Schwidefsky { 84953c99bd6SMartin Schwidefsky rest_init(); 85053c99bd6SMartin Schwidefsky } 85153c99bd6SMartin Schwidefsky 852f9409d58SAndrey Konovalov asmlinkage __visible void __init __no_sanitize_address start_kernel(void) 8531da177e4SLinus Torvalds { 854dd4d9fecSFabian Frederick char *command_line; 855dd4d9fecSFabian Frederick char *after_dashes; 856033ab7f8SAndrew Morton 857d4311ff1SAaron Tomlin set_task_stack_end_magic(&init_task); 85873839c5bSMing Lei smp_setup_processor_id(); 8593ac7fe5aSThomas Gleixner debug_objects_early_init(); 86042059429SIngo Molnar 861ddbcc7e8SPaul Menage cgroup_init_early(); 862fbb9ce95SIngo Molnar 863fbb9ce95SIngo Molnar local_irq_disable(); 8642ce802f6STejun Heo early_boot_irqs_disabled = true; 865fbb9ce95SIngo Molnar 866fbb9ce95SIngo Molnar /* 8671da177e4SLinus Torvalds * Interrupts are still disabled. Do necessary setups, then 8681b3b3b49SViresh Kumar * enable them. 8691da177e4SLinus Torvalds */ 87044fd2299SStas Sergeev boot_cpu_init(); 8711da177e4SLinus Torvalds page_address_init(); 872ea676e84SAndrew Morton pr_notice("%s", linux_banner); 873e6b1db98SMatthew Garrett early_security_init(); 8741da177e4SLinus Torvalds setup_arch(&command_line); 875*2b7d2fe7SCao jin setup_boot_config(); 87630d7e0d4SAlon Bar-Lev setup_command_line(command_line); 877e0982e90SMike Travis setup_nr_cpu_ids(); 878d6647bdfSTejun Heo setup_per_cpu_areas(); 87944fd2299SStas Sergeev smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ 880b5b1404dSLinus Torvalds boot_cpu_hotplug_init(); 8811da177e4SLinus Torvalds 88272675e13SMichal Hocko build_all_zonelists(NULL); 88383b519e8SPekka Enberg page_alloc_init(); 88483b519e8SPekka Enberg 88551887d03SMasami Hiramatsu pr_notice("Kernel command line: %s\n", saved_command_line); 8866041186aSDan Williams /* parameters may set static keys */ 8876041186aSDan Williams jump_label_init(); 88883b519e8SPekka Enberg parse_early_param(); 88951e158c1SRusty Russell after_dashes = parse_args("Booting kernel", 89051e158c1SRusty Russell static_command_line, __start___param, 89183b519e8SPekka Enberg __stop___param - __start___param, 892ecc86170SLuis R. Rodriguez -1, -1, NULL, &unknown_bootoption); 8933438cf54SDaniel Thompson if (!IS_ERR_OR_NULL(after_dashes)) 89451e158c1SRusty Russell parse_args("Setting init args", after_dashes, NULL, 0, -1, -1, 895ecc86170SLuis R. Rodriguez NULL, set_init_arg); 89613199162SMasami Hiramatsu if (extra_init_args) 89713199162SMasami Hiramatsu parse_args("Setting extra init args", extra_init_args, 89813199162SMasami Hiramatsu NULL, 0, -1, -1, NULL, set_init_arg); 89997ce2c88SJeremy Fitzhardinge 90083b519e8SPekka Enberg /* 90183b519e8SPekka Enberg * These use large bootmem allocations and must precede 90283b519e8SPekka Enberg * kmem_cache_init() 90383b519e8SPekka Enberg */ 904162a7e75SMike Travis setup_log_buf(0); 90583b519e8SPekka Enberg vfs_caches_init_early(); 90683b519e8SPekka Enberg sort_main_extable(); 90783b519e8SPekka Enberg trap_init(); 908444f478fSPekka Enberg mm_init(); 909de03c72cSKOSAKI Motohiro 910f631718dSSteven Rostedt (VMware) ftrace_init(); 911f631718dSSteven Rostedt (VMware) 912e725c731SSteven Rostedt (VMware) /* trace_printk can be enabled here */ 913e725c731SSteven Rostedt (VMware) early_trace_init(); 914e725c731SSteven Rostedt (VMware) 9151da177e4SLinus Torvalds /* 9161da177e4SLinus Torvalds * Set up the scheduler prior starting any interrupts (such as the 9171da177e4SLinus Torvalds * timer interrupt). Full topology setup happens at smp_init() 9181da177e4SLinus Torvalds * time - but meanwhile we still have a functioning scheduler. 9191da177e4SLinus Torvalds */ 9201da177e4SLinus Torvalds sched_init(); 9211da177e4SLinus Torvalds /* 9221da177e4SLinus Torvalds * Disable preemption - early bootup scheduling is extremely 9231da177e4SLinus Torvalds * fragile until we cpu_idle() for the first time. 9241da177e4SLinus Torvalds */ 9251da177e4SLinus Torvalds preempt_disable(); 926dd4d9fecSFabian Frederick if (WARN(!irqs_disabled(), 927dd4d9fecSFabian Frederick "Interrupts were enabled *very* early, fixing it\n")) 928c4a68306SArd van Breemen local_irq_disable(); 9290a835c4fSMatthew Wilcox radix_tree_init(); 9303347fa09STejun Heo 9313347fa09STejun Heo /* 9327d229c66STal Shorer * Set up housekeeping before setting up workqueues to allow the unbound 9337d229c66STal Shorer * workqueue to take non-housekeeping into account. 9347d229c66STal Shorer */ 9357d229c66STal Shorer housekeeping_init(); 9367d229c66STal Shorer 9377d229c66STal Shorer /* 9383347fa09STejun Heo * Allow workqueue creation and work item queueing/cancelling 9393347fa09STejun Heo * early. Work item execution depends on kthreads and starts after 9403347fa09STejun Heo * workqueue_init(). 9413347fa09STejun Heo */ 9423347fa09STejun Heo workqueue_init_early(); 9433347fa09STejun Heo 9441da177e4SLinus Torvalds rcu_init(); 9455f893b26SSteven Rostedt (Red Hat) 946e725c731SSteven Rostedt (VMware) /* Trace events are available after this */ 9475f893b26SSteven Rostedt (Red Hat) trace_init(); 9485f893b26SSteven Rostedt (Red Hat) 9494e37958dSSteven Rostedt (VMware) if (initcall_debug) 9504e37958dSSteven Rostedt (VMware) initcall_debug_enable(); 9514e37958dSSteven Rostedt (VMware) 95265f382fdSFrederic Weisbecker context_tracking_init(); 9530b8f1efaSYinghai Lu /* init some links before init_ISA_irqs() */ 9540b8f1efaSYinghai Lu early_irq_init(); 9551da177e4SLinus Torvalds init_IRQ(); 956ad2b1353SThomas Gleixner tick_init(); 957d6dd50e0SLinus Torvalds rcu_init_nohz(); 9581da177e4SLinus Torvalds init_timers(); 959c0a31329SThomas Gleixner hrtimers_init(); 9601da177e4SLinus Torvalds softirq_init(); 961ad596171Sjohn stultz timekeeping_init(); 9620ce20dd8SAlexander Potapenko kfence_init(); 963d5553523SKees Cook 964d5553523SKees Cook /* 965d5553523SKees Cook * For best initial stack canary entropy, prepare it after: 966d5553523SKees Cook * - setup_arch() for any UEFI RNG entropy and boot cmdline access 967d5553523SKees Cook * - timekeeping_init() for ktime entropy used in rand_initialize() 968d5553523SKees Cook * - rand_initialize() to get any arch-specific entropy like RDRAND 969d5553523SKees Cook * - add_latent_entropy() to get any latent entropy 970d5553523SKees Cook * - adding command line entropy 971d5553523SKees Cook */ 972d5553523SKees Cook rand_initialize(); 973d5553523SKees Cook add_latent_entropy(); 974d5553523SKees Cook add_device_randomness(command_line, strlen(command_line)); 975d5553523SKees Cook boot_init_stack_canary(); 976d5553523SKees Cook 97788fecaa2Sjohn stultz time_init(); 9789e630205SStephane Eranian perf_event_init(); 97993e02814SHeiko Carstens profile_init(); 980d8ad7d11STakao Indoh call_function_init(); 981f91eb62fSSteven Rostedt WARN(!irqs_disabled(), "Interrupts were enabled early\n"); 982c3bc8fd6SJoel Fernandes (Google) 9832ce802f6STejun Heo early_boot_irqs_disabled = false; 98493e02814SHeiko Carstens local_irq_enable(); 985dcce284aSBenjamin Herrenschmidt 9867e85ee0cSPekka Enberg kmem_cache_init_late(); 9871da177e4SLinus Torvalds 9881da177e4SLinus Torvalds /* 9891da177e4SLinus Torvalds * HACK ALERT! This is early. We're enabling the console before 9901da177e4SLinus Torvalds * we've done PCI setups etc, and console_init() must be aware of 9911da177e4SLinus Torvalds * this. But we do want output early, in case something goes wrong. 9921da177e4SLinus Torvalds */ 9931da177e4SLinus Torvalds console_init(); 9941da177e4SLinus Torvalds if (panic_later) 995499a4584STetsuo Handa panic("Too many boot %s vars at `%s'", panic_later, 996499a4584STetsuo Handa panic_param); 997fbb9ce95SIngo Molnar 998c3bc8fd6SJoel Fernandes (Google) lockdep_init(); 999fbb9ce95SIngo Molnar 10009a11b49aSIngo Molnar /* 10019a11b49aSIngo Molnar * Need to run this when irqs are enabled, because it wants 10029a11b49aSIngo Molnar * to self-test [hard/soft]-irqs on/off lock inversion bugs 10039a11b49aSIngo Molnar * too: 10049a11b49aSIngo Molnar */ 10059a11b49aSIngo Molnar locking_selftest(); 10069a11b49aSIngo Molnar 1007c7753208STom Lendacky /* 1008c7753208STom Lendacky * This needs to be called before any devices perform DMA 1009c7753208STom Lendacky * operations that might use the SWIOTLB bounce buffers. It will 1010c7753208STom Lendacky * mark the bounce buffers as decrypted so that their usage will 1011c7753208STom Lendacky * not cause "plain-text" data to be decrypted when accessed. 1012c7753208STom Lendacky */ 1013c7753208STom Lendacky mem_encrypt_init(); 1014c7753208STom Lendacky 10151da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 10161da177e4SLinus Torvalds if (initrd_start && !initrd_below_start_ok && 1017bd673c7cSGeert Uytterhoeven page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) { 1018ea676e84SAndrew Morton pr_crit("initrd overwritten (0x%08lx < 0x%08lx) - disabling it.\n", 1019bd673c7cSGeert Uytterhoeven page_to_pfn(virt_to_page((void *)initrd_start)), 1020bd673c7cSGeert Uytterhoeven min_low_pfn); 10211da177e4SLinus Torvalds initrd_start = 0; 10221da177e4SLinus Torvalds } 10231da177e4SLinus Torvalds #endif 1024e7c8d5c9SChristoph Lameter setup_per_cpu_pageset(); 10251da177e4SLinus Torvalds numa_policy_init(); 10269c71206dSDou Liyang acpi_early_init(); 10271da177e4SLinus Torvalds if (late_time_init) 10281da177e4SLinus Torvalds late_time_init(); 1029857baa87SPavel Tatashin sched_clock_init(); 10301da177e4SLinus Torvalds calibrate_delay(); 103195846ecfSGargi Sharma pid_idr_init(); 10321da177e4SLinus Torvalds anon_vma_init(); 103311520e5eSLinus Torvalds #ifdef CONFIG_X86 103483e68189SMatt Fleming if (efi_enabled(EFI_RUNTIME_SERVICES)) 103511520e5eSLinus Torvalds efi_enter_virtual_mode(); 103611520e5eSLinus Torvalds #endif 1037b235beeaSLinus Torvalds thread_stack_cache_init(); 1038d84f4f99SDavid Howells cred_init(); 1039ff691f6eSHeinrich Schuchardt fork_init(); 10401da177e4SLinus Torvalds proc_caches_init(); 10413ea056c5SAlexey Dobriyan uts_ns_init(); 10421da177e4SLinus Torvalds key_init(); 10431da177e4SLinus Torvalds security_init(); 10440b4b3827SJason Wessel dbg_late_init(); 10454248b0daSMel Gorman vfs_caches_init(); 104662906027SNicholas Piggin pagecache_init(); 10471da177e4SLinus Torvalds signals_init(); 104809652320SAlexey Dobriyan seq_file_init(); 10491da177e4SLinus Torvalds proc_root_init(); 1050e149ed2bSAl Viro nsfs_init(); 10511da177e4SLinus Torvalds cpuset_init(); 1052695df213SZefan Li cgroup_init(); 1053c757249aSShailabh Nagar taskstats_init_early(); 1054ca74e92bSShailabh Nagar delayacct_init(); 10551da177e4SLinus Torvalds 10564fc19708SNadav Amit poking_init(); 10571da177e4SLinus Torvalds check_bugs(); 10581da177e4SLinus Torvalds 1059b064a8faSRafael J. Wysocki acpi_subsystem_init(); 1060e7ff3a47SThomas Gleixner arch_post_acpi_subsys_init(); 1061dfd402a4SMarco Elver kcsan_init(); 10621da177e4SLinus Torvalds 10631da177e4SLinus Torvalds /* Do the rest non-__init'ed, we're now alive */ 106453c99bd6SMartin Schwidefsky arch_call_rest_init(); 1065a9a3ed1eSBorislav Petkov 1066a9a3ed1eSBorislav Petkov prevent_tail_call_optimization(); 10671da177e4SLinus Torvalds } 10681da177e4SLinus Torvalds 1069b99b87f7SPeter Oberparleiter /* Call all constructor functions linked into the kernel. */ 1070b99b87f7SPeter Oberparleiter static void __init do_ctors(void) 1071b99b87f7SPeter Oberparleiter { 107255b6f763SJohannes Berg /* 107355b6f763SJohannes Berg * For UML, the constructors have already been called by the 107455b6f763SJohannes Berg * normal setup code as it's just a normal ELF binary, so we 107555b6f763SJohannes Berg * cannot do it again - but we do need CONFIG_CONSTRUCTORS 107655b6f763SJohannes Berg * even on UML for modules. 107755b6f763SJohannes Berg */ 107855b6f763SJohannes Berg #if defined(CONFIG_CONSTRUCTORS) && !defined(CONFIG_UML) 1079196a15b4SH Hartley Sweeten ctor_fn_t *fn = (ctor_fn_t *) __ctors_start; 1080b99b87f7SPeter Oberparleiter 1081196a15b4SH Hartley Sweeten for (; fn < (ctor_fn_t *) __ctors_end; fn++) 1082196a15b4SH Hartley Sweeten (*fn)(); 1083b99b87f7SPeter Oberparleiter #endif 1084b99b87f7SPeter Oberparleiter } 1085b99b87f7SPeter Oberparleiter 10867b0b73d7SPrarit Bhargava #ifdef CONFIG_KALLSYMS 10877b0b73d7SPrarit Bhargava struct blacklist_entry { 10887b0b73d7SPrarit Bhargava struct list_head next; 10897b0b73d7SPrarit Bhargava char *buf; 10907b0b73d7SPrarit Bhargava }; 10917b0b73d7SPrarit Bhargava 10927b0b73d7SPrarit Bhargava static __initdata_or_module LIST_HEAD(blacklisted_initcalls); 10937b0b73d7SPrarit Bhargava 10947b0b73d7SPrarit Bhargava static int __init initcall_blacklist(char *str) 10957b0b73d7SPrarit Bhargava { 10967b0b73d7SPrarit Bhargava char *str_entry; 10977b0b73d7SPrarit Bhargava struct blacklist_entry *entry; 10987b0b73d7SPrarit Bhargava 10997b0b73d7SPrarit Bhargava /* str argument is a comma-separated list of functions */ 11007b0b73d7SPrarit Bhargava do { 11017b0b73d7SPrarit Bhargava str_entry = strsep(&str, ","); 11027b0b73d7SPrarit Bhargava if (str_entry) { 11037b0b73d7SPrarit Bhargava pr_debug("blacklisting initcall %s\n", str_entry); 11047e1c4e27SMike Rapoport entry = memblock_alloc(sizeof(*entry), 11057e1c4e27SMike Rapoport SMP_CACHE_BYTES); 1106f5c7310aSMike Rapoport if (!entry) 1107f5c7310aSMike Rapoport panic("%s: Failed to allocate %zu bytes\n", 1108f5c7310aSMike Rapoport __func__, sizeof(*entry)); 11097e1c4e27SMike Rapoport entry->buf = memblock_alloc(strlen(str_entry) + 1, 11107e1c4e27SMike Rapoport SMP_CACHE_BYTES); 1111f5c7310aSMike Rapoport if (!entry->buf) 1112f5c7310aSMike Rapoport panic("%s: Failed to allocate %zu bytes\n", 1113f5c7310aSMike Rapoport __func__, strlen(str_entry) + 1); 11147b0b73d7SPrarit Bhargava strcpy(entry->buf, str_entry); 11157b0b73d7SPrarit Bhargava list_add(&entry->next, &blacklisted_initcalls); 11167b0b73d7SPrarit Bhargava } 11177b0b73d7SPrarit Bhargava } while (str_entry); 11187b0b73d7SPrarit Bhargava 11197b0b73d7SPrarit Bhargava return 0; 11207b0b73d7SPrarit Bhargava } 11217b0b73d7SPrarit Bhargava 11227b0b73d7SPrarit Bhargava static bool __init_or_module initcall_blacklisted(initcall_t fn) 11237b0b73d7SPrarit Bhargava { 11247b0b73d7SPrarit Bhargava struct blacklist_entry *entry; 1125c8cdd2beSRasmus Villemoes char fn_name[KSYM_SYMBOL_LEN]; 11260fd5ed8dSRasmus Villemoes unsigned long addr; 11277b0b73d7SPrarit Bhargava 1128c8cdd2beSRasmus Villemoes if (list_empty(&blacklisted_initcalls)) 11297b0b73d7SPrarit Bhargava return false; 11307b0b73d7SPrarit Bhargava 11310fd5ed8dSRasmus Villemoes addr = (unsigned long) dereference_function_descriptor(fn); 11320fd5ed8dSRasmus Villemoes sprint_symbol_no_offset(fn_name, addr); 1133c8cdd2beSRasmus Villemoes 1134841c06d7SPrarit Bhargava /* 1135841c06d7SPrarit Bhargava * fn will be "function_name [module_name]" where [module_name] is not 1136841c06d7SPrarit Bhargava * displayed for built-in init functions. Strip off the [module_name]. 1137841c06d7SPrarit Bhargava */ 1138841c06d7SPrarit Bhargava strreplace(fn_name, ' ', '\0'); 1139841c06d7SPrarit Bhargava 1140e6fd1fb3SGeliang Tang list_for_each_entry(entry, &blacklisted_initcalls, next) { 11417b0b73d7SPrarit Bhargava if (!strcmp(fn_name, entry->buf)) { 11427b0b73d7SPrarit Bhargava pr_debug("initcall %s blacklisted\n", fn_name); 11437b0b73d7SPrarit Bhargava return true; 11447b0b73d7SPrarit Bhargava } 11457b0b73d7SPrarit Bhargava } 11467b0b73d7SPrarit Bhargava 11477b0b73d7SPrarit Bhargava return false; 11487b0b73d7SPrarit Bhargava } 11497b0b73d7SPrarit Bhargava #else 11507b0b73d7SPrarit Bhargava static int __init initcall_blacklist(char *str) 11517b0b73d7SPrarit Bhargava { 11527b0b73d7SPrarit Bhargava pr_warn("initcall_blacklist requires CONFIG_KALLSYMS\n"); 11537b0b73d7SPrarit Bhargava return 0; 11547b0b73d7SPrarit Bhargava } 11557b0b73d7SPrarit Bhargava 11567b0b73d7SPrarit Bhargava static bool __init_or_module initcall_blacklisted(initcall_t fn) 11577b0b73d7SPrarit Bhargava { 11587b0b73d7SPrarit Bhargava return false; 11597b0b73d7SPrarit Bhargava } 11607b0b73d7SPrarit Bhargava #endif 11617b0b73d7SPrarit Bhargava __setup("initcall_blacklist=", initcall_blacklist); 11627b0b73d7SPrarit Bhargava 11634e37958dSSteven Rostedt (VMware) static __init_or_module void 11644e37958dSSteven Rostedt (VMware) trace_initcall_start_cb(void *data, initcall_t fn) 11651da177e4SLinus Torvalds { 11664e37958dSSteven Rostedt (VMware) ktime_t *calltime = (ktime_t *)data; 11671da177e4SLinus Torvalds 1168d75f773cSSakari Ailus printk(KERN_DEBUG "calling %pS @ %i\n", fn, task_pid_nr(current)); 11694e37958dSSteven Rostedt (VMware) *calltime = ktime_get(); 11704e37958dSSteven Rostedt (VMware) } 11714e37958dSSteven Rostedt (VMware) 11724e37958dSSteven Rostedt (VMware) static __init_or_module void 11734e37958dSSteven Rostedt (VMware) trace_initcall_finish_cb(void *data, initcall_t fn, int ret) 11744e37958dSSteven Rostedt (VMware) { 11754e37958dSSteven Rostedt (VMware) ktime_t *calltime = (ktime_t *)data; 11764e37958dSSteven Rostedt (VMware) ktime_t delta, rettime; 11774e37958dSSteven Rostedt (VMware) unsigned long long duration; 11784e37958dSSteven Rostedt (VMware) 117974239072SFrederic Weisbecker rettime = ktime_get(); 11804e37958dSSteven Rostedt (VMware) delta = ktime_sub(rettime, *calltime); 118130dbb20eSAmérico Wang duration = (unsigned long long) ktime_to_ns(delta) >> 10; 1182d75f773cSSakari Ailus printk(KERN_DEBUG "initcall %pS returned %d after %lld usecs\n", 1183ea676e84SAndrew Morton fn, ret, duration); 11848f0c45cdSIngo Molnar } 11858f0c45cdSIngo Molnar 11864e37958dSSteven Rostedt (VMware) static ktime_t initcall_calltime; 11874e37958dSSteven Rostedt (VMware) 1188b0dc52f1SSteven Rostedt (VMware) #ifdef TRACEPOINTS_ENABLED 11894e37958dSSteven Rostedt (VMware) static void __init initcall_debug_enable(void) 11904e37958dSSteven Rostedt (VMware) { 11914e37958dSSteven Rostedt (VMware) int ret; 11924e37958dSSteven Rostedt (VMware) 11934e37958dSSteven Rostedt (VMware) ret = register_trace_initcall_start(trace_initcall_start_cb, 11944e37958dSSteven Rostedt (VMware) &initcall_calltime); 11954e37958dSSteven Rostedt (VMware) ret |= register_trace_initcall_finish(trace_initcall_finish_cb, 11964e37958dSSteven Rostedt (VMware) &initcall_calltime); 11974e37958dSSteven Rostedt (VMware) WARN(ret, "Failed to register initcall tracepoints\n"); 1198c1cda48aSAndrew Morton } 1199b0dc52f1SSteven Rostedt (VMware) # define do_trace_initcall_start trace_initcall_start 1200b0dc52f1SSteven Rostedt (VMware) # define do_trace_initcall_finish trace_initcall_finish 1201b0dc52f1SSteven Rostedt (VMware) #else 1202b0dc52f1SSteven Rostedt (VMware) static inline void do_trace_initcall_start(initcall_t fn) 1203b0dc52f1SSteven Rostedt (VMware) { 1204b0dc52f1SSteven Rostedt (VMware) if (!initcall_debug) 1205b0dc52f1SSteven Rostedt (VMware) return; 1206b0dc52f1SSteven Rostedt (VMware) trace_initcall_start_cb(&initcall_calltime, fn); 1207b0dc52f1SSteven Rostedt (VMware) } 1208b0dc52f1SSteven Rostedt (VMware) static inline void do_trace_initcall_finish(initcall_t fn, int ret) 1209b0dc52f1SSteven Rostedt (VMware) { 1210b0dc52f1SSteven Rostedt (VMware) if (!initcall_debug) 1211b0dc52f1SSteven Rostedt (VMware) return; 1212b0dc52f1SSteven Rostedt (VMware) trace_initcall_finish_cb(&initcall_calltime, fn, ret); 1213b0dc52f1SSteven Rostedt (VMware) } 1214b0dc52f1SSteven Rostedt (VMware) #endif /* !TRACEPOINTS_ENABLED */ 1215c1cda48aSAndrew Morton 1216e4461271SKevin Winchester int __init_or_module do_one_initcall(initcall_t fn) 121722c5c03bSKevin Winchester { 121822c5c03bSKevin Winchester int count = preempt_count(); 1219ff1c8facSSteven Rostedt char msgbuf[64]; 12204e37958dSSteven Rostedt (VMware) int ret; 122122c5c03bSKevin Winchester 12227b0b73d7SPrarit Bhargava if (initcall_blacklisted(fn)) 12237b0b73d7SPrarit Bhargava return -EPERM; 12247b0b73d7SPrarit Bhargava 1225b0dc52f1SSteven Rostedt (VMware) do_trace_initcall_start(fn); 122622c5c03bSKevin Winchester ret = fn(); 1227b0dc52f1SSteven Rostedt (VMware) do_trace_initcall_finish(fn, ret); 122822c5c03bSKevin Winchester 1229e662e1cfSCyrill Gorcunov msgbuf[0] = 0; 1230e662e1cfSCyrill Gorcunov 12311da177e4SLinus Torvalds if (preempt_count() != count) { 1232bf5d770bSSteven Rostedt sprintf(msgbuf, "preemption imbalance "); 12334a2b4b22SPeter Zijlstra preempt_count_set(count); 12341da177e4SLinus Torvalds } 12351da177e4SLinus Torvalds if (irqs_disabled()) { 1236a76bfd0dSCyrill Gorcunov strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf)); 12371da177e4SLinus Torvalds local_irq_enable(); 12381da177e4SLinus Torvalds } 1239d75f773cSSakari Ailus WARN(msgbuf[0], "initcall %pS returned with %s\n", fn, msgbuf); 124059f9415fSArjan van de Ven 124138addce8SEmese Revfy add_latent_entropy(); 124230dbb20eSAmérico Wang return ret; 12431da177e4SLinus Torvalds } 12441da177e4SLinus Torvalds 1245e0df154fSLinus Torvalds 12461b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall_start[]; 12471b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall0_start[]; 12481b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall1_start[]; 12491b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall2_start[]; 12501b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall3_start[]; 12511b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall4_start[]; 12521b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall5_start[]; 12531b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall6_start[]; 12541b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall7_start[]; 12551b1eeca7SArd Biesheuvel extern initcall_entry_t __initcall_end[]; 1256026cee00SPawel Moll 12571b1eeca7SArd Biesheuvel static initcall_entry_t *initcall_levels[] __initdata = { 1258026cee00SPawel Moll __initcall0_start, 1259026cee00SPawel Moll __initcall1_start, 1260026cee00SPawel Moll __initcall2_start, 1261026cee00SPawel Moll __initcall3_start, 1262026cee00SPawel Moll __initcall4_start, 1263026cee00SPawel Moll __initcall5_start, 1264026cee00SPawel Moll __initcall6_start, 1265026cee00SPawel Moll __initcall7_start, 1266026cee00SPawel Moll __initcall_end, 1267026cee00SPawel Moll }; 1268026cee00SPawel Moll 126996263d28SJim Cromie /* Keep these in sync with initcalls in include/linux/init.h */ 12707c8f7193SAlexey Dobriyan static const char *initcall_level_names[] __initdata = { 1271a6fb6012SSteven Rostedt (VMware) "pure", 12729fb48c74SJim Cromie "core", 12739fb48c74SJim Cromie "postcore", 12749fb48c74SJim Cromie "arch", 12759fb48c74SJim Cromie "subsys", 12769fb48c74SJim Cromie "fs", 12779fb48c74SJim Cromie "device", 12789fb48c74SJim Cromie "late", 1279026cee00SPawel Moll }; 1280026cee00SPawel Moll 12817e2762e1SArvind Sankar static int __init ignore_unknown_bootoption(char *param, char *val, 12827e2762e1SArvind Sankar const char *unused, void *arg) 12837e2762e1SArvind Sankar { 12847e2762e1SArvind Sankar return 0; 12857e2762e1SArvind Sankar } 12867e2762e1SArvind Sankar 12870068c92aSMasami Hiramatsu static void __init do_initcall_level(int level, char *command_line) 1288026cee00SPawel Moll { 12891b1eeca7SArd Biesheuvel initcall_entry_t *fn; 1290026cee00SPawel Moll 1291026cee00SPawel Moll parse_args(initcall_level_names[level], 12920068c92aSMasami Hiramatsu command_line, __start___param, 1293026cee00SPawel Moll __stop___param - __start___param, 1294026cee00SPawel Moll level, level, 12957e2762e1SArvind Sankar NULL, ignore_unknown_bootoption); 1296026cee00SPawel Moll 12974ee7c60dSSteven Rostedt (VMware) trace_initcall_level(initcall_level_names[level]); 1298026cee00SPawel Moll for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) 12991b1eeca7SArd Biesheuvel do_one_initcall(initcall_from_entry(fn)); 1300026cee00SPawel Moll } 1301e0df154fSLinus Torvalds 1302e0df154fSLinus Torvalds static void __init do_initcalls(void) 1303e0df154fSLinus Torvalds { 1304026cee00SPawel Moll int level; 13050068c92aSMasami Hiramatsu size_t len = strlen(saved_command_line) + 1; 13060068c92aSMasami Hiramatsu char *command_line; 1307e0df154fSLinus Torvalds 13080068c92aSMasami Hiramatsu command_line = kzalloc(len, GFP_KERNEL); 13090068c92aSMasami Hiramatsu if (!command_line) 13100068c92aSMasami Hiramatsu panic("%s: Failed to allocate %zu bytes\n", __func__, len); 13110068c92aSMasami Hiramatsu 13120068c92aSMasami Hiramatsu for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++) { 13130068c92aSMasami Hiramatsu /* Parser modifies command_line, restore it each time */ 13140068c92aSMasami Hiramatsu strcpy(command_line, saved_command_line); 13150068c92aSMasami Hiramatsu do_initcall_level(level, command_line); 13160068c92aSMasami Hiramatsu } 13170068c92aSMasami Hiramatsu 13180068c92aSMasami Hiramatsu kfree(command_line); 13191da177e4SLinus Torvalds } 13201da177e4SLinus Torvalds 13211da177e4SLinus Torvalds /* 13221da177e4SLinus Torvalds * Ok, the machine is now initialized. None of the devices 13231da177e4SLinus Torvalds * have been touched yet, but the CPU subsystem is up and 13241da177e4SLinus Torvalds * running, and memory and process management works. 13251da177e4SLinus Torvalds * 13261da177e4SLinus Torvalds * Now we can finally start doing some real work.. 13271da177e4SLinus Torvalds */ 13281da177e4SLinus Torvalds static void __init do_basic_setup(void) 13291da177e4SLinus Torvalds { 1330759ee091SLai Jiangshan cpuset_init_smp(); 13311da177e4SLinus Torvalds driver_init(); 1332b04c3afbSEric W. Biederman init_irq_proc(); 1333b99b87f7SPeter Oberparleiter do_ctors(); 1334d5767c53SLinus Torvalds usermodehelper_enable(); 1335b0f84374Swangyanqing do_initcalls(); 13361da177e4SLinus Torvalds } 13371da177e4SLinus Torvalds 13387babe8dbSEduard - Gabriel Munteanu static void __init do_pre_smp_initcalls(void) 1339c2147a50SEduard - Gabriel Munteanu { 13401b1eeca7SArd Biesheuvel initcall_entry_t *fn; 1341c2147a50SEduard - Gabriel Munteanu 13424ee7c60dSSteven Rostedt (VMware) trace_initcall_level("early"); 1343026cee00SPawel Moll for (fn = __initcall_start; fn < __initcall0_start; fn++) 13441b1eeca7SArd Biesheuvel do_one_initcall(initcall_from_entry(fn)); 1345c2147a50SEduard - Gabriel Munteanu } 1346c2147a50SEduard - Gabriel Munteanu 1347a74fb73cSAl Viro static int run_init_process(const char *init_filename) 13481da177e4SLinus Torvalds { 1349b88c50acSArvind Sankar const char *const *p; 1350b88c50acSArvind Sankar 13511da177e4SLinus Torvalds argv_init[0] = init_filename; 13523f5c15d8SPaul Menzel pr_info("Run %s as init process\n", init_filename); 1353b88c50acSArvind Sankar pr_debug(" with arguments:\n"); 1354b88c50acSArvind Sankar for (p = argv_init; *p; p++) 1355b88c50acSArvind Sankar pr_debug(" %s\n", *p); 1356b88c50acSArvind Sankar pr_debug(" with environment:\n"); 1357b88c50acSArvind Sankar for (p = envp_init; *p; p++) 1358b88c50acSArvind Sankar pr_debug(" %s\n", *p); 1359be619f7fSEric W. Biederman return kernel_execve(init_filename, argv_init, envp_init); 13601da177e4SLinus Torvalds } 13611da177e4SLinus Torvalds 1362ba24762bSMichael Opdenacker static int try_to_run_init_process(const char *init_filename) 1363ba24762bSMichael Opdenacker { 1364ba24762bSMichael Opdenacker int ret; 1365ba24762bSMichael Opdenacker 1366ba24762bSMichael Opdenacker ret = run_init_process(init_filename); 1367ba24762bSMichael Opdenacker 1368ba24762bSMichael Opdenacker if (ret && ret != -ENOENT) { 1369ba24762bSMichael Opdenacker pr_err("Starting init: %s exists but couldn't execute it (error %d)\n", 1370ba24762bSMichael Opdenacker init_filename, ret); 1371ba24762bSMichael Opdenacker } 1372ba24762bSMichael Opdenacker 1373ba24762bSMichael Opdenacker return ret; 1374ba24762bSMichael Opdenacker } 1375ba24762bSMichael Opdenacker 1376f80b0c90SVineet Gupta static noinline void __init kernel_init_freeable(void); 1377d6b21238SAl Viro 13780f5bf6d0SLaura Abbott #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX) 137939290b38SAKASHI Takahiro bool rodata_enabled __ro_after_init = true; 1380d2aa1acaSKees Cook static int __init set_debug_rodata(char *str) 1381d2aa1acaSKees Cook { 1382d2aa1acaSKees Cook return strtobool(str, &rodata_enabled); 1383d2aa1acaSKees Cook } 1384d2aa1acaSKees Cook __setup("rodata=", set_debug_rodata); 138539290b38SAKASHI Takahiro #endif 1386d2aa1acaSKees Cook 13870f5bf6d0SLaura Abbott #ifdef CONFIG_STRICT_KERNEL_RWX 1388d2aa1acaSKees Cook static void mark_readonly(void) 1389d2aa1acaSKees Cook { 13902959a5f7SJinbum Park if (rodata_enabled) { 1391ae646f0bSJeffrey Hugo /* 1392ba180314SPaul E. McKenney * load_module() results in W+X mappings, which are cleaned 1393ba180314SPaul E. McKenney * up with call_rcu(). Let's make sure that queued work is 1394ae646f0bSJeffrey Hugo * flushed so that we don't hit false positives looking for 1395ae646f0bSJeffrey Hugo * insecure pages which are W+X. 1396ae646f0bSJeffrey Hugo */ 1397ba180314SPaul E. McKenney rcu_barrier(); 1398d2aa1acaSKees Cook mark_rodata_ro(); 13992959a5f7SJinbum Park rodata_test(); 14002959a5f7SJinbum Park } else 1401d2aa1acaSKees Cook pr_info("Kernel memory protection disabled.\n"); 1402d2aa1acaSKees Cook } 1403f596ded1SChristophe Leroy #elif defined(CONFIG_ARCH_HAS_STRICT_KERNEL_RWX) 1404f596ded1SChristophe Leroy static inline void mark_readonly(void) 1405f596ded1SChristophe Leroy { 1406f596ded1SChristophe Leroy pr_warn("Kernel memory protection not selected by kernel config.\n"); 1407f596ded1SChristophe Leroy } 1408d2aa1acaSKees Cook #else 1409d2aa1acaSKees Cook static inline void mark_readonly(void) 1410d2aa1acaSKees Cook { 1411d2aa1acaSKees Cook pr_warn("This architecture does not have kernel memory protection.\n"); 1412d2aa1acaSKees Cook } 1413d2aa1acaSKees Cook #endif 1414d2aa1acaSKees Cook 1415997aef68SMike Rapoport void __weak free_initmem(void) 1416997aef68SMike Rapoport { 1417f4039999SMike Rapoport free_initmem_default(POISON_FREE_INITMEM); 1418997aef68SMike Rapoport } 1419997aef68SMike Rapoport 1420d6b21238SAl Viro static int __ref kernel_init(void *unused) 1421ee5bfa64SVivek Goyal { 1422ba24762bSMichael Opdenacker int ret; 1423ba24762bSMichael Opdenacker 1424d6b21238SAl Viro kernel_init_freeable(); 142522a9d645SArjan van de Ven /* need to finish all async __init code before freeing the memory */ 142622a9d645SArjan van de Ven async_synchronize_full(); 142782d083abSMasami Hiramatsu kprobe_free_init_mem(); 1428b80f0f6cSSteven Rostedt (VMware) ftrace_free_init_mem(); 1429d54ce615SSumit Garg kgdb_free_init_mem(); 1430ee5bfa64SVivek Goyal free_initmem(); 1431d2aa1acaSKees Cook mark_readonly(); 1432b976690fSJoerg Roedel 1433b976690fSJoerg Roedel /* 1434b976690fSJoerg Roedel * Kernel mappings are now finalized - update the userspace page-table 1435b976690fSJoerg Roedel * to finalize PTI. 1436b976690fSJoerg Roedel */ 1437b976690fSJoerg Roedel pti_finalize(); 1438b976690fSJoerg Roedel 1439ee5bfa64SVivek Goyal system_state = SYSTEM_RUNNING; 1440ee5bfa64SVivek Goyal numa_default_policy(); 1441ee5bfa64SVivek Goyal 1442967dcb8fSPaul E. McKenney rcu_end_inkernel_boot(); 1443967dcb8fSPaul E. McKenney 14443db978d4SVlastimil Babka do_sysctl_args(); 14453db978d4SVlastimil Babka 1446ee5bfa64SVivek Goyal if (ramdisk_execute_command) { 1447ba24762bSMichael Opdenacker ret = run_init_process(ramdisk_execute_command); 1448ba24762bSMichael Opdenacker if (!ret) 1449a74fb73cSAl Viro return 0; 1450ba24762bSMichael Opdenacker pr_err("Failed to execute %s (error %d)\n", 1451ba24762bSMichael Opdenacker ramdisk_execute_command, ret); 1452ee5bfa64SVivek Goyal } 1453ee5bfa64SVivek Goyal 1454ee5bfa64SVivek Goyal /* 1455ee5bfa64SVivek Goyal * We try each of these until one succeeds. 1456ee5bfa64SVivek Goyal * 1457ee5bfa64SVivek Goyal * The Bourne shell can be used instead of init if we are 1458ee5bfa64SVivek Goyal * trying to recover a really broken machine. 1459ee5bfa64SVivek Goyal */ 1460ee5bfa64SVivek Goyal if (execute_command) { 1461ba24762bSMichael Opdenacker ret = run_init_process(execute_command); 1462ba24762bSMichael Opdenacker if (!ret) 1463a74fb73cSAl Viro return 0; 14646ef4536eSAndy Lutomirski panic("Requested init %s failed (error %d).", 14656ef4536eSAndy Lutomirski execute_command, ret); 1466ee5bfa64SVivek Goyal } 1467ada4ab7aSChris Down 1468ada4ab7aSChris Down if (CONFIG_DEFAULT_INIT[0] != '\0') { 1469ada4ab7aSChris Down ret = run_init_process(CONFIG_DEFAULT_INIT); 1470ada4ab7aSChris Down if (ret) 1471ada4ab7aSChris Down pr_err("Default init %s failed (error %d)\n", 1472ada4ab7aSChris Down CONFIG_DEFAULT_INIT, ret); 1473ada4ab7aSChris Down else 1474ada4ab7aSChris Down return 0; 1475ada4ab7aSChris Down } 1476ada4ab7aSChris Down 1477ba24762bSMichael Opdenacker if (!try_to_run_init_process("/sbin/init") || 1478ba24762bSMichael Opdenacker !try_to_run_init_process("/etc/init") || 1479ba24762bSMichael Opdenacker !try_to_run_init_process("/bin/init") || 1480ba24762bSMichael Opdenacker !try_to_run_init_process("/bin/sh")) 1481a74fb73cSAl Viro return 0; 1482ee5bfa64SVivek Goyal 1483ba24762bSMichael Opdenacker panic("No working init found. Try passing init= option to kernel. " 14848c27ceffSMauro Carvalho Chehab "See Linux Documentation/admin-guide/init.rst for guidance."); 1485ee5bfa64SVivek Goyal } 1486ee5bfa64SVivek Goyal 14878f740636SChristoph Hellwig /* Open /dev/console, for stdin/stdout/stderr, this should never fail */ 1488a94b5214SChristoph Hellwig void __init console_on_rootfs(void) 1489b49a733dSDominik Brodowski { 14908f740636SChristoph Hellwig struct file *file = filp_open("/dev/console", O_RDWR, 0); 149174f1a299SDominik Brodowski 14928f740636SChristoph Hellwig if (IS_ERR(file)) { 1493a91bd622SPetr Mladek pr_err("Warning: unable to open an initial console.\n"); 14948f740636SChristoph Hellwig return; 14958f740636SChristoph Hellwig } 1496f0735310SChristoph Hellwig init_dup(file); 1497f0735310SChristoph Hellwig init_dup(file); 1498f0735310SChristoph Hellwig init_dup(file); 1499f0735310SChristoph Hellwig fput(file); 1500b49a733dSDominik Brodowski } 1501b49a733dSDominik Brodowski 1502f80b0c90SVineet Gupta static noinline void __init kernel_init_freeable(void) 15031da177e4SLinus Torvalds { 1504b433c3d4SPeter Zijlstra /* 1505b433c3d4SPeter Zijlstra * Wait until kthreadd is all set-up. 1506b433c3d4SPeter Zijlstra */ 1507b433c3d4SPeter Zijlstra wait_for_completion(&kthreadd_done); 150831a67102SLinus Torvalds 150931a67102SLinus Torvalds /* Now the scheduler is fully set up and can do blocking allocations */ 151031a67102SLinus Torvalds gfp_allowed_mask = __GFP_BITS_MASK; 151131a67102SLinus Torvalds 151258568d2aSMiao Xie /* 151358568d2aSMiao Xie * init can allocate pages on any node 151458568d2aSMiao Xie */ 15153c466d46SLai Jiangshan set_mems_allowed(node_states[N_MEMORY]); 15161da177e4SLinus Torvalds 15179ec52099SCedric Le Goater cad_pid = task_pid(current); 15189ec52099SCedric Le Goater 1519ca74a6f8SAndi Kleen smp_prepare_cpus(setup_max_cpus); 15201da177e4SLinus Torvalds 15213347fa09STejun Heo workqueue_init(); 15223347fa09STejun Heo 1523597b7305SMichal Hocko init_mm_internals(); 1524597b7305SMichal Hocko 15251b04fa99SUladzislau Rezki (Sony) rcu_init_tasks_generic(); 15261da177e4SLinus Torvalds do_pre_smp_initcalls(); 1527004417a6SPeter Zijlstra lockup_detector_init(); 15281da177e4SLinus Torvalds 15291da177e4SLinus Torvalds smp_init(); 15301da177e4SLinus Torvalds sched_init_smp(); 15311da177e4SLinus Torvalds 1532f1b192b1SDaniel Jordan padata_init(); 15330e1cc95bSMel Gorman page_alloc_init_late(); 15342f1ee091SQian Cai /* Initialize page ext after all struct pages are initialized. */ 15352f1ee091SQian Cai page_ext_init(); 15360e1cc95bSMel Gorman 15371da177e4SLinus Torvalds do_basic_setup(); 15381da177e4SLinus Torvalds 15398c0d8849SBrendan Higgins kunit_run_all_tests(); 15408c0d8849SBrendan Higgins 1541b49a733dSDominik Brodowski console_on_rootfs(); 15422bd3a997SEric W. Biederman 15431da177e4SLinus Torvalds /* 15441da177e4SLinus Torvalds * check if there is an early userspace init. If yes, let it do all 15451da177e4SLinus Torvalds * the work 15461da177e4SLinus Torvalds */ 1547eb9d7d39SChristoph Hellwig if (init_eaccess(ramdisk_execute_command) != 0) { 1548ffdfc409SOlof Johansson ramdisk_execute_command = NULL; 15491da177e4SLinus Torvalds prepare_namespace(); 1550ffdfc409SOlof Johansson } 15511da177e4SLinus Torvalds 15521da177e4SLinus Torvalds /* 15531da177e4SLinus Torvalds * Ok, we have completed the initial bootup, and 15541da177e4SLinus Torvalds * we're essentially up and running. Get rid of the 15551da177e4SLinus Torvalds * initmem segments and start the user-mode stuff.. 1556c9cd2ce2SDmitry Kasatkin * 1557c9cd2ce2SDmitry Kasatkin * rootfs is available now, try loading the public keys 1558c9cd2ce2SDmitry Kasatkin * and default modules 15591da177e4SLinus Torvalds */ 1560bb813f4cSTejun Heo 1561c9cd2ce2SDmitry Kasatkin integrity_load_keys(); 15621da177e4SLinus Torvalds } 1563