Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[pandora-kernel.git] / kernel / fork.c
index 6031800..4698389 100644 (file)
 #include <linux/acct.h>
 #include <linux/tsacct_kern.h>
 #include <linux/cn_proc.h>
+#include <linux/freezer.h>
 #include <linux/delayacct.h>
 #include <linux/taskstats_kern.h>
 #include <linux/random.h>
+#include <linux/tty.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -332,6 +334,8 @@ static struct mm_struct * mm_init(struct mm_struct * mm)
        atomic_set(&mm->mm_count, 1);
        init_rwsem(&mm->mmap_sem);
        INIT_LIST_HEAD(&mm->mmlist);
+       mm->flags = (current->mm) ? current->mm->flags
+                                 : MMF_DUMP_FILTER_DEFAULT;
        mm->core_waiters = 0;
        mm->nr_ptes = 0;
        set_mm_counter(mm, file_rss, 0);
@@ -876,7 +880,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
        sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
        sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0;
        sig->inblock = sig->oublock = sig->cinblock = sig->coublock = 0;
-       sig->sched_time = 0;
+       sig->sum_sched_runtime = 0;
        INIT_LIST_HEAD(&sig->cpu_timers[0]);
        INIT_LIST_HEAD(&sig->cpu_timers[1]);
        INIT_LIST_HEAD(&sig->cpu_timers[2]);
@@ -896,6 +900,8 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
        }
        acct_init_pacct(&sig->pacct);
 
+       tty_audit_fork(sig);
+
        return 0;
 }
 
@@ -919,7 +925,7 @@ static inline void copy_flags(unsigned long clone_flags, struct task_struct *p)
 {
        unsigned long new_flags = p->flags;
 
-       new_flags &= ~(PF_SUPERPRIV | PF_NOFREEZE);
+       new_flags &= ~PF_SUPERPRIV;
        new_flags |= PF_FORKNOEXEC;
        if (!(clone_flags & CLONE_PTRACE))
                p->ptrace = 0;
@@ -956,7 +962,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
                                        unsigned long stack_size,
                                        int __user *parent_tidptr,
                                        int __user *child_tidptr,
-                                       int pid)
+                                       struct pid *pid)
 {
        int retval;
        struct task_struct *p = NULL;
@@ -998,7 +1004,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
        if (atomic_read(&p->user->processes) >=
                        p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
                if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
-                               p->user != &root_user)
+                   p->user != current->nsproxy->user_ns->root_user)
                        goto bad_fork_free;
        }
 
@@ -1023,7 +1029,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
        p->did_exec = 0;
        delayacct_tsk_init(p);  /* Must remain after dup_task_struct() */
        copy_flags(clone_flags, p);
-       p->pid = pid;
+       p->pid = pid_nr(pid);
        retval = -EFAULT;
        if (clone_flags & CLONE_PARENT_SETTID)
                if (put_user(p->pid, parent_tidptr))
@@ -1039,7 +1045,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
 
        p->utime = cputime_zero;
        p->stime = cputime_zero;
-       p->sched_time = 0;
+
 #ifdef CONFIG_TASK_XACCT
        p->rchar = 0;           /* I/O counter: bytes read */
        p->wchar = 0;           /* I/O counter: bytes written */
@@ -1058,6 +1064,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
 
        p->lock_depth = -1;             /* -1 = no lock */
        do_posix_clock_monotonic_gettime(&p->start_time);
+       p->real_start_time = p->start_time;
+       monotonic_to_bootbased(&p->real_start_time);
        p->security = NULL;
        p->io_context = NULL;
        p->io_wait = NULL;
@@ -1249,19 +1257,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
                        __ptrace_link(p, current->parent);
 
                if (thread_group_leader(p)) {
-                       pid_t pgid = process_group(current);
-                       pid_t sid = process_session(current);
-
                        p->signal->tty = current->signal->tty;
-                       p->signal->pgrp = pgid;
+                       p->signal->pgrp = process_group(current);
                        set_signal_session(p->signal, process_session(current));
-                       attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
-                       attach_pid(p, PIDTYPE_SID, find_pid(sid));
+                       attach_pid(p, PIDTYPE_PGID, task_pgrp(current));
+                       attach_pid(p, PIDTYPE_SID, task_session(current));
 
                        list_add_tail_rcu(&p->tasks, &init_task.tasks);
                        __get_cpu_var(process_counts)++;
                }
-               attach_pid(p, PIDTYPE_PID, find_pid(p->pid));
+               attach_pid(p, PIDTYPE_PID, pid);
                nr_threads++;
        }
 
@@ -1325,7 +1330,8 @@ struct task_struct * __cpuinit fork_idle(int cpu)
        struct task_struct *task;
        struct pt_regs regs;
 
-       task = copy_process(CLONE_VM, 0, idle_regs(&regs), 0, NULL, NULL, 0);
+       task = copy_process(CLONE_VM, 0, idle_regs(&regs), 0, NULL, NULL,
+                               &init_struct_pid);
        if (!IS_ERR(task))
                init_idle(task, cpu);
 
@@ -1375,7 +1381,7 @@ long do_fork(unsigned long clone_flags,
                        clone_flags |= CLONE_PTRACE;
        }
 
-       p = copy_process(clone_flags, stack_start, regs, stack_size, parent_tidptr, child_tidptr, nr);
+       p = copy_process(clone_flags, stack_start, regs, stack_size, parent_tidptr, child_tidptr, pid);
        /*
         * Do this prior waking up the new thread - the thread pointer
         * might get invalid after that point, if the thread exits quickly.
@@ -1407,7 +1413,9 @@ long do_fork(unsigned long clone_flags,
                }
 
                if (clone_flags & CLONE_VFORK) {
+                       freezer_do_not_count();
                        wait_for_completion(&vfork);
+                       freezer_count();
                        if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE)) {
                                current->ptrace_message = nr;
                                ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP);
@@ -1424,12 +1432,13 @@ long do_fork(unsigned long clone_flags,
 #define ARCH_MIN_MMSTRUCT_ALIGN 0
 #endif
 
-static void sighand_ctor(void *data, struct kmem_cache *cachep, unsigned long flags)
+static void sighand_ctor(void *data, struct kmem_cache *cachep,
+                       unsigned long flags)
 {
        struct sighand_struct *sighand = data;
 
-       if (flags & SLAB_CTOR_CONSTRUCTOR)
-               spin_lock_init(&sighand->siglock);
+       spin_lock_init(&sighand->siglock);
+       INIT_LIST_HEAD(&sighand->signalfd_list);
 }
 
 void __init proc_caches_init(void)
@@ -1455,7 +1464,6 @@ void __init proc_caches_init(void)
                        SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
 }
 
-
 /*
  * Check constraints on flags passed to the unshare system call and
  * force unsharing of additional process context as appropriate.
@@ -1600,7 +1608,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
        err = -EINVAL;
        if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND|
                                CLONE_VM|CLONE_FILES|CLONE_SYSVSEM|
-                               CLONE_NEWUTS|CLONE_NEWIPC))
+                               CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWUSER))
                goto bad_unshare_out;
 
        if ((err = unshare_thread(unshare_flags)))