aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorHaavard Skinnemoen <haavard.skinnemoen@atmel.com>2009-10-06 11:36:55 -0400
committerHaavard Skinnemoen <haavard.skinnemoen@atmel.com>2009-10-06 11:36:55 -0400
commitd94e5fcbf1420366dcb4102bafe04dbcfc0d0d4b (patch)
treea9b7de7df6da5c3132cc68169b9c47ba288ccd42 /kernel/fork.c
parentd55651168a20078a94597a297d5cdfd807bf07b6 (diff)
parent374576a8b6f865022c0fd1ca62396889b23d66dd (diff)
Merge commit 'v2.6.32-rc3'
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c86
1 files changed, 61 insertions, 25 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index e6c04d462ab2..266c6af6ef1b 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -49,6 +49,7 @@
49#include <linux/ftrace.h> 49#include <linux/ftrace.h>
50#include <linux/profile.h> 50#include <linux/profile.h>
51#include <linux/rmap.h> 51#include <linux/rmap.h>
52#include <linux/ksm.h>
52#include <linux/acct.h> 53#include <linux/acct.h>
53#include <linux/tsacct_kern.h> 54#include <linux/tsacct_kern.h>
54#include <linux/cn_proc.h> 55#include <linux/cn_proc.h>
@@ -61,7 +62,8 @@
61#include <linux/blkdev.h> 62#include <linux/blkdev.h>
62#include <linux/fs_struct.h> 63#include <linux/fs_struct.h>
63#include <linux/magic.h> 64#include <linux/magic.h>
64#include <linux/perf_counter.h> 65#include <linux/perf_event.h>
66#include <linux/posix-timers.h>
65 67
66#include <asm/pgtable.h> 68#include <asm/pgtable.h>
67#include <asm/pgalloc.h> 69#include <asm/pgalloc.h>
@@ -136,9 +138,17 @@ struct kmem_cache *vm_area_cachep;
136/* SLAB cache for mm_struct structures (tsk->mm) */ 138/* SLAB cache for mm_struct structures (tsk->mm) */
137static struct kmem_cache *mm_cachep; 139static struct kmem_cache *mm_cachep;
138 140
141static void account_kernel_stack(struct thread_info *ti, int account)
142{
143 struct zone *zone = page_zone(virt_to_page(ti));
144
145 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
146}
147
139void free_task(struct task_struct *tsk) 148void free_task(struct task_struct *tsk)
140{ 149{
141 prop_local_destroy_single(&tsk->dirties); 150 prop_local_destroy_single(&tsk->dirties);
151 account_kernel_stack(tsk->stack, -1);
142 free_thread_info(tsk->stack); 152 free_thread_info(tsk->stack);
143 rt_mutex_debug_task_free(tsk); 153 rt_mutex_debug_task_free(tsk);
144 ftrace_graph_exit_task(tsk); 154 ftrace_graph_exit_task(tsk);
@@ -152,8 +162,7 @@ void __put_task_struct(struct task_struct *tsk)
152 WARN_ON(atomic_read(&tsk->usage)); 162 WARN_ON(atomic_read(&tsk->usage));
153 WARN_ON(tsk == current); 163 WARN_ON(tsk == current);
154 164
155 put_cred(tsk->real_cred); 165 exit_creds(tsk);
156 put_cred(tsk->cred);
157 delayacct_tsk_free(tsk); 166 delayacct_tsk_free(tsk);
158 167
159 if (!profile_handoff_task(tsk)) 168 if (!profile_handoff_task(tsk))
@@ -254,6 +263,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
254 tsk->btrace_seq = 0; 263 tsk->btrace_seq = 0;
255#endif 264#endif
256 tsk->splice_pipe = NULL; 265 tsk->splice_pipe = NULL;
266
267 account_kernel_stack(ti, 1);
268
257 return tsk; 269 return tsk;
258 270
259out: 271out:
@@ -289,6 +301,9 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
289 rb_link = &mm->mm_rb.rb_node; 301 rb_link = &mm->mm_rb.rb_node;
290 rb_parent = NULL; 302 rb_parent = NULL;
291 pprev = &mm->mmap; 303 pprev = &mm->mmap;
304 retval = ksm_fork(mm, oldmm);
305 if (retval)
306 goto out;
292 307
293 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) { 308 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
294 struct file *file; 309 struct file *file;
@@ -419,22 +434,30 @@ __setup("coredump_filter=", coredump_filter_setup);
419 434
420#include <linux/init_task.h> 435#include <linux/init_task.h>
421 436
437static void mm_init_aio(struct mm_struct *mm)
438{
439#ifdef CONFIG_AIO
440 spin_lock_init(&mm->ioctx_lock);
441 INIT_HLIST_HEAD(&mm->ioctx_list);
442#endif
443}
444
422static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p) 445static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p)
423{ 446{
424 atomic_set(&mm->mm_users, 1); 447 atomic_set(&mm->mm_users, 1);
425 atomic_set(&mm->mm_count, 1); 448 atomic_set(&mm->mm_count, 1);
426 init_rwsem(&mm->mmap_sem); 449 init_rwsem(&mm->mmap_sem);
427 INIT_LIST_HEAD(&mm->mmlist); 450 INIT_LIST_HEAD(&mm->mmlist);
428 mm->flags = (current->mm) ? current->mm->flags : default_dump_filter; 451 mm->flags = (current->mm) ?
452 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
429 mm->core_state = NULL; 453 mm->core_state = NULL;
430 mm->nr_ptes = 0; 454 mm->nr_ptes = 0;
431 set_mm_counter(mm, file_rss, 0); 455 set_mm_counter(mm, file_rss, 0);
432 set_mm_counter(mm, anon_rss, 0); 456 set_mm_counter(mm, anon_rss, 0);
433 spin_lock_init(&mm->page_table_lock); 457 spin_lock_init(&mm->page_table_lock);
434 spin_lock_init(&mm->ioctx_lock);
435 INIT_HLIST_HEAD(&mm->ioctx_list);
436 mm->free_area_cache = TASK_UNMAPPED_BASE; 458 mm->free_area_cache = TASK_UNMAPPED_BASE;
437 mm->cached_hole_size = ~0UL; 459 mm->cached_hole_size = ~0UL;
460 mm_init_aio(mm);
438 mm_init_owner(mm, p); 461 mm_init_owner(mm, p);
439 462
440 if (likely(!mm_alloc_pgd(mm))) { 463 if (likely(!mm_alloc_pgd(mm))) {
@@ -486,6 +509,7 @@ void mmput(struct mm_struct *mm)
486 509
487 if (atomic_dec_and_test(&mm->mm_users)) { 510 if (atomic_dec_and_test(&mm->mm_users)) {
488 exit_aio(mm); 511 exit_aio(mm);
512 ksm_exit(mm);
489 exit_mmap(mm); 513 exit_mmap(mm);
490 set_mm_exe_file(mm, NULL); 514 set_mm_exe_file(mm, NULL);
491 if (!list_empty(&mm->mmlist)) { 515 if (!list_empty(&mm->mmlist)) {
@@ -494,6 +518,8 @@ void mmput(struct mm_struct *mm)
494 spin_unlock(&mmlist_lock); 518 spin_unlock(&mmlist_lock);
495 } 519 }
496 put_swap_token(mm); 520 put_swap_token(mm);
521 if (mm->binfmt)
522 module_put(mm->binfmt->module);
497 mmdrop(mm); 523 mmdrop(mm);
498 } 524 }
499} 525}
@@ -619,9 +645,14 @@ struct mm_struct *dup_mm(struct task_struct *tsk)
619 mm->hiwater_rss = get_mm_rss(mm); 645 mm->hiwater_rss = get_mm_rss(mm);
620 mm->hiwater_vm = mm->total_vm; 646 mm->hiwater_vm = mm->total_vm;
621 647
648 if (mm->binfmt && !try_module_get(mm->binfmt->module))
649 goto free_pt;
650
622 return mm; 651 return mm;
623 652
624free_pt: 653free_pt:
654 /* don't put binfmt in mmput, we haven't got module yet */
655 mm->binfmt = NULL;
625 mmput(mm); 656 mmput(mm);
626 657
627fail_nomem: 658fail_nomem:
@@ -789,10 +820,10 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig)
789 thread_group_cputime_init(sig); 820 thread_group_cputime_init(sig);
790 821
791 /* Expiration times and increments. */ 822 /* Expiration times and increments. */
792 sig->it_virt_expires = cputime_zero; 823 sig->it[CPUCLOCK_PROF].expires = cputime_zero;
793 sig->it_virt_incr = cputime_zero; 824 sig->it[CPUCLOCK_PROF].incr = cputime_zero;
794 sig->it_prof_expires = cputime_zero; 825 sig->it[CPUCLOCK_VIRT].expires = cputime_zero;
795 sig->it_prof_incr = cputime_zero; 826 sig->it[CPUCLOCK_VIRT].incr = cputime_zero;
796 827
797 /* Cached expiration times. */ 828 /* Cached expiration times. */
798 sig->cputime_expires.prof_exp = cputime_zero; 829 sig->cputime_expires.prof_exp = cputime_zero;
@@ -850,6 +881,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
850 sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; 881 sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
851 sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; 882 sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0;
852 sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; 883 sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0;
884 sig->maxrss = sig->cmaxrss = 0;
853 task_io_accounting_init(&sig->ioac); 885 task_io_accounting_init(&sig->ioac);
854 sig->sum_sched_runtime = 0; 886 sig->sum_sched_runtime = 0;
855 taskstats_tgid_init(sig); 887 taskstats_tgid_init(sig);
@@ -864,6 +896,8 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
864 896
865 tty_audit_fork(sig); 897 tty_audit_fork(sig);
866 898
899 sig->oom_adj = current->signal->oom_adj;
900
867 return 0; 901 return 0;
868} 902}
869 903
@@ -959,6 +993,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
959 if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM)) 993 if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM))
960 return ERR_PTR(-EINVAL); 994 return ERR_PTR(-EINVAL);
961 995
996 /*
997 * Siblings of global init remain as zombies on exit since they are
998 * not reaped by their parent (swapper). To solve this and to avoid
999 * multi-rooted process trees, prevent global and container-inits
1000 * from creating siblings.
1001 */
1002 if ((clone_flags & CLONE_PARENT) &&
1003 current->signal->flags & SIGNAL_UNKILLABLE)
1004 return ERR_PTR(-EINVAL);
1005
962 retval = security_task_create(clone_flags); 1006 retval = security_task_create(clone_flags);
963 if (retval) 1007 if (retval)
964 goto fork_out; 1008 goto fork_out;
@@ -1000,18 +1044,12 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1000 if (!try_module_get(task_thread_info(p)->exec_domain->module)) 1044 if (!try_module_get(task_thread_info(p)->exec_domain->module))
1001 goto bad_fork_cleanup_count; 1045 goto bad_fork_cleanup_count;
1002 1046
1003 if (p->binfmt && !try_module_get(p->binfmt->module))
1004 goto bad_fork_cleanup_put_domain;
1005
1006 p->did_exec = 0; 1047 p->did_exec = 0;
1007 delayacct_tsk_init(p); /* Must remain after dup_task_struct() */ 1048 delayacct_tsk_init(p); /* Must remain after dup_task_struct() */
1008 copy_flags(clone_flags, p); 1049 copy_flags(clone_flags, p);
1009 INIT_LIST_HEAD(&p->children); 1050 INIT_LIST_HEAD(&p->children);
1010 INIT_LIST_HEAD(&p->sibling); 1051 INIT_LIST_HEAD(&p->sibling);
1011#ifdef CONFIG_PREEMPT_RCU 1052 rcu_copy_process(p);
1012 p->rcu_read_lock_nesting = 0;
1013 p->rcu_flipctr_idx = 0;
1014#endif /* #ifdef CONFIG_PREEMPT_RCU */
1015 p->vfork_done = NULL; 1053 p->vfork_done = NULL;
1016 spin_lock_init(&p->alloc_lock); 1054 spin_lock_init(&p->alloc_lock);
1017 1055
@@ -1079,10 +1117,12 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1079 1117
1080 p->bts = NULL; 1118 p->bts = NULL;
1081 1119
1120 p->stack_start = stack_start;
1121
1082 /* Perform scheduler related setup. Assign this task to a CPU. */ 1122 /* Perform scheduler related setup. Assign this task to a CPU. */
1083 sched_fork(p, clone_flags); 1123 sched_fork(p, clone_flags);
1084 1124
1085 retval = perf_counter_init_task(p); 1125 retval = perf_event_init_task(p);
1086 if (retval) 1126 if (retval)
1087 goto bad_fork_cleanup_policy; 1127 goto bad_fork_cleanup_policy;
1088 1128
@@ -1257,7 +1297,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1257 write_unlock_irq(&tasklist_lock); 1297 write_unlock_irq(&tasklist_lock);
1258 proc_fork_connector(p); 1298 proc_fork_connector(p);
1259 cgroup_post_fork(p); 1299 cgroup_post_fork(p);
1260 perf_counter_fork(p); 1300 perf_event_fork(p);
1261 return p; 1301 return p;
1262 1302
1263bad_fork_free_pid: 1303bad_fork_free_pid:
@@ -1284,21 +1324,17 @@ bad_fork_cleanup_semundo:
1284bad_fork_cleanup_audit: 1324bad_fork_cleanup_audit:
1285 audit_free(p); 1325 audit_free(p);
1286bad_fork_cleanup_policy: 1326bad_fork_cleanup_policy:
1287 perf_counter_free_task(p); 1327 perf_event_free_task(p);
1288#ifdef CONFIG_NUMA 1328#ifdef CONFIG_NUMA
1289 mpol_put(p->mempolicy); 1329 mpol_put(p->mempolicy);
1290bad_fork_cleanup_cgroup: 1330bad_fork_cleanup_cgroup:
1291#endif 1331#endif
1292 cgroup_exit(p, cgroup_callbacks_done); 1332 cgroup_exit(p, cgroup_callbacks_done);
1293 delayacct_tsk_free(p); 1333 delayacct_tsk_free(p);
1294 if (p->binfmt)
1295 module_put(p->binfmt->module);
1296bad_fork_cleanup_put_domain:
1297 module_put(task_thread_info(p)->exec_domain->module); 1334 module_put(task_thread_info(p)->exec_domain->module);
1298bad_fork_cleanup_count: 1335bad_fork_cleanup_count:
1299 atomic_dec(&p->cred->user->processes); 1336 atomic_dec(&p->cred->user->processes);
1300 put_cred(p->real_cred); 1337 exit_creds(p);
1301 put_cred(p->cred);
1302bad_fork_free: 1338bad_fork_free:
1303 free_task(p); 1339 free_task(p);
1304fork_out: 1340fork_out: