aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/exit.c')
-rw-r--r--kernel/exit.c88
1 files changed, 52 insertions, 36 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index f7864ac2ecc1..ce1e48c2d93d 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -49,6 +49,7 @@
49#include <linux/init_task.h> 49#include <linux/init_task.h>
50#include <linux/perf_event.h> 50#include <linux/perf_event.h>
51#include <trace/events/sched.h> 51#include <trace/events/sched.h>
52#include <linux/hw_breakpoint.h>
52 53
53#include <asm/uaccess.h> 54#include <asm/uaccess.h>
54#include <asm/unistd.h> 55#include <asm/unistd.h>
@@ -67,10 +68,10 @@ static void __unhash_process(struct task_struct *p)
67 detach_pid(p, PIDTYPE_SID); 68 detach_pid(p, PIDTYPE_SID);
68 69
69 list_del_rcu(&p->tasks); 70 list_del_rcu(&p->tasks);
71 list_del_init(&p->sibling);
70 __get_cpu_var(process_counts)--; 72 __get_cpu_var(process_counts)--;
71 } 73 }
72 list_del_rcu(&p->thread_group); 74 list_del_rcu(&p->thread_group);
73 list_del_init(&p->sibling);
74} 75}
75 76
76/* 77/*
@@ -84,7 +85,9 @@ static void __exit_signal(struct task_struct *tsk)
84 BUG_ON(!sig); 85 BUG_ON(!sig);
85 BUG_ON(!atomic_read(&sig->count)); 86 BUG_ON(!atomic_read(&sig->count));
86 87
87 sighand = rcu_dereference(tsk->sighand); 88 sighand = rcu_dereference_check(tsk->sighand,
89 rcu_read_lock_held() ||
90 lockdep_is_held(&tasklist_lock));
88 spin_lock(&sighand->siglock); 91 spin_lock(&sighand->siglock);
89 92
90 posix_cpu_timers_exit(tsk); 93 posix_cpu_timers_exit(tsk);
@@ -110,9 +113,9 @@ static void __exit_signal(struct task_struct *tsk)
110 * We won't ever get here for the group leader, since it 113 * We won't ever get here for the group leader, since it
111 * will have been the last reference on the signal_struct. 114 * will have been the last reference on the signal_struct.
112 */ 115 */
113 sig->utime = cputime_add(sig->utime, task_utime(tsk)); 116 sig->utime = cputime_add(sig->utime, tsk->utime);
114 sig->stime = cputime_add(sig->stime, task_stime(tsk)); 117 sig->stime = cputime_add(sig->stime, tsk->stime);
115 sig->gtime = cputime_add(sig->gtime, task_gtime(tsk)); 118 sig->gtime = cputime_add(sig->gtime, tsk->gtime);
116 sig->min_flt += tsk->min_flt; 119 sig->min_flt += tsk->min_flt;
117 sig->maj_flt += tsk->maj_flt; 120 sig->maj_flt += tsk->maj_flt;
118 sig->nvcsw += tsk->nvcsw; 121 sig->nvcsw += tsk->nvcsw;
@@ -169,8 +172,10 @@ void release_task(struct task_struct * p)
169repeat: 172repeat:
170 tracehook_prepare_release_task(p); 173 tracehook_prepare_release_task(p);
171 /* don't need to get the RCU readlock here - the process is dead and 174 /* don't need to get the RCU readlock here - the process is dead and
172 * can't be modifying its own credentials */ 175 * can't be modifying its own credentials. But shut RCU-lockdep up */
176 rcu_read_lock();
173 atomic_dec(&__task_cred(p)->user->processes); 177 atomic_dec(&__task_cred(p)->user->processes);
178 rcu_read_unlock();
174 179
175 proc_flush_task(p); 180 proc_flush_task(p);
176 181
@@ -472,9 +477,11 @@ static void close_files(struct files_struct * files)
472 /* 477 /*
473 * It is safe to dereference the fd table without RCU or 478 * It is safe to dereference the fd table without RCU or
474 * ->file_lock because this is the last reference to the 479 * ->file_lock because this is the last reference to the
475 * files structure. 480 * files structure. But use RCU to shut RCU-lockdep up.
476 */ 481 */
482 rcu_read_lock();
477 fdt = files_fdtable(files); 483 fdt = files_fdtable(files);
484 rcu_read_unlock();
478 for (;;) { 485 for (;;) {
479 unsigned long set; 486 unsigned long set;
480 i = j * __NFDBITS; 487 i = j * __NFDBITS;
@@ -520,10 +527,12 @@ void put_files_struct(struct files_struct *files)
520 * at the end of the RCU grace period. Otherwise, 527 * at the end of the RCU grace period. Otherwise,
521 * you can free files immediately. 528 * you can free files immediately.
522 */ 529 */
530 rcu_read_lock();
523 fdt = files_fdtable(files); 531 fdt = files_fdtable(files);
524 if (fdt != &files->fdtab) 532 if (fdt != &files->fdtab)
525 kmem_cache_free(files_cachep, files); 533 kmem_cache_free(files_cachep, files);
526 free_fdtable(fdt); 534 free_fdtable(fdt);
535 rcu_read_unlock();
527 } 536 }
528} 537}
529 538
@@ -735,12 +744,9 @@ static struct task_struct *find_new_reaper(struct task_struct *father)
735/* 744/*
736* Any that need to be release_task'd are put on the @dead list. 745* Any that need to be release_task'd are put on the @dead list.
737 */ 746 */
738static void reparent_thread(struct task_struct *father, struct task_struct *p, 747static void reparent_leader(struct task_struct *father, struct task_struct *p,
739 struct list_head *dead) 748 struct list_head *dead)
740{ 749{
741 if (p->pdeath_signal)
742 group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p);
743
744 list_move_tail(&p->sibling, &p->real_parent->children); 750 list_move_tail(&p->sibling, &p->real_parent->children);
745 751
746 if (task_detached(p)) 752 if (task_detached(p))
@@ -779,12 +785,18 @@ static void forget_original_parent(struct task_struct *father)
779 reaper = find_new_reaper(father); 785 reaper = find_new_reaper(father);
780 786
781 list_for_each_entry_safe(p, n, &father->children, sibling) { 787 list_for_each_entry_safe(p, n, &father->children, sibling) {
782 p->real_parent = reaper; 788 struct task_struct *t = p;
783 if (p->parent == father) { 789 do {
784 BUG_ON(task_ptrace(p)); 790 t->real_parent = reaper;
785 p->parent = p->real_parent; 791 if (t->parent == father) {
786 } 792 BUG_ON(task_ptrace(t));
787 reparent_thread(father, p, &dead_children); 793 t->parent = t->real_parent;
794 }
795 if (t->pdeath_signal)
796 group_send_sig_info(t->pdeath_signal,
797 SEND_SIG_NOINFO, t);
798 } while_each_thread(p, t);
799 reparent_leader(father, p, &dead_children);
788 } 800 }
789 write_unlock_irq(&tasklist_lock); 801 write_unlock_irq(&tasklist_lock);
790 802
@@ -932,7 +944,7 @@ NORET_TYPE void do_exit(long code)
932 * an exiting task cleaning up the robust pi futexes. 944 * an exiting task cleaning up the robust pi futexes.
933 */ 945 */
934 smp_mb(); 946 smp_mb();
935 spin_unlock_wait(&tsk->pi_lock); 947 raw_spin_unlock_wait(&tsk->pi_lock);
936 948
937 if (unlikely(in_atomic())) 949 if (unlikely(in_atomic()))
938 printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n", 950 printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n",
@@ -940,7 +952,8 @@ NORET_TYPE void do_exit(long code)
940 preempt_count()); 952 preempt_count());
941 953
942 acct_update_integrals(tsk); 954 acct_update_integrals(tsk);
943 955 /* sync mm's RSS info before statistics gathering */
956 sync_mm_rss(tsk, tsk->mm);
944 group_dead = atomic_dec_and_test(&tsk->signal->live); 957 group_dead = atomic_dec_and_test(&tsk->signal->live);
945 if (group_dead) { 958 if (group_dead) {
946 hrtimer_cancel(&tsk->signal->real_timer); 959 hrtimer_cancel(&tsk->signal->real_timer);
@@ -970,7 +983,7 @@ NORET_TYPE void do_exit(long code)
970 exit_thread(); 983 exit_thread();
971 cgroup_exit(tsk, 1); 984 cgroup_exit(tsk, 1);
972 985
973 if (group_dead && tsk->signal->leader) 986 if (group_dead)
974 disassociate_ctty(1); 987 disassociate_ctty(1);
975 988
976 module_put(task_thread_info(tsk)->exec_domain->module); 989 module_put(task_thread_info(tsk)->exec_domain->module);
@@ -978,6 +991,10 @@ NORET_TYPE void do_exit(long code)
978 proc_exit_connector(tsk); 991 proc_exit_connector(tsk);
979 992
980 /* 993 /*
994 * FIXME: do that only when needed, using sched_exit tracepoint
995 */
996 flush_ptrace_hw_breakpoint(tsk);
997 /*
981 * Flush inherited counters to the parent - before the parent 998 * Flush inherited counters to the parent - before the parent
982 * gets woken up by child-exit notifications. 999 * gets woken up by child-exit notifications.
983 */ 1000 */
@@ -1004,7 +1021,7 @@ NORET_TYPE void do_exit(long code)
1004 tsk->flags |= PF_EXITPIDONE; 1021 tsk->flags |= PF_EXITPIDONE;
1005 1022
1006 if (tsk->io_context) 1023 if (tsk->io_context)
1007 exit_io_context(); 1024 exit_io_context(tsk);
1008 1025
1009 if (tsk->splice_pipe) 1026 if (tsk->splice_pipe)
1010 __free_pipe_info(tsk->splice_pipe); 1027 __free_pipe_info(tsk->splice_pipe);
@@ -1172,7 +1189,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
1172 1189
1173 if (unlikely(wo->wo_flags & WNOWAIT)) { 1190 if (unlikely(wo->wo_flags & WNOWAIT)) {
1174 int exit_code = p->exit_code; 1191 int exit_code = p->exit_code;
1175 int why, status; 1192 int why;
1176 1193
1177 get_task_struct(p); 1194 get_task_struct(p);
1178 read_unlock(&tasklist_lock); 1195 read_unlock(&tasklist_lock);
@@ -1205,6 +1222,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
1205 struct signal_struct *psig; 1222 struct signal_struct *psig;
1206 struct signal_struct *sig; 1223 struct signal_struct *sig;
1207 unsigned long maxrss; 1224 unsigned long maxrss;
1225 cputime_t tgutime, tgstime;
1208 1226
1209 /* 1227 /*
1210 * The resource counters for the group leader are in its 1228 * The resource counters for the group leader are in its
@@ -1220,20 +1238,23 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
1220 * need to protect the access to parent->signal fields, 1238 * need to protect the access to parent->signal fields,
1221 * as other threads in the parent group can be right 1239 * as other threads in the parent group can be right
1222 * here reaping other children at the same time. 1240 * here reaping other children at the same time.
1241 *
1242 * We use thread_group_times() to get times for the thread
1243 * group, which consolidates times for all threads in the
1244 * group including the group leader.
1223 */ 1245 */
1246 thread_group_times(p, &tgutime, &tgstime);
1224 spin_lock_irq(&p->real_parent->sighand->siglock); 1247 spin_lock_irq(&p->real_parent->sighand->siglock);
1225 psig = p->real_parent->signal; 1248 psig = p->real_parent->signal;
1226 sig = p->signal; 1249 sig = p->signal;
1227 psig->cutime = 1250 psig->cutime =
1228 cputime_add(psig->cutime, 1251 cputime_add(psig->cutime,
1229 cputime_add(p->utime, 1252 cputime_add(tgutime,
1230 cputime_add(sig->utime, 1253 sig->cutime));
1231 sig->cutime)));
1232 psig->cstime = 1254 psig->cstime =
1233 cputime_add(psig->cstime, 1255 cputime_add(psig->cstime,
1234 cputime_add(p->stime, 1256 cputime_add(tgstime,
1235 cputime_add(sig->stime, 1257 sig->cstime));
1236 sig->cstime)));
1237 psig->cgtime = 1258 psig->cgtime =
1238 cputime_add(psig->cgtime, 1259 cputime_add(psig->cgtime,
1239 cputime_add(p->gtime, 1260 cputime_add(p->gtime,
@@ -1542,14 +1563,9 @@ static int do_wait_thread(struct wait_opts *wo, struct task_struct *tsk)
1542 struct task_struct *p; 1563 struct task_struct *p;
1543 1564
1544 list_for_each_entry(p, &tsk->children, sibling) { 1565 list_for_each_entry(p, &tsk->children, sibling) {
1545 /* 1566 int ret = wait_consider_task(wo, 0, p);
1546 * Do not consider detached threads. 1567 if (ret)
1547 */ 1568 return ret;
1548 if (!task_detached(p)) {
1549 int ret = wait_consider_task(wo, 0, p);
1550 if (ret)
1551 return ret;
1552 }
1553 } 1569 }
1554 1570
1555 return 0; 1571 return 0;