From 7e9916040b3020d0f36d68bb7512e3b80b623097 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Wed, 30 Jan 2008 13:30:54 +0100 Subject: 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 Signed-off-by: Ingo Molnar Signed-off-by: Thomas Gleixner --- arch/x86/kernel/process_32.c | 6 +++++- arch/x86/kernel/process_64.c | 3 +++ include/asm-x86/processor_32.h | 2 ++ include/asm-x86/processor_64.h | 2 ++ include/asm-x86/thread_info_32.h | 6 ++++-- include/asm-x86/thread_info_64.h | 4 +++- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c index d9905c9..d5462f2 100644 --- a/arch/x86/kernel/process_32.c +++ b/arch/x86/kernel/process_32.c @@ -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); diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index f7356e5..ae5eca1 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, 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); diff --git a/include/asm-x86/processor_32.h b/include/asm-x86/processor_32.h index 2540bf8..3c67eac 100644 --- a/include/asm-x86/processor_32.h +++ b/include/asm-x86/processor_32.h @@ -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 { \ diff --git a/include/asm-x86/processor_64.h b/include/asm-x86/processor_64.h index 20d8935..e7bea4f 100644 --- a/include/asm-x86/processor_64.h +++ b/include/asm-x86/processor_64.h @@ -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))); diff --git a/include/asm-x86/thread_info_32.h b/include/asm-x86/thread_info_32.h index 009ecc6..306fc80 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) #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<