X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=init%2Fmain.c;h=a92989e7836af6acb73bb6ce8b95ad76ee727f53;hb=c7258a4477b5ed0243c28ec107b98bb946757448;hp=7c79da57d3a29fd665042e5747e88bca78409aca;hpb=69c99ac17e2ee0eb45e2c9873e6e12d73260fc6b;p=safe%2Fjmp%2Flinux-2.6 diff --git a/init/main.c b/init/main.c index 7c79da5..a92989e 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,20 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include +#include +#include +#include +#include +#include +#include #include #include @@ -71,22 +78,22 @@ #error Sorry, your GCC is too old. It builds incorrect kernels. #endif +#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 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); @@ -115,8 +122,12 @@ 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; @@ -125,6 +136,18 @@ static char *ramdisk_execute_command; static unsigned int max_cpus = NR_CPUS; /* + * 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); + +/* * Setup routine for controlling SMP activation * * Command-line option of "nosmp" or "maxcpus=0" will disable SMP @@ -150,6 +173,14 @@ static int __init maxcpus(char *str) __setup("maxcpus=", maxcpus); +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, }; static const char *panic_later, *panic_param; @@ -159,16 +190,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 +212,8 @@ static int __init obsolete_checksetup(char *line) } p++; } while (p < __setup_end); - return 0; + + return had_early_param; } /* @@ -306,8 +341,6 @@ static int __init rdinit_setup(char *str) } __setup("rdinit=", rdinit_setup); -extern void setup_arch(char **); - #ifndef CONFIG_SMP #ifdef CONFIG_X86_LOCAL_APIC @@ -325,7 +358,7 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { } #else #ifdef __GENERIC_PER_CPU -unsigned long __per_cpu_offset[NR_CPUS]; +unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; EXPORT_SYMBOL(__per_cpu_offset); @@ -333,6 +366,7 @@ static void __init setup_per_cpu_areas(void) { unsigned long size, i; char *ptr; + 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); @@ -340,12 +374,12 @@ static void __init setup_per_cpu_areas(void) if (size < PERCPU_ENOUGH_ROOM) size = PERCPU_ENOUGH_ROOM; #endif + ptr = alloc_bootmem(size * nr_possible_cpus); - ptr = alloc_bootmem(size * NR_CPUS); - - for (i = 0; i < NR_CPUS; i++, ptr += size) { + 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; } } #endif /* !__GENERIC_PER_CPU */ @@ -353,29 +387,43 @@ 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; + unsigned highest = 0; + + for_each_cpu_mask(cpu, cpu_possible_map) + highest = cpu; + nr_cpu_ids = highest + 1; /* 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 @@ -429,7 +477,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; } @@ -438,26 +486,52 @@ void __init parse_early_param(void) * Activate the first processor. */ +static void __init boot_cpu_init(void) +{ + int cpu = smp_processor_id(); + /* Mark the boot cpu "present", "online" etc for SMP and UP case */ + cpu_set(cpu, cpu_online_map); + cpu_set(cpu, cpu_present_map); + 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(); setup_per_cpu_areas(); - - /* - * Mark the boot cpu "online" so that it can call console drivers in - * printk() and can access its per-cpu storage. - */ - smp_prepare_boot_cpu(); + smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */ /* * Set up the scheduler prior starting any interrupts (such as the @@ -472,11 +546,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(); @@ -485,7 +564,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 @@ -495,8 +580,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) { @@ -537,6 +630,8 @@ asmlinkage void __init start_kernel(void) proc_root_init(); #endif cpuset_init(); + taskstats_init_early(); + delayacct_init(); check_bugs(); @@ -555,8 +650,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) @@ -565,17 +658,23 @@ static void __init do_initcalls(void) int count = preempt_count(); for (call = __initcall_start; call < __initcall_end; call++) { - char *msg; + char *msg = NULL; + char msgbuf[40]; + int result; if (initcall_debug) { - printk(KERN_DEBUG "Calling initcall 0x%p", *call); - print_fn_descriptor_symbol(": %s()", (unsigned long) *call); + printk("Calling initcall 0x%p", *call); + print_fn_descriptor_symbol(": %s()", + (unsigned long) *call); printk("\n"); } - (*call)(); + result = (*call)(); - msg = NULL; + if (result && result != -ENODEV && initcall_debug) { + sprintf(msgbuf, "error code %d", result); + msg = msgbuf; + } if (preempt_count() != count) { msg = "preemption imbalance"; preempt_count() = count; @@ -585,8 +684,10 @@ static void __init do_initcalls(void) local_irq_enable(); } if (msg) { - printk(KERN_WARNING "error in initcall at 0x%p: " - "returned with %s\n", *call, msg); + printk(KERN_WARNING "initcall at 0x%p", *call); + print_fn_descriptor_symbol(": %s()", + (unsigned long) *call); + printk(": returned with %s\n", msg); } } @@ -607,15 +708,11 @@ static void __init do_basic_setup(void) init_workqueues(); usermodehelper_init(); driver_init(); - -#ifdef CONFIG_SYSCTL - sysctl_init(); -#endif - + init_irq_proc(); do_initcalls(); } -static void do_pre_smp_initcalls(void) +static void __init do_pre_smp_initcalls(void) { extern int spawn_ksoftirqd(void); #ifdef CONFIG_SMP @@ -630,28 +727,52 @@ static void do_pre_smp_initcalls(void) 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 init(void * unused) { lock_kernel(); /* @@ -666,25 +787,19 @@ 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; + + cad_pid = task_pid(current); - /* Sets up cpus_possible() */ 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(); /* @@ -705,39 +820,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; }