diff options
author | Oleg Nesterov <oleg@redhat.com> | 2013-07-08 19:00:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-09 13:33:26 -0400 |
commit | e6a7d6077106e5c72f0519ec113d986df67ee001 (patch) | |
tree | 90ff605d73b95af65700d47af64029b71c98cf5f /arch/x86 | |
parent | 7c8df28633bf0b7eb253f866029be0ac59ddb062 (diff) |
ptrace/x86: simplify the "disable" logic in ptrace_write_dr7()
ptrace_write_dr7() looks unnecessarily overcomplicated. We can factor
out ptrace_modify_breakpoint() and do not do "continue" twice, just we
need to pass the proper "disabled" argument to
ptrace_modify_breakpoint().
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: Michael Neuling <mikey@neuling.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Prasad <prasad@linux.vnet.ibm.com>
Cc: Russell King <linux@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/x86')
-rw-r--r-- | arch/x86/kernel/ptrace.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index 7a98b21945aa..0649f166d7c6 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c | |||
@@ -637,9 +637,7 @@ static int ptrace_write_dr7(struct task_struct *tsk, unsigned long data) | |||
637 | struct thread_struct *thread = &(tsk->thread); | 637 | struct thread_struct *thread = &(tsk->thread); |
638 | unsigned long old_dr7; | 638 | unsigned long old_dr7; |
639 | int i, orig_ret = 0, rc = 0; | 639 | int i, orig_ret = 0, rc = 0; |
640 | int enabled, second_pass = 0; | 640 | int second_pass = 0; |
641 | unsigned len, type; | ||
642 | struct perf_event *bp; | ||
643 | 641 | ||
644 | data &= ~DR_CONTROL_RESERVED; | 642 | data &= ~DR_CONTROL_RESERVED; |
645 | old_dr7 = ptrace_get_dr7(thread->ptrace_bps); | 643 | old_dr7 = ptrace_get_dr7(thread->ptrace_bps); |
@@ -649,30 +647,22 @@ restore: | |||
649 | * appropriate changes to each. | 647 | * appropriate changes to each. |
650 | */ | 648 | */ |
651 | for (i = 0; i < HBP_NUM; i++) { | 649 | for (i = 0; i < HBP_NUM; i++) { |
652 | enabled = decode_dr7(data, i, &len, &type); | 650 | unsigned len, type; |
653 | bp = thread->ptrace_bps[i]; | 651 | bool disabled = !decode_dr7(data, i, &len, &type); |
654 | 652 | struct perf_event *bp = thread->ptrace_bps[i]; | |
655 | if (!enabled) { | 653 | |
656 | if (bp) { | 654 | if (disabled) { |
657 | /* | 655 | /* |
658 | * Don't unregister the breakpoints right-away, | 656 | * Don't unregister the breakpoints right-away, unless |
659 | * unless all register_user_hw_breakpoint() | 657 | * all register_user_hw_breakpoint() requests have |
660 | * requests have succeeded. This prevents | 658 | * succeeded. This prevents any window of opportunity |
661 | * any window of opportunity for debug | 659 | * for debug register grabbing by other users. |
662 | * register grabbing by other users. | 660 | */ |
663 | */ | 661 | if (!bp || !second_pass) |
664 | if (!second_pass) | 662 | continue; |
665 | continue; | ||
666 | |||
667 | rc = ptrace_modify_breakpoint(bp, len, type, | ||
668 | tsk, 1); | ||
669 | if (rc) | ||
670 | break; | ||
671 | } | ||
672 | continue; | ||
673 | } | 663 | } |
674 | 664 | ||
675 | rc = ptrace_modify_breakpoint(bp, len, type, tsk, 0); | 665 | rc = ptrace_modify_breakpoint(bp, len, type, tsk, disabled); |
676 | if (rc) | 666 | if (rc) |
677 | break; | 667 | break; |
678 | } | 668 | } |