[PATCH 4/25][V3] Add debugreg/load_rsp native hooks

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Glauber de Oliveira Costa
Date: Wednesday, August 15, 2007 - 5:49 am

This patch adds native hooks for debugreg handling functions,
and for the native load_rsp0 function. The later also have its
call sites patched.

[  updates from v2
   * there were still a raw reference to cr4 missing
]

Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 arch/x86_64/kernel/process.c   |    2 +-
 arch/x86_64/kernel/smpboot.c   |    2 +-
 include/asm-x86_64/processor.h |   83 +++++++++++++++++++++++++++++++--------
 3 files changed, 68 insertions(+), 19 deletions(-)

diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c
index 2842f50..33046f1 100644
--- a/arch/x86_64/kernel/process.c
+++ b/arch/x86_64/kernel/process.c
@@ -595,7 +595,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 	/*
 	 * Reload esp0, LDT and the page table pointer:
 	 */
-	tss->rsp0 = next->rsp0;
+	load_rsp0(tss, next);
 
 	/* 
 	 * Switch DS and ES.
diff --git a/arch/x86_64/kernel/smpboot.c b/arch/x86_64/kernel/smpboot.c
index 32f5078..f99ced6 100644
--- a/arch/x86_64/kernel/smpboot.c
+++ b/arch/x86_64/kernel/smpboot.c
@@ -620,7 +620,7 @@ do_rest:
 	start_rip = setup_trampoline();
 
 	init_rsp = c_idle.idle->thread.rsp;
-	per_cpu(init_tss,cpu).rsp0 = init_rsp;
+	load_rsp0(&per_cpu(init_tss,cpu), &c_idle.idle->thread);
 	initial_code = start_secondary;
 	clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
 
diff --git a/include/asm-x86_64/processor.h b/include/asm-x86_64/processor.h
index 1952517..524390f 100644
--- a/include/asm-x86_64/processor.h
+++ b/include/asm-x86_64/processor.h
@@ -114,21 +114,13 @@ extern unsigned long mmu_cr4_features;
 static inline void set_in_cr4 (unsigned long mask)
 {
 	mmu_cr4_features |= mask;
-	__asm__("movq %%cr4,%%rax\n\t"
-		"orq %0,%%rax\n\t"
-		"movq %%rax,%%cr4\n"
-		: : "irg" (mask)
-		:"ax");
+	write_cr4(read_cr4() | mask);
 }
 
 static inline void clear_in_cr4 (unsigned long mask)
 {
 	mmu_cr4_features &= ~mask;
-	__asm__("movq %%cr4,%%rax\n\t"
-		"andq %0,%%rax\n\t"
-		"movq %%rax,%%cr4\n"
-		: : "irg" (~mask)
-		:"ax");
+	write_cr4(read_cr4() & ~mask);
 }
 
 
@@ -249,6 +241,12 @@ struct thread_struct {
 	.rsp0 = (unsigned long)&init_stack + sizeof(init_stack) \
 }
 
+static inline void native_load_rsp0(struct tss_struct *tss,
+				    struct thread_struct *thread)
+{
+	tss->rsp0 = thread->rsp0;
+}
+
 #define INIT_MMAP \
 { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
 
@@ -264,13 +262,64 @@ struct thread_struct {
 	set_fs(USER_DS);							 \
 } while(0) 
 
-#define get_debugreg(var, register)				\
-		__asm__("movq %%db" #register ", %0"		\
-			:"=r" (var))
-#define set_debugreg(value, register)			\
-		__asm__("movq %0,%%db" #register		\
-			: /* no output */			\
-			:"r" (value))
+static inline unsigned long native_get_debugreg(int regno)
+{
+	unsigned long val;
+
+	switch (regno) {
+	case 0:
+		asm("movq %%db0, %0" :"=r" (val)); break;
+	case 1:
+		asm("movq %%db1, %0" :"=r" (val)); break;
+	case 2:
+		asm("movq %%db2, %0" :"=r" (val)); break;
+	case 3:
+		asm("movq %%db3, %0" :"=r" (val)); break;
+	case 6:
+		asm("movq %%db6, %0" :"=r" (val)); break;
+	case 7:
+		asm("movq %%db7, %0" :"=r" (val)); break;
+	default:
+		val = 0; /* assign it to keep gcc quiet */
+		WARN_ON(1);
+	}
+	return val;
+}
+
+static inline void native_set_debugreg(unsigned long value, int regno)
+{
+	switch (regno) {
+	case 0:
+		asm("movq %0,%%db0"	: /* no output */ :"r" (value));
+		break;
+	case 1:
+		asm("movq %0,%%db1"	: /* no output */ :"r" (value));
+		break;
+	case 2:
+		asm("movq %0,%%db2"	: /* no output */ :"r" (value));
+		break;
+	case 3:
+		asm("movq %0,%%db3"	: /* no output */ :"r" (value));
+		break;
+	case 6:
+		asm("movq %0,%%db6"	: /* no output */ :"r" (value));
+		break;
+	case 7:
+		asm("movq %0,%%db7"	: /* no output */ :"r" (value));
+		break;
+	default:
+		BUG();
+	}
+}
+
+#ifdef CONFIG_PARAVIRT
+#include <asm/paravirt.h>
+#else
+#define paravirt_enabled()	0
+#define load_rsp0 		native_load_rsp0
+#define set_debugreg(val, reg)	native_set_debugreg(reg, val)
+#define get_debugreg(var, reg)	(var) = native_get_debugreg(reg)
+#endif
 
 struct task_struct;
 struct mm_struct;
-- 
1.4.4.2

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/25][V3] pvops_64 last round (hopefully), Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 1/25][V3] header file move, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 2/25][V3] tlb flushing routines, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 3/25][V3] irq_flags / halt routines, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 4/25][V3] Add debugreg/load_rsp native hooks, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 5/25][V3] native versions for system.h functions, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 6/25][V3] add native_apic read and write functions, ..., Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 7/25][V3] interrupt related native paravirt functions., Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 8/25][V3] use macro for sti/cli in spinlock definitions, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 9/25][V3] report ring kernel is running without par ..., Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 10/25][V3] export math_state_restore, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 11/25][V3] native versions for set pagetables, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 12/25][V3] turn msr.h functions into native versions, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 13/25][V3] add native functions for descriptors han ..., Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 14/25][V3] get rid of inline asm for load_cr3, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 15/25][V3] introducing paravirt_activate_mm, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 16/25][V3] turn page operations into native versions, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 17/25][V3] introduce paravirt_release_pgd(), Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 18/25][V3] turn priviled operations into macros in ..., Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 19/25][V3] time-related functions paravirt provisions, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 20/25][V3] replace syscall_init, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 21/25][V3] export cpu_gdt_descr, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 22/25][V3] turn priviled operation into a macro, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 23/25][V3] provide paravirt patching function, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 24/25][V3] paravirt hooks for arch initialization, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
[PATCH 25/25][V3] add paravirtualization support for x86_64, Glauber de Oliveira ..., (Wed Aug 15, 5:49 am)
Re: [PATCH 3/25][V3] irq_flags / halt routines, Andi Kleen, (Wed Aug 15, 6:55 am)
Re: [PATCH 21/25][V3] export cpu_gdt_descr, Andi Kleen, (Wed Aug 15, 7:03 am)
Re: [PATCH 3/25][V3] irq_flags / halt routines, Glauber de Oliveira ..., (Wed Aug 15, 7:18 am)
Re: [PATCH 18/25][V3] turn priviled operations into macros ..., Glauber de Oliveira ..., (Wed Aug 15, 7:19 am)
Re: [PATCH 21/25][V3] export cpu_gdt_descr, Glauber de Oliveira ..., (Wed Aug 15, 7:25 am)
Re: [PATCH 3/25][V3] irq_flags / halt routines, Glauber de Oliveira ..., (Wed Aug 15, 8:09 am)
Re: [PATCH 3/25][V3] irq_flags / halt routines, Avi Kivity, (Wed Aug 15, 8:13 am)
Re: [PATCH 3/25][V3] irq_flags / halt routines, Glauber de Oliveira ..., (Wed Aug 15, 8:17 am)
Re: [PATCH 3/25][V3] irq_flags / halt routines, Andi Kleen, (Wed Aug 15, 8:42 am)
Re: [PATCH 21/25][V3] export cpu_gdt_descr, Andi Kleen, (Wed Aug 15, 8:43 am)
Re: [PATCH 3/25][V3] irq_flags / halt routines, Andi Kleen, (Wed Aug 15, 9:36 am)
Re: [PATCH 0/25][V3] pvops_64 last round (hopefully), Jeremy Fitzhardinge, (Wed Aug 15, 11:04 am)