]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
x86: debugctlmsr arch_has_block_step
authorRoland McGrath <roland@redhat.com>
Wed, 30 Jan 2008 12:30:54 +0000 (13:30 +0100)
committerIngo Molnar <mingo@elte.hu>
Wed, 30 Jan 2008 12:30:54 +0000 (13:30 +0100)
This implements user-mode step-until-branch on x86 using the BTF bit
in MSR_IA32_DEBUGCTLMSR.  It's just like single-step, only less so.

Signed-off-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
arch/x86/kernel/step.c
arch/x86/kernel/traps_32.c
arch/x86/kernel/traps_64.c
include/asm-x86/ptrace.h

index 243bff650ca5ddb7777abec824329399dff9f730..cf4b9dac4a0538d15f47a3c1c41974d2c81a551d 100644 (file)
@@ -107,7 +107,10 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
        return 0;
 }
 
-void user_enable_single_step(struct task_struct *child)
+/*
+ * Enable single-stepping.  Return nonzero if user mode is not using TF itself.
+ */
+static int enable_single_step(struct task_struct *child)
 {
        struct pt_regs *regs = task_pt_regs(child);
 
@@ -122,7 +125,7 @@ void user_enable_single_step(struct task_struct *child)
         * If TF was already set, don't do anything else
         */
        if (regs->eflags & X86_EFLAGS_TF)
-               return;
+               return 0;
 
        /* Set TF on the kernel stack.. */
        regs->eflags |= X86_EFLAGS_TF;
@@ -133,13 +136,68 @@ void user_enable_single_step(struct task_struct *child)
         * won't clear it by hand later.
         */
        if (is_setting_trap_flag(child, regs))
-               return;
+               return 0;
 
        set_tsk_thread_flag(child, TIF_FORCED_TF);
+
+       return 1;
+}
+
+/*
+ * Install this value in MSR_IA32_DEBUGCTLMSR whenever child is running.
+ */
+static void write_debugctlmsr(struct task_struct *child, unsigned long val)
+{
+       child->thread.debugctlmsr = val;
+
+       if (child != current)
+               return;
+
+#ifdef CONFIG_X86_64
+       wrmsrl(MSR_IA32_DEBUGCTLMSR, val);
+#else
+       wrmsr(MSR_IA32_DEBUGCTLMSR, val, 0);
+#endif
+}
+
+/*
+ * Enable single or block step.
+ */
+static void enable_step(struct task_struct *child, bool block)
+{
+       /*
+        * Make sure block stepping (BTF) is not enabled unless it should be.
+        * Note that we don't try to worry about any is_setting_trap_flag()
+        * instructions after the first when using block stepping.
+        * So noone should try to use debugger block stepping in a program
+        * that uses user-mode single stepping itself.
+        */
+       if (enable_single_step(child) && block) {
+               set_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
+               write_debugctlmsr(child, DEBUGCTLMSR_BTF);
+       } else if (test_and_clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR)) {
+               write_debugctlmsr(child, 0);
+       }
+}
+
+void user_enable_single_step(struct task_struct *child)
+{
+       enable_step(child, 0);
+}
+
+void user_enable_block_step(struct task_struct *child)
+{
+       enable_step(child, 1);
 }
 
 void user_disable_single_step(struct task_struct *child)
 {
+       /*
+        * Make sure block stepping (BTF) is disabled.
+        */
+       if (test_and_clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR))
+               write_debugctlmsr(child, 0);
+
        /* Always clear TIF_SINGLESTEP... */
        clear_tsk_thread_flag(child, TIF_SINGLESTEP);
 
index 02d1e1e58e819211fed1813113d945b0baeb0e9d..9b0bbd508cd58b312159edde69e709c2af236798 100644 (file)
@@ -837,6 +837,12 @@ fastcall void __kprobes do_debug(struct pt_regs * regs, long error_code)
 
        get_debugreg(condition, 6);
 
+       /*
+        * The processor cleared BTF, so don't mark that we need it set.
+        */
+       clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
+       tsk->thread.debugctlmsr = 0;
+
        if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
                                        SIGTRAP) == NOTIFY_STOP)
                return;
index 874aca397b02428f6f342142f28b11b841ae7b0d..610a64d6bdf0eff62af45778a15e21843c4a5ae2 100644 (file)
@@ -850,6 +850,12 @@ asmlinkage void __kprobes do_debug(struct pt_regs * regs,
 
        get_debugreg(condition, 6);
 
+       /*
+        * The processor cleared BTF, so don't mark that we need it set.
+        */
+       clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
+       tsk->thread.debugctlmsr = 0;
+
        if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
                                                SIGTRAP) == NOTIFY_STOP)
                return;
index d223decd7b013441814ca0cb5aa3eb6781284ba8..04204f3592983a231b33a957d6fe8f4d54ecd7fc 100644 (file)
@@ -150,6 +150,13 @@ enum {
 extern void user_enable_single_step(struct task_struct *);
 extern void user_disable_single_step(struct task_struct *);
 
+extern void user_enable_block_step(struct task_struct *);
+#ifdef CONFIG_X86_DEBUGCTLMSR
+#define arch_has_block_step()  (1)
+#else
+#define arch_has_block_step()  (boot_cpu_data.x86 >= 6)
+#endif
+
 struct user_desc;
 extern int do_get_thread_area(struct task_struct *p, int idx,
                              struct user_desc __user *info);