cgroups: add cpu_relax() calls in css_tryget() and cgroup_clear_css_refs()
[safe/jmp/linux-2.6] / kernel / panic.c
index 8010b9b..2a2ff36 100644 (file)
 #include <linux/nmi.h>
 #include <linux/kexec.h>
 #include <linux/debug_locks.h>
+#include <linux/random.h>
+#include <linux/kallsyms.h>
+#include <linux/dmi.h>
 
 int panic_on_oops;
-int tainted;
+static unsigned long tainted_mask;
 static int pause_on_oops;
 static int pause_on_oops_flag;
 static DEFINE_SPINLOCK(pause_on_oops_lock);
@@ -32,13 +35,6 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
 
 EXPORT_SYMBOL(panic_notifier_list);
 
-static int __init panic_setup(char *str)
-{
-       panic_timeout = simple_strtoul(str, NULL, 0);
-       return 1;
-}
-__setup("panic=", panic_setup);
-
 static long no_blink(long time)
 {
        return 0;
@@ -56,14 +52,14 @@ EXPORT_SYMBOL(panic_blink);
  *
  *     This function never returns.
  */
+
 NORET_TYPE void panic(const char * fmt, ...)
 {
        long i;
        static char buf[1024];
        va_list args;
 #if defined(CONFIG_S390)
-        unsigned long caller = (unsigned long) __builtin_return_address(0);
+       unsigned long caller = (unsigned long) __builtin_return_address(0);
 #endif
 
        /*
@@ -128,7 +124,7 @@ NORET_TYPE void panic(const char * fmt, ...)
        }
 #endif
 #if defined(CONFIG_S390)
-        disabled_wait(caller);
+       disabled_wait(caller);
 #endif
        local_irq_enable();
        for (i = 0;;) {
@@ -141,6 +137,27 @@ NORET_TYPE void panic(const char * fmt, ...)
 
 EXPORT_SYMBOL(panic);
 
+
+struct tnt {
+       u8 bit;
+       char true;
+       char false;
+};
+
+static const struct tnt tnts[] = {
+       { TAINT_PROPRIETARY_MODULE, 'P', 'G' },
+       { TAINT_FORCED_MODULE, 'F', ' ' },
+       { TAINT_UNSAFE_SMP, 'S', ' ' },
+       { TAINT_FORCED_RMMOD, 'R', ' ' },
+       { TAINT_MACHINE_CHECK, 'M', ' ' },
+       { TAINT_BAD_PAGE, 'B', ' ' },
+       { TAINT_USER, 'U', ' ' },
+       { TAINT_DIE, 'D', ' ' },
+       { TAINT_OVERRIDDEN_ACPI_TABLE, 'A', ' ' },
+       { TAINT_WARN, 'W', ' ' },
+       { TAINT_CRAP, 'C', ' ' },
+};
+
 /**
  *     print_tainted - return a string to represent the kernel taint state.
  *
@@ -148,42 +165,53 @@ EXPORT_SYMBOL(panic);
  *  'F' - Module has been forcibly loaded.
  *  'S' - SMP with CPUs not designed for SMP.
  *  'R' - User forced a module unload.
- *  'M' - Machine had a machine check experience.
+ *  'M' - System experienced a machine check exception.
  *  'B' - System has hit bad_page.
+ *  'U' - Userspace-defined naughtiness.
+ *  'D' - Kernel has oopsed before
+ *  'A' - ACPI table overridden.
+ *  'W' - Taint on warning.
+ *  'C' - modules from drivers/staging are loaded.
  *
  *     The string is overwritten by the next call to print_taint().
  */
 const char *print_tainted(void)
 {
-       static char buf[20];
-       if (tainted) {
-               snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c",
-                       tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
-                       tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
-                       tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
-                       tainted & TAINT_FORCED_RMMOD ? 'R' : ' ',
-                       tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
-                       tainted & TAINT_BAD_PAGE ? 'B' : ' ');
-       }
-       else
+       static char buf[ARRAY_SIZE(tnts) + sizeof("Tainted: ") + 1];
+
+       if (tainted_mask) {
+               char *s;
+               int i;
+
+               s = buf + sprintf(buf, "Tainted: ");
+               for (i = 0; i < ARRAY_SIZE(tnts); i++) {
+                       const struct tnt *t = &tnts[i];
+                       *s++ = test_bit(t->bit, &tainted_mask) ?
+                                       t->true : t->false;
+               }
+               *s = 0;
+       } else
                snprintf(buf, sizeof(buf), "Not tainted");
        return(buf);
 }
 
-void add_taint(unsigned flag)
+int test_taint(unsigned flag)
 {
-       debug_locks = 0; /* can't trust the integrity of the kernel anymore */
-       tainted |= flag;
+       return test_bit(flag, &tainted_mask);
+}
+EXPORT_SYMBOL(test_taint);
+
+unsigned long get_taint(void)
+{
+       return tainted_mask;
 }
-EXPORT_SYMBOL(add_taint);
 
-static int __init pause_on_oops_setup(char *str)
+void add_taint(unsigned flag)
 {
-       pause_on_oops = simple_strtoul(str, NULL, 0);
-       return 1;
+       debug_locks = 0; /* can't trust the integrity of the kernel anymore */
+       set_bit(flag, &tainted_mask);
 }
-__setup("pause_on_oops=", pause_on_oops_setup);
+EXPORT_SYMBOL(add_taint);
 
 static void spin_msec(int msecs)
 {
@@ -263,10 +291,80 @@ void oops_enter(void)
 }
 
 /*
+ * 64-bit random ID for oopses:
+ */
+static u64 oops_id;
+
+static int init_oops_id(void)
+{
+       if (!oops_id)
+               get_random_bytes(&oops_id, sizeof(oops_id));
+       else
+               oops_id++;
+
+       return 0;
+}
+late_initcall(init_oops_id);
+
+static void print_oops_end_marker(void)
+{
+       init_oops_id();
+       printk(KERN_WARNING "---[ end trace %016llx ]---\n",
+               (unsigned long long)oops_id);
+}
+
+/*
  * Called when the architecture exits its oops handler, after printing
  * everything.
  */
 void oops_exit(void)
 {
        do_oops_enter_exit();
+       print_oops_end_marker();
 }
+
+#ifdef WANT_WARN_ON_SLOWPATH
+void warn_slowpath(const char *file, int line, const char *fmt, ...)
+{
+       va_list args;
+       char function[KSYM_SYMBOL_LEN];
+       unsigned long caller = (unsigned long)__builtin_return_address(0);
+       const char *board;
+
+       sprint_symbol(function, caller);
+
+       printk(KERN_WARNING "------------[ cut here ]------------\n");
+       printk(KERN_WARNING "WARNING: at %s:%d %s()\n", file,
+               line, function);
+       board = dmi_get_system_info(DMI_PRODUCT_NAME);
+       if (board)
+               printk(KERN_WARNING "Hardware name: %s\n", board);
+
+       if (fmt) {
+               va_start(args, fmt);
+               vprintk(fmt, args);
+               va_end(args);
+       }
+
+       print_modules();
+       dump_stack();
+       print_oops_end_marker();
+       add_taint(TAINT_WARN);
+}
+EXPORT_SYMBOL(warn_slowpath);
+#endif
+
+#ifdef CONFIG_CC_STACKPROTECTOR
+/*
+ * Called when gcc's -fstack-protector feature is used, and
+ * gcc detects corruption of the on-stack canary value
+ */
+void __stack_chk_fail(void)
+{
+       panic("stack-protector: Kernel stack is corrupted");
+}
+EXPORT_SYMBOL(__stack_chk_fail);
+#endif
+
+core_param(panic, panic_timeout, int, 0644);
+core_param(pause_on_oops, pause_on_oops, int, 0644);