Merge branch 'upstream-fixes' of master.kernel.org:/pub/scm/linux/kernel/git/jikos/hid
[sfrench/cifs-2.6.git] / arch / x86_64 / kernel / traps.c
index b54ccc07f37944dba409ac9a27761c5d5e0ce848..d28f01379b9b5f31aff3c17bad2964c7bfa2ff5d 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/unwind.h>
 #include <linux/uaccess.h>
 #include <linux/bug.h>
+#include <linux/kdebug.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
@@ -39,7 +40,6 @@
 #include <asm/debugreg.h>
 #include <asm/desc.h>
 #include <asm/i387.h>
-#include <asm/kdebug.h>
 #include <asm/processor.h>
 #include <asm/unwind.h>
 #include <asm/smp.h>
@@ -71,22 +71,6 @@ asmlinkage void alignment_check(void);
 asmlinkage void machine_check(void);
 asmlinkage void spurious_interrupt_bug(void);
 
-ATOMIC_NOTIFIER_HEAD(die_chain);
-EXPORT_SYMBOL(die_chain);
-
-int register_die_notifier(struct notifier_block *nb)
-{
-       vmalloc_sync_all();
-       return atomic_notifier_chain_register(&die_chain, nb);
-}
-EXPORT_SYMBOL(register_die_notifier); /* used modular by kdb */
-
-int unregister_die_notifier(struct notifier_block *nb)
-{
-       return atomic_notifier_chain_unregister(&die_chain, nb);
-}
-EXPORT_SYMBOL(unregister_die_notifier); /* used modular by kdb */
-
 static inline void conditional_sti(struct pt_regs *regs)
 {
        if (regs->eflags & X86_EFLAGS_IF)
@@ -110,11 +94,6 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
 }
 
 int kstack_depth_to_print = 12;
-#ifdef CONFIG_STACK_UNWIND
-static int call_trace = 1;
-#else
-#define call_trace (-1)
-#endif
 
 #ifdef CONFIG_KALLSYMS
 void printk_address(unsigned long address)
@@ -217,32 +196,6 @@ static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
        return NULL;
 }
 
-struct ops_and_data {
-       struct stacktrace_ops *ops;
-       void *data;
-};
-
-static int dump_trace_unwind(struct unwind_frame_info *info, void *context)
-{
-       struct ops_and_data *oad = (struct ops_and_data *)context;
-       int n = 0;
-       unsigned long sp = UNW_SP(info);
-
-       if (arch_unw_user_mode(info))
-               return -1;
-       while (unwind(info) == 0 && UNW_PC(info)) {
-               n++;
-               oad->ops->address(oad->data, UNW_PC(info));
-               if (arch_unw_user_mode(info))
-                       break;
-               if ((sp & ~(PAGE_SIZE - 1)) == (UNW_SP(info) & ~(PAGE_SIZE - 1))
-                   && sp > UNW_SP(info))
-                       break;
-               sp = UNW_SP(info);
-       }
-       return n;
-}
-
 #define MSG(txt) ops->warning(data, txt)
 
 /*
@@ -270,40 +223,6 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
        if (!tsk)
                tsk = current;
 
-       if (call_trace >= 0) {
-               int unw_ret = 0;
-               struct unwind_frame_info info;
-               struct ops_and_data oad = { .ops = ops, .data = data };
-
-               if (regs) {
-                       if (unwind_init_frame_info(&info, tsk, regs) == 0)
-                               unw_ret = dump_trace_unwind(&info, &oad);
-               } else if (tsk == current)
-                       unw_ret = unwind_init_running(&info, dump_trace_unwind,
-                                                     &oad);
-               else {
-                       if (unwind_init_blocked(&info, tsk) == 0)
-                               unw_ret = dump_trace_unwind(&info, &oad);
-               }
-               if (unw_ret > 0) {
-                       if (call_trace == 1 && !arch_unw_user_mode(&info)) {
-                               ops->warning_symbol(data,
-                                            "DWARF2 unwinder stuck at %s",
-                                            UNW_PC(&info));
-                               if ((long)UNW_SP(&info) < 0) {
-                                       MSG("Leftover inexact backtrace:");
-                                       stack = (unsigned long *)UNW_SP(&info);
-                                       if (!stack)
-                                               goto out;
-                               } else
-                                       MSG("Full inexact backtrace again:");
-                       } else if (call_trace >= 1)
-                               goto out;
-                       else
-                               MSG("Full inexact backtrace again:");
-               } else
-                       MSG("Inexact backtrace:");
-       }
        if (!stack) {
                unsigned long dummy;
                stack = &dummy;
@@ -384,10 +303,9 @@ void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
        /*
         * This handles the process stack:
         */
-       tinfo = current_thread_info();
+       tinfo = task_thread_info(tsk);
        HANDLE_STACK (valid_stack_ptr(tinfo, stack));
 #undef HANDLE_STACK
-out:
        put_cpu();
 }
 EXPORT_SYMBOL(dump_trace);
@@ -492,8 +410,7 @@ void show_registers(struct pt_regs *regs)
        const int cpu = smp_processor_id();
        struct task_struct *cur = cpu_pda(cpu)->pcurrent;
 
-               rsp = regs->rsp;
-
+       rsp = regs->rsp;
        printk("CPU %d ", cpu);
        __show_regs(regs);
        printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
@@ -504,7 +421,6 @@ void show_registers(struct pt_regs *regs)
         * time of the fault..
         */
        if (in_kernel) {
-
                printk("Stack: ");
                _show_stack(NULL, regs, (unsigned long*)rsp);
 
@@ -647,10 +563,20 @@ static void __kprobes do_trap(int trapnr, int signr, char *str,
 {
        struct task_struct *tsk = current;
 
-       tsk->thread.error_code = error_code;
-       tsk->thread.trap_no = trapnr;
-
        if (user_mode(regs)) {
+               /*
+                * We want error_code and trap_no set for userspace
+                * faults and kernelspace faults which result in
+                * die(), but not kernelspace faults which are fixed
+                * up.  die() gives the process no chance to handle
+                * the signal and notice the kernel fault information,
+                * so that won't result in polluting the information
+                * about previously queued, but not yet delivered,
+                * faults.  See also do_general_protection below.
+                */
+               tsk->thread.error_code = error_code;
+               tsk->thread.trap_no = trapnr;
+
                if (exception_trace && unhandled_signal(tsk, signr))
                        printk(KERN_INFO
                               "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n",
@@ -671,8 +597,11 @@ static void __kprobes do_trap(int trapnr, int signr, char *str,
                fixup = search_exception_tables(regs->rip);
                if (fixup)
                        regs->rip = fixup->fixup;
-               else    
+               else {
+                       tsk->thread.error_code = error_code;
+                       tsk->thread.trap_no = trapnr;
                        die(str, regs, error_code);
+               }
                return;
        }
 }
@@ -748,10 +677,10 @@ asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
 
        conditional_sti(regs);
 
-       tsk->thread.error_code = error_code;
-       tsk->thread.trap_no = 13;
-
        if (user_mode(regs)) {
+               tsk->thread.error_code = error_code;
+               tsk->thread.trap_no = 13;
+
                if (exception_trace && unhandled_signal(tsk, SIGSEGV))
                        printk(KERN_INFO
                       "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n",
@@ -770,6 +699,9 @@ asmlinkage void __kprobes do_general_protection(struct pt_regs * regs,
                        regs->rip = fixup->fixup;
                        return;
                }
+
+               tsk->thread.error_code = error_code;
+               tsk->thread.trap_no = 13;
                if (notify_die(DIE_GPF, "general protection fault", regs,
                                        error_code, 13, SIGSEGV) == NOTIFY_STOP)
                        return;
@@ -844,6 +776,9 @@ asmlinkage __kprobes void default_do_nmi(struct pt_regs *regs)
                 */
                if (nmi_watchdog_tick(regs,reason))
                        return;
+               if (notify_die(DIE_NMI_POST, "nmi_post", regs, reason, 2, 0)
+                                                               == NOTIFY_STOP)
+                       return;
                if (!do_nmi_callback(regs,cpu))
                        unknown_nmi_error(reason, regs);
 
@@ -1188,21 +1123,3 @@ static int __init kstack_setup(char *s)
        return 0;
 }
 early_param("kstack", kstack_setup);
-
-#ifdef CONFIG_STACK_UNWIND
-static int __init call_trace_setup(char *s)
-{
-       if (!s)
-               return -EINVAL;
-       if (strcmp(s, "old") == 0)
-               call_trace = -1;
-       else if (strcmp(s, "both") == 0)
-               call_trace = 0;
-       else if (strcmp(s, "newfallback") == 0)
-               call_trace = 1;
-       else if (strcmp(s, "new") == 0)
-               call_trace = 2;
-       return 0;
-}
-early_param("call_trace", call_trace_setup);
-#endif