aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/process_32.c
diff options
context:
space:
mode:
authorK.Prasad <prasad@linux.vnet.ibm.com>2009-06-01 14:14:55 -0400
committerFrederic Weisbecker <fweisbec@gmail.com>2009-06-02 16:46:59 -0400
commit66cb5917295958652ff6ba36d83f98f2379c46b4 (patch)
tree1e30c4524cb5d53ecd4980b83ead4e9548dfb8f5 /arch/x86/kernel/process_32.c
parent1e3500666f7c5daaadadb8431a2927cdbbdb7dd4 (diff)
hw-breakpoints: use the new wrapper routines to access debug registers in process/thread code
This patch enables the use of abstract debug registers in process-handling routines, according to the new hardware breakpoint Api. [ Impact: adapt thread breakpoints handling code to the new breakpoint Api ] Original-patch-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: K.Prasad <prasad@linux.vnet.ibm.com> Reviewed-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Diffstat (limited to 'arch/x86/kernel/process_32.c')
-rw-r--r--arch/x86/kernel/process_32.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index b5e4bfef4472..297ffff2ffc2 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -61,6 +61,8 @@
61#include <asm/idle.h> 61#include <asm/idle.h>
62#include <asm/syscalls.h> 62#include <asm/syscalls.h>
63#include <asm/ds.h> 63#include <asm/ds.h>
64#include <asm/debugreg.h>
65#include <asm/hw_breakpoint.h>
64 66
65asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); 67asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
66 68
@@ -265,7 +267,13 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
265 267
266 task_user_gs(p) = get_user_gs(regs); 268 task_user_gs(p) = get_user_gs(regs);
267 269
270 p->thread.io_bitmap_ptr = NULL;
268 tsk = current; 271 tsk = current;
272 err = -ENOMEM;
273 if (unlikely(test_tsk_thread_flag(tsk, TIF_DEBUG)))
274 if (copy_thread_hw_breakpoint(tsk, p, clone_flags))
275 goto out;
276
269 if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) { 277 if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) {
270 p->thread.io_bitmap_ptr = kmemdup(tsk->thread.io_bitmap_ptr, 278 p->thread.io_bitmap_ptr = kmemdup(tsk->thread.io_bitmap_ptr,
271 IO_BITMAP_BYTES, GFP_KERNEL); 279 IO_BITMAP_BYTES, GFP_KERNEL);
@@ -285,10 +293,13 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
285 err = do_set_thread_area(p, -1, 293 err = do_set_thread_area(p, -1,
286 (struct user_desc __user *)childregs->si, 0); 294 (struct user_desc __user *)childregs->si, 0);
287 295
296out:
288 if (err && p->thread.io_bitmap_ptr) { 297 if (err && p->thread.io_bitmap_ptr) {
289 kfree(p->thread.io_bitmap_ptr); 298 kfree(p->thread.io_bitmap_ptr);
290 p->thread.io_bitmap_max = 0; 299 p->thread.io_bitmap_max = 0;
291 } 300 }
301 if (err)
302 flush_thread_hw_breakpoint(p);
292 303
293 clear_tsk_thread_flag(p, TIF_DS_AREA_MSR); 304 clear_tsk_thread_flag(p, TIF_DS_AREA_MSR);
294 p->thread.ds_ctx = NULL; 305 p->thread.ds_ctx = NULL;
@@ -427,6 +438,23 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
427 lazy_load_gs(next->gs); 438 lazy_load_gs(next->gs);
428 439
429 percpu_write(current_task, next_p); 440 percpu_write(current_task, next_p);
441 /*
442 * There's a problem with moving the arch_install_thread_hw_breakpoint()
443 * call before current is updated. Suppose a kernel breakpoint is
444 * triggered in between the two, the hw-breakpoint handler will see that
445 * the 'current' task does not have TIF_DEBUG flag set and will think it
446 * is leftover from an old task (lazy switching) and will erase it. Then
447 * until the next context switch, no user-breakpoints will be installed.
448 *
449 * The real problem is that it's impossible to update both current and
450 * physical debug registers at the same instant, so there will always be
451 * a window in which they disagree and a breakpoint might get triggered.
452 * Since we use lazy switching, we are forced to assume that a
453 * disagreement means that current is correct and the exception is due
454 * to lazy debug register switching.
455 */
456 if (unlikely(test_tsk_thread_flag(next_p, TIF_DEBUG)))
457 arch_install_thread_hw_breakpoint(next_p);
430 458
431 return prev_p; 459 return prev_p;
432} 460}