x86 single_step: TIF_FORCED_TF
[pandora-kernel.git] / arch / x86 / kernel / traps_64.c
index bc7116a..874aca3 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/uaccess.h>
 #include <linux/bug.h>
 #include <linux/kdebug.h>
+#include <linux/utsname.h>
 
 #if defined(CONFIG_EDAC)
 #include <linux/edac.h>
@@ -201,7 +202,7 @@ static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
 #define MSG(txt) ops->warning(data, txt)
 
 /*
- * x86-64 can have upto three kernel stacks: 
+ * x86-64 can have up to three kernel stacks: 
  * process stack
  * interrupt stack
  * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
@@ -215,7 +216,7 @@ static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
 
 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
                unsigned long *stack,
-               struct stacktrace_ops *ops, void *data)
+               const struct stacktrace_ops *ops, void *data)
 {
        const unsigned cpu = get_cpu();
        unsigned long *irqstack_end = (unsigned long*)cpu_pda(cpu)->irqstackptr;
@@ -336,7 +337,7 @@ static void print_trace_address(void *data, unsigned long addr)
        printk_address(addr);
 }
 
-static struct stacktrace_ops print_trace_ops = {
+static const struct stacktrace_ops print_trace_ops = {
        .warning = print_trace_warning,
        .warning_symbol = print_trace_warning_symbol,
        .stack = print_trace_stack,
@@ -400,6 +401,12 @@ void show_stack(struct task_struct *tsk, unsigned long * rsp)
 void dump_stack(void)
 {
        unsigned long dummy;
+
+       printk("Pid: %d, comm: %.20s %s %s %.*s\n",
+               current->pid, current->comm, print_tainted(),
+               init_utsname()->release,
+               (int)strcspn(init_utsname()->version, " "),
+               init_utsname()->version);
        show_trace(NULL, NULL, &dummy);
 }
 
@@ -454,15 +461,7 @@ int is_valid_bugaddr(unsigned long rip)
        return ud2 == 0x0b0f;
 }
 
-#ifdef CONFIG_BUG
-void out_of_line_bug(void)
-{ 
-       BUG(); 
-} 
-EXPORT_SYMBOL(out_of_line_bug);
-#endif
-
-static DEFINE_SPINLOCK(die_lock);
+static raw_spinlock_t die_lock = __RAW_SPIN_LOCK_UNLOCKED;
 static int die_owner = -1;
 static unsigned int die_nest_count;
 
@@ -474,13 +473,13 @@ unsigned __kprobes long oops_begin(void)
        oops_enter();
 
        /* racy, but better than risking deadlock. */
-       local_irq_save(flags);
+       raw_local_irq_save(flags);
        cpu = smp_processor_id();
-       if (!spin_trylock(&die_lock)) { 
+       if (!__raw_spin_trylock(&die_lock)) {
                if (cpu == die_owner) 
                        /* nested oops. should stop eventually */;
                else
-                       spin_lock(&die_lock);
+                       __raw_spin_lock(&die_lock);
        }
        die_nest_count++;
        die_owner = cpu;
@@ -494,12 +493,10 @@ void __kprobes oops_end(unsigned long flags)
        die_owner = -1;
        bust_spinlocks(0);
        die_nest_count--;
-       if (die_nest_count)
-               /* We still own the lock */
-               local_irq_restore(flags);
-       else
+       if (!die_nest_count)
                /* Nest count reaches zero, release the lock. */
-               spin_unlock_irqrestore(&die_lock, flags);
+               __raw_spin_unlock(&die_lock);
+       raw_local_irq_restore(flags);
        if (panic_on_oops)
                panic("Fatal exception");
        oops_exit();
@@ -630,6 +627,7 @@ asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
        info.si_errno = 0; \
        info.si_code = sicode; \
        info.si_addr = (void __user *)siaddr; \
+       trace_hardirqs_fixup(); \
        if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) \
                                                        == NOTIFY_STOP) \
                return; \
@@ -809,6 +807,8 @@ asmlinkage __kprobes void default_do_nmi(struct pt_regs *regs)
 /* runs on IST stack. */
 asmlinkage void __kprobes do_int3(struct pt_regs * regs, long error_code)
 {
+       trace_hardirqs_fixup();
+
        if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) == NOTIFY_STOP) {
                return;
        }
@@ -846,6 +846,8 @@ asmlinkage void __kprobes do_debug(struct pt_regs * regs,
        struct task_struct *tsk = current;
        siginfo_t info;
 
+       trace_hardirqs_fixup();
+
        get_debugreg(condition, 6);
 
        if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
@@ -863,27 +865,14 @@ asmlinkage void __kprobes do_debug(struct pt_regs * regs,
 
        tsk->thread.debugreg6 = condition;
 
-       /* Mask out spurious TF errors due to lazy TF clearing */
+
+       /*
+        * Single-stepping through TF: make sure we ignore any events in
+        * kernel space (but re-enable TF when returning to user mode).
+        */
        if (condition & DR_STEP) {
-               /*
-                * The TF error should be masked out only if the current
-                * process is not traced and if the TRAP flag has been set
-                * previously by a tracing process (condition detected by
-                * the PT_DTRACE flag); remember that the i386 TRAP flag
-                * can be modified by the process itself in user mode,
-                * allowing programs to debug themselves without the ptrace()
-                * interface.
-                */
                 if (!user_mode(regs))
                        goto clear_TF_reenable;
-               /*
-                * Was the TF flag set by a debugger? If so, clear it now,
-                * so that register information is correct.
-                */
-               if (tsk->ptrace & PT_DTRACE) {
-                       regs->eflags &= ~TF_MASK;
-                       tsk->ptrace &= ~PT_DTRACE;
-               }
        }
 
        /* Ok, finally something we can handle */