diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-10-28 11:26:12 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-10-28 11:26:12 -0400 |
commit | 7a9787e1eba95a166265e6a260cf30af04ef0a99 (patch) | |
tree | e730a4565e0318140d2fbd2f0415d18a339d7336 /kernel/fork.c | |
parent | 41b9eb264c8407655db57b60b4457fe1b2ec9977 (diff) | |
parent | 0173a3265b228da319ceb9c1ec6a5682fd1b2d92 (diff) |
Merge commit 'v2.6.28-rc2' into x86/pci-ioapic-boot-irq-quirks
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 235 |
1 files changed, 129 insertions, 106 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index adefc1131f27..f6083561dfe0 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -27,15 +27,18 @@ | |||
27 | #include <linux/key.h> | 27 | #include <linux/key.h> |
28 | #include <linux/binfmts.h> | 28 | #include <linux/binfmts.h> |
29 | #include <linux/mman.h> | 29 | #include <linux/mman.h> |
30 | #include <linux/mmu_notifier.h> | ||
30 | #include <linux/fs.h> | 31 | #include <linux/fs.h> |
31 | #include <linux/nsproxy.h> | 32 | #include <linux/nsproxy.h> |
32 | #include <linux/capability.h> | 33 | #include <linux/capability.h> |
33 | #include <linux/cpu.h> | 34 | #include <linux/cpu.h> |
34 | #include <linux/cgroup.h> | 35 | #include <linux/cgroup.h> |
35 | #include <linux/security.h> | 36 | #include <linux/security.h> |
37 | #include <linux/hugetlb.h> | ||
36 | #include <linux/swap.h> | 38 | #include <linux/swap.h> |
37 | #include <linux/syscalls.h> | 39 | #include <linux/syscalls.h> |
38 | #include <linux/jiffies.h> | 40 | #include <linux/jiffies.h> |
41 | #include <linux/tracehook.h> | ||
39 | #include <linux/futex.h> | 42 | #include <linux/futex.h> |
40 | #include <linux/task_io_accounting_ops.h> | 43 | #include <linux/task_io_accounting_ops.h> |
41 | #include <linux/rcupdate.h> | 44 | #include <linux/rcupdate.h> |
@@ -55,6 +58,7 @@ | |||
55 | #include <linux/tty.h> | 58 | #include <linux/tty.h> |
56 | #include <linux/proc_fs.h> | 59 | #include <linux/proc_fs.h> |
57 | #include <linux/blkdev.h> | 60 | #include <linux/blkdev.h> |
61 | #include <trace/sched.h> | ||
58 | 62 | ||
59 | #include <asm/pgtable.h> | 63 | #include <asm/pgtable.h> |
60 | #include <asm/pgalloc.h> | 64 | #include <asm/pgalloc.h> |
@@ -92,6 +96,23 @@ int nr_processes(void) | |||
92 | static struct kmem_cache *task_struct_cachep; | 96 | static struct kmem_cache *task_struct_cachep; |
93 | #endif | 97 | #endif |
94 | 98 | ||
99 | #ifndef __HAVE_ARCH_THREAD_INFO_ALLOCATOR | ||
100 | static inline struct thread_info *alloc_thread_info(struct task_struct *tsk) | ||
101 | { | ||
102 | #ifdef CONFIG_DEBUG_STACK_USAGE | ||
103 | gfp_t mask = GFP_KERNEL | __GFP_ZERO; | ||
104 | #else | ||
105 | gfp_t mask = GFP_KERNEL; | ||
106 | #endif | ||
107 | return (struct thread_info *)__get_free_pages(mask, THREAD_SIZE_ORDER); | ||
108 | } | ||
109 | |||
110 | static inline void free_thread_info(struct thread_info *ti) | ||
111 | { | ||
112 | free_pages((unsigned long)ti, THREAD_SIZE_ORDER); | ||
113 | } | ||
114 | #endif | ||
115 | |||
95 | /* SLAB cache for signal_struct structures (tsk->signal) */ | 116 | /* SLAB cache for signal_struct structures (tsk->signal) */ |
96 | static struct kmem_cache *signal_cachep; | 117 | static struct kmem_cache *signal_cachep; |
97 | 118 | ||
@@ -307,6 +328,14 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) | |||
307 | } | 328 | } |
308 | 329 | ||
309 | /* | 330 | /* |
331 | * Clear hugetlb-related page reserves for children. This only | ||
332 | * affects MAP_PRIVATE mappings. Faults generated by the child | ||
333 | * are not guaranteed to succeed, even if read-only | ||
334 | */ | ||
335 | if (is_vm_hugetlb_page(tmp)) | ||
336 | reset_vma_resv_huge_pages(tmp); | ||
337 | |||
338 | /* | ||
310 | * Link in the new vma and copy the page table entries. | 339 | * Link in the new vma and copy the page table entries. |
311 | */ | 340 | */ |
312 | *pprev = tmp; | 341 | *pprev = tmp; |
@@ -374,7 +403,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p) | |||
374 | INIT_LIST_HEAD(&mm->mmlist); | 403 | INIT_LIST_HEAD(&mm->mmlist); |
375 | mm->flags = (current->mm) ? current->mm->flags | 404 | mm->flags = (current->mm) ? current->mm->flags |
376 | : MMF_DUMP_FILTER_DEFAULT; | 405 | : MMF_DUMP_FILTER_DEFAULT; |
377 | mm->core_waiters = 0; | 406 | mm->core_state = NULL; |
378 | mm->nr_ptes = 0; | 407 | mm->nr_ptes = 0; |
379 | set_mm_counter(mm, file_rss, 0); | 408 | set_mm_counter(mm, file_rss, 0); |
380 | set_mm_counter(mm, anon_rss, 0); | 409 | set_mm_counter(mm, anon_rss, 0); |
@@ -387,6 +416,7 @@ static struct mm_struct * mm_init(struct mm_struct * mm, struct task_struct *p) | |||
387 | 416 | ||
388 | if (likely(!mm_alloc_pgd(mm))) { | 417 | if (likely(!mm_alloc_pgd(mm))) { |
389 | mm->def_flags = 0; | 418 | mm->def_flags = 0; |
419 | mmu_notifier_mm_init(mm); | ||
390 | return mm; | 420 | return mm; |
391 | } | 421 | } |
392 | 422 | ||
@@ -419,6 +449,7 @@ void __mmdrop(struct mm_struct *mm) | |||
419 | BUG_ON(mm == &init_mm); | 449 | BUG_ON(mm == &init_mm); |
420 | mm_free_pgd(mm); | 450 | mm_free_pgd(mm); |
421 | destroy_context(mm); | 451 | destroy_context(mm); |
452 | mmu_notifier_mm_destroy(mm); | ||
422 | free_mm(mm); | 453 | free_mm(mm); |
423 | } | 454 | } |
424 | EXPORT_SYMBOL_GPL(__mmdrop); | 455 | EXPORT_SYMBOL_GPL(__mmdrop); |
@@ -448,7 +479,7 @@ EXPORT_SYMBOL_GPL(mmput); | |||
448 | /** | 479 | /** |
449 | * get_task_mm - acquire a reference to the task's mm | 480 | * get_task_mm - acquire a reference to the task's mm |
450 | * | 481 | * |
451 | * Returns %NULL if the task has no mm. Checks PF_BORROWED_MM (meaning | 482 | * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning |
452 | * this kernel workthread has transiently adopted a user mm with use_mm, | 483 | * this kernel workthread has transiently adopted a user mm with use_mm, |
453 | * to do its AIO) is not set and if so returns a reference to it, after | 484 | * to do its AIO) is not set and if so returns a reference to it, after |
454 | * bumping up the use count. User must release the mm via mmput() | 485 | * bumping up the use count. User must release the mm via mmput() |
@@ -461,7 +492,7 @@ struct mm_struct *get_task_mm(struct task_struct *task) | |||
461 | task_lock(task); | 492 | task_lock(task); |
462 | mm = task->mm; | 493 | mm = task->mm; |
463 | if (mm) { | 494 | if (mm) { |
464 | if (task->flags & PF_BORROWED_MM) | 495 | if (task->flags & PF_KTHREAD) |
465 | mm = NULL; | 496 | mm = NULL; |
466 | else | 497 | else |
467 | atomic_inc(&mm->mm_users); | 498 | atomic_inc(&mm->mm_users); |
@@ -630,13 +661,6 @@ static struct fs_struct *__copy_fs_struct(struct fs_struct *old) | |||
630 | path_get(&old->root); | 661 | path_get(&old->root); |
631 | fs->pwd = old->pwd; | 662 | fs->pwd = old->pwd; |
632 | path_get(&old->pwd); | 663 | path_get(&old->pwd); |
633 | if (old->altroot.dentry) { | ||
634 | fs->altroot = old->altroot; | ||
635 | path_get(&old->altroot); | ||
636 | } else { | ||
637 | fs->altroot.mnt = NULL; | ||
638 | fs->altroot.dentry = NULL; | ||
639 | } | ||
640 | read_unlock(&old->lock); | 664 | read_unlock(&old->lock); |
641 | } | 665 | } |
642 | return fs; | 666 | return fs; |
@@ -736,15 +760,44 @@ void __cleanup_sighand(struct sighand_struct *sighand) | |||
736 | kmem_cache_free(sighand_cachep, sighand); | 760 | kmem_cache_free(sighand_cachep, sighand); |
737 | } | 761 | } |
738 | 762 | ||
763 | |||
764 | /* | ||
765 | * Initialize POSIX timer handling for a thread group. | ||
766 | */ | ||
767 | static void posix_cpu_timers_init_group(struct signal_struct *sig) | ||
768 | { | ||
769 | /* Thread group counters. */ | ||
770 | thread_group_cputime_init(sig); | ||
771 | |||
772 | /* Expiration times and increments. */ | ||
773 | sig->it_virt_expires = cputime_zero; | ||
774 | sig->it_virt_incr = cputime_zero; | ||
775 | sig->it_prof_expires = cputime_zero; | ||
776 | sig->it_prof_incr = cputime_zero; | ||
777 | |||
778 | /* Cached expiration times. */ | ||
779 | sig->cputime_expires.prof_exp = cputime_zero; | ||
780 | sig->cputime_expires.virt_exp = cputime_zero; | ||
781 | sig->cputime_expires.sched_exp = 0; | ||
782 | |||
783 | /* The timer lists. */ | ||
784 | INIT_LIST_HEAD(&sig->cpu_timers[0]); | ||
785 | INIT_LIST_HEAD(&sig->cpu_timers[1]); | ||
786 | INIT_LIST_HEAD(&sig->cpu_timers[2]); | ||
787 | } | ||
788 | |||
739 | static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | 789 | static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) |
740 | { | 790 | { |
741 | struct signal_struct *sig; | 791 | struct signal_struct *sig; |
742 | int ret; | 792 | int ret; |
743 | 793 | ||
744 | if (clone_flags & CLONE_THREAD) { | 794 | if (clone_flags & CLONE_THREAD) { |
745 | atomic_inc(¤t->signal->count); | 795 | ret = thread_group_cputime_clone_thread(current); |
746 | atomic_inc(¤t->signal->live); | 796 | if (likely(!ret)) { |
747 | return 0; | 797 | atomic_inc(¤t->signal->count); |
798 | atomic_inc(¤t->signal->live); | ||
799 | } | ||
800 | return ret; | ||
748 | } | 801 | } |
749 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); | 802 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); |
750 | tsk->signal = sig; | 803 | tsk->signal = sig; |
@@ -772,38 +825,25 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
772 | sig->it_real_incr.tv64 = 0; | 825 | sig->it_real_incr.tv64 = 0; |
773 | sig->real_timer.function = it_real_fn; | 826 | sig->real_timer.function = it_real_fn; |
774 | 827 | ||
775 | sig->it_virt_expires = cputime_zero; | ||
776 | sig->it_virt_incr = cputime_zero; | ||
777 | sig->it_prof_expires = cputime_zero; | ||
778 | sig->it_prof_incr = cputime_zero; | ||
779 | |||
780 | sig->leader = 0; /* session leadership doesn't inherit */ | 828 | sig->leader = 0; /* session leadership doesn't inherit */ |
781 | sig->tty_old_pgrp = NULL; | 829 | sig->tty_old_pgrp = NULL; |
830 | sig->tty = NULL; | ||
782 | 831 | ||
783 | sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero; | 832 | sig->cutime = sig->cstime = cputime_zero; |
784 | sig->gtime = cputime_zero; | 833 | sig->gtime = cputime_zero; |
785 | sig->cgtime = cputime_zero; | 834 | sig->cgtime = cputime_zero; |
786 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; | 835 | sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; |
787 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; | 836 | sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0; |
788 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; | 837 | sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0; |
789 | sig->sum_sched_runtime = 0; | 838 | task_io_accounting_init(&sig->ioac); |
790 | INIT_LIST_HEAD(&sig->cpu_timers[0]); | ||
791 | INIT_LIST_HEAD(&sig->cpu_timers[1]); | ||
792 | INIT_LIST_HEAD(&sig->cpu_timers[2]); | ||
793 | taskstats_tgid_init(sig); | 839 | taskstats_tgid_init(sig); |
794 | 840 | ||
795 | task_lock(current->group_leader); | 841 | task_lock(current->group_leader); |
796 | memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim); | 842 | memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim); |
797 | task_unlock(current->group_leader); | 843 | task_unlock(current->group_leader); |
798 | 844 | ||
799 | if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) { | 845 | posix_cpu_timers_init_group(sig); |
800 | /* | 846 | |
801 | * New sole thread in the process gets an expiry time | ||
802 | * of the whole CPU time limit. | ||
803 | */ | ||
804 | tsk->it_prof_expires = | ||
805 | secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur); | ||
806 | } | ||
807 | acct_init_pacct(&sig->pacct); | 847 | acct_init_pacct(&sig->pacct); |
808 | 848 | ||
809 | tty_audit_fork(sig); | 849 | tty_audit_fork(sig); |
@@ -813,7 +853,9 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
813 | 853 | ||
814 | void __cleanup_signal(struct signal_struct *sig) | 854 | void __cleanup_signal(struct signal_struct *sig) |
815 | { | 855 | { |
856 | thread_group_cputime_free(sig); | ||
816 | exit_thread_group_keys(sig); | 857 | exit_thread_group_keys(sig); |
858 | tty_kref_put(sig->tty); | ||
817 | kmem_cache_free(signal_cachep, sig); | 859 | kmem_cache_free(signal_cachep, sig); |
818 | } | 860 | } |
819 | 861 | ||
@@ -833,8 +875,7 @@ static void copy_flags(unsigned long clone_flags, struct task_struct *p) | |||
833 | 875 | ||
834 | new_flags &= ~PF_SUPERPRIV; | 876 | new_flags &= ~PF_SUPERPRIV; |
835 | new_flags |= PF_FORKNOEXEC; | 877 | new_flags |= PF_FORKNOEXEC; |
836 | if (!(clone_flags & CLONE_PTRACE)) | 878 | new_flags |= PF_STARTING; |
837 | p->ptrace = 0; | ||
838 | p->flags = new_flags; | 879 | p->flags = new_flags; |
839 | clear_freeze_flag(p); | 880 | clear_freeze_flag(p); |
840 | } | 881 | } |
@@ -863,6 +904,19 @@ void mm_init_owner(struct mm_struct *mm, struct task_struct *p) | |||
863 | #endif /* CONFIG_MM_OWNER */ | 904 | #endif /* CONFIG_MM_OWNER */ |
864 | 905 | ||
865 | /* | 906 | /* |
907 | * Initialize POSIX timer handling for a single task. | ||
908 | */ | ||
909 | static void posix_cpu_timers_init(struct task_struct *tsk) | ||
910 | { | ||
911 | tsk->cputime_expires.prof_exp = cputime_zero; | ||
912 | tsk->cputime_expires.virt_exp = cputime_zero; | ||
913 | tsk->cputime_expires.sched_exp = 0; | ||
914 | INIT_LIST_HEAD(&tsk->cpu_timers[0]); | ||
915 | INIT_LIST_HEAD(&tsk->cpu_timers[1]); | ||
916 | INIT_LIST_HEAD(&tsk->cpu_timers[2]); | ||
917 | } | ||
918 | |||
919 | /* | ||
866 | * This creates a new process as a copy of the old one, | 920 | * This creates a new process as a copy of the old one, |
867 | * but does not actually start it yet. | 921 | * but does not actually start it yet. |
868 | * | 922 | * |
@@ -875,7 +929,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
875 | struct pt_regs *regs, | 929 | struct pt_regs *regs, |
876 | unsigned long stack_size, | 930 | unsigned long stack_size, |
877 | int __user *child_tidptr, | 931 | int __user *child_tidptr, |
878 | struct pid *pid) | 932 | struct pid *pid, |
933 | int trace) | ||
879 | { | 934 | { |
880 | int retval; | 935 | int retval; |
881 | struct task_struct *p; | 936 | struct task_struct *p; |
@@ -963,26 +1018,17 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
963 | p->prev_utime = cputime_zero; | 1018 | p->prev_utime = cputime_zero; |
964 | p->prev_stime = cputime_zero; | 1019 | p->prev_stime = cputime_zero; |
965 | 1020 | ||
1021 | p->default_timer_slack_ns = current->timer_slack_ns; | ||
1022 | |||
966 | #ifdef CONFIG_DETECT_SOFTLOCKUP | 1023 | #ifdef CONFIG_DETECT_SOFTLOCKUP |
967 | p->last_switch_count = 0; | 1024 | p->last_switch_count = 0; |
968 | p->last_switch_timestamp = 0; | 1025 | p->last_switch_timestamp = 0; |
969 | #endif | 1026 | #endif |
970 | 1027 | ||
971 | #ifdef CONFIG_TASK_XACCT | 1028 | task_io_accounting_init(&p->ioac); |
972 | p->rchar = 0; /* I/O counter: bytes read */ | ||
973 | p->wchar = 0; /* I/O counter: bytes written */ | ||
974 | p->syscr = 0; /* I/O counter: read syscalls */ | ||
975 | p->syscw = 0; /* I/O counter: write syscalls */ | ||
976 | #endif | ||
977 | task_io_accounting_init(p); | ||
978 | acct_clear_integrals(p); | 1029 | acct_clear_integrals(p); |
979 | 1030 | ||
980 | p->it_virt_expires = cputime_zero; | 1031 | posix_cpu_timers_init(p); |
981 | p->it_prof_expires = cputime_zero; | ||
982 | p->it_sched_expires = 0; | ||
983 | INIT_LIST_HEAD(&p->cpu_timers[0]); | ||
984 | INIT_LIST_HEAD(&p->cpu_timers[1]); | ||
985 | INIT_LIST_HEAD(&p->cpu_timers[2]); | ||
986 | 1032 | ||
987 | p->lock_depth = -1; /* -1 = no lock */ | 1033 | p->lock_depth = -1; /* -1 = no lock */ |
988 | do_posix_clock_monotonic_gettime(&p->start_time); | 1034 | do_posix_clock_monotonic_gettime(&p->start_time); |
@@ -1081,6 +1127,12 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1081 | if (clone_flags & CLONE_THREAD) | 1127 | if (clone_flags & CLONE_THREAD) |
1082 | p->tgid = current->tgid; | 1128 | p->tgid = current->tgid; |
1083 | 1129 | ||
1130 | if (current->nsproxy != p->nsproxy) { | ||
1131 | retval = ns_cgroup_clone(p, pid); | ||
1132 | if (retval) | ||
1133 | goto bad_fork_free_pid; | ||
1134 | } | ||
1135 | |||
1084 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; | 1136 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; |
1085 | /* | 1137 | /* |
1086 | * Clear TID on mm_release()? | 1138 | * Clear TID on mm_release()? |
@@ -1125,8 +1177,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1125 | */ | 1177 | */ |
1126 | p->group_leader = p; | 1178 | p->group_leader = p; |
1127 | INIT_LIST_HEAD(&p->thread_group); | 1179 | INIT_LIST_HEAD(&p->thread_group); |
1128 | INIT_LIST_HEAD(&p->ptrace_entry); | ||
1129 | INIT_LIST_HEAD(&p->ptraced); | ||
1130 | 1180 | ||
1131 | /* Now that the task is set up, run cgroup callbacks if | 1181 | /* Now that the task is set up, run cgroup callbacks if |
1132 | * necessary. We need to run them before the task is visible | 1182 | * necessary. We need to run them before the task is visible |
@@ -1157,7 +1207,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1157 | p->real_parent = current->real_parent; | 1207 | p->real_parent = current->real_parent; |
1158 | else | 1208 | else |
1159 | p->real_parent = current; | 1209 | p->real_parent = current; |
1160 | p->parent = p->real_parent; | ||
1161 | 1210 | ||
1162 | spin_lock(¤t->sighand->siglock); | 1211 | spin_lock(¤t->sighand->siglock); |
1163 | 1212 | ||
@@ -1180,34 +1229,19 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1180 | if (clone_flags & CLONE_THREAD) { | 1229 | if (clone_flags & CLONE_THREAD) { |
1181 | p->group_leader = current->group_leader; | 1230 | p->group_leader = current->group_leader; |
1182 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); | 1231 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); |
1183 | |||
1184 | if (!cputime_eq(current->signal->it_virt_expires, | ||
1185 | cputime_zero) || | ||
1186 | !cputime_eq(current->signal->it_prof_expires, | ||
1187 | cputime_zero) || | ||
1188 | current->signal->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY || | ||
1189 | !list_empty(¤t->signal->cpu_timers[0]) || | ||
1190 | !list_empty(¤t->signal->cpu_timers[1]) || | ||
1191 | !list_empty(¤t->signal->cpu_timers[2])) { | ||
1192 | /* | ||
1193 | * Have child wake up on its first tick to check | ||
1194 | * for process CPU timers. | ||
1195 | */ | ||
1196 | p->it_prof_expires = jiffies_to_cputime(1); | ||
1197 | } | ||
1198 | } | 1232 | } |
1199 | 1233 | ||
1200 | if (likely(p->pid)) { | 1234 | if (likely(p->pid)) { |
1201 | list_add_tail(&p->sibling, &p->real_parent->children); | 1235 | list_add_tail(&p->sibling, &p->real_parent->children); |
1202 | if (unlikely(p->ptrace & PT_PTRACED)) | 1236 | tracehook_finish_clone(p, clone_flags, trace); |
1203 | __ptrace_link(p, current->parent); | ||
1204 | 1237 | ||
1205 | if (thread_group_leader(p)) { | 1238 | if (thread_group_leader(p)) { |
1206 | if (clone_flags & CLONE_NEWPID) | 1239 | if (clone_flags & CLONE_NEWPID) |
1207 | p->nsproxy->pid_ns->child_reaper = p; | 1240 | p->nsproxy->pid_ns->child_reaper = p; |
1208 | 1241 | ||
1209 | p->signal->leader_pid = pid; | 1242 | p->signal->leader_pid = pid; |
1210 | p->signal->tty = current->signal->tty; | 1243 | tty_kref_put(p->signal->tty); |
1244 | p->signal->tty = tty_kref_get(current->signal->tty); | ||
1211 | set_task_pgrp(p, task_pgrp_nr(current)); | 1245 | set_task_pgrp(p, task_pgrp_nr(current)); |
1212 | set_task_session(p, task_session_nr(current)); | 1246 | set_task_session(p, task_session_nr(current)); |
1213 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); | 1247 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); |
@@ -1285,29 +1319,13 @@ struct task_struct * __cpuinit fork_idle(int cpu) | |||
1285 | struct pt_regs regs; | 1319 | struct pt_regs regs; |
1286 | 1320 | ||
1287 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, | 1321 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, |
1288 | &init_struct_pid); | 1322 | &init_struct_pid, 0); |
1289 | if (!IS_ERR(task)) | 1323 | if (!IS_ERR(task)) |
1290 | init_idle(task, cpu); | 1324 | init_idle(task, cpu); |
1291 | 1325 | ||
1292 | return task; | 1326 | return task; |
1293 | } | 1327 | } |
1294 | 1328 | ||
1295 | static int fork_traceflag(unsigned clone_flags) | ||
1296 | { | ||
1297 | if (clone_flags & CLONE_UNTRACED) | ||
1298 | return 0; | ||
1299 | else if (clone_flags & CLONE_VFORK) { | ||
1300 | if (current->ptrace & PT_TRACE_VFORK) | ||
1301 | return PTRACE_EVENT_VFORK; | ||
1302 | } else if ((clone_flags & CSIGNAL) != SIGCHLD) { | ||
1303 | if (current->ptrace & PT_TRACE_CLONE) | ||
1304 | return PTRACE_EVENT_CLONE; | ||
1305 | } else if (current->ptrace & PT_TRACE_FORK) | ||
1306 | return PTRACE_EVENT_FORK; | ||
1307 | |||
1308 | return 0; | ||
1309 | } | ||
1310 | |||
1311 | /* | 1329 | /* |
1312 | * Ok, this is the main fork-routine. | 1330 | * Ok, this is the main fork-routine. |
1313 | * | 1331 | * |
@@ -1342,14 +1360,14 @@ long do_fork(unsigned long clone_flags, | |||
1342 | } | 1360 | } |
1343 | } | 1361 | } |
1344 | 1362 | ||
1345 | if (unlikely(current->ptrace)) { | 1363 | /* |
1346 | trace = fork_traceflag (clone_flags); | 1364 | * When called from kernel_thread, don't do user tracing stuff. |
1347 | if (trace) | 1365 | */ |
1348 | clone_flags |= CLONE_PTRACE; | 1366 | if (likely(user_mode(regs))) |
1349 | } | 1367 | trace = tracehook_prepare_clone(clone_flags); |
1350 | 1368 | ||
1351 | p = copy_process(clone_flags, stack_start, regs, stack_size, | 1369 | p = copy_process(clone_flags, stack_start, regs, stack_size, |
1352 | child_tidptr, NULL); | 1370 | child_tidptr, NULL, trace); |
1353 | /* | 1371 | /* |
1354 | * Do this prior waking up the new thread - the thread pointer | 1372 | * Do this prior waking up the new thread - the thread pointer |
1355 | * might get invalid after that point, if the thread exits quickly. | 1373 | * might get invalid after that point, if the thread exits quickly. |
@@ -1357,6 +1375,8 @@ long do_fork(unsigned long clone_flags, | |||
1357 | if (!IS_ERR(p)) { | 1375 | if (!IS_ERR(p)) { |
1358 | struct completion vfork; | 1376 | struct completion vfork; |
1359 | 1377 | ||
1378 | trace_sched_process_fork(current, p); | ||
1379 | |||
1360 | nr = task_pid_vnr(p); | 1380 | nr = task_pid_vnr(p); |
1361 | 1381 | ||
1362 | if (clone_flags & CLONE_PARENT_SETTID) | 1382 | if (clone_flags & CLONE_PARENT_SETTID) |
@@ -1367,32 +1387,35 @@ long do_fork(unsigned long clone_flags, | |||
1367 | init_completion(&vfork); | 1387 | init_completion(&vfork); |
1368 | } | 1388 | } |
1369 | 1389 | ||
1370 | if ((p->ptrace & PT_PTRACED) || (clone_flags & CLONE_STOPPED)) { | 1390 | tracehook_report_clone(trace, regs, clone_flags, nr, p); |
1391 | |||
1392 | /* | ||
1393 | * We set PF_STARTING at creation in case tracing wants to | ||
1394 | * use this to distinguish a fully live task from one that | ||
1395 | * hasn't gotten to tracehook_report_clone() yet. Now we | ||
1396 | * clear it and set the child going. | ||
1397 | */ | ||
1398 | p->flags &= ~PF_STARTING; | ||
1399 | |||
1400 | if (unlikely(clone_flags & CLONE_STOPPED)) { | ||
1371 | /* | 1401 | /* |
1372 | * We'll start up with an immediate SIGSTOP. | 1402 | * We'll start up with an immediate SIGSTOP. |
1373 | */ | 1403 | */ |
1374 | sigaddset(&p->pending.signal, SIGSTOP); | 1404 | sigaddset(&p->pending.signal, SIGSTOP); |
1375 | set_tsk_thread_flag(p, TIF_SIGPENDING); | 1405 | set_tsk_thread_flag(p, TIF_SIGPENDING); |
1376 | } | ||
1377 | |||
1378 | if (!(clone_flags & CLONE_STOPPED)) | ||
1379 | wake_up_new_task(p, clone_flags); | ||
1380 | else | ||
1381 | __set_task_state(p, TASK_STOPPED); | 1406 | __set_task_state(p, TASK_STOPPED); |
1382 | 1407 | } else { | |
1383 | if (unlikely (trace)) { | 1408 | wake_up_new_task(p, clone_flags); |
1384 | current->ptrace_message = nr; | ||
1385 | ptrace_notify ((trace << 8) | SIGTRAP); | ||
1386 | } | 1409 | } |
1387 | 1410 | ||
1411 | tracehook_report_clone_complete(trace, regs, | ||
1412 | clone_flags, nr, p); | ||
1413 | |||
1388 | if (clone_flags & CLONE_VFORK) { | 1414 | if (clone_flags & CLONE_VFORK) { |
1389 | freezer_do_not_count(); | 1415 | freezer_do_not_count(); |
1390 | wait_for_completion(&vfork); | 1416 | wait_for_completion(&vfork); |
1391 | freezer_count(); | 1417 | freezer_count(); |
1392 | if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE)) { | 1418 | tracehook_report_vfork_done(p, nr); |
1393 | current->ptrace_message = nr; | ||
1394 | ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP); | ||
1395 | } | ||
1396 | } | 1419 | } |
1397 | } else { | 1420 | } else { |
1398 | nr = PTR_ERR(p); | 1421 | nr = PTR_ERR(p); |
@@ -1404,7 +1427,7 @@ long do_fork(unsigned long clone_flags, | |||
1404 | #define ARCH_MIN_MMSTRUCT_ALIGN 0 | 1427 | #define ARCH_MIN_MMSTRUCT_ALIGN 0 |
1405 | #endif | 1428 | #endif |
1406 | 1429 | ||
1407 | static void sighand_ctor(struct kmem_cache *cachep, void *data) | 1430 | static void sighand_ctor(void *data) |
1408 | { | 1431 | { |
1409 | struct sighand_struct *sighand = data; | 1432 | struct sighand_struct *sighand = data; |
1410 | 1433 | ||