x86 ptrace: avoid unnecessary wrmsr
authorRoland McGrath <roland@redhat.com>
Thu, 3 Apr 2008 21:18:55 +0000 (14:18 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 3 Apr 2008 22:42:43 +0000 (15:42 -0700)
This avoids using wrmsr on MSR_IA32_DEBUGCTLMSR when it's not needed.
No wrmsr ever needs to be done if noone has ever used block stepping.

Without this change, using ptrace on 2.6.25 on an x86 KVM guest
will tickle KVM's missing support for the MSR and crash the guest
kernel.  Though host KVM is the buggy one, this makes for a regression
in the guest behavior from 2.6.24->2.6.25 that we can easily avoid.

I also corrected some bad whitespace.

Signed-off-by: Roland McGrath <roland@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/x86/kernel/step.c

index 9d406cdc847f4da493611d3f48a634e8f868792b..071ff4798236736f9d961050954589a4adb54fe4 100644 (file)
@@ -140,6 +140,9 @@ static int enable_single_step(struct task_struct *child)
  */
 static void write_debugctlmsr(struct task_struct *child, unsigned long val)
 {
  */
 static void write_debugctlmsr(struct task_struct *child, unsigned long val)
 {
+       if (child->thread.debugctlmsr == val)
+               return;
+
        child->thread.debugctlmsr = val;
 
        if (child != current)
        child->thread.debugctlmsr = val;
 
        if (child != current)
@@ -165,11 +168,11 @@ static void enable_step(struct task_struct *child, bool block)
                write_debugctlmsr(child,
                                  child->thread.debugctlmsr | DEBUGCTLMSR_BTF);
        } else {
                write_debugctlmsr(child,
                                  child->thread.debugctlmsr | DEBUGCTLMSR_BTF);
        } else {
-           write_debugctlmsr(child,
-                             child->thread.debugctlmsr & ~DEBUGCTLMSR_BTF);
+               write_debugctlmsr(child,
+                                 child->thread.debugctlmsr & ~DEBUGCTLMSR_BTF);
 
 
-           if (!child->thread.debugctlmsr)
-                   clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
+               if (!child->thread.debugctlmsr)
+                       clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
        }
 }
 
        }
 }