aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/exit.c')
-rw-r--r--kernel/exit.c87
1 files changed, 39 insertions, 48 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index ae2b92be5fae..167e1e3ad7c6 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -40,19 +40,24 @@
40#include <linux/cn_proc.h> 40#include <linux/cn_proc.h>
41#include <linux/mutex.h> 41#include <linux/mutex.h>
42#include <linux/futex.h> 42#include <linux/futex.h>
43#include <linux/compat.h>
44#include <linux/pipe_fs_i.h> 43#include <linux/pipe_fs_i.h>
45#include <linux/audit.h> /* for audit_free() */ 44#include <linux/audit.h> /* for audit_free() */
46#include <linux/resource.h> 45#include <linux/resource.h>
47#include <linux/blkdev.h> 46#include <linux/blkdev.h>
48#include <linux/task_io_accounting_ops.h> 47#include <linux/task_io_accounting_ops.h>
49#include <linux/tracehook.h> 48#include <linux/tracehook.h>
49#include <linux/init_task.h>
50#include <trace/sched.h> 50#include <trace/sched.h>
51 51
52#include <asm/uaccess.h> 52#include <asm/uaccess.h>
53#include <asm/unistd.h> 53#include <asm/unistd.h>
54#include <asm/pgtable.h> 54#include <asm/pgtable.h>
55#include <asm/mmu_context.h> 55#include <asm/mmu_context.h>
56#include "cred-internals.h"
57
58DEFINE_TRACE(sched_process_free);
59DEFINE_TRACE(sched_process_exit);
60DEFINE_TRACE(sched_process_wait);
56 61
57static void exit_mm(struct task_struct * tsk); 62static void exit_mm(struct task_struct * tsk);
58 63
@@ -113,6 +118,8 @@ static void __exit_signal(struct task_struct *tsk)
113 * We won't ever get here for the group leader, since it 118 * We won't ever get here for the group leader, since it
114 * will have been the last reference on the signal_struct. 119 * will have been the last reference on the signal_struct.
115 */ 120 */
121 sig->utime = cputime_add(sig->utime, task_utime(tsk));
122 sig->stime = cputime_add(sig->stime, task_stime(tsk));
116 sig->gtime = cputime_add(sig->gtime, task_gtime(tsk)); 123 sig->gtime = cputime_add(sig->gtime, task_gtime(tsk));
117 sig->min_flt += tsk->min_flt; 124 sig->min_flt += tsk->min_flt;
118 sig->maj_flt += tsk->maj_flt; 125 sig->maj_flt += tsk->maj_flt;
@@ -121,6 +128,7 @@ static void __exit_signal(struct task_struct *tsk)
121 sig->inblock += task_io_get_inblock(tsk); 128 sig->inblock += task_io_get_inblock(tsk);
122 sig->oublock += task_io_get_oublock(tsk); 129 sig->oublock += task_io_get_oublock(tsk);
123 task_io_accounting_add(&sig->ioac, &tsk->ioac); 130 task_io_accounting_add(&sig->ioac, &tsk->ioac);
131 sig->sum_sched_runtime += tsk->se.sum_exec_runtime;
124 sig = NULL; /* Marker for below. */ 132 sig = NULL; /* Marker for below. */
125 } 133 }
126 134
@@ -165,7 +173,10 @@ void release_task(struct task_struct * p)
165 int zap_leader; 173 int zap_leader;
166repeat: 174repeat:
167 tracehook_prepare_release_task(p); 175 tracehook_prepare_release_task(p);
168 atomic_dec(&p->user->processes); 176 /* don't need to get the RCU readlock here - the process is dead and
177 * can't be modifying its own credentials */
178 atomic_dec(&__task_cred(p)->user->processes);
179
169 proc_flush_task(p); 180 proc_flush_task(p);
170 write_lock_irq(&tasklist_lock); 181 write_lock_irq(&tasklist_lock);
171 tracehook_finish_release_task(p); 182 tracehook_finish_release_task(p);
@@ -340,12 +351,12 @@ static void reparent_to_kthreadd(void)
340 /* cpus_allowed? */ 351 /* cpus_allowed? */
341 /* rt_priority? */ 352 /* rt_priority? */
342 /* signals? */ 353 /* signals? */
343 security_task_reparent_to_init(current);
344 memcpy(current->signal->rlim, init_task.signal->rlim, 354 memcpy(current->signal->rlim, init_task.signal->rlim,
345 sizeof(current->signal->rlim)); 355 sizeof(current->signal->rlim));
346 atomic_inc(&(INIT_USER->__count)); 356
357 atomic_inc(&init_cred.usage);
358 commit_creds(&init_cred);
347 write_unlock_irq(&tasklist_lock); 359 write_unlock_irq(&tasklist_lock);
348 switch_uid(INIT_USER);
349} 360}
350 361
351void __set_special_pids(struct pid *pid) 362void __set_special_pids(struct pid *pid)
@@ -634,35 +645,31 @@ retry:
634 /* 645 /*
635 * We found no owner yet mm_users > 1: this implies that we are 646 * We found no owner yet mm_users > 1: this implies that we are
636 * most likely racing with swapoff (try_to_unuse()) or /proc or 647 * most likely racing with swapoff (try_to_unuse()) or /proc or
637 * ptrace or page migration (get_task_mm()). Mark owner as NULL, 648 * ptrace or page migration (get_task_mm()). Mark owner as NULL.
638 * so that subsystems can understand the callback and take action.
639 */ 649 */
640 down_write(&mm->mmap_sem);
641 cgroup_mm_owner_callbacks(mm->owner, NULL);
642 mm->owner = NULL; 650 mm->owner = NULL;
643 up_write(&mm->mmap_sem);
644 return; 651 return;
645 652
646assign_new_owner: 653assign_new_owner:
647 BUG_ON(c == p); 654 BUG_ON(c == p);
648 get_task_struct(c); 655 get_task_struct(c);
649 read_unlock(&tasklist_lock);
650 down_write(&mm->mmap_sem);
651 /* 656 /*
652 * The task_lock protects c->mm from changing. 657 * The task_lock protects c->mm from changing.
653 * We always want mm->owner->mm == mm 658 * We always want mm->owner->mm == mm
654 */ 659 */
655 task_lock(c); 660 task_lock(c);
661 /*
662 * Delay read_unlock() till we have the task_lock()
663 * to ensure that c does not slip away underneath us
664 */
665 read_unlock(&tasklist_lock);
656 if (c->mm != mm) { 666 if (c->mm != mm) {
657 task_unlock(c); 667 task_unlock(c);
658 up_write(&mm->mmap_sem);
659 put_task_struct(c); 668 put_task_struct(c);
660 goto retry; 669 goto retry;
661 } 670 }
662 cgroup_mm_owner_callbacks(mm->owner, c);
663 mm->owner = c; 671 mm->owner = c;
664 task_unlock(c); 672 task_unlock(c);
665 up_write(&mm->mmap_sem);
666 put_task_struct(c); 673 put_task_struct(c);
667} 674}
668#endif /* CONFIG_MM_OWNER */ 675#endif /* CONFIG_MM_OWNER */
@@ -973,12 +980,9 @@ static void check_stack_usage(void)
973{ 980{
974 static DEFINE_SPINLOCK(low_water_lock); 981 static DEFINE_SPINLOCK(low_water_lock);
975 static int lowest_to_date = THREAD_SIZE; 982 static int lowest_to_date = THREAD_SIZE;
976 unsigned long *n = end_of_stack(current);
977 unsigned long free; 983 unsigned long free;
978 984
979 while (*n == 0) 985 free = stack_not_used(current);
980 n++;
981 free = (unsigned long)n - (unsigned long)end_of_stack(current);
982 986
983 if (free >= lowest_to_date) 987 if (free >= lowest_to_date)
984 return; 988 return;
@@ -1029,8 +1033,6 @@ NORET_TYPE void do_exit(long code)
1029 * task into the wait for ever nirwana as well. 1033 * task into the wait for ever nirwana as well.
1030 */ 1034 */
1031 tsk->flags |= PF_EXITPIDONE; 1035 tsk->flags |= PF_EXITPIDONE;
1032 if (tsk->io_context)
1033 exit_io_context();
1034 set_current_state(TASK_UNINTERRUPTIBLE); 1036 set_current_state(TASK_UNINTERRUPTIBLE);
1035 schedule(); 1037 schedule();
1036 } 1038 }
@@ -1049,24 +1051,13 @@ NORET_TYPE void do_exit(long code)
1049 preempt_count()); 1051 preempt_count());
1050 1052
1051 acct_update_integrals(tsk); 1053 acct_update_integrals(tsk);
1052 if (tsk->mm) { 1054
1053 update_hiwater_rss(tsk->mm);
1054 update_hiwater_vm(tsk->mm);
1055 }
1056 group_dead = atomic_dec_and_test(&tsk->signal->live); 1055 group_dead = atomic_dec_and_test(&tsk->signal->live);
1057 if (group_dead) { 1056 if (group_dead) {
1058 hrtimer_cancel(&tsk->signal->real_timer); 1057 hrtimer_cancel(&tsk->signal->real_timer);
1059 exit_itimers(tsk->signal); 1058 exit_itimers(tsk->signal);
1060 } 1059 }
1061 acct_collect(code, group_dead); 1060 acct_collect(code, group_dead);
1062#ifdef CONFIG_FUTEX
1063 if (unlikely(tsk->robust_list))
1064 exit_robust_list(tsk);
1065#ifdef CONFIG_COMPAT
1066 if (unlikely(tsk->compat_robust_list))
1067 compat_exit_robust_list(tsk);
1068#endif
1069#endif
1070 if (group_dead) 1061 if (group_dead)
1071 tty_audit_exit(); 1062 tty_audit_exit();
1072 if (unlikely(tsk->audit_context)) 1063 if (unlikely(tsk->audit_context))
@@ -1087,7 +1078,6 @@ NORET_TYPE void do_exit(long code)
1087 check_stack_usage(); 1078 check_stack_usage();
1088 exit_thread(); 1079 exit_thread();
1089 cgroup_exit(tsk, 1); 1080 cgroup_exit(tsk, 1);
1090 exit_keys(tsk);
1091 1081
1092 if (group_dead && tsk->signal->leader) 1082 if (group_dead && tsk->signal->leader)
1093 disassociate_ctty(1); 1083 disassociate_ctty(1);
@@ -1132,7 +1122,6 @@ NORET_TYPE void do_exit(long code)
1132 preempt_disable(); 1122 preempt_disable();
1133 /* causes final put_task_struct in finish_task_switch(). */ 1123 /* causes final put_task_struct in finish_task_switch(). */
1134 tsk->state = TASK_DEAD; 1124 tsk->state = TASK_DEAD;
1135
1136 schedule(); 1125 schedule();
1137 BUG(); 1126 BUG();
1138 /* Avoid "noreturn function does return". */ 1127 /* Avoid "noreturn function does return". */
@@ -1152,7 +1141,7 @@ NORET_TYPE void complete_and_exit(struct completion *comp, long code)
1152 1141
1153EXPORT_SYMBOL(complete_and_exit); 1142EXPORT_SYMBOL(complete_and_exit);
1154 1143
1155asmlinkage long sys_exit(int error_code) 1144SYSCALL_DEFINE1(exit, int, error_code)
1156{ 1145{
1157 do_exit((error_code&0xff)<<8); 1146 do_exit((error_code&0xff)<<8);
1158} 1147}
@@ -1193,9 +1182,11 @@ do_group_exit(int exit_code)
1193 * wait4()-ing process will get the correct exit code - even if this 1182 * wait4()-ing process will get the correct exit code - even if this
1194 * thread is not the thread group leader. 1183 * thread is not the thread group leader.
1195 */ 1184 */
1196asmlinkage void sys_exit_group(int error_code) 1185SYSCALL_DEFINE1(exit_group, int, error_code)
1197{ 1186{
1198 do_group_exit((error_code & 0xff) << 8); 1187 do_group_exit((error_code & 0xff) << 8);
1188 /* NOTREACHED */
1189 return 0;
1199} 1190}
1200 1191
1201static struct pid *task_pid_type(struct task_struct *task, enum pid_type type) 1192static struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
@@ -1272,12 +1263,12 @@ static int wait_task_zombie(struct task_struct *p, int options,
1272 unsigned long state; 1263 unsigned long state;
1273 int retval, status, traced; 1264 int retval, status, traced;
1274 pid_t pid = task_pid_vnr(p); 1265 pid_t pid = task_pid_vnr(p);
1266 uid_t uid = __task_cred(p)->uid;
1275 1267
1276 if (!likely(options & WEXITED)) 1268 if (!likely(options & WEXITED))
1277 return 0; 1269 return 0;
1278 1270
1279 if (unlikely(options & WNOWAIT)) { 1271 if (unlikely(options & WNOWAIT)) {
1280 uid_t uid = p->uid;
1281 int exit_code = p->exit_code; 1272 int exit_code = p->exit_code;
1282 int why, status; 1273 int why, status;
1283 1274
@@ -1330,10 +1321,10 @@ static int wait_task_zombie(struct task_struct *p, int options,
1330 * group, which consolidates times for all threads in the 1321 * group, which consolidates times for all threads in the
1331 * group including the group leader. 1322 * group including the group leader.
1332 */ 1323 */
1324 thread_group_cputime(p, &cputime);
1333 spin_lock_irq(&p->parent->sighand->siglock); 1325 spin_lock_irq(&p->parent->sighand->siglock);
1334 psig = p->parent->signal; 1326 psig = p->parent->signal;
1335 sig = p->signal; 1327 sig = p->signal;
1336 thread_group_cputime(p, &cputime);
1337 psig->cutime = 1328 psig->cutime =
1338 cputime_add(psig->cutime, 1329 cputime_add(psig->cutime,
1339 cputime_add(cputime.utime, 1330 cputime_add(cputime.utime,
@@ -1398,7 +1389,7 @@ static int wait_task_zombie(struct task_struct *p, int options,
1398 if (!retval && infop) 1389 if (!retval && infop)
1399 retval = put_user(pid, &infop->si_pid); 1390 retval = put_user(pid, &infop->si_pid);
1400 if (!retval && infop) 1391 if (!retval && infop)
1401 retval = put_user(p->uid, &infop->si_uid); 1392 retval = put_user(uid, &infop->si_uid);
1402 if (!retval) 1393 if (!retval)
1403 retval = pid; 1394 retval = pid;
1404 1395
@@ -1463,7 +1454,8 @@ static int wait_task_stopped(int ptrace, struct task_struct *p,
1463 if (!unlikely(options & WNOWAIT)) 1454 if (!unlikely(options & WNOWAIT))
1464 p->exit_code = 0; 1455 p->exit_code = 0;
1465 1456
1466 uid = p->uid; 1457 /* don't need the RCU readlock here as we're holding a spinlock */
1458 uid = __task_cred(p)->uid;
1467unlock_sig: 1459unlock_sig:
1468 spin_unlock_irq(&p->sighand->siglock); 1460 spin_unlock_irq(&p->sighand->siglock);
1469 if (!exit_code) 1461 if (!exit_code)
@@ -1537,10 +1529,10 @@ static int wait_task_continued(struct task_struct *p, int options,
1537 } 1529 }
1538 if (!unlikely(options & WNOWAIT)) 1530 if (!unlikely(options & WNOWAIT))
1539 p->signal->flags &= ~SIGNAL_STOP_CONTINUED; 1531 p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
1532 uid = __task_cred(p)->uid;
1540 spin_unlock_irq(&p->sighand->siglock); 1533 spin_unlock_irq(&p->sighand->siglock);
1541 1534
1542 pid = task_pid_vnr(p); 1535 pid = task_pid_vnr(p);
1543 uid = p->uid;
1544 get_task_struct(p); 1536 get_task_struct(p);
1545 read_unlock(&tasklist_lock); 1537 read_unlock(&tasklist_lock);
1546 1538
@@ -1762,9 +1754,8 @@ end:
1762 return retval; 1754 return retval;
1763} 1755}
1764 1756
1765asmlinkage long sys_waitid(int which, pid_t upid, 1757SYSCALL_DEFINE5(waitid, int, which, pid_t, upid, struct siginfo __user *,
1766 struct siginfo __user *infop, int options, 1758 infop, int, options, struct rusage __user *, ru)
1767 struct rusage __user *ru)
1768{ 1759{
1769 struct pid *pid = NULL; 1760 struct pid *pid = NULL;
1770 enum pid_type type; 1761 enum pid_type type;
@@ -1803,8 +1794,8 @@ asmlinkage long sys_waitid(int which, pid_t upid,
1803 return ret; 1794 return ret;
1804} 1795}
1805 1796
1806asmlinkage long sys_wait4(pid_t upid, int __user *stat_addr, 1797SYSCALL_DEFINE4(wait4, pid_t, upid, int __user *, stat_addr,
1807 int options, struct rusage __user *ru) 1798 int, options, struct rusage __user *, ru)
1808{ 1799{
1809 struct pid *pid = NULL; 1800 struct pid *pid = NULL;
1810 enum pid_type type; 1801 enum pid_type type;
@@ -1841,7 +1832,7 @@ asmlinkage long sys_wait4(pid_t upid, int __user *stat_addr,
1841 * sys_waitpid() remains for compatibility. waitpid() should be 1832 * sys_waitpid() remains for compatibility. waitpid() should be
1842 * implemented by calling sys_wait4() from libc.a. 1833 * implemented by calling sys_wait4() from libc.a.
1843 */ 1834 */
1844asmlinkage long sys_waitpid(pid_t pid, int __user *stat_addr, int options) 1835SYSCALL_DEFINE3(waitpid, pid_t, pid, int __user *, stat_addr, int, options)
1845{ 1836{
1846 return sys_wait4(pid, stat_addr, options, NULL); 1837 return sys_wait4(pid, stat_addr, options, NULL);
1847} 1838}