Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / kernel / panic.c
index d96469de72dc555434818411625ff8a3f855f748..535c96510a448f351dc89f3a36c01b2372f0decf 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/init.h>
 #include <linux/nmi.h>
 #include <linux/console.h>
+#include <linux/bug.h>
 
 #define PANIC_TIMER_STEP 100
 #define PANIC_BLINK_SPD 18
@@ -72,6 +73,26 @@ void __weak nmi_panic_self_stop(struct pt_regs *regs)
 
 atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
 
+/*
+ * A variant of panic() called from NMI context. We return if we've already
+ * panicked on this CPU. If another CPU already panicked, loop in
+ * nmi_panic_self_stop() which can provide architecture dependent code such
+ * as saving register state for crash dump.
+ */
+void nmi_panic(struct pt_regs *regs, const char *msg)
+{
+       int old_cpu, cpu;
+
+       cpu = raw_smp_processor_id();
+       old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu);
+
+       if (old_cpu == PANIC_CPU_INVALID)
+               panic("%s", msg);
+       else if (old_cpu != cpu)
+               nmi_panic_self_stop(regs);
+}
+EXPORT_SYMBOL(nmi_panic);
+
 /**
  *     panic - halt the system
  *     @fmt: The text string to print
@@ -449,20 +470,25 @@ void oops_exit(void)
        kmsg_dump(KMSG_DUMP_OOPS);
 }
 
-#ifdef WANT_WARN_ON_SLOWPATH
-struct slowpath_args {
+struct warn_args {
        const char *fmt;
        va_list args;
 };
 
-static void warn_slowpath_common(const char *file, int line, void *caller,
-                                unsigned taint, struct slowpath_args *args)
+void __warn(const char *file, int line, void *caller, unsigned taint,
+           struct pt_regs *regs, struct warn_args *args)
 {
        disable_trace_on_warning();
 
        pr_warn("------------[ cut here ]------------\n");
-       pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
-               raw_smp_processor_id(), current->pid, file, line, caller);
+
+       if (file)
+               pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
+                       raw_smp_processor_id(), current->pid, file, line,
+                       caller);
+       else
+               pr_warn("WARNING: CPU: %d PID: %d at %pS\n",
+                       raw_smp_processor_id(), current->pid, caller);
 
        if (args)
                vprintk(args->fmt, args->args);
@@ -479,20 +505,27 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
        }
 
        print_modules();
-       dump_stack();
+
+       if (regs)
+               show_regs(regs);
+       else
+               dump_stack();
+
        print_oops_end_marker();
+
        /* Just a warning, don't kill lockdep. */
        add_taint(taint, LOCKDEP_STILL_OK);
 }
 
+#ifdef WANT_WARN_ON_SLOWPATH
 void warn_slowpath_fmt(const char *file, int line, const char *fmt, ...)
 {
-       struct slowpath_args args;
+       struct warn_args args;
 
        args.fmt = fmt;
        va_start(args.args, fmt);
-       warn_slowpath_common(file, line, __builtin_return_address(0),
-                            TAINT_WARN, &args);
+       __warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL,
+              &args);
        va_end(args.args);
 }
 EXPORT_SYMBOL(warn_slowpath_fmt);
@@ -500,20 +533,18 @@ EXPORT_SYMBOL(warn_slowpath_fmt);
 void warn_slowpath_fmt_taint(const char *file, int line,
                             unsigned taint, const char *fmt, ...)
 {
-       struct slowpath_args args;
+       struct warn_args args;
 
        args.fmt = fmt;
        va_start(args.args, fmt);
-       warn_slowpath_common(file, line, __builtin_return_address(0),
-                            taint, &args);
+       __warn(file, line, __builtin_return_address(0), taint, NULL, &args);
        va_end(args.args);
 }
 EXPORT_SYMBOL(warn_slowpath_fmt_taint);
 
 void warn_slowpath_null(const char *file, int line)
 {
-       warn_slowpath_common(file, line, __builtin_return_address(0),
-                            TAINT_WARN, NULL);
+       __warn(file, line, __builtin_return_address(0), TAINT_WARN, NULL, NULL);
 }
 EXPORT_SYMBOL(warn_slowpath_null);
 #endif