x86: debugctlmsr context switch
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 adds low-level support for a per-thread value of MSR_IA32_DEBUGCTLMSR.
The per-thread value is switched in when TIF_DEBUGCTLMSR is set.

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/process_32.c
arch/x86/kernel/process_64.c
include/asm-x86/processor_32.h
include/asm-x86/processor_64.h
include/asm-x86/thread_info_32.h
include/asm-x86/thread_info_64.h

index d9905c9..d5462f2 100644 (file)
@@ -602,10 +602,14 @@ static noinline void
 __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
                 struct tss_struct *tss)
 {
-       struct thread_struct *next;
+       struct thread_struct *prev, *next;
 
+       prev = &prev_p->thread;
        next = &next_p->thread;
 
+       if (next->debugctlmsr != prev->debugctlmsr)
+               wrmsr(MSR_IA32_DEBUGCTLMSR, next->debugctlmsr, 0);
+
        if (test_tsk_thread_flag(next_p, TIF_DEBUG)) {
                set_debugreg(next->debugreg[0], 0);
                set_debugreg(next->debugreg[1], 1);
index f7356e5..ae5eca1 100644 (file)
@@ -555,6 +555,9 @@ static inline void __switch_to_xtra(struct task_struct *prev_p,
        prev = &prev_p->thread,
        next = &next_p->thread;
 
+       if (next->debugctlmsr != prev->debugctlmsr)
+               wrmsrl(MSR_IA32_DEBUGCTLMSR, next->debugctlmsr);
+
        if (test_tsk_thread_flag(next_p, TIF_DEBUG)) {
                loaddebug(next, 0);
                loaddebug(next, 1);
index 2540bf8..3c67eac 100644 (file)
@@ -368,6 +368,8 @@ struct thread_struct {
        unsigned long   iopl;
 /* max allowed port in the bitmap, in bytes: */
        unsigned long   io_bitmap_max;
+/* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set.  */
+       unsigned long   debugctlmsr;
 };
 
 #define INIT_THREAD  {                                                 \
index 20d8935..e7bea4f 100644 (file)
@@ -238,6 +238,8 @@ struct thread_struct {
        int             ioperm;
        unsigned long   *io_bitmap_ptr;
        unsigned io_bitmap_max;
+/* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set.  */
+       unsigned long   debugctlmsr;
 /* cached TLS descriptors. */
        u64 tls_array[GDT_ENTRY_TLS_ENTRIES];
 } __attribute__((aligned(16)));
index 009ecc6..306fc80 100644 (file)
@@ -139,6 +139,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_FREEZE             19      /* is freezing for suspend */
 #define TIF_NOTSC              20      /* TSC is not accessible in userland */
 #define TIF_FORCED_TF          21      /* true if TF in eflags artificially */
+#define TIF_DEBUGCTLMSR                22      /* uses thread_struct.debugctlmsr */
 
 #define _TIF_SYSCALL_TRACE     (1<<TIF_SYSCALL_TRACE)
 #define _TIF_SIGPENDING                (1<<TIF_SIGPENDING)
@@ -155,6 +156,7 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_FREEZE            (1<<TIF_FREEZE)
 #define _TIF_NOTSC             (1<<TIF_NOTSC)
 #define _TIF_FORCED_TF         (1<<TIF_FORCED_TF)
+#define _TIF_DEBUGCTLMSR       (1<<TIF_DEBUGCTLMSR)
 
 /* work to do on interrupt/exception return */
 #define _TIF_WORK_MASK \
@@ -164,8 +166,8 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_ALLWORK_MASK      (0x0000FFFF & ~_TIF_SECCOMP)
 
 /* flags to check in __switch_to() */
-#define _TIF_WORK_CTXSW_NEXT (_TIF_IO_BITMAP | _TIF_NOTSC | _TIF_DEBUG)
-#define _TIF_WORK_CTXSW_PREV (_TIF_IO_BITMAP | _TIF_NOTSC)
+#define _TIF_WORK_CTXSW_NEXT (_TIF_IO_BITMAP | _TIF_NOTSC | _TIF_DEBUG | _TIF_DEBUGCTLMSR)
+#define _TIF_WORK_CTXSW_PREV (_TIF_IO_BITMAP | _TIF_NOTSC | _TIF_DEBUGCTLMSR)
 
 /*
  * Thread-synchronous status.
index e0f41b3..ee35fd1 100644 (file)
@@ -122,6 +122,7 @@ static inline struct thread_info *stack_thread_info(void)
 #define TIF_IO_BITMAP          22      /* uses I/O bitmap */
 #define TIF_FREEZE             23      /* is freezing for suspend */
 #define TIF_FORCED_TF          24      /* true if TF in eflags artificially */
+#define TIF_DEBUGCTLMSR                25      /* uses thread_struct.debugctlmsr */
 
 #define _TIF_SYSCALL_TRACE     (1<<TIF_SYSCALL_TRACE)
 #define _TIF_SIGPENDING                (1<<TIF_SIGPENDING)
@@ -140,6 +141,7 @@ static inline struct thread_info *stack_thread_info(void)
 #define _TIF_IO_BITMAP         (1<<TIF_IO_BITMAP)
 #define _TIF_FREEZE            (1<<TIF_FREEZE)
 #define _TIF_FORCED_TF         (1<<TIF_FORCED_TF)
+#define _TIF_DEBUGCTLMSR       (1<<TIF_DEBUGCTLMSR)
 
 /* work to do on interrupt/exception return */
 #define _TIF_WORK_MASK \
@@ -151,7 +153,7 @@ static inline struct thread_info *stack_thread_info(void)
        (_TIF_SIGPENDING|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY|_TIF_HRTICK_RESCHED)
 
 /* flags to check in __switch_to() */
-#define _TIF_WORK_CTXSW (_TIF_DEBUG|_TIF_IO_BITMAP)
+#define _TIF_WORK_CTXSW (_TIF_DEBUG|_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR)
 
 #define PREEMPT_ACTIVE     0x10000000