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/stackprotector.h>
18 #include <linux/string.h>
19 #include <linux/ctype.h>
20 #include <linux/delay.h>
21 #include <linux/ioport.h>
22 #include <linux/init.h>
23 #include <linux/initrd.h>
24 #include <linux/bootmem.h>
25 #include <linux/acpi.h>
26 #include <linux/tty.h>
27 #include <linux/percpu.h>
28 #include <linux/kmod.h>
29 #include <linux/vmalloc.h>
30 #include <linux/kernel_stat.h>
31 #include <linux/start_kernel.h>
32 #include <linux/security.h>
33 #include <linux/smp.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/cgroup.h>
42 #include <linux/efi.h>
43 #include <linux/tick.h>
44 #include <linux/interrupt.h>
45 #include <linux/taskstats_kern.h>
46 #include <linux/delayacct.h>
47 #include <linux/unistd.h>
48 #include <linux/rmap.h>
49 #include <linux/mempolicy.h>
50 #include <linux/key.h>
51 #include <linux/buffer_head.h>
52 #include <linux/page_cgroup.h>
53 #include <linux/debug_locks.h>
54 #include <linux/debugobjects.h>
55 #include <linux/lockdep.h>
56 #include <linux/kmemleak.h>
57 #include <linux/pid_namespace.h>
58 #include <linux/device.h>
59 #include <linux/kthread.h>
60 #include <linux/sched.h>
61 #include <linux/signal.h>
62 #include <linux/idr.h>
63 #include <linux/kgdb.h>
64 #include <linux/ftrace.h>
65 #include <linux/async.h>
66 #include <linux/kmemcheck.h>
67 #include <linux/sfi.h>
68 #include <linux/shmem_fs.h>
69 #include <linux/slab.h>
70 #include <linux/perf_event.h>
71 #include <linux/file.h>
72 #include <linux/ptrace.h>
81 #include <asm/setup.h>
82 #include <asm/sections.h>
83 #include <asm/cacheflush.h>
84 #include <linux/virgo_config.h>
87 int num_cloud_nodes=2;
88 EXPORT_SYMBOL(num_cloud_nodes);
90 char* node_ip_addrs_in_cloud[3000]={
"127.0.0.1",
"127.0.0.1",NULL,};
91 EXPORT_SYMBOL(node_ip_addrs_in_cloud);
95 #ifdef CONFIG_X86_LOCAL_APIC
99 void do_virgo_cloud_init(
void);
101 void read_virgo_clone_config(
void);
103 static int kernel_init(
void *);
105 extern void init_IRQ(
void);
106 extern void fork_init(
unsigned long);
107 extern void mca_init(
void);
108 extern void sbus_init(
void);
109 extern void radix_tree_init(
void);
110 #ifndef CONFIG_DEBUG_RODATA
111 static inline void mark_rodata_ro(
void) { }
115 extern void tc_init(
void);
125 bool early_boot_irqs_disabled __read_mostly;
127 enum system_states system_state __read_mostly;
128 EXPORT_SYMBOL(system_state);
133 #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
134 #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
136 extern void time_init(
void);
138 void (*__initdata late_time_init)(void);
139 extern void softirq_init(
void);
142 char __initdata boot_command_line[COMMAND_LINE_SIZE];
144 char *saved_command_line;
146 static char *static_command_line;
148 static char *execute_command;
149 static char *ramdisk_execute_command;
160 unsigned int reset_devices;
161 EXPORT_SYMBOL(reset_devices);
163 static int __init set_reset_devices(
char *str)
169 __setup(
"reset_devices", set_reset_devices);
171 static const char * argv_init[MAX_INIT_ARGS+2] = {
"init", NULL, };
172 const char * envp_init[MAX_INIT_ENVS+2] = {
"HOME=/",
"TERM=linux", NULL, };
173 static const char *panic_later, *panic_param;
177 static int __init obsolete_checksetup(
char *line)
180 int had_early_param = 0;
184 int n = strlen(p->str);
185 if (parameqn(line, p->str, n)) {
191 if (line[n] ==
'\0' || line[n] ==
'=')
193 }
else if (!p->setup_func) {
194 printk(KERN_WARNING
"Parameter %s is obsolete,"
195 " ignored\n", p->str);
197 }
else if (p->setup_func(line + n))
201 }
while (p < __setup_end);
203 return had_early_param;
210 unsigned long loops_per_jiffy = (1<<12);
212 EXPORT_SYMBOL(loops_per_jiffy);
214 static int __init debug_kernel(
char *str)
216 console_loglevel = 10;
220 static int __init quiet_kernel(
char *str)
222 console_loglevel = 4;
226 early_param(
"debug", debug_kernel);
227 early_param(
"quiet", quiet_kernel);
229 static int __init loglevel(
char *str)
238 if (get_option(&str, &newlevel)) {
239 console_loglevel = newlevel;
246 early_param(
"loglevel", loglevel);
249 static int __init repair_env_string(
char *param,
char *val,
const char *unused)
253 if (val == param+strlen(param)+1)
255 else if (val == param+strlen(param)+2) {
257 memmove(val-1, val, strlen(val)+1);
269 static int __init unknown_bootoption(
char *param,
char *val,
const char *unused)
271 repair_env_string(param, val, unused);
274 if (obsolete_checksetup(param))
278 if (strchr(param,
'.') && (!val || strchr(param,
'.') < val))
287 for (i = 0; envp_init[i]; i++) {
288 if (i == MAX_INIT_ENVS) {
289 panic_later =
"Too many boot env vars at `%s'";
292 if (!strncmp(param, envp_init[i], val - param))
295 envp_init[i] = param;
299 for (i = 0; argv_init[i]; i++) {
300 if (i == MAX_INIT_ARGS) {
301 panic_later =
"Too many boot init vars at `%s'";
305 argv_init[i] = param;
310 static int __init init_setup(
char *str)
314 execute_command = str;
321 for (i = 1; i < MAX_INIT_ARGS; i++)
325 __setup(
"init=", init_setup);
327 static int __init rdinit_setup(
char *str)
331 ramdisk_execute_command = str;
333 for (i = 1; i < MAX_INIT_ARGS; i++)
337 __setup(
"rdinit=", rdinit_setup);
340 static const unsigned int setup_max_cpus = NR_CPUS;
341 #ifdef CONFIG_X86_LOCAL_APIC
342 static void __init smp_init(
void)
344 APIC_init_uniprocessor();
347 #define smp_init() do { } while (0)
350 static inline void setup_nr_cpu_ids(
void) { }
351 static inline void smp_prepare_cpus(
unsigned int maxcpus) { }
360 static void __init setup_command_line(
char *command_line)
362 saved_command_line = alloc_bootmem(strlen (boot_command_line)+1);
363 static_command_line = alloc_bootmem(strlen (command_line)+1);
364 strcpy (saved_command_line, boot_command_line);
365 strcpy (static_command_line, command_line);
377 static __initdata DECLARE_COMPLETION(kthreadd_done);
379 static noinline
void __init_refok rest_init(
void)
383 rcu_scheduler_starting();
389 kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
390 numa_default_policy();
391 pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
393 kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
395 complete(&kthreadd_done);
401 init_idle_bootup_task(current);
402 schedule_preempt_disabled();
408 static int __init do_early_param(
char *param,
char *val,
const char *unused)
412 for (p = __setup_start; p < __setup_end; p++) {
413 if ((p->early && parameq(param, p->str)) ||
414 (strcmp(param,
"console") == 0 &&
415 strcmp(p->str,
"earlycon") == 0)
417 if (p->setup_func(val) != 0)
419 "Malformed early option '%s'\n", param);
426 void __init parse_early_options(
char *cmdline)
428 parse_args(
"early options", cmdline, NULL, 0, 0, 0, do_early_param);
432 void __init parse_early_param(
void)
434 static __initdata
int done = 0;
435 static __initdata
char tmp_cmdline[COMMAND_LINE_SIZE];
441 strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
442 parse_early_options(tmp_cmdline);
450 static void __init boot_cpu_init(
void)
452 int cpu = smp_processor_id();
454 set_cpu_online(cpu,
true);
455 set_cpu_active(cpu,
true);
456 set_cpu_present(cpu,
true);
457 set_cpu_possible(cpu,
true);
460 void __init __weak smp_setup_processor_id(
void)
464 # if THREAD_SIZE >= PAGE_SIZE
465 void __init __weak thread_info_cache_init(
void)
473 static void __init mm_init(
void)
479 page_cgroup_init_flatmem();
483 pgtable_cache_init();
487 asmlinkage
void __init start_kernel(
void)
490 extern const struct kernel_param __start___param[], __stop___param[];
497 smp_setup_processor_id();
498 debug_objects_early_init();
503 boot_init_stack_canary();
508 early_boot_irqs_disabled =
true;
517 printk(KERN_NOTICE
"%s", linux_banner);
518 setup_arch(&command_line);
519 mm_init_owner(&init_mm, &init_task);
520 mm_init_cpumask(&init_mm);
521 setup_command_line(command_line);
523 setup_per_cpu_areas();
524 smp_prepare_boot_cpu();
526 build_all_zonelists(NULL, NULL);
529 printk(KERN_NOTICE
"Kernel command line: %s\n", boot_command_line);
531 parse_args(
"Booting kernel", static_command_line, __start___param,
532 __stop___param - __start___param,
533 -1, -1, &unknown_bootoption);
543 vfs_caches_init_early();
559 if (!irqs_disabled()) {
560 printk(KERN_WARNING
"start_kernel(): bug: interrupts were "
561 "enabled *very* early, fixing it\n");
577 call_function_init();
578 if (!irqs_disabled())
579 printk(KERN_CRIT
"start_kernel(): bug: interrupts were "
581 early_boot_irqs_disabled =
false;
584 kmem_cache_init_late();
593 panic(panic_later, panic_param);
604 #ifdef CONFIG_BLK_DEV_INITRD
605 if (initrd_start && !initrd_below_start_ok &&
606 page_to_pfn(virt_to_page((
void *)initrd_start)) < min_low_pfn) {
607 printk(KERN_CRIT
"initrd overwritten (0x%08lx < 0x%08lx) - "
609 page_to_pfn(virt_to_page((
void *)initrd_start)),
615 debug_objects_mem_init();
617 setup_per_cpu_pageset();
626 if (efi_enabled(EFI_RUNTIME_SERVICES))
627 efi_enter_virtual_mode();
629 thread_info_cache_init();
631 fork_init(totalram_pages);
637 vfs_caches_init(totalram_pages);
640 page_writeback_init();
641 #ifdef CONFIG_PROC_FS
646 taskstats_init_early();
654 if (efi_enabled(EFI_RUNTIME_SERVICES)) {
656 efi_free_boot_services();
666 static void __init do_ctors(
void)
668 #ifdef CONFIG_CONSTRUCTORS
669 ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
671 for (; fn < (ctor_fn_t *) __ctors_end; fn++)
677 core_param(initcall_debug, initcall_debug,
bool, 0644);
679 static char msgbuf[64];
681 static int __init_or_module do_one_initcall_debug(initcall_t fn)
683 ktime_t calltime, delta, rettime;
684 unsigned long long duration;
687 printk(KERN_DEBUG
"calling %pF @ %i\n", fn, task_pid_nr(current));
688 calltime = ktime_get();
690 rettime = ktime_get();
691 delta = ktime_sub(rettime, calltime);
692 duration = (
unsigned long long) ktime_to_ns(delta) >> 10;
693 printk(KERN_DEBUG
"initcall %pF returned %d after %lld usecs\n", fn,
699 int __init_or_module do_one_initcall(initcall_t fn)
701 int count = preempt_count();
705 ret = do_one_initcall_debug(fn);
711 if (ret && ret != -ENODEV && initcall_debug)
712 sprintf(msgbuf,
"error code %d ", ret);
714 if (preempt_count() != count) {
715 strlcat(msgbuf,
"preemption imbalance ",
sizeof(msgbuf));
716 preempt_count() = count;
718 if (irqs_disabled()) {
719 strlcat(msgbuf,
"disabled interrupts ",
sizeof(msgbuf));
723 printk(
"initcall %pF returned with %s\n", fn, msgbuf);
730 extern initcall_t __initcall_start[];
731 extern initcall_t __initcall0_start[];
732 extern initcall_t __initcall1_start[];
733 extern initcall_t __initcall2_start[];
734 extern initcall_t __initcall3_start[];
735 extern initcall_t __initcall4_start[];
736 extern initcall_t __initcall5_start[];
737 extern initcall_t __initcall6_start[];
738 extern initcall_t __initcall7_start[];
739 extern initcall_t __initcall_end[];
741 static initcall_t *initcall_levels[] __initdata = {
754 static char *initcall_level_names[] __initdata = {
765 static void __init do_initcall_level(
int level)
767 extern const struct kernel_param __start___param[], __stop___param[];
770 strcpy(static_command_line, saved_command_line);
771 parse_args(initcall_level_names[level],
772 static_command_line, __start___param,
773 __stop___param - __start___param,
777 for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
778 do_one_initcall(*fn);
781 static void __init do_initcalls(
void)
785 for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
786 do_initcall_level(level);
796 static void __init do_basic_setup(
void)
799 usermodehelper_init();
804 usermodehelper_enable();
826 void do_virgo_cloud_init()
828 read_virgo_clone_config();
831 void read_virgo_clone_config()
862 f=filp_open(
"/etc/virgo_cloud.conf", O_RDONLY, 0);
882 bytesread=vfs_read(f, buf, 256, &pos);
891 char* bufdup=kstrdup(buf,GFP_ATOMIC);
893 while(bufdup != NULL)
895 token=strsep(&bufdup, delim);
897 node_ip_addrs_in_cloud[i]=kstrdup(token,GFP_ATOMIC);
917 static void __init do_pre_smp_initcalls(
void)
921 for (fn = __initcall_start; fn < __initcall0_start; fn++)
922 do_one_initcall(*fn);
925 static int run_init_process(
const char *init_filename)
927 argv_init[0] = init_filename;
928 return kernel_execve(init_filename, argv_init, envp_init);
931 static noinline
void __init kernel_init_freeable(
void);
933 static int __ref kernel_init(
void *unused)
935 kernel_init_freeable();
937 async_synchronize_full();
940 system_state = SYSTEM_RUNNING;
941 numa_default_policy();
943 current->signal->flags |= SIGNAL_UNKILLABLE;
944 flush_delayed_fput();
946 if (ramdisk_execute_command) {
947 if (!run_init_process(ramdisk_execute_command))
949 printk(KERN_WARNING
"Failed to execute %s\n",
950 ramdisk_execute_command);
959 if (execute_command) {
960 if (!run_init_process(execute_command))
962 printk(KERN_WARNING
"Failed to execute %s. Attempting "
963 "defaults...\n", execute_command);
965 if (!run_init_process(
"/sbin/init") ||
966 !run_init_process(
"/etc/init") ||
967 !run_init_process(
"/bin/init") ||
968 !run_init_process(
"/bin/sh"))
971 panic(
"No init found. Try passing init= option to kernel. "
972 "See Linux Documentation/init.txt for guidance.");
975 static noinline
void __init kernel_init_freeable(
void)
980 wait_for_completion(&kthreadd_done);
983 gfp_allowed_mask = __GFP_BITS_MASK;
988 set_mems_allowed(node_states[N_HIGH_MEMORY]);
992 set_cpus_allowed_ptr(current, cpu_all_mask);
994 cad_pid = task_pid(current);
996 smp_prepare_cpus(setup_max_cpus);
998 do_pre_smp_initcalls();
999 lockup_detector_init();
1007 if (sys_open((
const char __user *)
"/dev/console", O_RDWR, 0) < 0)
1008 printk(KERN_WARNING
"Warning: unable to open an initial console.\n");
1017 if (!ramdisk_execute_command)
1018 ramdisk_execute_command =
"/init";
1020 if (sys_access((
const char __user *) ramdisk_execute_command, 0) != 0) {
1021 ramdisk_execute_command = NULL;
1022 prepare_namespace();