aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>2008-01-30 07:30:54 -0500
committerIngo Molnar <mingo@elte.hu>2008-01-30 07:30:54 -0500
commit7e9916040b3020d0f36d68bb7512e3b80b623097 (patch)
tree7c391bcdb7a5d917b54ae968304e8a951997e16e
parent0a049bb0ab807b4a95dce9cd0b603c01c199a287 (diff)
x86: debugctlmsr context switch
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>
-rw-r--r--arch/x86/kernel/process_32.c6
-rw-r--r--arch/x86/kernel/process_64.c3
-rw-r--r--include/asm-x86/processor_32.h2
-rw-r--r--include/asm-x86/processor_64.h2
-rw-r--r--include/asm-x86/thread_info_32.h6
-rw-r--r--include/asm-x86/thread_info_64.h4
6 files changed, 19 insertions, 4 deletions
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index d9905c9d0fd5..d5462f228daf 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -602,10 +602,14 @@ static noinline void
602__switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, 602__switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
603 struct tss_struct *tss) 603 struct tss_struct *tss)
604{ 604{
605 struct thread_struct *next; 605 struct thread_struct *prev, *next;
606 606
607 prev = &prev_p->thread;
607 next = &next_p->thread; 608 next = &next_p->thread;
608 609
610 if (next->debugctlmsr != prev->debugctlmsr)
611 wrmsr(MSR_IA32_DEBUGCTLMSR, next->debugctlmsr, 0);
612
609 if (test_tsk_thread_flag(next_p, TIF_DEBUG)) { 613 if (test_tsk_thread_flag(next_p, TIF_DEBUG)) {
610 set_debugreg(next->debugreg[0], 0); 614 set_debugreg(next->debugreg[0], 0);
611 set_debugreg(next->debugreg[1], 1); 615 set_debugreg(next->debugreg[1], 1);
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index f7356e5517f6..ae5eca17aa3c 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -555,6 +555,9 @@ static inline void __switch_to_xtra(struct task_struct *prev_p,
555 prev = &prev_p->thread, 555 prev = &prev_p->thread,
556 next = &next_p->thread; 556 next = &next_p->thread;
557 557
558 if (next->debugctlmsr != prev->debugctlmsr)
559 wrmsrl(MSR_IA32_DEBUGCTLMSR, next->debugctlmsr);
560
558 if (test_tsk_thread_flag(next_p, TIF_DEBUG)) { 561 if (test_tsk_thread_flag(next_p, TIF_DEBUG)) {
559 loaddebug(next, 0); 562 loaddebug(next, 0);
560 loaddebug(next, 1); 563 loaddebug(next, 1);
diff --git a/include/asm-x86/processor_32.h b/include/asm-x86/processor_32.h
index 2540bf8d5724..3c67eacb3168 100644
--- a/include/asm-x86/processor_32.h
+++ b/include/asm-x86/processor_32.h
@@ -368,6 +368,8 @@ struct thread_struct {
368 unsigned long iopl; 368 unsigned long iopl;
369/* max allowed port in the bitmap, in bytes: */ 369/* max allowed port in the bitmap, in bytes: */
370 unsigned long io_bitmap_max; 370 unsigned long io_bitmap_max;
371/* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set. */
372 unsigned long debugctlmsr;
371}; 373};
372 374
373#define INIT_THREAD { \ 375#define INIT_THREAD { \
diff --git a/include/asm-x86/processor_64.h b/include/asm-x86/processor_64.h
index 20d8935d141a..e7bea4fed642 100644
--- a/include/asm-x86/processor_64.h
+++ b/include/asm-x86/processor_64.h
@@ -238,6 +238,8 @@ struct thread_struct {
238 int ioperm; 238 int ioperm;
239 unsigned long *io_bitmap_ptr; 239 unsigned long *io_bitmap_ptr;
240 unsigned io_bitmap_max; 240 unsigned io_bitmap_max;
241/* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set. */
242 unsigned long debugctlmsr;
241/* cached TLS descriptors. */ 243/* cached TLS descriptors. */
242 u64 tls_array[GDT_ENTRY_TLS_ENTRIES]; 244 u64 tls_array[GDT_ENTRY_TLS_ENTRIES];
243} __attribute__((aligned(16))); 245} __attribute__((aligned(16)));
diff --git a/include/asm-x86/thread_info_32.h b/include/asm-x86/thread_info_32.h
index 009ecc6ad38b..306fc80800e1 100644
--- a/include/asm-x86/thread_info_32.h
+++ b/include/asm-x86/thread_info_32.h
@@ -139,6 +139,7 @@ static inline struct thread_info *current_thread_info(void)
139#define TIF_FREEZE 19 /* is freezing for suspend */ 139#define TIF_FREEZE 19 /* is freezing for suspend */
140#define TIF_NOTSC 20 /* TSC is not accessible in userland */ 140#define TIF_NOTSC 20 /* TSC is not accessible in userland */
141#define TIF_FORCED_TF 21 /* true if TF in eflags artificially */ 141#define TIF_FORCED_TF 21 /* true if TF in eflags artificially */
142#define TIF_DEBUGCTLMSR 22 /* uses thread_struct.debugctlmsr */
142 143
143#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) 144#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
144#define _TIF_SIGPENDING (1<<TIF_SIGPENDING) 145#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
@@ -155,6 +156,7 @@ static inline struct thread_info *current_thread_info(void)
155#define _TIF_FREEZE (1<<TIF_FREEZE) 156#define _TIF_FREEZE (1<<TIF_FREEZE)
156#define _TIF_NOTSC (1<<TIF_NOTSC) 157#define _TIF_NOTSC (1<<TIF_NOTSC)
157#define _TIF_FORCED_TF (1<<TIF_FORCED_TF) 158#define _TIF_FORCED_TF (1<<TIF_FORCED_TF)
159#define _TIF_DEBUGCTLMSR (1<<TIF_DEBUGCTLMSR)
158 160
159/* work to do on interrupt/exception return */ 161/* work to do on interrupt/exception return */
160#define _TIF_WORK_MASK \ 162#define _TIF_WORK_MASK \
@@ -164,8 +166,8 @@ static inline struct thread_info *current_thread_info(void)
164#define _TIF_ALLWORK_MASK (0x0000FFFF & ~_TIF_SECCOMP) 166#define _TIF_ALLWORK_MASK (0x0000FFFF & ~_TIF_SECCOMP)
165 167
166/* flags to check in __switch_to() */ 168/* flags to check in __switch_to() */
167#define _TIF_WORK_CTXSW_NEXT (_TIF_IO_BITMAP | _TIF_NOTSC | _TIF_DEBUG) 169#define _TIF_WORK_CTXSW_NEXT (_TIF_IO_BITMAP | _TIF_NOTSC | _TIF_DEBUG | _TIF_DEBUGCTLMSR)
168#define _TIF_WORK_CTXSW_PREV (_TIF_IO_BITMAP | _TIF_NOTSC) 170#define _TIF_WORK_CTXSW_PREV (_TIF_IO_BITMAP | _TIF_NOTSC | _TIF_DEBUGCTLMSR)
169 171
170/* 172/*
171 * Thread-synchronous status. 173 * Thread-synchronous status.
diff --git a/include/asm-x86/thread_info_64.h b/include/asm-x86/thread_info_64.h
index e0f41b3deced..ee35fd12b541 100644
--- a/include/asm-x86/thread_info_64.h
+++ b/include/asm-x86/thread_info_64.h
@@ -122,6 +122,7 @@ static inline struct thread_info *stack_thread_info(void)
122#define TIF_IO_BITMAP 22 /* uses I/O bitmap */ 122#define TIF_IO_BITMAP 22 /* uses I/O bitmap */
123#define TIF_FREEZE 23 /* is freezing for suspend */ 123#define TIF_FREEZE 23 /* is freezing for suspend */
124#define TIF_FORCED_TF 24 /* true if TF in eflags artificially */ 124#define TIF_FORCED_TF 24 /* true if TF in eflags artificially */
125#define TIF_DEBUGCTLMSR 25 /* uses thread_struct.debugctlmsr */
125 126
126#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) 127#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
127#define _TIF_SIGPENDING (1<<TIF_SIGPENDING) 128#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
@@ -140,6 +141,7 @@ static inline struct thread_info *stack_thread_info(void)
140#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP) 141#define _TIF_IO_BITMAP (1<<TIF_IO_BITMAP)
141#define _TIF_FREEZE (1<<TIF_FREEZE) 142#define _TIF_FREEZE (1<<TIF_FREEZE)
142#define _TIF_FORCED_TF (1<<TIF_FORCED_TF) 143#define _TIF_FORCED_TF (1<<TIF_FORCED_TF)
144#define _TIF_DEBUGCTLMSR (1<<TIF_DEBUGCTLMSR)
143 145
144/* work to do on interrupt/exception return */ 146/* work to do on interrupt/exception return */
145#define _TIF_WORK_MASK \ 147#define _TIF_WORK_MASK \
@@ -151,7 +153,7 @@ static inline struct thread_info *stack_thread_info(void)
151 (_TIF_SIGPENDING|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY|_TIF_HRTICK_RESCHED) 153 (_TIF_SIGPENDING|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY|_TIF_HRTICK_RESCHED)
152 154
153/* flags to check in __switch_to() */ 155/* flags to check in __switch_to() */
154#define _TIF_WORK_CTXSW (_TIF_DEBUG|_TIF_IO_BITMAP) 156#define _TIF_WORK_CTXSW (_TIF_DEBUG|_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR)
155 157
156#define PREEMPT_ACTIVE 0x10000000 158#define PREEMPT_ACTIVE 0x10000000
157 159