main.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. /*
  2. * linux/init/main.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * GK 2/5/95 - Changed to support mounting root fs via NFS
  7. * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96
  8. * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96
  9. * Simplified starting of init: Michael A. Griffith <grif@acm.org>
  10. */
  11. #include <linux/types.h>
  12. #include <linux/module.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/kernel.h>
  15. #include <linux/syscalls.h>
  16. #include <linux/string.h>
  17. #include <linux/ctype.h>
  18. #include <linux/delay.h>
  19. #include <linux/utsname.h>
  20. #include <linux/ioport.h>
  21. #include <linux/init.h>
  22. #include <linux/smp_lock.h>
  23. #include <linux/initrd.h>
  24. #include <linux/hdreg.h>
  25. #include <linux/bootmem.h>
  26. #include <linux/tty.h>
  27. #include <linux/gfp.h>
  28. #include <linux/percpu.h>
  29. #include <linux/kmod.h>
  30. #include <linux/kernel_stat.h>
  31. #include <linux/start_kernel.h>
  32. #include <linux/security.h>
  33. #include <linux/workqueue.h>
  34. #include <linux/profile.h>
  35. #include <linux/rcupdate.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/kallsyms.h>
  38. #include <linux/writeback.h>
  39. #include <linux/cpu.h>
  40. #include <linux/cpuset.h>
  41. #include <linux/efi.h>
  42. #include <linux/taskstats_kern.h>
  43. #include <linux/delayacct.h>
  44. #include <linux/unistd.h>
  45. #include <linux/rmap.h>
  46. #include <linux/mempolicy.h>
  47. #include <linux/key.h>
  48. #include <linux/unwind.h>
  49. #include <linux/buffer_head.h>
  50. #include <linux/debug_locks.h>
  51. #include <linux/lockdep.h>
  52. #include <linux/pid_namespace.h>
  53. #include <linux/device.h>
  54. #include <asm/io.h>
  55. #include <asm/bugs.h>
  56. #include <asm/setup.h>
  57. #include <asm/sections.h>
  58. #include <asm/cacheflush.h>
  59. #ifdef CONFIG_X86_LOCAL_APIC
  60. #include <asm/smp.h>
  61. #endif
  62. /*
  63. * This is one of the first .c files built. Error out early if we have compiler
  64. * trouble.
  65. *
  66. * Versions of gcc older than that listed below may actually compile and link
  67. * okay, but the end product can have subtle run time bugs. To avoid associated
  68. * bogus bug reports, we flatly refuse to compile with a gcc that is known to be
  69. * too old from the very beginning.
  70. */
  71. #if (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 2)
  72. #error Sorry, your GCC is too old. It builds incorrect kernels.
  73. #endif
  74. #if __GNUC__ == 4 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ == 0
  75. #warning gcc-4.1.0 is known to miscompile the kernel. A different compiler version is recommended.
  76. #endif
  77. static int init(void *);
  78. extern void init_IRQ(void);
  79. extern void fork_init(unsigned long);
  80. extern void mca_init(void);
  81. extern void sbus_init(void);
  82. extern void sysctl_init(void);
  83. extern void signals_init(void);
  84. extern void pidhash_init(void);
  85. extern void pidmap_init(void);
  86. extern void prio_tree_init(void);
  87. extern void radix_tree_init(void);
  88. extern void free_initmem(void);
  89. extern void prepare_namespace(void);
  90. #ifdef CONFIG_ACPI
  91. extern void acpi_early_init(void);
  92. #else
  93. static inline void acpi_early_init(void) { }
  94. #endif
  95. #ifndef CONFIG_DEBUG_RODATA
  96. static inline void mark_rodata_ro(void) { }
  97. #endif
  98. #ifdef CONFIG_TC
  99. extern void tc_init(void);
  100. #endif
  101. enum system_states system_state;
  102. EXPORT_SYMBOL(system_state);
  103. /*
  104. * Boot command-line arguments
  105. */
  106. #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
  107. #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
  108. extern void time_init(void);
  109. /* Default late time init is NULL. archs can override this later. */
  110. void (*late_time_init)(void);
  111. extern void softirq_init(void);
  112. /* Untouched command line (eg. for /proc) saved by arch-specific code. */
  113. char saved_command_line[COMMAND_LINE_SIZE];
  114. static char *execute_command;
  115. static char *ramdisk_execute_command;
  116. /* Setup configured maximum number of CPUs to activate */
  117. static unsigned int max_cpus = NR_CPUS;
  118. /*
  119. * If set, this is an indication to the drivers that reset the underlying
  120. * device before going ahead with the initialization otherwise driver might
  121. * rely on the BIOS and skip the reset operation.
  122. *
  123. * This is useful if kernel is booting in an unreliable environment.
  124. * For ex. kdump situaiton where previous kernel has crashed, BIOS has been
  125. * skipped and devices will be in unknown state.
  126. */
  127. unsigned int reset_devices;
  128. EXPORT_SYMBOL(reset_devices);
  129. /*
  130. * Setup routine for controlling SMP activation
  131. *
  132. * Command-line option of "nosmp" or "maxcpus=0" will disable SMP
  133. * activation entirely (the MPS table probe still happens, though).
  134. *
  135. * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer
  136. * greater than 0, limits the maximum number of CPUs activated in
  137. * SMP mode to <NUM>.
  138. */
  139. static int __init nosmp(char *str)
  140. {
  141. max_cpus = 0;
  142. return 1;
  143. }
  144. __setup("nosmp", nosmp);
  145. static int __init maxcpus(char *str)
  146. {
  147. get_option(&str, &max_cpus);
  148. return 1;
  149. }
  150. __setup("maxcpus=", maxcpus);
  151. static int __init set_reset_devices(char *str)
  152. {
  153. reset_devices = 1;
  154. return 1;
  155. }
  156. __setup("reset_devices", set_reset_devices);
  157. static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
  158. char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
  159. static const char *panic_later, *panic_param;
  160. extern struct obs_kernel_param __setup_start[], __setup_end[];
  161. static int __init obsolete_checksetup(char *line)
  162. {
  163. struct obs_kernel_param *p;
  164. int had_early_param = 0;
  165. p = __setup_start;
  166. do {
  167. int n = strlen(p->str);
  168. if (!strncmp(line, p->str, n)) {
  169. if (p->early) {
  170. /* Already done in parse_early_param?
  171. * (Needs exact match on param part).
  172. * Keep iterating, as we can have early
  173. * params and __setups of same names 8( */
  174. if (line[n] == '\0' || line[n] == '=')
  175. had_early_param = 1;
  176. } else if (!p->setup_func) {
  177. printk(KERN_WARNING "Parameter %s is obsolete,"
  178. " ignored\n", p->str);
  179. return 1;
  180. } else if (p->setup_func(line + n))
  181. return 1;
  182. }
  183. p++;
  184. } while (p < __setup_end);
  185. return had_early_param;
  186. }
  187. /*
  188. * This should be approx 2 Bo*oMips to start (note initial shift), and will
  189. * still work even if initially too large, it will just take slightly longer
  190. */
  191. unsigned long loops_per_jiffy = (1<<12);
  192. EXPORT_SYMBOL(loops_per_jiffy);
  193. static int __init debug_kernel(char *str)
  194. {
  195. if (*str)
  196. return 0;
  197. console_loglevel = 10;
  198. return 1;
  199. }
  200. static int __init quiet_kernel(char *str)
  201. {
  202. if (*str)
  203. return 0;
  204. console_loglevel = 4;
  205. return 1;
  206. }
  207. __setup("debug", debug_kernel);
  208. __setup("quiet", quiet_kernel);
  209. static int __init loglevel(char *str)
  210. {
  211. get_option(&str, &console_loglevel);
  212. return 1;
  213. }
  214. __setup("loglevel=", loglevel);
  215. /*
  216. * Unknown boot options get handed to init, unless they look like
  217. * failed parameters
  218. */
  219. static int __init unknown_bootoption(char *param, char *val)
  220. {
  221. /* Change NUL term back to "=", to make "param" the whole string. */
  222. if (val) {
  223. /* param=val or param="val"? */
  224. if (val == param+strlen(param)+1)
  225. val[-1] = '=';
  226. else if (val == param+strlen(param)+2) {
  227. val[-2] = '=';
  228. memmove(val-1, val, strlen(val)+1);
  229. val--;
  230. } else
  231. BUG();
  232. }
  233. /* Handle obsolete-style parameters */
  234. if (obsolete_checksetup(param))
  235. return 0;
  236. /*
  237. * Preemptive maintenance for "why didn't my mispelled command
  238. * line work?"
  239. */
  240. if (strchr(param, '.') && (!val || strchr(param, '.') < val)) {
  241. printk(KERN_ERR "Unknown boot option `%s': ignoring\n", param);
  242. return 0;
  243. }
  244. if (panic_later)
  245. return 0;
  246. if (val) {
  247. /* Environment option */
  248. unsigned int i;
  249. for (i = 0; envp_init[i]; i++) {
  250. if (i == MAX_INIT_ENVS) {
  251. panic_later = "Too many boot env vars at `%s'";
  252. panic_param = param;
  253. }
  254. if (!strncmp(param, envp_init[i], val - param))
  255. break;
  256. }
  257. envp_init[i] = param;
  258. } else {
  259. /* Command line option */
  260. unsigned int i;
  261. for (i = 0; argv_init[i]; i++) {
  262. if (i == MAX_INIT_ARGS) {
  263. panic_later = "Too many boot init vars at `%s'";
  264. panic_param = param;
  265. }
  266. }
  267. argv_init[i] = param;
  268. }
  269. return 0;
  270. }
  271. static int __init init_setup(char *str)
  272. {
  273. unsigned int i;
  274. execute_command = str;
  275. /*
  276. * In case LILO is going to boot us with default command line,
  277. * it prepends "auto" before the whole cmdline which makes
  278. * the shell think it should execute a script with such name.
  279. * So we ignore all arguments entered _before_ init=... [MJ]
  280. */
  281. for (i = 1; i < MAX_INIT_ARGS; i++)
  282. argv_init[i] = NULL;
  283. return 1;
  284. }
  285. __setup("init=", init_setup);
  286. static int __init rdinit_setup(char *str)
  287. {
  288. unsigned int i;
  289. ramdisk_execute_command = str;
  290. /* See "auto" comment in init_setup */
  291. for (i = 1; i < MAX_INIT_ARGS; i++)
  292. argv_init[i] = NULL;
  293. return 1;
  294. }
  295. __setup("rdinit=", rdinit_setup);
  296. #ifndef CONFIG_SMP
  297. #ifdef CONFIG_X86_LOCAL_APIC
  298. static void __init smp_init(void)
  299. {
  300. APIC_init_uniprocessor();
  301. }
  302. #else
  303. #define smp_init() do { } while (0)
  304. #endif
  305. static inline void setup_per_cpu_areas(void) { }
  306. static inline void smp_prepare_cpus(unsigned int maxcpus) { }
  307. #else
  308. #ifdef __GENERIC_PER_CPU
  309. unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
  310. EXPORT_SYMBOL(__per_cpu_offset);
  311. static void __init setup_per_cpu_areas(void)
  312. {
  313. unsigned long size, i;
  314. char *ptr;
  315. unsigned long nr_possible_cpus = num_possible_cpus();
  316. /* Copy section for each CPU (we discard the original) */
  317. size = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES);
  318. #ifdef CONFIG_MODULES
  319. if (size < PERCPU_ENOUGH_ROOM)
  320. size = PERCPU_ENOUGH_ROOM;
  321. #endif
  322. ptr = alloc_bootmem(size * nr_possible_cpus);
  323. for_each_possible_cpu(i) {
  324. __per_cpu_offset[i] = ptr - __per_cpu_start;
  325. memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
  326. ptr += size;
  327. }
  328. }
  329. #endif /* !__GENERIC_PER_CPU */
  330. /* Called by boot processor to activate the rest. */
  331. static void __init smp_init(void)
  332. {
  333. unsigned int i;
  334. /* FIXME: This should be done in userspace --RR */
  335. for_each_present_cpu(i) {
  336. if (num_online_cpus() >= max_cpus)
  337. break;
  338. if (!cpu_online(i))
  339. cpu_up(i);
  340. }
  341. /* Any cleanup work */
  342. printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus());
  343. smp_cpus_done(max_cpus);
  344. #if 0
  345. /* Get other processors into their bootup holding patterns. */
  346. smp_commence();
  347. #endif
  348. }
  349. #endif
  350. /*
  351. * We need to finalize in a non-__init function or else race conditions
  352. * between the root thread and the init thread may cause start_kernel to
  353. * be reaped by free_initmem before the root thread has proceeded to
  354. * cpu_idle.
  355. *
  356. * gcc-3.4 accidentally inlines this function, so use noinline.
  357. */
  358. static void noinline rest_init(void)
  359. __releases(kernel_lock)
  360. {
  361. kernel_thread(init, NULL, CLONE_FS | CLONE_SIGHAND);
  362. numa_default_policy();
  363. unlock_kernel();
  364. /*
  365. * The boot idle thread must execute schedule()
  366. * at least one to get things moving:
  367. */
  368. preempt_enable_no_resched();
  369. schedule();
  370. preempt_disable();
  371. /* Call into cpu_idle with preempt disabled */
  372. cpu_idle();
  373. }
  374. /* Check for early params. */
  375. static int __init do_early_param(char *param, char *val)
  376. {
  377. struct obs_kernel_param *p;
  378. for (p = __setup_start; p < __setup_end; p++) {
  379. if (p->early && strcmp(param, p->str) == 0) {
  380. if (p->setup_func(val) != 0)
  381. printk(KERN_WARNING
  382. "Malformed early option '%s'\n", param);
  383. }
  384. }
  385. /* We accept everything at this stage. */
  386. return 0;
  387. }
  388. /* Arch code calls this early on, or if not, just before other parsing. */
  389. void __init parse_early_param(void)
  390. {
  391. static __initdata int done = 0;
  392. static __initdata char tmp_cmdline[COMMAND_LINE_SIZE];
  393. if (done)
  394. return;
  395. /* All fall through to do_early_param. */
  396. strlcpy(tmp_cmdline, saved_command_line, COMMAND_LINE_SIZE);
  397. parse_args("early options", tmp_cmdline, NULL, 0, do_early_param);
  398. done = 1;
  399. }
  400. /*
  401. * Activate the first processor.
  402. */
  403. static void __init boot_cpu_init(void)
  404. {
  405. int cpu = smp_processor_id();
  406. /* Mark the boot cpu "present", "online" etc for SMP and UP case */
  407. cpu_set(cpu, cpu_online_map);
  408. cpu_set(cpu, cpu_present_map);
  409. cpu_set(cpu, cpu_possible_map);
  410. }
  411. void __init __attribute__((weak)) smp_setup_processor_id(void)
  412. {
  413. }
  414. asmlinkage void __init start_kernel(void)
  415. {
  416. char * command_line;
  417. extern struct kernel_param __start___param[], __stop___param[];
  418. smp_setup_processor_id();
  419. /*
  420. * Need to run as early as possible, to initialize the
  421. * lockdep hash:
  422. */
  423. unwind_init();
  424. lockdep_init();
  425. local_irq_disable();
  426. early_boot_irqs_off();
  427. early_init_irq_lock_class();
  428. /*
  429. * Interrupts are still disabled. Do necessary setups, then
  430. * enable them
  431. */
  432. lock_kernel();
  433. boot_cpu_init();
  434. page_address_init();
  435. printk(KERN_NOTICE);
  436. printk(linux_banner);
  437. setup_arch(&command_line);
  438. unwind_setup();
  439. setup_per_cpu_areas();
  440. smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
  441. /*
  442. * Set up the scheduler prior starting any interrupts (such as the
  443. * timer interrupt). Full topology setup happens at smp_init()
  444. * time - but meanwhile we still have a functioning scheduler.
  445. */
  446. sched_init();
  447. /*
  448. * Disable preemption - early bootup scheduling is extremely
  449. * fragile until we cpu_idle() for the first time.
  450. */
  451. preempt_disable();
  452. build_all_zonelists();
  453. page_alloc_init();
  454. printk(KERN_NOTICE "Kernel command line: %s\n", saved_command_line);
  455. parse_early_param();
  456. parse_args("Booting kernel", command_line, __start___param,
  457. __stop___param - __start___param,
  458. &unknown_bootoption);
  459. if (!irqs_disabled()) {
  460. printk(KERN_WARNING "start_kernel(): bug: interrupts were "
  461. "enabled *very* early, fixing it\n");
  462. local_irq_disable();
  463. }
  464. sort_main_extable();
  465. trap_init();
  466. rcu_init();
  467. init_IRQ();
  468. pidhash_init();
  469. init_timers();
  470. hrtimers_init();
  471. softirq_init();
  472. timekeeping_init();
  473. time_init();
  474. profile_init();
  475. if (!irqs_disabled())
  476. printk("start_kernel(): bug: interrupts were enabled early\n");
  477. early_boot_irqs_on();
  478. local_irq_enable();
  479. /*
  480. * HACK ALERT! This is early. We're enabling the console before
  481. * we've done PCI setups etc, and console_init() must be aware of
  482. * this. But we do want output early, in case something goes wrong.
  483. */
  484. console_init();
  485. if (panic_later)
  486. panic(panic_later, panic_param);
  487. lockdep_info();
  488. /*
  489. * Need to run this when irqs are enabled, because it wants
  490. * to self-test [hard/soft]-irqs on/off lock inversion bugs
  491. * too:
  492. */
  493. locking_selftest();
  494. #ifdef CONFIG_BLK_DEV_INITRD
  495. if (initrd_start && !initrd_below_start_ok &&
  496. initrd_start < min_low_pfn << PAGE_SHIFT) {
  497. printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
  498. "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
  499. initrd_start = 0;
  500. }
  501. #endif
  502. vfs_caches_init_early();
  503. cpuset_init_early();
  504. mem_init();
  505. kmem_cache_init();
  506. setup_per_cpu_pageset();
  507. numa_policy_init();
  508. if (late_time_init)
  509. late_time_init();
  510. calibrate_delay();
  511. pidmap_init();
  512. pgtable_cache_init();
  513. prio_tree_init();
  514. anon_vma_init();
  515. #ifdef CONFIG_X86
  516. if (efi_enabled)
  517. efi_enter_virtual_mode();
  518. #endif
  519. fork_init(num_physpages);
  520. proc_caches_init();
  521. buffer_init();
  522. unnamed_dev_init();
  523. key_init();
  524. security_init();
  525. vfs_caches_init(num_physpages);
  526. radix_tree_init();
  527. signals_init();
  528. /* rootfs populating might need page-writeback */
  529. page_writeback_init();
  530. #ifdef CONFIG_PROC_FS
  531. proc_root_init();
  532. #endif
  533. cpuset_init();
  534. taskstats_init_early();
  535. delayacct_init();
  536. check_bugs();
  537. acpi_early_init(); /* before LAPIC and SMP init */
  538. /* Do the rest non-__init'ed, we're now alive */
  539. rest_init();
  540. }
  541. static int __initdata initcall_debug;
  542. static int __init initcall_debug_setup(char *str)
  543. {
  544. initcall_debug = 1;
  545. return 1;
  546. }
  547. __setup("initcall_debug", initcall_debug_setup);
  548. extern initcall_t __initcall_start[], __initcall_end[];
  549. static void __init do_initcalls(void)
  550. {
  551. initcall_t *call;
  552. int count = preempt_count();
  553. for (call = __initcall_start; call < __initcall_end; call++) {
  554. char *msg = NULL;
  555. char msgbuf[40];
  556. int result;
  557. if (initcall_debug) {
  558. printk("Calling initcall 0x%p", *call);
  559. print_fn_descriptor_symbol(": %s()",
  560. (unsigned long) *call);
  561. printk("\n");
  562. }
  563. result = (*call)();
  564. if (result && result != -ENODEV && initcall_debug) {
  565. sprintf(msgbuf, "error code %d", result);
  566. msg = msgbuf;
  567. }
  568. if (preempt_count() != count) {
  569. msg = "preemption imbalance";
  570. preempt_count() = count;
  571. }
  572. if (irqs_disabled()) {
  573. msg = "disabled interrupts";
  574. local_irq_enable();
  575. }
  576. if (msg) {
  577. printk(KERN_WARNING "initcall at 0x%p", *call);
  578. print_fn_descriptor_symbol(": %s()",
  579. (unsigned long) *call);
  580. printk(": returned with %s\n", msg);
  581. }
  582. }
  583. /* Make sure there is no pending stuff from the initcall sequence */
  584. flush_scheduled_work();
  585. }
  586. /*
  587. * Ok, the machine is now initialized. None of the devices
  588. * have been touched yet, but the CPU subsystem is up and
  589. * running, and memory and process management works.
  590. *
  591. * Now we can finally start doing some real work..
  592. */
  593. static void __init do_basic_setup(void)
  594. {
  595. /* drivers will send hotplug events */
  596. init_workqueues();
  597. usermodehelper_init();
  598. driver_init();
  599. #ifdef CONFIG_SYSCTL
  600. sysctl_init();
  601. #endif
  602. do_initcalls();
  603. }
  604. static void __init do_pre_smp_initcalls(void)
  605. {
  606. extern int spawn_ksoftirqd(void);
  607. #ifdef CONFIG_SMP
  608. extern int migration_init(void);
  609. migration_init();
  610. #endif
  611. spawn_ksoftirqd();
  612. spawn_softlockup_task();
  613. }
  614. static void run_init_process(char *init_filename)
  615. {
  616. argv_init[0] = init_filename;
  617. kernel_execve(init_filename, argv_init, envp_init);
  618. }
  619. static int init(void * unused)
  620. {
  621. lock_kernel();
  622. /*
  623. * init can run on any cpu.
  624. */
  625. set_cpus_allowed(current, CPU_MASK_ALL);
  626. /*
  627. * Tell the world that we're going to be the grim
  628. * reaper of innocent orphaned children.
  629. *
  630. * We don't want people to have to make incorrect
  631. * assumptions about where in the task array this
  632. * can be found.
  633. */
  634. init_pid_ns.child_reaper = current;
  635. cad_pid = task_pid(current);
  636. smp_prepare_cpus(max_cpus);
  637. do_pre_smp_initcalls();
  638. smp_init();
  639. sched_init_smp();
  640. cpuset_init_smp();
  641. do_basic_setup();
  642. /*
  643. * check if there is an early userspace init. If yes, let it do all
  644. * the work
  645. */
  646. if (!ramdisk_execute_command)
  647. ramdisk_execute_command = "/init";
  648. if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
  649. ramdisk_execute_command = NULL;
  650. prepare_namespace();
  651. }
  652. /*
  653. * Ok, we have completed the initial bootup, and
  654. * we're essentially up and running. Get rid of the
  655. * initmem segments and start the user-mode stuff..
  656. */
  657. free_initmem();
  658. unlock_kernel();
  659. mark_rodata_ro();
  660. system_state = SYSTEM_RUNNING;
  661. numa_default_policy();
  662. if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
  663. printk(KERN_WARNING "Warning: unable to open an initial console.\n");
  664. (void) sys_dup(0);
  665. (void) sys_dup(0);
  666. if (ramdisk_execute_command) {
  667. run_init_process(ramdisk_execute_command);
  668. printk(KERN_WARNING "Failed to execute %s\n",
  669. ramdisk_execute_command);
  670. }
  671. /*
  672. * We try each of these until one succeeds.
  673. *
  674. * The Bourne shell can be used instead of init if we are
  675. * trying to recover a really broken machine.
  676. */
  677. if (execute_command) {
  678. run_init_process(execute_command);
  679. printk(KERN_WARNING "Failed to execute %s. Attempting "
  680. "defaults...\n", execute_command);
  681. }
  682. run_init_process("/sbin/init");
  683. run_init_process("/etc/init");
  684. run_init_process("/bin/init");
  685. run_init_process("/bin/sh");
  686. panic("No init found. Try passing init= option to kernel.");
  687. }