diff options
Diffstat (limited to 'arch/x86/kernel/process_32.c')
-rw-r--r-- | arch/x86/kernel/process_32.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c index 59f4524984a..00a8fe4c58b 100644 --- a/arch/x86/kernel/process_32.c +++ b/arch/x86/kernel/process_32.c | |||
@@ -58,6 +58,8 @@ | |||
58 | #include <asm/idle.h> | 58 | #include <asm/idle.h> |
59 | #include <asm/syscalls.h> | 59 | #include <asm/syscalls.h> |
60 | #include <asm/ds.h> | 60 | #include <asm/ds.h> |
61 | #include <asm/debugreg.h> | ||
62 | #include <asm/hw_breakpoint.h> | ||
61 | 63 | ||
62 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); | 64 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); |
63 | 65 | ||
@@ -262,7 +264,13 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, | |||
262 | 264 | ||
263 | task_user_gs(p) = get_user_gs(regs); | 265 | task_user_gs(p) = get_user_gs(regs); |
264 | 266 | ||
267 | p->thread.io_bitmap_ptr = NULL; | ||
265 | tsk = current; | 268 | tsk = current; |
269 | err = -ENOMEM; | ||
270 | if (unlikely(test_tsk_thread_flag(tsk, TIF_DEBUG))) | ||
271 | if (copy_thread_hw_breakpoint(tsk, p, clone_flags)) | ||
272 | goto out; | ||
273 | |||
266 | if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) { | 274 | if (unlikely(test_tsk_thread_flag(tsk, TIF_IO_BITMAP))) { |
267 | p->thread.io_bitmap_ptr = kmemdup(tsk->thread.io_bitmap_ptr, | 275 | p->thread.io_bitmap_ptr = kmemdup(tsk->thread.io_bitmap_ptr, |
268 | IO_BITMAP_BYTES, GFP_KERNEL); | 276 | IO_BITMAP_BYTES, GFP_KERNEL); |
@@ -282,10 +290,13 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, | |||
282 | err = do_set_thread_area(p, -1, | 290 | err = do_set_thread_area(p, -1, |
283 | (struct user_desc __user *)childregs->si, 0); | 291 | (struct user_desc __user *)childregs->si, 0); |
284 | 292 | ||
293 | out: | ||
285 | if (err && p->thread.io_bitmap_ptr) { | 294 | if (err && p->thread.io_bitmap_ptr) { |
286 | kfree(p->thread.io_bitmap_ptr); | 295 | kfree(p->thread.io_bitmap_ptr); |
287 | p->thread.io_bitmap_max = 0; | 296 | p->thread.io_bitmap_max = 0; |
288 | } | 297 | } |
298 | if (err) | ||
299 | flush_thread_hw_breakpoint(p); | ||
289 | 300 | ||
290 | clear_tsk_thread_flag(p, TIF_DS_AREA_MSR); | 301 | clear_tsk_thread_flag(p, TIF_DS_AREA_MSR); |
291 | p->thread.ds_ctx = NULL; | 302 | p->thread.ds_ctx = NULL; |
@@ -424,6 +435,23 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) | |||
424 | lazy_load_gs(next->gs); | 435 | lazy_load_gs(next->gs); |
425 | 436 | ||
426 | percpu_write(current_task, next_p); | 437 | percpu_write(current_task, next_p); |
438 | /* | ||
439 | * There's a problem with moving the arch_install_thread_hw_breakpoint() | ||
440 | * call before current is updated. Suppose a kernel breakpoint is | ||
441 | * triggered in between the two, the hw-breakpoint handler will see that | ||
442 | * the 'current' task does not have TIF_DEBUG flag set and will think it | ||
443 | * is leftover from an old task (lazy switching) and will erase it. Then | ||
444 | * until the next context switch, no user-breakpoints will be installed. | ||
445 | * | ||
446 | * The real problem is that it's impossible to update both current and | ||
447 | * physical debug registers at the same instant, so there will always be | ||
448 | * a window in which they disagree and a breakpoint might get triggered. | ||
449 | * Since we use lazy switching, we are forced to assume that a | ||
450 | * disagreement means that current is correct and the exception is due | ||
451 | * to lazy debug register switching. | ||
452 | */ | ||
453 | if (unlikely(test_tsk_thread_flag(next_p, TIF_DEBUG))) | ||
454 | arch_install_thread_hw_breakpoint(next_p); | ||
427 | 455 | ||
428 | return prev_p; | 456 | return prev_p; |
429 | } | 457 | } |