startup.patch 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. diff -Nur linux-or1k-fixes-4.9.orig/init/initramfs.c linux-or1k-fixes-4.9/init/initramfs.c
  2. --- linux-or1k-fixes-4.9.orig/init/initramfs.c 2016-11-16 07:38:36.000000000 +0100
  3. +++ linux-or1k-fixes-4.9/init/initramfs.c 2016-11-16 07:55:29.361385994 +0100
  4. @@ -653,6 +653,9 @@
  5. */
  6. load_default_modules();
  7. }
  8. +#ifdef CONFIG_DEVTMPFS_MOUNT
  9. + devtmpfs_mount("dev");
  10. +#endif
  11. return 0;
  12. }
  13. rootfs_initcall(populate_rootfs);
  14. diff -Nur linux-or1k-fixes-4.9.orig/init/main.c linux-or1k-fixes-4.9/init/main.c
  15. --- linux-or1k-fixes-4.9.orig/init/main.c 2016-11-16 07:38:36.000000000 +0100
  16. +++ linux-or1k-fixes-4.9/init/main.c 2016-11-16 07:55:29.369386302 +0100
  17. @@ -1020,6 +1020,8 @@
  18. if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
  19. pr_err("Warning: unable to open an initial console.\n");
  20. + printk(KERN_WARNING "Starting Linux (built with OpenADK).\n");
  21. +
  22. (void) sys_dup(0);
  23. (void) sys_dup(0);
  24. /*
  25. @@ -1028,7 +1030,7 @@
  26. */
  27. if (!ramdisk_execute_command)
  28. - ramdisk_execute_command = "/init";
  29. + ramdisk_execute_command = "/sbin/init";
  30. if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
  31. ramdisk_execute_command = NULL;
  32. diff -Nur linux-or1k-fixes-4.9.orig/init/main.c.orig linux-or1k-fixes-4.9/init/main.c.orig
  33. --- linux-or1k-fixes-4.9.orig/init/main.c.orig 1970-01-01 01:00:00.000000000 +0100
  34. +++ linux-or1k-fixes-4.9/init/main.c.orig 2016-11-16 07:38:36.000000000 +0100
  35. @@ -0,0 +1,1049 @@
  36. +/*
  37. + * linux/init/main.c
  38. + *
  39. + * Copyright (C) 1991, 1992 Linus Torvalds
  40. + *
  41. + * GK 2/5/95 - Changed to support mounting root fs via NFS
  42. + * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96
  43. + * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96
  44. + * Simplified starting of init: Michael A. Griffith <grif@acm.org>
  45. + */
  46. +
  47. +#define DEBUG /* Enable initcall_debug */
  48. +
  49. +#include <linux/types.h>
  50. +#include <linux/module.h>
  51. +#include <linux/proc_fs.h>
  52. +#include <linux/kernel.h>
  53. +#include <linux/syscalls.h>
  54. +#include <linux/stackprotector.h>
  55. +#include <linux/string.h>
  56. +#include <linux/ctype.h>
  57. +#include <linux/delay.h>
  58. +#include <linux/ioport.h>
  59. +#include <linux/init.h>
  60. +#include <linux/initrd.h>
  61. +#include <linux/bootmem.h>
  62. +#include <linux/acpi.h>
  63. +#include <linux/tty.h>
  64. +#include <linux/percpu.h>
  65. +#include <linux/kmod.h>
  66. +#include <linux/vmalloc.h>
  67. +#include <linux/kernel_stat.h>
  68. +#include <linux/start_kernel.h>
  69. +#include <linux/security.h>
  70. +#include <linux/smp.h>
  71. +#include <linux/profile.h>
  72. +#include <linux/rcupdate.h>
  73. +#include <linux/moduleparam.h>
  74. +#include <linux/kallsyms.h>
  75. +#include <linux/writeback.h>
  76. +#include <linux/cpu.h>
  77. +#include <linux/cpuset.h>
  78. +#include <linux/cgroup.h>
  79. +#include <linux/efi.h>
  80. +#include <linux/tick.h>
  81. +#include <linux/interrupt.h>
  82. +#include <linux/taskstats_kern.h>
  83. +#include <linux/delayacct.h>
  84. +#include <linux/unistd.h>
  85. +#include <linux/rmap.h>
  86. +#include <linux/mempolicy.h>
  87. +#include <linux/key.h>
  88. +#include <linux/buffer_head.h>
  89. +#include <linux/page_ext.h>
  90. +#include <linux/debug_locks.h>
  91. +#include <linux/debugobjects.h>
  92. +#include <linux/lockdep.h>
  93. +#include <linux/kmemleak.h>
  94. +#include <linux/pid_namespace.h>
  95. +#include <linux/device.h>
  96. +#include <linux/kthread.h>
  97. +#include <linux/sched.h>
  98. +#include <linux/signal.h>
  99. +#include <linux/idr.h>
  100. +#include <linux/kgdb.h>
  101. +#include <linux/ftrace.h>
  102. +#include <linux/async.h>
  103. +#include <linux/kmemcheck.h>
  104. +#include <linux/sfi.h>
  105. +#include <linux/shmem_fs.h>
  106. +#include <linux/slab.h>
  107. +#include <linux/perf_event.h>
  108. +#include <linux/file.h>
  109. +#include <linux/ptrace.h>
  110. +#include <linux/blkdev.h>
  111. +#include <linux/elevator.h>
  112. +#include <linux/sched_clock.h>
  113. +#include <linux/context_tracking.h>
  114. +#include <linux/random.h>
  115. +#include <linux/list.h>
  116. +#include <linux/integrity.h>
  117. +#include <linux/proc_ns.h>
  118. +#include <linux/io.h>
  119. +
  120. +#include <asm/io.h>
  121. +#include <asm/bugs.h>
  122. +#include <asm/setup.h>
  123. +#include <asm/sections.h>
  124. +#include <asm/cacheflush.h>
  125. +
  126. +static int kernel_init(void *);
  127. +
  128. +extern void init_IRQ(void);
  129. +extern void fork_init(void);
  130. +extern void radix_tree_init(void);
  131. +
  132. +/*
  133. + * Debug helper: via this flag we know that we are in 'early bootup code'
  134. + * where only the boot processor is running with IRQ disabled. This means
  135. + * two things - IRQ must not be enabled before the flag is cleared and some
  136. + * operations which are not allowed with IRQ disabled are allowed while the
  137. + * flag is set.
  138. + */
  139. +bool early_boot_irqs_disabled __read_mostly;
  140. +
  141. +enum system_states system_state __read_mostly;
  142. +EXPORT_SYMBOL(system_state);
  143. +
  144. +/*
  145. + * Boot command-line arguments
  146. + */
  147. +#define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
  148. +#define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
  149. +
  150. +extern void time_init(void);
  151. +/* Default late time init is NULL. archs can override this later. */
  152. +void (*__initdata late_time_init)(void);
  153. +
  154. +/* Untouched command line saved by arch-specific code. */
  155. +char __initdata boot_command_line[COMMAND_LINE_SIZE];
  156. +/* Untouched saved command line (eg. for /proc) */
  157. +char *saved_command_line;
  158. +/* Command line for parameter parsing */
  159. +static char *static_command_line;
  160. +/* Command line for per-initcall parameter parsing */
  161. +static char *initcall_command_line;
  162. +
  163. +static char *execute_command;
  164. +static char *ramdisk_execute_command;
  165. +
  166. +/*
  167. + * Used to generate warnings if static_key manipulation functions are used
  168. + * before jump_label_init is called.
  169. + */
  170. +bool static_key_initialized __read_mostly;
  171. +EXPORT_SYMBOL_GPL(static_key_initialized);
  172. +
  173. +/*
  174. + * If set, this is an indication to the drivers that reset the underlying
  175. + * device before going ahead with the initialization otherwise driver might
  176. + * rely on the BIOS and skip the reset operation.
  177. + *
  178. + * This is useful if kernel is booting in an unreliable environment.
  179. + * For ex. kdump situation where previous kernel has crashed, BIOS has been
  180. + * skipped and devices will be in unknown state.
  181. + */
  182. +unsigned int reset_devices;
  183. +EXPORT_SYMBOL(reset_devices);
  184. +
  185. +static int __init set_reset_devices(char *str)
  186. +{
  187. + reset_devices = 1;
  188. + return 1;
  189. +}
  190. +
  191. +__setup("reset_devices", set_reset_devices);
  192. +
  193. +static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
  194. +const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
  195. +static const char *panic_later, *panic_param;
  196. +
  197. +extern const struct obs_kernel_param __setup_start[], __setup_end[];
  198. +
  199. +static bool __init obsolete_checksetup(char *line)
  200. +{
  201. + const struct obs_kernel_param *p;
  202. + bool had_early_param = false;
  203. +
  204. + p = __setup_start;
  205. + do {
  206. + int n = strlen(p->str);
  207. + if (parameqn(line, p->str, n)) {
  208. + if (p->early) {
  209. + /* Already done in parse_early_param?
  210. + * (Needs exact match on param part).
  211. + * Keep iterating, as we can have early
  212. + * params and __setups of same names 8( */
  213. + if (line[n] == '\0' || line[n] == '=')
  214. + had_early_param = true;
  215. + } else if (!p->setup_func) {
  216. + pr_warn("Parameter %s is obsolete, ignored\n",
  217. + p->str);
  218. + return true;
  219. + } else if (p->setup_func(line + n))
  220. + return true;
  221. + }
  222. + p++;
  223. + } while (p < __setup_end);
  224. +
  225. + return had_early_param;
  226. +}
  227. +
  228. +/*
  229. + * This should be approx 2 Bo*oMips to start (note initial shift), and will
  230. + * still work even if initially too large, it will just take slightly longer
  231. + */
  232. +unsigned long loops_per_jiffy = (1<<12);
  233. +EXPORT_SYMBOL(loops_per_jiffy);
  234. +
  235. +static int __init debug_kernel(char *str)
  236. +{
  237. + console_loglevel = CONSOLE_LOGLEVEL_DEBUG;
  238. + return 0;
  239. +}
  240. +
  241. +static int __init quiet_kernel(char *str)
  242. +{
  243. + console_loglevel = CONSOLE_LOGLEVEL_QUIET;
  244. + return 0;
  245. +}
  246. +
  247. +early_param("debug", debug_kernel);
  248. +early_param("quiet", quiet_kernel);
  249. +
  250. +static int __init loglevel(char *str)
  251. +{
  252. + int newlevel;
  253. +
  254. + /*
  255. + * Only update loglevel value when a correct setting was passed,
  256. + * to prevent blind crashes (when loglevel being set to 0) that
  257. + * are quite hard to debug
  258. + */
  259. + if (get_option(&str, &newlevel)) {
  260. + console_loglevel = newlevel;
  261. + return 0;
  262. + }
  263. +
  264. + return -EINVAL;
  265. +}
  266. +
  267. +early_param("loglevel", loglevel);
  268. +
  269. +/* Change NUL term back to "=", to make "param" the whole string. */
  270. +static int __init repair_env_string(char *param, char *val,
  271. + const char *unused, void *arg)
  272. +{
  273. + if (val) {
  274. + /* param=val or param="val"? */
  275. + if (val == param+strlen(param)+1)
  276. + val[-1] = '=';
  277. + else if (val == param+strlen(param)+2) {
  278. + val[-2] = '=';
  279. + memmove(val-1, val, strlen(val)+1);
  280. + val--;
  281. + } else
  282. + BUG();
  283. + }
  284. + return 0;
  285. +}
  286. +
  287. +/* Anything after -- gets handed straight to init. */
  288. +static int __init set_init_arg(char *param, char *val,
  289. + const char *unused, void *arg)
  290. +{
  291. + unsigned int i;
  292. +
  293. + if (panic_later)
  294. + return 0;
  295. +
  296. + repair_env_string(param, val, unused, NULL);
  297. +
  298. + for (i = 0; argv_init[i]; i++) {
  299. + if (i == MAX_INIT_ARGS) {
  300. + panic_later = "init";
  301. + panic_param = param;
  302. + return 0;
  303. + }
  304. + }
  305. + argv_init[i] = param;
  306. + return 0;
  307. +}
  308. +
  309. +/*
  310. + * Unknown boot options get handed to init, unless they look like
  311. + * unused parameters (modprobe will find them in /proc/cmdline).
  312. + */
  313. +static int __init unknown_bootoption(char *param, char *val,
  314. + const char *unused, void *arg)
  315. +{
  316. + repair_env_string(param, val, unused, NULL);
  317. +
  318. + /* Handle obsolete-style parameters */
  319. + if (obsolete_checksetup(param))
  320. + return 0;
  321. +
  322. + /* Unused module parameter. */
  323. + if (strchr(param, '.') && (!val || strchr(param, '.') < val))
  324. + return 0;
  325. +
  326. + if (panic_later)
  327. + return 0;
  328. +
  329. + if (val) {
  330. + /* Environment option */
  331. + unsigned int i;
  332. + for (i = 0; envp_init[i]; i++) {
  333. + if (i == MAX_INIT_ENVS) {
  334. + panic_later = "env";
  335. + panic_param = param;
  336. + }
  337. + if (!strncmp(param, envp_init[i], val - param))
  338. + break;
  339. + }
  340. + envp_init[i] = param;
  341. + } else {
  342. + /* Command line option */
  343. + unsigned int i;
  344. + for (i = 0; argv_init[i]; i++) {
  345. + if (i == MAX_INIT_ARGS) {
  346. + panic_later = "init";
  347. + panic_param = param;
  348. + }
  349. + }
  350. + argv_init[i] = param;
  351. + }
  352. + return 0;
  353. +}
  354. +
  355. +static int __init init_setup(char *str)
  356. +{
  357. + unsigned int i;
  358. +
  359. + execute_command = str;
  360. + /*
  361. + * In case LILO is going to boot us with default command line,
  362. + * it prepends "auto" before the whole cmdline which makes
  363. + * the shell think it should execute a script with such name.
  364. + * So we ignore all arguments entered _before_ init=... [MJ]
  365. + */
  366. + for (i = 1; i < MAX_INIT_ARGS; i++)
  367. + argv_init[i] = NULL;
  368. + return 1;
  369. +}
  370. +__setup("init=", init_setup);
  371. +
  372. +static int __init rdinit_setup(char *str)
  373. +{
  374. + unsigned int i;
  375. +
  376. + ramdisk_execute_command = str;
  377. + /* See "auto" comment in init_setup */
  378. + for (i = 1; i < MAX_INIT_ARGS; i++)
  379. + argv_init[i] = NULL;
  380. + return 1;
  381. +}
  382. +__setup("rdinit=", rdinit_setup);
  383. +
  384. +#ifndef CONFIG_SMP
  385. +static const unsigned int setup_max_cpus = NR_CPUS;
  386. +static inline void setup_nr_cpu_ids(void) { }
  387. +static inline void smp_prepare_cpus(unsigned int maxcpus) { }
  388. +#endif
  389. +
  390. +/*
  391. + * We need to store the untouched command line for future reference.
  392. + * We also need to store the touched command line since the parameter
  393. + * parsing is performed in place, and we should allow a component to
  394. + * store reference of name/value for future reference.
  395. + */
  396. +static void __init setup_command_line(char *command_line)
  397. +{
  398. + saved_command_line =
  399. + memblock_virt_alloc(strlen(boot_command_line) + 1, 0);
  400. + initcall_command_line =
  401. + memblock_virt_alloc(strlen(boot_command_line) + 1, 0);
  402. + static_command_line = memblock_virt_alloc(strlen(command_line) + 1, 0);
  403. + strcpy(saved_command_line, boot_command_line);
  404. + strcpy(static_command_line, command_line);
  405. +}
  406. +
  407. +/*
  408. + * We need to finalize in a non-__init function or else race conditions
  409. + * between the root thread and the init thread may cause start_kernel to
  410. + * be reaped by free_initmem before the root thread has proceeded to
  411. + * cpu_idle.
  412. + *
  413. + * gcc-3.4 accidentally inlines this function, so use noinline.
  414. + */
  415. +
  416. +static __initdata DECLARE_COMPLETION(kthreadd_done);
  417. +
  418. +static noinline void __ref rest_init(void)
  419. +{
  420. + int pid;
  421. +
  422. + rcu_scheduler_starting();
  423. + /*
  424. + * We need to spawn init first so that it obtains pid 1, however
  425. + * the init task will end up wanting to create kthreads, which, if
  426. + * we schedule it before we create kthreadd, will OOPS.
  427. + */
  428. + kernel_thread(kernel_init, NULL, CLONE_FS);
  429. + numa_default_policy();
  430. + pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
  431. + rcu_read_lock();
  432. + kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
  433. + rcu_read_unlock();
  434. + complete(&kthreadd_done);
  435. +
  436. + /*
  437. + * The boot idle thread must execute schedule()
  438. + * at least once to get things moving:
  439. + */
  440. + init_idle_bootup_task(current);
  441. + schedule_preempt_disabled();
  442. + /* Call into cpu_idle with preempt disabled */
  443. + cpu_startup_entry(CPUHP_ONLINE);
  444. +}
  445. +
  446. +/* Check for early params. */
  447. +static int __init do_early_param(char *param, char *val,
  448. + const char *unused, void *arg)
  449. +{
  450. + const struct obs_kernel_param *p;
  451. +
  452. + for (p = __setup_start; p < __setup_end; p++) {
  453. + if ((p->early && parameq(param, p->str)) ||
  454. + (strcmp(param, "console") == 0 &&
  455. + strcmp(p->str, "earlycon") == 0)
  456. + ) {
  457. + if (p->setup_func(val) != 0)
  458. + pr_warn("Malformed early option '%s'\n", param);
  459. + }
  460. + }
  461. + /* We accept everything at this stage. */
  462. + return 0;
  463. +}
  464. +
  465. +void __init parse_early_options(char *cmdline)
  466. +{
  467. + parse_args("early options", cmdline, NULL, 0, 0, 0, NULL,
  468. + do_early_param);
  469. +}
  470. +
  471. +/* Arch code calls this early on, or if not, just before other parsing. */
  472. +void __init parse_early_param(void)
  473. +{
  474. + static int done __initdata;
  475. + static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
  476. +
  477. + if (done)
  478. + return;
  479. +
  480. + /* All fall through to do_early_param. */
  481. + strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  482. + parse_early_options(tmp_cmdline);
  483. + done = 1;
  484. +}
  485. +
  486. +void __init __weak smp_setup_processor_id(void)
  487. +{
  488. +}
  489. +
  490. +# if THREAD_SIZE >= PAGE_SIZE
  491. +void __init __weak thread_stack_cache_init(void)
  492. +{
  493. +}
  494. +#endif
  495. +
  496. +/*
  497. + * Set up kernel memory allocators
  498. + */
  499. +static void __init mm_init(void)
  500. +{
  501. + /*
  502. + * page_ext requires contiguous pages,
  503. + * bigger than MAX_ORDER unless SPARSEMEM.
  504. + */
  505. + page_ext_init_flatmem();
  506. + mem_init();
  507. + kmem_cache_init();
  508. + percpu_init_late();
  509. + pgtable_init();
  510. + vmalloc_init();
  511. + ioremap_huge_init();
  512. +}
  513. +
  514. +asmlinkage __visible void __init start_kernel(void)
  515. +{
  516. + char *command_line;
  517. + char *after_dashes;
  518. +
  519. + set_task_stack_end_magic(&init_task);
  520. + smp_setup_processor_id();
  521. + debug_objects_early_init();
  522. +
  523. + /*
  524. + * Set up the the initial canary ASAP:
  525. + */
  526. + boot_init_stack_canary();
  527. +
  528. + cgroup_init_early();
  529. +
  530. + local_irq_disable();
  531. + early_boot_irqs_disabled = true;
  532. +
  533. +/*
  534. + * Interrupts are still disabled. Do necessary setups, then
  535. + * enable them
  536. + */
  537. + boot_cpu_init();
  538. + page_address_init();
  539. + pr_notice("%s", linux_banner);
  540. + setup_arch(&command_line);
  541. + mm_init_cpumask(&init_mm);
  542. + setup_command_line(command_line);
  543. + setup_nr_cpu_ids();
  544. + setup_per_cpu_areas();
  545. + boot_cpu_state_init();
  546. + smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
  547. +
  548. + build_all_zonelists(NULL, NULL);
  549. + page_alloc_init();
  550. +
  551. + pr_notice("Kernel command line: %s\n", boot_command_line);
  552. + parse_early_param();
  553. + after_dashes = parse_args("Booting kernel",
  554. + static_command_line, __start___param,
  555. + __stop___param - __start___param,
  556. + -1, -1, NULL, &unknown_bootoption);
  557. + if (!IS_ERR_OR_NULL(after_dashes))
  558. + parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
  559. + NULL, set_init_arg);
  560. +
  561. + jump_label_init();
  562. +
  563. + /*
  564. + * These use large bootmem allocations and must precede
  565. + * kmem_cache_init()
  566. + */
  567. + setup_log_buf(0);
  568. + pidhash_init();
  569. + vfs_caches_init_early();
  570. + sort_main_extable();
  571. + trap_init();
  572. + mm_init();
  573. +
  574. + /*
  575. + * Set up the scheduler prior starting any interrupts (such as the
  576. + * timer interrupt). Full topology setup happens at smp_init()
  577. + * time - but meanwhile we still have a functioning scheduler.
  578. + */
  579. + sched_init();
  580. + /*
  581. + * Disable preemption - early bootup scheduling is extremely
  582. + * fragile until we cpu_idle() for the first time.
  583. + */
  584. + preempt_disable();
  585. + if (WARN(!irqs_disabled(),
  586. + "Interrupts were enabled *very* early, fixing it\n"))
  587. + local_irq_disable();
  588. + idr_init_cache();
  589. + rcu_init();
  590. +
  591. + /* trace_printk() and trace points may be used after this */
  592. + trace_init();
  593. +
  594. + context_tracking_init();
  595. + radix_tree_init();
  596. + /* init some links before init_ISA_irqs() */
  597. + early_irq_init();
  598. + init_IRQ();
  599. + tick_init();
  600. + rcu_init_nohz();
  601. + init_timers();
  602. + hrtimers_init();
  603. + softirq_init();
  604. + timekeeping_init();
  605. + time_init();
  606. + sched_clock_postinit();
  607. + printk_nmi_init();
  608. + perf_event_init();
  609. + profile_init();
  610. + call_function_init();
  611. + WARN(!irqs_disabled(), "Interrupts were enabled early\n");
  612. + early_boot_irqs_disabled = false;
  613. + local_irq_enable();
  614. +
  615. + kmem_cache_init_late();
  616. +
  617. + /*
  618. + * HACK ALERT! This is early. We're enabling the console before
  619. + * we've done PCI setups etc, and console_init() must be aware of
  620. + * this. But we do want output early, in case something goes wrong.
  621. + */
  622. + console_init();
  623. + if (panic_later)
  624. + panic("Too many boot %s vars at `%s'", panic_later,
  625. + panic_param);
  626. +
  627. + lockdep_info();
  628. +
  629. + /*
  630. + * Need to run this when irqs are enabled, because it wants
  631. + * to self-test [hard/soft]-irqs on/off lock inversion bugs
  632. + * too:
  633. + */
  634. + locking_selftest();
  635. +
  636. +#ifdef CONFIG_BLK_DEV_INITRD
  637. + if (initrd_start && !initrd_below_start_ok &&
  638. + page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
  639. + pr_crit("initrd overwritten (0x%08lx < 0x%08lx) - disabling it.\n",
  640. + page_to_pfn(virt_to_page((void *)initrd_start)),
  641. + min_low_pfn);
  642. + initrd_start = 0;
  643. + }
  644. +#endif
  645. + page_ext_init();
  646. + debug_objects_mem_init();
  647. + kmemleak_init();
  648. + setup_per_cpu_pageset();
  649. + numa_policy_init();
  650. + if (late_time_init)
  651. + late_time_init();
  652. + sched_clock_init();
  653. + calibrate_delay();
  654. + pidmap_init();
  655. + anon_vma_init();
  656. + acpi_early_init();
  657. +#ifdef CONFIG_X86
  658. + if (efi_enabled(EFI_RUNTIME_SERVICES))
  659. + efi_enter_virtual_mode();
  660. +#endif
  661. +#ifdef CONFIG_X86_ESPFIX64
  662. + /* Should be run before the first non-init thread is created */
  663. + init_espfix_bsp();
  664. +#endif
  665. + thread_stack_cache_init();
  666. + cred_init();
  667. + fork_init();
  668. + proc_caches_init();
  669. + buffer_init();
  670. + key_init();
  671. + security_init();
  672. + dbg_late_init();
  673. + vfs_caches_init();
  674. + signals_init();
  675. + /* rootfs populating might need page-writeback */
  676. + page_writeback_init();
  677. + proc_root_init();
  678. + nsfs_init();
  679. + cpuset_init();
  680. + cgroup_init();
  681. + taskstats_init_early();
  682. + delayacct_init();
  683. +
  684. + check_bugs();
  685. +
  686. + acpi_subsystem_init();
  687. + sfi_init_late();
  688. +
  689. + if (efi_enabled(EFI_RUNTIME_SERVICES)) {
  690. + efi_late_init();
  691. + efi_free_boot_services();
  692. + }
  693. +
  694. + ftrace_init();
  695. +
  696. + /* Do the rest non-__init'ed, we're now alive */
  697. + rest_init();
  698. +}
  699. +
  700. +/* Call all constructor functions linked into the kernel. */
  701. +static void __init do_ctors(void)
  702. +{
  703. +#ifdef CONFIG_CONSTRUCTORS
  704. + ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
  705. +
  706. + for (; fn < (ctor_fn_t *) __ctors_end; fn++)
  707. + (*fn)();
  708. +#endif
  709. +}
  710. +
  711. +bool initcall_debug;
  712. +core_param(initcall_debug, initcall_debug, bool, 0644);
  713. +
  714. +#ifdef CONFIG_KALLSYMS
  715. +struct blacklist_entry {
  716. + struct list_head next;
  717. + char *buf;
  718. +};
  719. +
  720. +static __initdata_or_module LIST_HEAD(blacklisted_initcalls);
  721. +
  722. +static int __init initcall_blacklist(char *str)
  723. +{
  724. + char *str_entry;
  725. + struct blacklist_entry *entry;
  726. +
  727. + /* str argument is a comma-separated list of functions */
  728. + do {
  729. + str_entry = strsep(&str, ",");
  730. + if (str_entry) {
  731. + pr_debug("blacklisting initcall %s\n", str_entry);
  732. + entry = alloc_bootmem(sizeof(*entry));
  733. + entry->buf = alloc_bootmem(strlen(str_entry) + 1);
  734. + strcpy(entry->buf, str_entry);
  735. + list_add(&entry->next, &blacklisted_initcalls);
  736. + }
  737. + } while (str_entry);
  738. +
  739. + return 0;
  740. +}
  741. +
  742. +static bool __init_or_module initcall_blacklisted(initcall_t fn)
  743. +{
  744. + struct blacklist_entry *entry;
  745. + char fn_name[KSYM_SYMBOL_LEN];
  746. + unsigned long addr;
  747. +
  748. + if (list_empty(&blacklisted_initcalls))
  749. + return false;
  750. +
  751. + addr = (unsigned long) dereference_function_descriptor(fn);
  752. + sprint_symbol_no_offset(fn_name, addr);
  753. +
  754. + /*
  755. + * fn will be "function_name [module_name]" where [module_name] is not
  756. + * displayed for built-in init functions. Strip off the [module_name].
  757. + */
  758. + strreplace(fn_name, ' ', '\0');
  759. +
  760. + list_for_each_entry(entry, &blacklisted_initcalls, next) {
  761. + if (!strcmp(fn_name, entry->buf)) {
  762. + pr_debug("initcall %s blacklisted\n", fn_name);
  763. + return true;
  764. + }
  765. + }
  766. +
  767. + return false;
  768. +}
  769. +#else
  770. +static int __init initcall_blacklist(char *str)
  771. +{
  772. + pr_warn("initcall_blacklist requires CONFIG_KALLSYMS\n");
  773. + return 0;
  774. +}
  775. +
  776. +static bool __init_or_module initcall_blacklisted(initcall_t fn)
  777. +{
  778. + return false;
  779. +}
  780. +#endif
  781. +__setup("initcall_blacklist=", initcall_blacklist);
  782. +
  783. +static int __init_or_module do_one_initcall_debug(initcall_t fn)
  784. +{
  785. + ktime_t calltime, delta, rettime;
  786. + unsigned long long duration;
  787. + int ret;
  788. +
  789. + printk(KERN_DEBUG "calling %pF @ %i\n", fn, task_pid_nr(current));
  790. + calltime = ktime_get();
  791. + ret = fn();
  792. + rettime = ktime_get();
  793. + delta = ktime_sub(rettime, calltime);
  794. + duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  795. + printk(KERN_DEBUG "initcall %pF returned %d after %lld usecs\n",
  796. + fn, ret, duration);
  797. +
  798. + return ret;
  799. +}
  800. +
  801. +int __init_or_module do_one_initcall(initcall_t fn)
  802. +{
  803. + int count = preempt_count();
  804. + int ret;
  805. + char msgbuf[64];
  806. +
  807. + if (initcall_blacklisted(fn))
  808. + return -EPERM;
  809. +
  810. + if (initcall_debug)
  811. + ret = do_one_initcall_debug(fn);
  812. + else
  813. + ret = fn();
  814. +
  815. + msgbuf[0] = 0;
  816. +
  817. + if (preempt_count() != count) {
  818. + sprintf(msgbuf, "preemption imbalance ");
  819. + preempt_count_set(count);
  820. + }
  821. + if (irqs_disabled()) {
  822. + strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
  823. + local_irq_enable();
  824. + }
  825. + WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
  826. +
  827. + add_latent_entropy();
  828. + return ret;
  829. +}
  830. +
  831. +
  832. +extern initcall_t __initcall_start[];
  833. +extern initcall_t __initcall0_start[];
  834. +extern initcall_t __initcall1_start[];
  835. +extern initcall_t __initcall2_start[];
  836. +extern initcall_t __initcall3_start[];
  837. +extern initcall_t __initcall4_start[];
  838. +extern initcall_t __initcall5_start[];
  839. +extern initcall_t __initcall6_start[];
  840. +extern initcall_t __initcall7_start[];
  841. +extern initcall_t __initcall_end[];
  842. +
  843. +static initcall_t *initcall_levels[] __initdata = {
  844. + __initcall0_start,
  845. + __initcall1_start,
  846. + __initcall2_start,
  847. + __initcall3_start,
  848. + __initcall4_start,
  849. + __initcall5_start,
  850. + __initcall6_start,
  851. + __initcall7_start,
  852. + __initcall_end,
  853. +};
  854. +
  855. +/* Keep these in sync with initcalls in include/linux/init.h */
  856. +static char *initcall_level_names[] __initdata = {
  857. + "early",
  858. + "core",
  859. + "postcore",
  860. + "arch",
  861. + "subsys",
  862. + "fs",
  863. + "device",
  864. + "late",
  865. +};
  866. +
  867. +static void __init do_initcall_level(int level)
  868. +{
  869. + initcall_t *fn;
  870. +
  871. + strcpy(initcall_command_line, saved_command_line);
  872. + parse_args(initcall_level_names[level],
  873. + initcall_command_line, __start___param,
  874. + __stop___param - __start___param,
  875. + level, level,
  876. + NULL, &repair_env_string);
  877. +
  878. + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
  879. + do_one_initcall(*fn);
  880. +}
  881. +
  882. +static void __init do_initcalls(void)
  883. +{
  884. + int level;
  885. +
  886. + for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
  887. + do_initcall_level(level);
  888. +}
  889. +
  890. +/*
  891. + * Ok, the machine is now initialized. None of the devices
  892. + * have been touched yet, but the CPU subsystem is up and
  893. + * running, and memory and process management works.
  894. + *
  895. + * Now we can finally start doing some real work..
  896. + */
  897. +static void __init do_basic_setup(void)
  898. +{
  899. + cpuset_init_smp();
  900. + shmem_init();
  901. + driver_init();
  902. + init_irq_proc();
  903. + do_ctors();
  904. + usermodehelper_enable();
  905. + do_initcalls();
  906. + random_int_secret_init();
  907. +}
  908. +
  909. +static void __init do_pre_smp_initcalls(void)
  910. +{
  911. + initcall_t *fn;
  912. +
  913. + for (fn = __initcall_start; fn < __initcall0_start; fn++)
  914. + do_one_initcall(*fn);
  915. +}
  916. +
  917. +/*
  918. + * This function requests modules which should be loaded by default and is
  919. + * called twice right after initrd is mounted and right before init is
  920. + * exec'd. If such modules are on either initrd or rootfs, they will be
  921. + * loaded before control is passed to userland.
  922. + */
  923. +void __init load_default_modules(void)
  924. +{
  925. + load_default_elevator_module();
  926. +}
  927. +
  928. +static int run_init_process(const char *init_filename)
  929. +{
  930. + argv_init[0] = init_filename;
  931. + return do_execve(getname_kernel(init_filename),
  932. + (const char __user *const __user *)argv_init,
  933. + (const char __user *const __user *)envp_init);
  934. +}
  935. +
  936. +static int try_to_run_init_process(const char *init_filename)
  937. +{
  938. + int ret;
  939. +
  940. + ret = run_init_process(init_filename);
  941. +
  942. + if (ret && ret != -ENOENT) {
  943. + pr_err("Starting init: %s exists but couldn't execute it (error %d)\n",
  944. + init_filename, ret);
  945. + }
  946. +
  947. + return ret;
  948. +}
  949. +
  950. +static noinline void __init kernel_init_freeable(void);
  951. +
  952. +#ifdef CONFIG_DEBUG_RODATA
  953. +static bool rodata_enabled = true;
  954. +static int __init set_debug_rodata(char *str)
  955. +{
  956. + return strtobool(str, &rodata_enabled);
  957. +}
  958. +__setup("rodata=", set_debug_rodata);
  959. +
  960. +static void mark_readonly(void)
  961. +{
  962. + if (rodata_enabled)
  963. + mark_rodata_ro();
  964. + else
  965. + pr_info("Kernel memory protection disabled.\n");
  966. +}
  967. +#else
  968. +static inline void mark_readonly(void)
  969. +{
  970. + pr_warn("This architecture does not have kernel memory protection.\n");
  971. +}
  972. +#endif
  973. +
  974. +static int __ref kernel_init(void *unused)
  975. +{
  976. + int ret;
  977. +
  978. + kernel_init_freeable();
  979. + /* need to finish all async __init code before freeing the memory */
  980. + async_synchronize_full();
  981. + free_initmem();
  982. + mark_readonly();
  983. + system_state = SYSTEM_RUNNING;
  984. + numa_default_policy();
  985. +
  986. + flush_delayed_fput();
  987. +
  988. + rcu_end_inkernel_boot();
  989. +
  990. + if (ramdisk_execute_command) {
  991. + ret = run_init_process(ramdisk_execute_command);
  992. + if (!ret)
  993. + return 0;
  994. + pr_err("Failed to execute %s (error %d)\n",
  995. + ramdisk_execute_command, ret);
  996. + }
  997. +
  998. + /*
  999. + * We try each of these until one succeeds.
  1000. + *
  1001. + * The Bourne shell can be used instead of init if we are
  1002. + * trying to recover a really broken machine.
  1003. + */
  1004. + if (execute_command) {
  1005. + ret = run_init_process(execute_command);
  1006. + if (!ret)
  1007. + return 0;
  1008. + panic("Requested init %s failed (error %d).",
  1009. + execute_command, ret);
  1010. + }
  1011. + if (!try_to_run_init_process("/sbin/init") ||
  1012. + !try_to_run_init_process("/etc/init") ||
  1013. + !try_to_run_init_process("/bin/init") ||
  1014. + !try_to_run_init_process("/bin/sh"))
  1015. + return 0;
  1016. +
  1017. + panic("No working init found. Try passing init= option to kernel. "
  1018. + "See Linux Documentation/init.txt for guidance.");
  1019. +}
  1020. +
  1021. +static noinline void __init kernel_init_freeable(void)
  1022. +{
  1023. + /*
  1024. + * Wait until kthreadd is all set-up.
  1025. + */
  1026. + wait_for_completion(&kthreadd_done);
  1027. +
  1028. + /* Now the scheduler is fully set up and can do blocking allocations */
  1029. + gfp_allowed_mask = __GFP_BITS_MASK;
  1030. +
  1031. + /*
  1032. + * init can allocate pages on any node
  1033. + */
  1034. + set_mems_allowed(node_states[N_MEMORY]);
  1035. + /*
  1036. + * init can run on any cpu.
  1037. + */
  1038. + set_cpus_allowed_ptr(current, cpu_all_mask);
  1039. +
  1040. + cad_pid = task_pid(current);
  1041. +
  1042. + smp_prepare_cpus(setup_max_cpus);
  1043. +
  1044. + do_pre_smp_initcalls();
  1045. + lockup_detector_init();
  1046. +
  1047. + smp_init();
  1048. + sched_init_smp();
  1049. +
  1050. + page_alloc_init_late();
  1051. +
  1052. + do_basic_setup();
  1053. +
  1054. + /* Open the /dev/console on the rootfs, this should never fail */
  1055. + if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
  1056. + pr_err("Warning: unable to open an initial console.\n");
  1057. +
  1058. + (void) sys_dup(0);
  1059. + (void) sys_dup(0);
  1060. + /*
  1061. + * check if there is an early userspace init. If yes, let it do all
  1062. + * the work
  1063. + */
  1064. +
  1065. + if (!ramdisk_execute_command)
  1066. + ramdisk_execute_command = "/init";
  1067. +
  1068. + if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
  1069. + ramdisk_execute_command = NULL;
  1070. + prepare_namespace();
  1071. + }
  1072. +
  1073. + /*
  1074. + * Ok, we have completed the initial bootup, and
  1075. + * we're essentially up and running. Get rid of the
  1076. + * initmem segments and start the user-mode stuff..
  1077. + *
  1078. + * rootfs is available now, try loading the public keys
  1079. + * and default modules
  1080. + */
  1081. +
  1082. + integrity_load_keys();
  1083. + load_default_modules();
  1084. +}