X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=init%2Fmain.c;h=d3bcb3b11620784a37dd6d44561a874e9df1d982;hb=e22841c637dc8b308b40f59d64a5b6683d458ab7;hp=006dcd547dc2e72bd3280ac31e746d34da1970bf;hpb=77d47582c2345e071df02afaf9191641009287c4;p=safe%2Fjmp%2Flinux-2.6 diff --git a/init/main.c b/init/main.c index 006dcd5..d3bcb3b 100644 --- a/init/main.c +++ b/init/main.c @@ -9,13 +9,9 @@ * Simplified starting of init: Michael A. Griffith */ -#define __KERNEL_SYSCALLS__ - -#include #include #include #include -#include #include #include #include @@ -33,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -43,10 +40,21 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -71,23 +79,22 @@ #error Sorry, your GCC is too old. It builds incorrect kernels. #endif -static int init(void *); +#if __GNUC__ == 4 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ == 0 +#warning gcc-4.1.0 is known to miscompile the kernel. A different compiler version is recommended. +#endif + +static int kernel_init(void *); extern void init_IRQ(void); extern void fork_init(unsigned long); extern void mca_init(void); extern void sbus_init(void); -extern void sysctl_init(void); extern void signals_init(void); -extern void buffer_init(void); extern void pidhash_init(void); extern void pidmap_init(void); extern void prio_tree_init(void); extern void radix_tree_init(void); extern void free_initmem(void); -extern void populate_rootfs(void); -extern void driver_init(void); -extern void prepare_namespace(void); #ifdef CONFIG_ACPI extern void acpi_early_init(void); #else @@ -115,14 +122,19 @@ extern void time_init(void); void (*late_time_init)(void); extern void softirq_init(void); -/* Untouched command line (eg. for /proc) saved by arch-specific code. */ -char saved_command_line[COMMAND_LINE_SIZE]; +/* Untouched command line saved by arch-specific code. */ +char __initdata boot_command_line[COMMAND_LINE_SIZE]; +/* Untouched saved command line (eg. for /proc) */ +char *saved_command_line; +/* Command line for parameter parsing */ +static char *static_command_line; static char *execute_command; static char *ramdisk_execute_command; +#ifdef CONFIG_SMP /* Setup configured maximum number of CPUs to activate */ -static unsigned int max_cpus = NR_CPUS; +static unsigned int __initdata max_cpus = NR_CPUS; /* * Setup routine for controlling SMP activation @@ -137,10 +149,10 @@ static unsigned int max_cpus = NR_CPUS; static int __init nosmp(char *str) { max_cpus = 0; - return 1; + return 0; } -__setup("nosmp", nosmp); +early_param("nosmp", nosmp); static int __init maxcpus(char *str) { @@ -149,6 +161,29 @@ static int __init maxcpus(char *str) } __setup("maxcpus=", maxcpus); +#else +#define max_cpus NR_CPUS +#endif + +/* + * If set, this is an indication to the drivers that reset the underlying + * device before going ahead with the initialization otherwise driver might + * rely on the BIOS and skip the reset operation. + * + * This is useful if kernel is booting in an unreliable environment. + * For ex. kdump situaiton where previous kernel has crashed, BIOS has been + * skipped and devices will be in unknown state. + */ +unsigned int reset_devices; +EXPORT_SYMBOL(reset_devices); + +static int __init set_reset_devices(char *str) +{ + reset_devices = 1; + return 1; +} + +__setup("reset_devices", set_reset_devices); static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, }; char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; @@ -159,16 +194,19 @@ extern struct obs_kernel_param __setup_start[], __setup_end[]; static int __init obsolete_checksetup(char *line) { struct obs_kernel_param *p; + int had_early_param = 0; p = __setup_start; do { int n = strlen(p->str); if (!strncmp(line, p->str, n)) { if (p->early) { - /* Already done in parse_early_param? (Needs - * exact match on param part) */ + /* Already done in parse_early_param? + * (Needs exact match on param part). + * Keep iterating, as we can have early + * params and __setups of same names 8( */ if (line[n] == '\0' || line[n] == '=') - return 1; + had_early_param = 1; } else if (!p->setup_func) { printk(KERN_WARNING "Parameter %s is obsolete," " ignored\n", p->str); @@ -178,7 +216,8 @@ static int __init obsolete_checksetup(char *line) } p++; } while (p < __setup_end); - return 0; + + return had_early_param; } /* @@ -334,14 +373,10 @@ static void __init setup_per_cpu_areas(void) unsigned long nr_possible_cpus = num_possible_cpus(); /* Copy section for each CPU (we discard the original) */ - size = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES); -#ifdef CONFIG_MODULES - if (size < PERCPU_ENOUGH_ROOM) - size = PERCPU_ENOUGH_ROOM; -#endif - ptr = alloc_bootmem(size * nr_possible_cpus); + size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE); + ptr = alloc_bootmem_pages(size * nr_possible_cpus); - for_each_cpu(i) { + for_each_possible_cpu(i) { __per_cpu_offset[i] = ptr - __per_cpu_start; memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); ptr += size; @@ -352,29 +387,42 @@ static void __init setup_per_cpu_areas(void) /* Called by boot processor to activate the rest. */ static void __init smp_init(void) { - unsigned int i; + unsigned int cpu; + +#ifndef CONFIG_HOTPLUG_CPU + cpu_possible_map = cpu_present_map; +#endif /* FIXME: This should be done in userspace --RR */ - for_each_present_cpu(i) { + for_each_present_cpu(cpu) { if (num_online_cpus() >= max_cpus) break; - if (!cpu_online(i)) - cpu_up(i); + if (!cpu_online(cpu)) + cpu_up(cpu); } /* Any cleanup work */ printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus()); smp_cpus_done(max_cpus); -#if 0 - /* Get other processors into their bootup holding patterns. */ - - smp_commence(); -#endif } #endif /* + * We need to store the untouched command line for future reference. + * We also need to store the touched command line since the parameter + * parsing is performed in place, and we should allow a component to + * store reference of name/value for future reference. + */ +static void __init setup_command_line(char *command_line) +{ + saved_command_line = alloc_bootmem(strlen (boot_command_line)+1); + static_command_line = alloc_bootmem(strlen (command_line)+1); + strcpy (saved_command_line, boot_command_line); + strcpy (static_command_line, command_line); +} + +/* * We need to finalize in a non-__init function or else race conditions * between the root thread and the init thread may cause start_kernel to * be reaped by free_initmem before the root thread has proceeded to @@ -383,24 +431,29 @@ static void __init smp_init(void) * gcc-3.4 accidentally inlines this function, so use noinline. */ -static void noinline rest_init(void) +static void noinline __init_refok rest_init(void) __releases(kernel_lock) { - kernel_thread(init, NULL, CLONE_FS | CLONE_SIGHAND); + int pid; + + kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND); numa_default_policy(); + pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES); + kthreadd_task = find_task_by_pid(pid); unlock_kernel(); /* * The boot idle thread must execute schedule() - * at least one to get things moving: + * at least once to get things moving: */ + init_idle_bootup_task(current); preempt_enable_no_resched(); schedule(); preempt_disable(); /* Call into cpu_idle with preempt disabled */ cpu_idle(); -} +} /* Check for early params. */ static int __init do_early_param(char *param, char *val) @@ -408,7 +461,10 @@ static int __init do_early_param(char *param, char *val) struct obs_kernel_param *p; for (p = __setup_start; p < __setup_end; p++) { - if (p->early && strcmp(param, p->str) == 0) { + if ((p->early && strcmp(param, p->str) == 0) || + (strcmp(param, "console") == 0 && + strcmp(p->str, "earlycon") == 0) + ) { if (p->setup_func(val) != 0) printk(KERN_WARNING "Malformed early option '%s'\n", param); @@ -428,7 +484,7 @@ void __init parse_early_param(void) return; /* All fall through to do_early_param. */ - strlcpy(tmp_cmdline, saved_command_line, COMMAND_LINE_SIZE); + strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); parse_args("early options", tmp_cmdline, NULL, 0, do_early_param); done = 1; } @@ -446,20 +502,45 @@ static void __init boot_cpu_init(void) cpu_set(cpu, cpu_possible_map); } +void __init __attribute__((weak)) smp_setup_processor_id(void) +{ +} + asmlinkage void __init start_kernel(void) { char * command_line; extern struct kernel_param __start___param[], __stop___param[]; + + smp_setup_processor_id(); + + /* + * Need to run as early as possible, to initialize the + * lockdep hash: + */ + unwind_init(); + lockdep_init(); + + local_irq_disable(); + early_boot_irqs_off(); + early_init_irq_lock_class(); + /* * Interrupts are still disabled. Do necessary setups, then * enable them */ lock_kernel(); + tick_init(); boot_cpu_init(); page_address_init(); printk(KERN_NOTICE); printk(linux_banner); setup_arch(&command_line); + setup_command_line(command_line); + unwind_setup(); +#ifndef CONFIG_HOTPLUG_CPU + if (max_cpus < 2) + cpu_possible_map = cpu_online_map; +#endif setup_per_cpu_areas(); smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ @@ -476,11 +557,16 @@ asmlinkage void __init start_kernel(void) preempt_disable(); build_all_zonelists(); page_alloc_init(); - printk(KERN_NOTICE "Kernel command line: %s\n", saved_command_line); + printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line); parse_early_param(); - parse_args("Booting kernel", command_line, __start___param, + parse_args("Booting kernel", static_command_line, __start___param, __stop___param - __start___param, &unknown_bootoption); + if (!irqs_disabled()) { + printk(KERN_WARNING "start_kernel(): bug: interrupts were " + "enabled *very* early, fixing it\n"); + local_irq_disable(); + } sort_main_extable(); trap_init(); rcu_init(); @@ -489,7 +575,13 @@ asmlinkage void __init start_kernel(void) init_timers(); hrtimers_init(); softirq_init(); + timekeeping_init(); time_init(); + profile_init(); + if (!irqs_disabled()) + printk("start_kernel(): bug: interrupts were enabled early\n"); + early_boot_irqs_on(); + local_irq_enable(); /* * HACK ALERT! This is early. We're enabling the console before @@ -499,8 +591,16 @@ asmlinkage void __init start_kernel(void) console_init(); if (panic_later) panic(panic_later, panic_param); - profile_init(); - local_irq_enable(); + + lockdep_info(); + + /* + * Need to run this when irqs are enabled, because it wants + * to self-test [hard/soft]-irqs on/off lock inversion bugs + * too: + */ + locking_selftest(); + #ifdef CONFIG_BLK_DEV_INITRD if (initrd_start && !initrd_below_start_ok && initrd_start < min_low_pfn << PAGE_SHIFT) { @@ -541,6 +641,8 @@ asmlinkage void __init start_kernel(void) proc_root_init(); #endif cpuset_init(); + taskstats_init_early(); + delayacct_init(); check_bugs(); @@ -559,8 +661,6 @@ static int __init initcall_debug_setup(char *str) } __setup("initcall_debug", initcall_debug_setup); -struct task_struct *child_reaper = &init_task; - extern initcall_t __initcall_start[], __initcall_end[]; static void __init do_initcalls(void) @@ -569,6 +669,7 @@ static void __init do_initcalls(void) int count = preempt_count(); for (call = __initcall_start; call < __initcall_end; call++) { + ktime_t t0, t1, delta; char *msg = NULL; char msgbuf[40]; int result; @@ -578,11 +679,27 @@ static void __init do_initcalls(void) print_fn_descriptor_symbol(": %s()", (unsigned long) *call); printk("\n"); + t0 = ktime_get(); } result = (*call)(); - if (result && (result != -ENODEV || initcall_debug)) { + if (initcall_debug) { + t1 = ktime_get(); + delta = ktime_sub(t1, t0); + + printk("initcall 0x%p", *call); + print_fn_descriptor_symbol(": %s()", + (unsigned long) *call); + printk(" returned %d.\n", result); + + printk("initcall 0x%p ran for %Ld msecs: ", + *call, (unsigned long long)delta.tv64 >> 20); + print_fn_descriptor_symbol("%s()\n", + (unsigned long) *call); + } + + if (result && result != -ENODEV && initcall_debug) { sprintf(msgbuf, "error code %d", result); msg = msgbuf; } @@ -619,15 +736,20 @@ static void __init do_basic_setup(void) init_workqueues(); usermodehelper_init(); driver_init(); + init_irq_proc(); + do_initcalls(); +} -#ifdef CONFIG_SYSCTL - sysctl_init(); -#endif +static int __initdata nosoftlockup; - do_initcalls(); +static int __init nosoftlockup_setup(char *str) +{ + nosoftlockup = 1; + return 1; } +__setup("nosoftlockup", nosoftlockup_setup); -static void do_pre_smp_initcalls(void) +static void __init do_pre_smp_initcalls(void) { extern int spawn_ksoftirqd(void); #ifdef CONFIG_SMP @@ -636,34 +758,59 @@ static void do_pre_smp_initcalls(void) migration_init(); #endif spawn_ksoftirqd(); - spawn_softlockup_task(); + if (!nosoftlockup) + spawn_softlockup_task(); } static void run_init_process(char *init_filename) { argv_init[0] = init_filename; - execve(init_filename, argv_init, envp_init); + kernel_execve(init_filename, argv_init, envp_init); } -static inline void fixup_cpu_present_map(void) +/* This is a non __init function. Force it to be noinline otherwise gcc + * makes it inline to init() and it becomes part of init.text section + */ +static int noinline init_post(void) { -#ifdef CONFIG_SMP - int i; + free_initmem(); + unlock_kernel(); + mark_rodata_ro(); + system_state = SYSTEM_RUNNING; + numa_default_policy(); + + if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) + printk(KERN_WARNING "Warning: unable to open an initial console.\n"); + + (void) sys_dup(0); + (void) sys_dup(0); + + if (ramdisk_execute_command) { + run_init_process(ramdisk_execute_command); + printk(KERN_WARNING "Failed to execute %s\n", + ramdisk_execute_command); + } /* - * If arch is not hotplug ready and did not populate - * cpu_present_map, just make cpu_present_map same as cpu_possible_map - * for other cpu bringup code to function as normal. e.g smp_init() etc. + * We try each of these until one succeeds. + * + * The Bourne shell can be used instead of init if we are + * trying to recover a really broken machine. */ - if (cpus_empty(cpu_present_map)) { - for_each_cpu(i) { - cpu_set(i, cpu_present_map); - } + if (execute_command) { + run_init_process(execute_command); + printk(KERN_WARNING "Failed to execute %s. Attempting " + "defaults...\n", execute_command); } -#endif + run_init_process("/sbin/init"); + run_init_process("/etc/init"); + run_init_process("/bin/init"); + run_init_process("/bin/sh"); + + panic("No init found. Try passing init= option to kernel."); } -static int init(void * unused) +static int __init kernel_init(void * unused) { lock_kernel(); /* @@ -678,24 +825,20 @@ static int init(void * unused) * assumptions about where in the task array this * can be found. */ - child_reaper = current; + init_pid_ns.child_reaper = current; + + __set_special_pids(1, 1); + cad_pid = task_pid(current); smp_prepare_cpus(max_cpus); do_pre_smp_initcalls(); - fixup_cpu_present_map(); smp_init(); sched_init_smp(); cpuset_init_smp(); - /* - * Do this before initcalls, because some drivers want to access - * firmware files. - */ - populate_rootfs(); - do_basic_setup(); /* @@ -716,39 +859,6 @@ static int init(void * unused) * we're essentially up and running. Get rid of the * initmem segments and start the user-mode stuff.. */ - free_initmem(); - unlock_kernel(); - mark_rodata_ro(); - system_state = SYSTEM_RUNNING; - numa_default_policy(); - - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) - printk(KERN_WARNING "Warning: unable to open an initial console.\n"); - - (void) sys_dup(0); - (void) sys_dup(0); - - if (ramdisk_execute_command) { - run_init_process(ramdisk_execute_command); - printk(KERN_WARNING "Failed to execute %s\n", - ramdisk_execute_command); - } - - /* - * We try each of these until one succeeds. - * - * The Bourne shell can be used instead of init if we are - * trying to recover a really broken machine. - */ - if (execute_command) { - run_init_process(execute_command); - printk(KERN_WARNING "Failed to execute %s. Attempting " - "defaults...\n", execute_command); - } - run_init_process("/sbin/init"); - run_init_process("/etc/init"); - run_init_process("/bin/init"); - run_init_process("/bin/sh"); - - panic("No init found. Try passing init= option to kernel."); + init_post(); + return 0; }