diff options
author | Oleg Nesterov <oleg@redhat.com> | 2014-12-10 18:45:33 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-10 20:41:10 -0500 |
commit | 7c8bd2322c7fd973d089b27de55e29c92c667a06 (patch) | |
tree | 8d9c9d6dbc32eabc303368d913dab3c683b94e2d | |
parent | 2831096e21503897ee474c23131c3feb8db0ffb1 (diff) |
exit: ptrace: shift "reap dead" code from exit_ptrace() to forget_original_parent()
Now that forget_original_parent() uses ->ptrace_entry for EXIT_DEAD tasks,
we can simply pass "dead_children" list to exit_ptrace() and remove
another release_task() loop. Plus this way we do not need to drop and
reacquire tasklist_lock.
Also shift the list_empty(ptraced) check, if we want this optimization it
makes sense to eliminate the function call altogether.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Aaron Tomlin <atomlin@redhat.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Cc: Sterling Alexander <stalexan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@hack.frob.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/ptrace.h | 2 | ||||
-rw-r--r-- | kernel/exit.c | 10 | ||||
-rw-r--r-- | kernel/ptrace.c | 23 |
3 files changed, 8 insertions, 27 deletions
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index cc79eff4a1ad..987a73a40ef8 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h | |||
@@ -52,7 +52,7 @@ extern void ptrace_notify(int exit_code); | |||
52 | extern void __ptrace_link(struct task_struct *child, | 52 | extern void __ptrace_link(struct task_struct *child, |
53 | struct task_struct *new_parent); | 53 | struct task_struct *new_parent); |
54 | extern void __ptrace_unlink(struct task_struct *child); | 54 | extern void __ptrace_unlink(struct task_struct *child); |
55 | extern void exit_ptrace(struct task_struct *tracer); | 55 | extern void exit_ptrace(struct task_struct *tracer, struct list_head *dead); |
56 | #define PTRACE_MODE_READ 0x01 | 56 | #define PTRACE_MODE_READ 0x01 |
57 | #define PTRACE_MODE_ATTACH 0x02 | 57 | #define PTRACE_MODE_ATTACH 0x02 |
58 | #define PTRACE_MODE_NOAUDIT 0x04 | 58 | #define PTRACE_MODE_NOAUDIT 0x04 |
diff --git a/kernel/exit.c b/kernel/exit.c index 772e9175735c..9c9526d87276 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -553,13 +553,11 @@ static void forget_original_parent(struct task_struct *father) | |||
553 | LIST_HEAD(dead_children); | 553 | LIST_HEAD(dead_children); |
554 | 554 | ||
555 | write_lock_irq(&tasklist_lock); | 555 | write_lock_irq(&tasklist_lock); |
556 | /* | 556 | if (unlikely(!list_empty(&father->ptraced))) |
557 | * Note that exit_ptrace() and find_new_reaper() might | 557 | exit_ptrace(father, &dead_children); |
558 | * drop tasklist_lock and reacquire it. | ||
559 | */ | ||
560 | exit_ptrace(father); | ||
561 | reaper = find_new_reaper(father); | ||
562 | 558 | ||
559 | /* Can drop and reacquire tasklist_lock */ | ||
560 | reaper = find_new_reaper(father); | ||
563 | list_for_each_entry(p, &father->children, sibling) { | 561 | list_for_each_entry(p, &father->children, sibling) { |
564 | for_each_thread(p, t) { | 562 | for_each_thread(p, t) { |
565 | t->real_parent = reaper; | 563 | t->real_parent = reaper; |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 54e75226c2c4..1eb9d90c3af9 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -485,36 +485,19 @@ static int ptrace_detach(struct task_struct *child, unsigned int data) | |||
485 | 485 | ||
486 | /* | 486 | /* |
487 | * Detach all tasks we were using ptrace on. Called with tasklist held | 487 | * Detach all tasks we were using ptrace on. Called with tasklist held |
488 | * for writing, and returns with it held too. But note it can release | 488 | * for writing. |
489 | * and reacquire the lock. | ||
490 | */ | 489 | */ |
491 | void exit_ptrace(struct task_struct *tracer) | 490 | void exit_ptrace(struct task_struct *tracer, struct list_head *dead) |
492 | __releases(&tasklist_lock) | ||
493 | __acquires(&tasklist_lock) | ||
494 | { | 491 | { |
495 | struct task_struct *p, *n; | 492 | struct task_struct *p, *n; |
496 | LIST_HEAD(ptrace_dead); | ||
497 | |||
498 | if (likely(list_empty(&tracer->ptraced))) | ||
499 | return; | ||
500 | 493 | ||
501 | list_for_each_entry_safe(p, n, &tracer->ptraced, ptrace_entry) { | 494 | list_for_each_entry_safe(p, n, &tracer->ptraced, ptrace_entry) { |
502 | if (unlikely(p->ptrace & PT_EXITKILL)) | 495 | if (unlikely(p->ptrace & PT_EXITKILL)) |
503 | send_sig_info(SIGKILL, SEND_SIG_FORCED, p); | 496 | send_sig_info(SIGKILL, SEND_SIG_FORCED, p); |
504 | 497 | ||
505 | if (__ptrace_detach(tracer, p)) | 498 | if (__ptrace_detach(tracer, p)) |
506 | list_add(&p->ptrace_entry, &ptrace_dead); | 499 | list_add(&p->ptrace_entry, dead); |
507 | } | ||
508 | |||
509 | write_unlock_irq(&tasklist_lock); | ||
510 | BUG_ON(!list_empty(&tracer->ptraced)); | ||
511 | |||
512 | list_for_each_entry_safe(p, n, &ptrace_dead, ptrace_entry) { | ||
513 | list_del_init(&p->ptrace_entry); | ||
514 | release_task(p); | ||
515 | } | 500 | } |
516 | |||
517 | write_lock_irq(&tasklist_lock); | ||
518 | } | 501 | } |
519 | 502 | ||
520 | int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len) | 503 | int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len) |