itimer: Schedule silent NULL pointer fixup in setitimer() for removal
[linux-flexiantxendom0-3.2.10.git] / kernel / panic.c
index 3b16cd9..80aed44 100644 (file)
@@ -24,6 +24,9 @@
 #include <linux/nmi.h>
 #include <linux/dmi.h>
 
+#define PANIC_TIMER_STEP 100
+#define PANIC_BLINK_SPD 18
+
 int panic_on_oops;
 static unsigned long tainted_mask;
 static int pause_on_oops;
@@ -31,39 +34,28 @@ static int pause_on_oops_flag;
 static DEFINE_SPINLOCK(pause_on_oops_lock);
 
 int panic_timeout;
+EXPORT_SYMBOL_GPL(panic_timeout);
 
 ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
 
 EXPORT_SYMBOL(panic_notifier_list);
 
+static long no_blink(int state)
+{
+       return 0;
+}
+
 /* Returns how long it waited in ms */
-long (*panic_blink)(long time);
+long (*panic_blink)(int state);
 EXPORT_SYMBOL(panic_blink);
 
-static void panic_blink_one_second(void)
+/*
+ * Stop ourself in panic -- architecture code may override this
+ */
+void __weak panic_smp_self_stop(void)
 {
-       static long i = 0, end;
-
-       if (panic_blink) {
-               end = i + MSEC_PER_SEC;
-
-               while (i < end) {
-                       i += panic_blink(i);
-                       mdelay(1);
-                       i++;
-               }
-       } else {
-               /*
-                * When running under a hypervisor a small mdelay may get
-                * rounded up to the hypervisor timeslice. For example, with
-                * a 1ms in 10ms hypervisor timeslice we might inflate a
-                * mdelay(1) loop by 10x.
-                *
-                * If we have nothing to blink, spin on 1 second calls to
-                * mdelay to avoid this.
-                */
-               mdelay(MSEC_PER_SEC);
-       }
+       while (1)
+               cpu_relax();
 }
 
 /**
@@ -74,18 +66,26 @@ static void panic_blink_one_second(void)
  *
  *     This function never returns.
  */
-NORET_TYPE void panic(const char * fmt, ...)
+void panic(const char *fmt, ...)
 {
+       static DEFINE_SPINLOCK(panic_lock);
        static char buf[1024];
        va_list args;
-       long i;
+       long i, i_next = 0;
+       int state = 0;
 
        /*
         * It's possible to come here directly from a panic-assertion and
         * not have preempt disabled. Some functions called from here want
         * preempt to be disabled. No point enabling it later though...
+        *
+        * Only one CPU is allowed to execute the panic code from here. For
+        * multiple parallel invocations of panic, all other CPUs either
+        * stop themself or will wait until they are stopped by the 1st CPU
+        * with smp_send_stop().
         */
-       preempt_disable();
+       if (!spin_trylock(&panic_lock))
+               panic_smp_self_stop();
 
        console_verbose();
        bust_spinlocks(1);
@@ -94,7 +94,11 @@ NORET_TYPE void panic(const char * fmt, ...)
        va_end(args);
        printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
 #ifdef CONFIG_DEBUG_BUGVERBOSE
-       dump_stack();
+       /*
+        * Avoid nested stack-dumping if a panic occurs during oops processing
+        */
+       if (!oops_in_progress)
+               dump_stack();
 #endif
 
        /*
@@ -117,6 +121,9 @@ NORET_TYPE void panic(const char * fmt, ...)
 
        bust_spinlocks(0);
 
+       if (!panic_blink)
+               panic_blink = no_blink;
+
        if (panic_timeout > 0) {
                /*
                 * Delay timeout seconds before rebooting the machine.
@@ -124,10 +131,16 @@ NORET_TYPE void panic(const char * fmt, ...)
                 */
                printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout);
 
-               for (i = 0; i < panic_timeout; i++) {
+               for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) {
                        touch_nmi_watchdog();
-                       panic_blink_one_second();
+                       if (i >= i_next) {
+                               i += panic_blink(state ^= 1);
+                               i_next = i + 3600 / PANIC_BLINK_SPD;
+                       }
+                       mdelay(PANIC_TIMER_STEP);
                }
+       }
+       if (panic_timeout != 0) {
                /*
                 * This will not be a clean reboot, with everything
                 * shutting down.  But if there is a chance of
@@ -152,9 +165,13 @@ NORET_TYPE void panic(const char * fmt, ...)
        }
 #endif
        local_irq_enable();
-       while (1) {
+       for (i = 0; ; i += PANIC_TIMER_STEP) {
                touch_softlockup_watchdog();
-               panic_blink_one_second();
+               if (i >= i_next) {
+                       i += panic_blink(state ^= 1);
+                       i_next = i + 3600 / PANIC_BLINK_SPD;
+               }
+               mdelay(PANIC_TIMER_STEP);
        }
 }
 
@@ -180,6 +197,7 @@ static const struct tnt tnts[] = {
        { TAINT_WARN,                   'W', ' ' },
        { TAINT_CRAP,                   'C', ' ' },
        { TAINT_FIRMWARE_WORKAROUND,    'I', ' ' },
+       { TAINT_OOT_MODULE,             'O', ' ' },
 };
 
 /**
@@ -197,6 +215,7 @@ static const struct tnt tnts[] = {
  *  'W' - Taint on warning.
  *  'C' - modules from drivers/staging are loaded.
  *  'I' - Working around severe firmware bug.
+ *  'O' - Out-of-tree module has been loaded.
  *
  *     The string is overwritten by the next call to print_tainted().
  */
@@ -238,11 +257,20 @@ void add_taint(unsigned flag)
         * Can't trust the integrity of the kernel anymore.
         * We don't call directly debug_locks_off() because the issue
         * is not necessarily serious enough to set oops_in_progress to 1
-        * Also we want to keep up lockdep for staging development and
-        * post-warning case.
+        * Also we want to keep up lockdep for staging/out-of-tree
+        * development and post-warning case.
         */
-       if (flag != TAINT_CRAP && flag != TAINT_WARN && __debug_locks_off())
-               printk(KERN_WARNING "Disabling lock debugging due to kernel taint\n");
+       switch (flag) {
+       case TAINT_CRAP:
+       case TAINT_OOT_MODULE:
+       case TAINT_WARN:
+       case TAINT_FIRMWARE_WORKAROUND:
+               break;
+
+       default:
+               if (__debug_locks_off())
+                       printk(KERN_WARNING "Disabling lock debugging due to kernel taint\n");
+       }
 
        set_bit(flag, &tainted_mask);
 }
@@ -344,7 +372,7 @@ static int init_oops_id(void)
 }
 late_initcall(init_oops_id);
 
-static void print_oops_end_marker(void)
+void print_oops_end_marker(void)
 {
        init_oops_id();
        printk(KERN_WARNING "---[ end trace %016llx ]---\n",
@@ -438,3 +466,13 @@ EXPORT_SYMBOL(__stack_chk_fail);
 
 core_param(panic, panic_timeout, int, 0644);
 core_param(pause_on_oops, pause_on_oops, int, 0644);
+
+static int __init oops_setup(char *s)
+{
+       if (!s)
+               return -EINVAL;
+       if (!strcmp(s, "panic"))
+               panic_on_oops = 1;
+       return 0;
+}
+early_param("oops", oops_setup);