x86/PCI: use host bridge _CRS info on MSI MS-7253
[linux-flexiantxendom0.git] / init / main.c
index 5c85402..c98afa1 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/delay.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
-#include <linux/smp_lock.h>
 #include <linux/initrd.h>
 #include <linux/bootmem.h>
 #include <linux/acpi.h>
@@ -32,7 +31,6 @@
 #include <linux/start_kernel.h>
 #include <linux/security.h>
 #include <linux/smp.h>
-#include <linux/workqueue.h>
 #include <linux/profile.h>
 #include <linux/rcupdate.h>
 #include <linux/moduleparam.h>
 #include <linux/sched.h>
 #include <linux/signal.h>
 #include <linux/idr.h>
+#include <linux/kgdb.h>
 #include <linux/ftrace.h>
 #include <linux/async.h>
 #include <linux/kmemcheck.h>
-#include <linux/kmemtrace.h>
 #include <linux/sfi.h>
 #include <linux/shmem_fs.h>
 #include <linux/slab.h>
-#include <trace/boot.h>
+#include <linux/perf_event.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -98,6 +96,15 @@ static inline void mark_rodata_ro(void) { }
 extern void tc_init(void);
 #endif
 
+/*
+ * Debug helper: via this flag we know that we are in 'early bootup code'
+ * where only the boot processor is running with IRQ disabled.  This means
+ * two things - IRQ must not be enabled before the flag is cleared and some
+ * operations which are not allowed with IRQ disabled are allowed while the
+ * flag is set.
+ */
+bool early_boot_irqs_disabled __read_mostly;
+
 enum system_states system_state __read_mostly;
 EXPORT_SYMBOL(system_state);
 
@@ -106,6 +113,11 @@ EXPORT_SYMBOL(system_state);
  */
 #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
 #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
+#ifdef CONFIG_INIT_PASS_ALL_PARAMS
+#define INIT_PASS_FUNCTION pass_all_bootoptions
+#else
+#define INIT_PASS_FUNCTION pass_unknown_bootoptions
+#endif
 
 extern void time_init(void);
 /* Default late time init is NULL. archs can override this later. */
@@ -122,61 +134,6 @@ 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 */
-unsigned int __initdata setup_max_cpus = NR_CPUS;
-
-/*
- * Setup routine for controlling SMP activation
- *
- * Command-line option of "nosmp" or "maxcpus=0" will disable SMP
- * activation entirely (the MPS table probe still happens, though).
- *
- * Command-line option of "maxcpus=<NUM>", where <NUM> is an integer
- * greater than 0, limits the maximum number of CPUs activated in
- * SMP mode to <NUM>.
- */
-
-void __weak arch_disable_smp_support(void) { }
-
-static int __init nosmp(char *str)
-{
-       setup_max_cpus = 0;
-       arch_disable_smp_support();
-
-       return 0;
-}
-
-early_param("nosmp", nosmp);
-
-/* this is hard limit */
-static int __init nrcpus(char *str)
-{
-       int nr_cpus;
-
-       get_option(&str, &nr_cpus);
-       if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
-               nr_cpu_ids = nr_cpus;
-
-       return 0;
-}
-
-early_param("nr_cpus", nrcpus);
-
-static int __init maxcpus(char *str)
-{
-       get_option(&str, &setup_max_cpus);
-       if (setup_max_cpus == 0)
-               arch_disable_smp_support();
-
-       return 0;
-}
-
-early_param("maxcpus", maxcpus);
-#else
-static const unsigned int setup_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
@@ -197,21 +154,21 @@ static int __init set_reset_devices(char *str)
 
 __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 * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
+const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
 static const char *panic_later, *panic_param;
 
-extern struct obs_kernel_param __setup_start[], __setup_end[];
+extern const struct obs_kernel_param __setup_start[], __setup_end[];
 
 static int __init obsolete_checksetup(char *line)
 {
-       struct obs_kernel_param *p;
+       const 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 (parameqn(line, p->str, n)) {
                        if (p->early) {
                                /* Already done in parse_early_param?
                                 * (Needs exact match on param part).
@@ -248,7 +205,7 @@ static int __init debug_kernel(char *str)
 
 static int __init quiet_kernel(char *str)
 {
-       console_loglevel = 4;
+       console_loglevel = 2;
        return 0;
 }
 
@@ -257,17 +214,29 @@ early_param("quiet", quiet_kernel);
 
 static int __init loglevel(char *str)
 {
-       get_option(&str, &console_loglevel);
-       return 0;
+       int newlevel;
+
+       /*
+        * Only update loglevel value when a correct setting was passed,
+        * to prevent blind crashes (when loglevel being set to 0) that
+        * are quite hard to debug
+        */
+       if (get_option(&str, &newlevel)) {
+               console_loglevel = newlevel;
+               return 0;
+       }
+
+       return -EINVAL;
 }
 
 early_param("loglevel", loglevel);
 
 /*
- * Unknown boot options get handed to init, unless they look like
- * unused parameters (modprobe will find them in /proc/cmdline).
+ * Select boot options to hand to init.  If all is set hand off them all
+ * otherwise only hand off unused ones which do not apply to modules
+ * (modprobe will find them in /proc/cmdline).
  */
-static int __init unknown_bootoption(char *param, char *val)
+static int __init pass_bootoption(char *param, char *val, int all)
 {
        /* Change NUL term back to "=", to make "param" the whole string. */
        if (val) {
@@ -283,11 +252,11 @@ static int __init unknown_bootoption(char *param, char *val)
        }
 
        /* Handle obsolete-style parameters */
-       if (obsolete_checksetup(param))
+       if (obsolete_checksetup(param) && !all)
                return 0;
 
        /* Unused module parameter. */
-       if (strchr(param, '.') && (!val || strchr(param, '.') < val))
+       if (!all && strchr(param, '.') && (!val || strchr(param, '.') < val))
                return 0;
 
        if (panic_later)
@@ -318,6 +287,16 @@ static int __init unknown_bootoption(char *param, char *val)
        }
        return 0;
 }
+static int __init pass_unknown_bootoptions(char *param, char *val, int known)
+{
+       if (known)
+               return 0;
+       return pass_bootoption(param, val, 0);
+}
+static int __init pass_all_bootoptions(char *param, char *val, int known)
+{
+       return pass_bootoption(param, val, 1);
+}
 
 #ifdef CONFIG_DEBUG_PAGEALLOC
 int __read_mostly debug_pagealloc_enabled = 0;
@@ -353,7 +332,7 @@ static int __init rdinit_setup(char *str)
 __setup("rdinit=", rdinit_setup);
 
 #ifndef CONFIG_SMP
-
+static const unsigned int setup_max_cpus = NR_CPUS;
 #ifdef CONFIG_X86_LOCAL_APIC
 static void __init smp_init(void)
 {
@@ -365,37 +344,6 @@ static void __init smp_init(void)
 
 static inline void setup_nr_cpu_ids(void) { }
 static inline void smp_prepare_cpus(unsigned int maxcpus) { }
-
-#else
-
-/* Setup number of possible processor ids */
-int nr_cpu_ids __read_mostly = NR_CPUS;
-EXPORT_SYMBOL(nr_cpu_ids);
-
-/* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
-static void __init setup_nr_cpu_ids(void)
-{
-       nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
-}
-
-/* Called by boot processor to activate the rest. */
-static void __init smp_init(void)
-{
-       unsigned int cpu;
-
-       /* FIXME: This should be done in userspace --RR */
-       for_each_present_cpu(cpu) {
-               if (num_online_cpus() >= setup_max_cpus)
-                       break;
-               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(setup_max_cpus);
-}
-
 #endif
 
 /*
@@ -421,19 +369,25 @@ static void __init setup_command_line(char *command_line)
  * gcc-3.4 accidentally inlines this function, so use noinline.
  */
 
+static __initdata DECLARE_COMPLETION(kthreadd_done);
+
 static noinline void __init_refok rest_init(void)
-       __releases(kernel_lock)
 {
        int pid;
 
        rcu_scheduler_starting();
+       /*
+        * We need to spawn init first so that it obtains pid 1, however
+        * the init task will end up wanting to create kthreads, which, if
+        * we schedule it before we create kthreadd, will OOPS.
+        */
        kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
        numa_default_policy();
        pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
        rcu_read_lock();
        kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
        rcu_read_unlock();
-       unlock_kernel();
+       complete(&kthreadd_done);
 
        /*
         * The boot idle thread must execute schedule()
@@ -442,19 +396,22 @@ static noinline void __init_refok rest_init(void)
        init_idle_bootup_task(current);
        preempt_enable_no_resched();
        schedule();
-       preempt_disable();
 
        /* Call into cpu_idle with preempt disabled */
+       preempt_disable();
        cpu_idle();
 }
 
 /* Check for early params. */
-static int __init do_early_param(char *param, char *val)
+static int __init do_early_param(char *param, char *val, int known)
 {
-       struct obs_kernel_param *p;
+       const struct obs_kernel_param *p;
+
+       if (known)
+               return 0;
 
        for (p = __setup_start; p < __setup_end; p++) {
-               if ((p->early && strcmp(param, p->str) == 0) ||
+               if ((p->early && parameq(param, p->str)) ||
                    (strcmp(param, "console") == 0 &&
                     strcmp(p->str, "earlycon") == 0)
                ) {
@@ -521,6 +478,7 @@ static void __init mm_init(void)
        page_cgroup_init_flatmem();
        mem_init();
        kmem_cache_init();
+       percpu_init_late();
        pgtable_cache_init();
        vmalloc_init();
 }
@@ -528,7 +486,7 @@ static void __init mm_init(void)
 asmlinkage void __init start_kernel(void)
 {
        char * command_line;
-       extern struct kernel_param __start___param[], __stop___param[];
+       extern const struct kernel_param __start___param[], __stop___param[];
 
        smp_setup_processor_id();
 
@@ -547,42 +505,46 @@ asmlinkage void __init start_kernel(void)
        cgroup_init_early();
 
        local_irq_disable();
-       early_boot_irqs_off();
-       early_init_irq_lock_class();
+       early_boot_irqs_disabled = true;
 
 /*
  * Interrupts are still disabled. Do necessary setups, then
  * enable them
  */
-       lock_kernel();
        tick_init();
        boot_cpu_init();
        page_address_init();
        printk(KERN_NOTICE "%s", linux_banner);
        setup_arch(&command_line);
        mm_init_owner(&init_mm, &init_task);
+       mm_init_cpumask(&init_mm);
        setup_command_line(command_line);
        setup_nr_cpu_ids();
        setup_per_cpu_areas();
        smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
 
-       build_all_zonelists();
+       build_all_zonelists(NULL);
        page_alloc_init();
 
        printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);
        parse_early_param();
        parse_args("Booting kernel", static_command_line, __start___param,
                   __stop___param - __start___param,
-                  &unknown_bootoption);
+                  &INIT_PASS_FUNCTION);
+
+       jump_label_init();
+
        /*
         * These use large bootmem allocations and must precede
         * kmem_cache_init()
         */
+       setup_log_buf(0);
        pidhash_init();
        vfs_caches_init_early();
        sort_main_extable();
        trap_init();
        mm_init();
+
        /*
         * Set up the scheduler prior starting any interrupts (such as the
         * timer interrupt). Full topology setup happens at smp_init()
@@ -599,6 +561,8 @@ asmlinkage void __init start_kernel(void)
                                "enabled *very* early, fixing it\n");
                local_irq_disable();
        }
+       idr_init_cache();
+       perf_event_init();
        rcu_init();
        radix_tree_init();
        /* init some links before init_ISA_irqs() */
@@ -611,10 +575,11 @@ asmlinkage void __init start_kernel(void)
        timekeeping_init();
        time_init();
        profile_init();
+       call_function_init();
        if (!irqs_disabled())
                printk(KERN_CRIT "start_kernel(): bug: interrupts were "
                                 "enabled early\n");
-       early_boot_irqs_on();
+       early_boot_irqs_disabled = false;
        local_irq_enable();
 
        /* Interrupts are enabled now so all GFP allocations are safe. */
@@ -652,10 +617,8 @@ asmlinkage void __init start_kernel(void)
 #endif
        page_cgroup_init();
        enable_debug_pagealloc();
-       kmemtrace_init();
-       kmemleak_init();
        debug_objects_mem_init();
-       idr_init_cache();
+       kmemleak_init();
        setup_per_cpu_pageset();
        numa_policy_init();
        if (late_time_init)
@@ -675,6 +638,7 @@ asmlinkage void __init start_kernel(void)
        buffer_init();
        key_init();
        security_init();
+       dbg_late_init();
        vfs_caches_init(totalram_pages);
        signals_init();
        /* rootfs populating might need page-writeback */
@@ -713,38 +677,39 @@ int initcall_debug;
 core_param(initcall_debug, initcall_debug, bool, 0644);
 
 static char msgbuf[64];
-static struct boot_trace_call call;
-static struct boot_trace_ret ret;
 
-int do_one_initcall(initcall_t fn)
+static int __init_or_module do_one_initcall_debug(initcall_t fn)
 {
-       int count = preempt_count();
        ktime_t calltime, delta, rettime;
+       unsigned long long duration;
+       int ret;
 
-       if (initcall_debug) {
-               call.caller = task_pid_nr(current);
-               printk("calling  %pF @ %i\n", fn, call.caller);
-               calltime = ktime_get();
-               trace_boot_call(&call, fn);
-               enable_boot_trace();
-       }
+       printk(KERN_DEBUG "calling  %pF @ %i\n", fn, task_pid_nr(current));
+       calltime = ktime_get();
+       ret = fn();
+       rettime = ktime_get();
+       delta = ktime_sub(rettime, calltime);
+       duration = (unsigned long long) ktime_to_ns(delta) >> 10;
+       printk(KERN_DEBUG "initcall %pF returned %d after %lld usecs\n", fn,
+               ret, duration);
 
-       ret.result = fn();
+       return ret;
+}
 
-       if (initcall_debug) {
-               disable_boot_trace();
-               rettime = ktime_get();
-               delta = ktime_sub(rettime, calltime);
-               ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
-               trace_boot_ret(&ret, fn);
-               printk("initcall %pF returned %d after %Ld usecs\n", fn,
-                       ret.result, ret.duration);
-       }
+int __init_or_module do_one_initcall(initcall_t fn)
+{
+       int count = preempt_count();
+       int ret;
+
+       if (initcall_debug)
+               ret = do_one_initcall_debug(fn);
+       else
+               ret = fn();
 
        msgbuf[0] = 0;
 
-       if (ret.result && ret.result != -ENODEV && initcall_debug)
-               sprintf(msgbuf, "error code %d ", ret.result);
+       if (ret && ret != -ENODEV && initcall_debug)
+               sprintf(msgbuf, "error code %d ", ret);
 
        if (preempt_count() != count) {
                strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
@@ -758,7 +723,7 @@ int do_one_initcall(initcall_t fn)
                printk("initcall %pF returned with %s\n", fn, msgbuf);
        }
 
-       return ret.result;
+       return ret;
 }
 
 
@@ -770,9 +735,6 @@ static void __init do_initcalls(void)
 
        for (fn = __early_initcall_end; fn < __initcall_end; fn++)
                do_one_initcall(*fn);
-
-       /* Make sure there is no pending stuff from the initcall sequence */
-       flush_scheduled_work();
 }
 
 /*
@@ -784,13 +746,13 @@ static void __init do_initcalls(void)
  */
 static void __init do_basic_setup(void)
 {
-       init_workqueues();
        cpuset_init_smp();
        usermodehelper_init();
-       init_tmpfs();
+       shmem_init();
        driver_init();
        init_irq_proc();
        do_ctors();
+       usermodehelper_enable();
        do_initcalls();
 }
 
@@ -802,7 +764,7 @@ static void __init do_pre_smp_initcalls(void)
                do_one_initcall(*fn);
 }
 
-static void run_init_process(char *init_filename)
+static void run_init_process(const char *init_filename)
 {
        argv_init[0] = init_filename;
        kernel_execve(init_filename, argv_init, envp_init);
@@ -812,12 +774,10 @@ static void run_init_process(char *init_filename)
  * makes it inline to init() and it becomes part of init.text section
  */
 static noinline int init_post(void)
-       __releases(kernel_lock)
 {
        /* need to finish all async __init code before freeing the memory */
        async_synchronize_full();
        free_initmem();
-       unlock_kernel();
        mark_rodata_ro();
        system_state = SYSTEM_RUNNING;
        numa_default_policy();
@@ -853,8 +813,10 @@ static noinline int init_post(void)
 
 static int __init kernel_init(void * unused)
 {
-       lock_kernel();
-
+       /*
+        * Wait until kthreadd is all set-up.
+        */
+       wait_for_completion(&kthreadd_done);
        /*
         * init can allocate pages on any node
         */
@@ -863,22 +825,13 @@ static int __init kernel_init(void * unused)
         * init can run on any cpu.
         */
        set_cpus_allowed_ptr(current, cpu_all_mask);
-       /*
-        * Tell the world that we're going to be the grim
-        * reaper of innocent orphaned children.
-        *
-        * We don't want people to have to make incorrect
-        * assumptions about where in the task array this
-        * can be found.
-        */
-       init_pid_ns.child_reaper = current;
 
        cad_pid = task_pid(current);
 
        smp_prepare_cpus(setup_max_cpus);
 
        do_pre_smp_initcalls();
-       start_boot_trace();
+       lockup_detector_init();
 
        smp_init();
        sched_init_smp();
@@ -892,6 +845,12 @@ static int __init kernel_init(void * unused)
        (void) sys_dup(0);
        (void) sys_dup(0);
        /*
+        * We need to ensure that the filesystem is ready by this point, wait for
+        * async_populate_rootfs to complete.
+        */
+       populate_rootfs_wait();
+
+       /*
         * check if there is an early userspace init.  If yes, let it do all
         * the work
         */