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
12 #include <linux/types.h>
13 #include <linux/module.h>
14 #include <linux/proc_fs.h>
15 #include <linux/kernel.h>
16 #include <linux/syscalls.h>
17 #include <linux/string.h>
18 #include <linux/ctype.h>
19 #include <linux/delay.h>
20 #include <linux/utsname.h>
21 #include <linux/ioport.h>
22 #include <linux/init.h>
23 #include <linux/smp_lock.h>
24 #include <linux/initrd.h>
25 #include <linux/hdreg.h>
26 #include <linux/bootmem.h>
27 #include <linux/tty.h>
28 #include <linux/gfp.h>
29 #include <linux/percpu.h>
30 #include <linux/kmod.h>
31 #include <linux/kernel_stat.h>
32 #include <linux/start_kernel.h>
33 #include <linux/security.h>
34 #include <linux/workqueue.h>
35 #include <linux/profile.h>
36 #include <linux/rcupdate.h>
37 #include <linux/posix-timers.h>
38 #include <linux/moduleparam.h>
39 #include <linux/kallsyms.h>
40 #include <linux/writeback.h>
41 #include <linux/cpu.h>
42 #include <linux/cpuset.h>
43 #include <linux/cgroup.h>
44 #include <linux/efi.h>
45 #include <linux/tick.h>
46 #include <linux/interrupt.h>
47 #include <linux/taskstats_kern.h>
48 #include <linux/delayacct.h>
49 #include <linux/unistd.h>
50 #include <linux/rmap.h>
51 #include <linux/irq.h>
52 #include <linux/mempolicy.h>
53 #include <linux/key.h>
54 #include <linux/unwind.h>
55 #include <linux/buffer_head.h>
56 #include <linux/debug_locks.h>
57 #include <linux/lockdep.h>
58 #include <linux/pid_namespace.h>
59 #include <linux/device.h>
60 #include <linux/kthread.h>
61 #include <linux/sched.h>
62 #include <linux/signal.h>
63 #include <linux/ftrace.h>
64
65 #include <asm/io.h>
66 #include <asm/bugs.h>
67 #include <asm/setup.h>
68 #include <asm/sections.h>
69 #include <asm/cacheflush.h>
70
71 #ifdef CONFIG_X86_LOCAL_APIC
72 #include <asm/smp.h>
73 #endif
74
75 /*
76 * This is one of the first .c files built. Error out early if we have compiler
77 * trouble.
78 */
79
80 #if __GNUC__ == 4 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ == 0
81 #warning gcc-4.1.0 is known to miscompile the kernel. A different compiler version is recommended.
82 #endif
83
84 static int kernel_init(void *);
85
86 extern void init_IRQ(void);
87 extern void fork_init(unsigned long);
88 extern void mca_init(void);
89 extern void sbus_init(void);
90 extern void pidhash_init(void);
91 extern void pidmap_init(void);
92 extern void prio_tree_init(void);
93 extern void radix_tree_init(void);
94 extern void free_initmem(void);
95 #ifdef CONFIG_ACPI
96 extern void acpi_early_init(void);
97 #else
98 static inline void acpi_early_init(void) { }
99 #endif
100 #ifndef CONFIG_DEBUG_RODATA
101 static inline void mark_rodata_ro(void) { }
102 #endif
103 #ifdef CONFIG_ALLOC_RTSJ_MEM
104 extern void alloc_rtsj_mem_early_setup(void);
105 #else
106 static inline void alloc_rtsj_mem_early_setup(void) { }
107 #endif
108
109
110 #ifdef CONFIG_TC
111 extern void tc_init(void);
112 #endif
113
114 enum system_states system_state;
115 EXPORT_SYMBOL(system_state);
116
117 /*
118 * Boot command-line arguments
119 */
120 #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
121 #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
122
123 extern void time_init(void);
124 /* Default late time init is NULL. archs can override this later. */
125 void (*late_time_init)(void);
126 extern void softirq_init(void);
127
128 /* Untouched command line saved by arch-specific code. */
129 char __initdata boot_command_line[COMMAND_LINE_SIZE];
130 /* Untouched saved command line (eg. for /proc) */
131 char *saved_command_line;
132 /* Command line for parameter parsing */
133 static char *static_command_line;
134
135 static char *execute_command;
136 static char *ramdisk_execute_command;
137
138 #ifdef CONFIG_SMP
139 /* Setup configured maximum number of CPUs to activate */
140 unsigned int __initdata setup_max_cpus = NR_CPUS;
141
142 /*
143 * Setup routine for controlling SMP activation
144 *
145 * Command-line option of "nosmp" or "maxcpus=0" will disable SMP
146 * activation entirely (the MPS table probe still happens, though).
147 *
148 * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer
149 * greater than 0, limits the maximum number of CPUs activated in
150 * SMP mode to <NUM>.
151 */
152 #ifndef CONFIG_X86_IO_APIC
153 static inline void disable_ioapic_setup(void) {};
154 #endif
155
156 static int __init nosmp(char *str)
157 {
158 setup_max_cpus = 0;
159 disable_ioapic_setup();
160 return 0;
161 }
162
163 early_param("nosmp", nosmp);
164
165 static int __init maxcpus(char *str)
166 {
167 get_option(&str, &setup_max_cpus);
168 if (setup_max_cpus == 0)
169 disable_ioapic_setup();
170
171 return 0;
172 }
173
174 early_param("maxcpus", maxcpus);
175 #else
176 #define setup_max_cpus NR_CPUS
177 #endif
178
179 /*
180 * If set, this is an indication to the drivers that reset the underlying
181 * device before going ahead with the initialization otherwise driver might
182 * rely on the BIOS and skip the reset operation.
183 *
184 * This is useful if kernel is booting in an unreliable environment.
185 * For ex. kdump situaiton where previous kernel has crashed, BIOS has been
186 * skipped and devices will be in unknown state.
187 */
188 unsigned int reset_devices;
189 EXPORT_SYMBOL(reset_devices);
190
191 static int __init set_reset_devices(char *str)
192 {
193 reset_devices = 1;
194 return 1;
195 }
196
197 __setup("reset_devices", set_reset_devices);
198
199 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
200 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
201 static const char *panic_later, *panic_param;
202
203 extern struct obs_kernel_param __setup_start[], __setup_end[];
204
205 static int __init obsolete_checksetup(char *line)
206 {
207 struct obs_kernel_param *p;
208 int had_early_param = 0;
209
210 p = __setup_start;
211 do {
212 int n = strlen(p->str);
213 if (!strncmp(line, p->str, n)) {
214 if (p->early) {
215 /* Already done in parse_early_param?
216 * (Needs exact match on param part).
217 * Keep iterating, as we can have early
218 * params and __setups of same names 8( */
219 if (line[n] == '\0' || line[n] == '=')
220 had_early_param = 1;
221 } else if (!p->setup_func) {
222 printk(KERN_WARNING "Parameter %s is obsolete,"
223 " ignored\n", p->str);
224 return 1;
225 } else if (p->setup_func(line + n))
226 return 1;
227 }
228 p++;
229 } while (p < __setup_end);
230
231 return had_early_param;
232 }
233
234 /*
235 * This should be approx 2 Bo*oMips to start (note initial shift), and will
236 * still work even if initially too large, it will just take slightly longer
237 */
238 unsigned long loops_per_jiffy = (1<<12);
239
240 EXPORT_SYMBOL(loops_per_jiffy);
241
242 static int __init debug_kernel(char *str)
243 {
244 console_loglevel = 10;
245 return 0;
246 }
247
248 static int __init quiet_kernel(char *str)
249 {
250 console_loglevel = 4;
251 return 0;
252 }
253
254 early_param("debug", debug_kernel);
255 early_param("quiet", quiet_kernel);
256
257 static int __init loglevel(char *str)
258 {
259 get_option(&str, &console_loglevel);
260 return 0;
261 }
262
263 early_param("loglevel", loglevel);
264
265 /*
266 * Unknown boot options get handed to init, unless they look like
267 * failed parameters
268 */
269 static int __init unknown_bootoption(char *param, char *val)
270 {
271 /* Change NUL term back to "=", to make "param" the whole string. */
272 if (val) {
273 /* param=val or param="val"? */
274 if (val == param+strlen(param)+1)
275 val[-1] = '=';
276 else if (val == param+strlen(param)+2) {
277 val[-2] = '=';
278 memmove(val-1, val, strlen(val)+1);
279 val--;
280 } else
281 BUG();
282 }
283
284 /* Handle obsolete-style parameters */
285 if (obsolete_checksetup(param))
286 return 0;
287
288 /*
289 * Preemptive maintenance for "why didn't my misspelled command
290 * line work?"
291 */
292 if (strchr(param, '.') && (!val || strchr(param, '.') < val)) {
293 printk(KERN_ERR "Unknown boot option `%s': ignoring\n", param);
294 return 0;
295 }
296
297 if (panic_later)
298 return 0;
299
300 if (val) {
301 /* Environment option */
302 unsigned int i;
303 for (i = 0; envp_init[i]; i++) {
304 if (i == MAX_INIT_ENVS) {
305 panic_later = "Too many boot env vars at `%s'";
306 panic_param = param;
307 }
308 if (!strncmp(param, envp_init[i], val - param))
309 break;
310 }
311 envp_init[i] = param;
312 } else {
313 /* Command line option */
314 unsigned int i;
315 for (i = 0; argv_init[i]; i++) {
316 if (i == MAX_INIT_ARGS) {
317 panic_later = "Too many boot init vars at `%s'";
318 panic_param = param;
319 }
320 }
321 argv_init[i] = param;
322 }
323 return 0;
324 }
325
326 #ifdef CONFIG_DEBUG_PAGEALLOC
327 int __read_mostly debug_pagealloc_enabled = 0;
328 #endif
329
330 static int __init init_setup(char *str)
331 {
332 unsigned int i;
333
334 execute_command = str;
335 /*
336 * In case LILO is going to boot us with default command line,
337 * it prepends "auto" before the whole cmdline which makes
338 * the shell think it should execute a script with such name.
339 * So we ignore all arguments entered _before_ init=... [MJ]
340 */
341 for (i = 1; i < MAX_INIT_ARGS; i++)
342 argv_init[i] = NULL;
343 return 1;
344 }
345 __setup("init=", init_setup);
346
347 static int __init rdinit_setup(char *str)
348 {
349 unsigned int i;
350
351 ramdisk_execute_command = str;
352 /* See "auto" comment in init_setup */
353 for (i = 1; i < MAX_INIT_ARGS; i++)
354 argv_init[i] = NULL;
355 return 1;
356 }
357 __setup("rdinit=", rdinit_setup);
358
359 #ifndef CONFIG_SMP
360
361 #ifdef CONFIG_X86_LOCAL_APIC
362 static void __init smp_init(void)
363 {
364 APIC_init_uniprocessor();
365 }
366 #else
367 #define smp_init() do { } while (0)
368 #endif
369
370 static inline void setup_per_cpu_areas(void) { }
371 static inline void smp_prepare_cpus(unsigned int maxcpus) { }
372
373 #else
374
375 #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
376 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
377
378 EXPORT_SYMBOL(__per_cpu_offset);
379
380 static void __init setup_per_cpu_areas(void)
381 {
382 unsigned long size, i;
383 char *ptr;
384 unsigned long nr_possible_cpus = num_possible_cpus();
385
386 /* Copy section for each CPU (we discard the original) */
387 size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
388 ptr = alloc_bootmem_pages(size * nr_possible_cpus);
389
390 for_each_possible_cpu(i) {
391 __per_cpu_offset[i] = ptr - __per_cpu_start;
392 memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
393 ptr += size;
394 }
395 }
396 #endif /* CONFIG_HAVE_SETUP_PER_CPU_AREA */
397
398 /* Called by boot processor to activate the rest. */
399 static void __init smp_init(void)
400 {
401 unsigned int cpu;
402
403 /* FIXME: This should be done in userspace --RR */
404 for_each_present_cpu(cpu) {
405 if (num_online_cpus() >= setup_max_cpus)
406 break;
407 if (!cpu_online(cpu))
408 cpu_up(cpu);
409 }
410
411 /* Any cleanup work */
412 printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus());
413 smp_cpus_done(setup_max_cpus);
414 }
415
416 #endif
417
418 /*
419 * We need to store the untouched command line for future reference.
420 * We also need to store the touched command line since the parameter
421 * parsing is performed in place, and we should allow a component to
422 * store reference of name/value for future reference.
423 */
424 static void __init setup_command_line(char *command_line)
425 {
426 saved_command_line = alloc_bootmem(strlen (boot_command_line)+1);
427 static_command_line = alloc_bootmem(strlen (command_line)+1);
428 strcpy (saved_command_line, boot_command_line);
429 strcpy (static_command_line, command_line);
430 }
431
432 /*
433 * We need to finalize in a non-__init function or else race conditions
434 * between the root thread and the init thread may cause start_kernel to
435 * be reaped by free_initmem before the root thread has proceeded to
436 * cpu_idle.
437 *
438 * gcc-3.4 accidentally inlines this function, so use noinline.
439 */
440
441 static void noinline __init_refok rest_init(void)
442 __releases(kernel_lock)
443 {
444 int pid;
445
446 system_state = SYSTEM_BOOTING_SCHEDULER_OK;
447
448 kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
449 numa_default_policy();
450 pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
451 kthreadd_task = find_task_by_pid(pid);
452 unlock_kernel();
453
454 /*
455 * The boot idle thread must execute schedule()
456 * at least once to get things moving:
457 */
458 init_idle_bootup_task(current);
459 __preempt_enable_no_resched();
460 schedule();
461 preempt_disable();
462
463 /* Call into cpu_idle with preempt disabled */
464 cpu_idle();
465 }
466
467 /* Check for early params. */
468 static int __init do_early_param(char *param, char *val)
469 {
470 struct obs_kernel_param *p;
471
472 for (p = __setup_start; p < __setup_end; p++) {
473 if ((p->early && strcmp(param, p->str) == 0) ||
474 (strcmp(param, "console") == 0 &&
475 strcmp(p->str, "earlycon") == 0)
476 ) {
477 if (p->setup_func(val) != 0)
478 printk(KERN_WARNING
479 "Malformed early option '%s'\n", param);
480 }
481 }
482 /* We accept everything at this stage. */
483 return 0;
484 }
485
486 /* Arch code calls this early on, or if not, just before other parsing. */
487 void __init parse_early_param(void)
488 {
489 static __initdata int done = 0;
490 static __initdata char tmp_cmdline[COMMAND_LINE_SIZE];
491
492 if (done)
493 return;
494
495 /* All fall through to do_early_param. */
496 strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
497 parse_args("early options", tmp_cmdline, NULL, 0, do_early_param);
498 done = 1;
499 }
500
501 /*
502 * Activate the first processor.
503 */
504
505 static void __init boot_cpu_init(void)
506 {
507 int cpu = smp_processor_id();
508 /* Mark the boot cpu "present", "online" etc for SMP and UP case */
509 cpu_set(cpu, cpu_online_map);
510 cpu_set(cpu, cpu_present_map);
511 cpu_set(cpu, cpu_possible_map);
512 }
513
514 void __init __attribute__((weak)) smp_setup_processor_id(void)
515 {
516 }
517
518 asmlinkage void __init start_kernel(void)
519 {
520 char * command_line;
521 extern struct kernel_param __start___param[], __stop___param[];
522
523 smp_setup_processor_id();
524
525 /*
526 * Need to run as early as possible, to initialize the
527 * lockdep hash:
528 */
529 unwind_init();
530 lockdep_init();
531 cgroup_init_early();
532
533 local_irq_disable();
534 early_boot_irqs_off();
535 early_init_irq_lock_class();
536
537 /*
538 * Interrupts are still disabled. Do necessary setups, then
539 * enable them
540 */
541 lock_kernel();
542 tick_init();
543 boot_cpu_init();
544 page_address_init();
545 printk(KERN_NOTICE);
546 printk(linux_banner);
547 setup_arch(&command_line);
548 setup_command_line(command_line);
549 unwind_setup();
550 setup_per_cpu_areas();
551 smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
552
553 /*
554 * Set up the scheduler prior starting any interrupts (such as the
555 * timer interrupt). Full topology setup happens at smp_init()
556 * time - but meanwhile we still have a functioning scheduler.
557 */
558 sched_init();
559 /*
560 * Disable preemption - early bootup scheduling is extremely
561 * fragile until we cpu_idle() for the first time.
562 */
563 preempt_disable();
564
565 build_all_zonelists();
566 page_alloc_init();
567 early_init_hardirqs();
568 printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);
569 parse_early_param();
570 parse_args("Booting kernel", static_command_line, __start___param,
571 __stop___param - __start___param,
572 &unknown_bootoption);
573 if (!irqs_disabled()) {
574 printk(KERN_WARNING "start_kernel(): bug: interrupts were "
575 "enabled *very* early, fixing it\n");
576 local_irq_disable();
577 }
578 sort_main_extable();
579 trap_init();
580 rcu_init();
581 init_IRQ();
582 pidhash_init();
583 init_timers();
584 hrtimers_init();
585 softirq_init();
586 timekeeping_init();
587 time_init();
588 sched_clock_init();
589 profile_init();
590 if (!irqs_disabled())
591 printk("start_kernel(): bug: interrupts were enabled early\n");
592 early_boot_irqs_on();
593 local_irq_enable();
594
595 /*
596 * HACK ALERT! This is early. We're enabling the console before
597 * we've done PCI setups etc, and console_init() must be aware of
598 * this. But we do want output early, in case something goes wrong.
599 */
600 console_init();
601 if (panic_later)
602 panic(panic_later, panic_param);
603
604 lockdep_info();
605
606 /*
607 * Need to run this when irqs are enabled, because it wants
608 * to self-test [hard/soft]-irqs on/off lock inversion bugs
609 * too:
610 */
611 locking_selftest();
612
613 #ifdef CONFIG_BLK_DEV_INITRD
614 if (initrd_start && !initrd_below_start_ok &&
615 initrd_start < min_low_pfn << PAGE_SHIFT) {
616 printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
617 "disabling it.\n",initrd_start,min_low_pfn << PAGE_SHIFT);
618 initrd_start = 0;
619 }
620 #endif
621 vfs_caches_init_early();
622 cpuset_init_early();
623 alloc_rtsj_mem_early_setup();
624 mem_init();
625 enable_debug_pagealloc();
626 cpu_hotplug_init();
627 kmem_cache_init();
628 setup_per_cpu_pageset();
629 numa_policy_init();
630 if (late_time_init)
631 late_time_init();
632 calibrate_delay();
633 pidmap_init();
634 pgtable_cache_init();
635 prio_tree_init();
636 anon_vma_init();
637 #ifdef CONFIG_X86
638 if (efi_enabled)
639 efi_enter_virtual_mode();
640 #endif
641 fork_init(num_physpages);
642 proc_caches_init();
643 buffer_init();
644 unnamed_dev_init();
645 key_init();
646 security_init();
647 vfs_caches_init(num_physpages);
648 radix_tree_init();
649 signals_init();
650 /* rootfs populating might need page-writeback */
651 page_writeback_init();
652 #ifdef CONFIG_PROC_FS
653 proc_root_init();
654 #endif
655 cgroup_init();
656 cpuset_init();
657 taskstats_init_early();
658 delayacct_init();
659
660 check_bugs();
661
662 acpi_early_init(); /* before LAPIC and SMP init */
663
664 #ifdef CONFIG_PREEMPT_RT
665 WARN_ON(irqs_disabled());
666 #endif
667 /* Do the rest non-__init'ed, we're now alive */
668 rest_init();
669 }
670
671 static int __initdata initcall_debug;
672
673 static int __init initcall_debug_setup(char *str)
674 {
675 initcall_debug = 1;
676 return 1;
677 }
678 __setup("initcall_debug", initcall_debug_setup);
679
680 extern initcall_t __initcall_start[], __initcall_end[];
681
682 static void __init do_initcalls(void)
683 {
684 initcall_t *call;
685 int count = preempt_count();
686
687 for (call = __initcall_start; call < __initcall_end; call++) {
688 ktime_t t0, t1, delta;
689 char *msg = NULL;
690 char msgbuf[40];
691 int result;
692
693 if (initcall_debug) {
694 printk("Calling initcall 0x%p", *call);
695 print_fn_descriptor_symbol(": %s()",
696 (unsigned long) *call);
697 printk("\n");
698 t0 = ktime_get();
699 }
700
701 result = (*call)();
702
703 if (initcall_debug) {
704 t1 = ktime_get();
705 delta = ktime_sub(t1, t0);
706
707 printk("initcall 0x%p", *call);
708 print_fn_descriptor_symbol(": %s()",
709 (unsigned long) *call);
710 printk(" returned %d.\n", result);
711
712 printk("initcall 0x%p ran for %Ld msecs: ",
713 *call, (unsigned long long)delta.tv64 >> 20);
714 print_fn_descriptor_symbol("%s()\n",
715 (unsigned long) *call);
716 }
717
718 if (result && result != -ENODEV && initcall_debug) {
719 sprintf(msgbuf, "error code %d", result);
720 msg = msgbuf;
721 }
722 if (preempt_count() != count) {
723 msg = "preemption imbalance";
724 preempt_count() = count;
725 }
726 if (irqs_disabled()) {
727 msg = "disabled interrupts";
728 local_irq_enable();
729 }
730 if (msg) {
731 printk(KERN_WARNING "initcall at 0x%p", *call);
732 print_fn_descriptor_symbol(": %s()",
733 (unsigned long) *call);
734 printk(": returned with %s\n", msg);
735 }
736 }
737
738 /* Make sure there is no pending stuff from the initcall sequence */
739 flush_scheduled_work();
740 }
741
742 /*
743 * Ok, the machine is now initialized. None of the devices
744 * have been touched yet, but the CPU subsystem is up and
745 * running, and memory and process management works.
746 *
747 * Now we can finally start doing some real work..
748 */
749 static void __init do_basic_setup(void)
750 {
751 /* drivers will send hotplug events */
752 init_workqueues();
753 usermodehelper_init();
754 driver_init();
755 init_irq_proc();
756 do_initcalls();
757 }
758
759 static int __initdata nosoftlockup;
760
761 static int __init nosoftlockup_setup(char *str)
762 {
763 nosoftlockup = 1;
764 return 1;
765 }
766 __setup("nosoftlockup", nosoftlockup_setup);
767
768 static void __init do_pre_smp_initcalls(void)
769 {
770 extern int spawn_ksoftirqd(void);
771 extern int spawn_desched_task(void);
772
773 migration_init();
774 posix_cpu_thread_init();
775 spawn_ksoftirqd();
776 if (!nosoftlockup)
777 spawn_softlockup_task();
778 spawn_desched_task();
779 }
780
781 static void run_init_process(char *init_filename)
782 {
783 argv_init[0] = init_filename;
784 kernel_execve(init_filename, argv_init, envp_init);
785 }
786
787 /* This is a non __init function. Force it to be noinline otherwise gcc
788 * makes it inline to init() and it becomes part of init.text section
789 */
790 static int noinline init_post(void)
791 {
792 free_initmem();
793 unlock_kernel();
794 mark_rodata_ro();
795 system_state = SYSTEM_RUNNING;
796 numa_default_policy();
797
798 if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
799 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
800
801 (void) sys_dup(0);
802 (void) sys_dup(0);
803
804 #ifdef CONFIG_PREEMPT_RT
805 ftrace_disable_daemon();
806 #endif
807 if (ramdisk_execute_command) {
808 run_init_process(ramdisk_execute_command);
809 printk(KERN_WARNING "Failed to execute %s\n",
810 ramdisk_execute_command);
811 }
812 #ifdef CONFIG_PREEMPT_RT
813 WARN_ON(irqs_disabled());
814 #endif
815
816 /*
817 * We try each of these until one succeeds.
818 *
819 * The Bourne shell can be used instead of init if we are
820 * trying to recover a really broken machine.
821 */
822 if (execute_command) {
823 run_init_process(execute_command);
824 printk(KERN_WARNING "Failed to execute %s. Attempting "
825 "defaults...\n", execute_command);
826 }
827 run_init_process("/sbin/init");
828 run_init_process("/etc/init");
829 run_init_process("/bin/init");
830 run_init_process("/bin/sh");
831
832 panic("No init found. Try passing init= option to kernel.");
833 }
834
835 static int __init kernel_init(void * unused)
836 {
837 lock_kernel();
838 /*
839 * init can run on any cpu.
840 */
841 set_cpus_allowed(current, CPU_MASK_ALL);
842 /*
843 * Tell the world that we're going to be the grim
844 * reaper of innocent orphaned children.
845 *
846 * We don't want people to have to make incorrect
847 * assumptions about where in the task array this
848 * can be found.
849 */
850 init_pid_ns.child_reaper = current;
851
852 cad_pid = task_pid(current);
853
854 smp_prepare_cpus(setup_max_cpus);
855
856 init_hardirqs();
857
858 do_pre_smp_initcalls();
859
860 smp_init();
861 sched_init_smp();
862
863 cpuset_init_smp();
864
865 do_basic_setup();
866
867 /*
868 * check if there is an early userspace init. If yes, let it do all
869 * the work
870 */
871
872 if (!ramdisk_execute_command)
873 ramdisk_execute_command = "/init";
874
875 if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
876 ramdisk_execute_command = NULL;
877 prepare_namespace();
878 }
879 #ifdef CONFIG_PREEMPT_RT
880 WARN_ON(irqs_disabled());
881 #endif
882
883 #define DEBUG_COUNT (defined(CONFIG_DEBUG_RT_MUTEXES) + defined(CONFIG_IRQSOFF_TRACER) + defined(CONFIG_PREEMPT_TRACER) + defined(CONFIG_FTRACE) + defined(CONFIG_WAKEUP_LATENCY_HIST) + defined(CONFIG_DEBUG_SLAB) + defined(CONFIG_DEBUG_PAGEALLOC) + defined(CONFIG_LOCKDEP))
884
885 #if DEBUG_COUNT > 0
886 printk(KERN_ERR "*****************************************************************************\n");
887 printk(KERN_ERR "* *\n");
888 #if DEBUG_COUNT == 1
889 printk(KERN_ERR "* REMINDER, the following debugging option is turned on in your .config: *\n");
890 #else
891 printk(KERN_ERR "* REMINDER, the following debugging options are turned on in your .config: *\n");
892 #endif
893 printk(KERN_ERR "* *\n");
894 #ifdef CONFIG_DEBUG_RT_MUTEXES
895 printk(KERN_ERR "* CONFIG_DEBUG_RT_MUTEXES *\n");
896 #endif
897 #ifdef CONFIG_IRQSOFF_TRACER
898 printk(KERN_ERR "* CONFIG_IRQSOFF_TRACER *\n");
899 #endif
900 #ifdef CONFIG_PREEMPT_TRACER
901 printk(KERN_ERR "* CONFIG_PREEMPT_TRACER *\n");
902 #endif
903 #ifdef CONFIG_FTRACE
904 printk(KERN_ERR "* CONFIG_FTRACE *\n");
905 #endif
906 #ifdef CONFIG_WAKEUP_LATENCY_HIST
907 printk(KERN_ERR "* CONFIG_WAKEUP_LATENCY_HIST *\n");
908 #endif
909 #ifdef CONFIG_DEBUG_SLAB
910 printk(KERN_ERR "* CONFIG_DEBUG_SLAB *\n");
911 #endif
912 #ifdef CONFIG_DEBUG_PAGEALLOC
913 printk(KERN_ERR "* CONFIG_DEBUG_PAGEALLOC *\n");
914 #endif
915 #ifdef CONFIG_LOCKDEP
916 printk(KERN_ERR "* CONFIG_LOCKDEP *\n");
917 #endif
918 printk(KERN_ERR "* *\n");
919 #if DEBUG_COUNT == 1
920 printk(KERN_ERR "* it may increase runtime overhead and latencies. *\n");
921 #else
922 printk(KERN_ERR "* they may increase runtime overhead and latencies. *\n");
923 #endif
924 printk(KERN_ERR "* *\n");
925 printk(KERN_ERR "*****************************************************************************\n");
926 #endif
927 /*
928 * Ok, we have completed the initial bootup, and
929 * we're essentially up and running. Get rid of the
930 * initmem segments and start the user-mode stuff..
931 */
932 init_post();
933 WARN_ON(debug_direct_keyboard);
934
935 return 0;
936 }
937
|
This page was automatically generated by the
LXR engine.
|