x86: fix RTC_AIE with CONFIG_HPET_EMULATE_RTC
[safe/jmp/linux-2.6] / kernel / sys.c
index fe1f3ab..d1fe71e 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/prctl.h>
 #include <linux/highuid.h>
 #include <linux/fs.h>
+#include <linux/resource.h>
 #include <linux/kernel.h>
 #include <linux/kexec.h>
 #include <linux/workqueue.h>
 #include <linux/signal.h>
 #include <linux/cn_proc.h>
 #include <linux/getcpu.h>
+#include <linux/task_io_accounting_ops.h>
+#include <linux/seccomp.h>
+#include <linux/cpu.h>
 
 #include <linux/compat.h>
 #include <linux/syscalls.h>
 #include <linux/kprobes.h>
+#include <linux/user_namespace.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -96,475 +101,10 @@ struct pid *cad_pid;
 EXPORT_SYMBOL(cad_pid);
 
 /*
- *     Notifier list for kernel code which wants to be called
- *     at shutdown. This is used to stop any idling DMA operations
- *     and the like. 
+ * If set, this is used for preparing the system to power off.
  */
 
-static BLOCKING_NOTIFIER_HEAD(reboot_notifier_list);
-
-/*
- *     Notifier chain core routines.  The exported routines below
- *     are layered on top of these, with appropriate locking added.
- */
-
-static int notifier_chain_register(struct notifier_block **nl,
-               struct notifier_block *n)
-{
-       while ((*nl) != NULL) {
-               if (n->priority > (*nl)->priority)
-                       break;
-               nl = &((*nl)->next);
-       }
-       n->next = *nl;
-       rcu_assign_pointer(*nl, n);
-       return 0;
-}
-
-static int notifier_chain_unregister(struct notifier_block **nl,
-               struct notifier_block *n)
-{
-       while ((*nl) != NULL) {
-               if ((*nl) == n) {
-                       rcu_assign_pointer(*nl, n->next);
-                       return 0;
-               }
-               nl = &((*nl)->next);
-       }
-       return -ENOENT;
-}
-
-static int __kprobes notifier_call_chain(struct notifier_block **nl,
-               unsigned long val, void *v)
-{
-       int ret = NOTIFY_DONE;
-       struct notifier_block *nb, *next_nb;
-
-       nb = rcu_dereference(*nl);
-       while (nb) {
-               next_nb = rcu_dereference(nb->next);
-               ret = nb->notifier_call(nb, val, v);
-               if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK)
-                       break;
-               nb = next_nb;
-       }
-       return ret;
-}
-
-/*
- *     Atomic notifier chain routines.  Registration and unregistration
- *     use a spinlock, and call_chain is synchronized by RCU (no locks).
- */
-
-/**
- *     atomic_notifier_chain_register - Add notifier to an atomic notifier chain
- *     @nh: Pointer to head of the atomic notifier chain
- *     @n: New entry in notifier chain
- *
- *     Adds a notifier to an atomic notifier chain.
- *
- *     Currently always returns zero.
- */
-
-int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
-               struct notifier_block *n)
-{
-       unsigned long flags;
-       int ret;
-
-       spin_lock_irqsave(&nh->lock, flags);
-       ret = notifier_chain_register(&nh->head, n);
-       spin_unlock_irqrestore(&nh->lock, flags);
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(atomic_notifier_chain_register);
-
-/**
- *     atomic_notifier_chain_unregister - Remove notifier from an atomic notifier chain
- *     @nh: Pointer to head of the atomic notifier chain
- *     @n: Entry to remove from notifier chain
- *
- *     Removes a notifier from an atomic notifier chain.
- *
- *     Returns zero on success or %-ENOENT on failure.
- */
-int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
-               struct notifier_block *n)
-{
-       unsigned long flags;
-       int ret;
-
-       spin_lock_irqsave(&nh->lock, flags);
-       ret = notifier_chain_unregister(&nh->head, n);
-       spin_unlock_irqrestore(&nh->lock, flags);
-       synchronize_rcu();
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
-
-/**
- *     atomic_notifier_call_chain - Call functions in an atomic notifier chain
- *     @nh: Pointer to head of the atomic notifier chain
- *     @val: Value passed unmodified to notifier function
- *     @v: Pointer passed unmodified to notifier function
- *
- *     Calls each function in a notifier chain in turn.  The functions
- *     run in an atomic context, so they must not block.
- *     This routine uses RCU to synchronize with changes to the chain.
- *
- *     If the return value of the notifier can be and'ed
- *     with %NOTIFY_STOP_MASK then atomic_notifier_call_chain()
- *     will return immediately, with the return value of
- *     the notifier function which halted execution.
- *     Otherwise the return value is the return value
- *     of the last notifier function called.
- */
-int __kprobes atomic_notifier_call_chain(struct atomic_notifier_head *nh,
-               unsigned long val, void *v)
-{
-       int ret;
-
-       rcu_read_lock();
-       ret = notifier_call_chain(&nh->head, val, v);
-       rcu_read_unlock();
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(atomic_notifier_call_chain);
-
-/*
- *     Blocking notifier chain routines.  All access to the chain is
- *     synchronized by an rwsem.
- */
-
-/**
- *     blocking_notifier_chain_register - Add notifier to a blocking notifier chain
- *     @nh: Pointer to head of the blocking notifier chain
- *     @n: New entry in notifier chain
- *
- *     Adds a notifier to a blocking notifier chain.
- *     Must be called in process context.
- *
- *     Currently always returns zero.
- */
-int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
-               struct notifier_block *n)
-{
-       int ret;
-
-       /*
-        * This code gets used during boot-up, when task switching is
-        * not yet working and interrupts must remain disabled.  At
-        * such times we must not call down_write().
-        */
-       if (unlikely(system_state == SYSTEM_BOOTING))
-               return notifier_chain_register(&nh->head, n);
-
-       down_write(&nh->rwsem);
-       ret = notifier_chain_register(&nh->head, n);
-       up_write(&nh->rwsem);
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(blocking_notifier_chain_register);
-
-/**
- *     blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain
- *     @nh: Pointer to head of the blocking notifier chain
- *     @n: Entry to remove from notifier chain
- *
- *     Removes a notifier from a blocking notifier chain.
- *     Must be called from process context.
- *
- *     Returns zero on success or %-ENOENT on failure.
- */
-int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
-               struct notifier_block *n)
-{
-       int ret;
-
-       /*
-        * This code gets used during boot-up, when task switching is
-        * not yet working and interrupts must remain disabled.  At
-        * such times we must not call down_write().
-        */
-       if (unlikely(system_state == SYSTEM_BOOTING))
-               return notifier_chain_unregister(&nh->head, n);
-
-       down_write(&nh->rwsem);
-       ret = notifier_chain_unregister(&nh->head, n);
-       up_write(&nh->rwsem);
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister);
-
-/**
- *     blocking_notifier_call_chain - Call functions in a blocking notifier chain
- *     @nh: Pointer to head of the blocking notifier chain
- *     @val: Value passed unmodified to notifier function
- *     @v: Pointer passed unmodified to notifier function
- *
- *     Calls each function in a notifier chain in turn.  The functions
- *     run in a process context, so they are allowed to block.
- *
- *     If the return value of the notifier can be and'ed
- *     with %NOTIFY_STOP_MASK then blocking_notifier_call_chain()
- *     will return immediately, with the return value of
- *     the notifier function which halted execution.
- *     Otherwise the return value is the return value
- *     of the last notifier function called.
- */
-int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
-               unsigned long val, void *v)
-{
-       int ret = NOTIFY_DONE;
-
-       /*
-        * We check the head outside the lock, but if this access is
-        * racy then it does not matter what the result of the test
-        * is, we re-check the list after having taken the lock anyway:
-        */
-       if (rcu_dereference(nh->head)) {
-               down_read(&nh->rwsem);
-               ret = notifier_call_chain(&nh->head, val, v);
-               up_read(&nh->rwsem);
-       }
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
-
-/*
- *     Raw notifier chain routines.  There is no protection;
- *     the caller must provide it.  Use at your own risk!
- */
-
-/**
- *     raw_notifier_chain_register - Add notifier to a raw notifier chain
- *     @nh: Pointer to head of the raw notifier chain
- *     @n: New entry in notifier chain
- *
- *     Adds a notifier to a raw notifier chain.
- *     All locking must be provided by the caller.
- *
- *     Currently always returns zero.
- */
-
-int raw_notifier_chain_register(struct raw_notifier_head *nh,
-               struct notifier_block *n)
-{
-       return notifier_chain_register(&nh->head, n);
-}
-
-EXPORT_SYMBOL_GPL(raw_notifier_chain_register);
-
-/**
- *     raw_notifier_chain_unregister - Remove notifier from a raw notifier chain
- *     @nh: Pointer to head of the raw notifier chain
- *     @n: Entry to remove from notifier chain
- *
- *     Removes a notifier from a raw notifier chain.
- *     All locking must be provided by the caller.
- *
- *     Returns zero on success or %-ENOENT on failure.
- */
-int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
-               struct notifier_block *n)
-{
-       return notifier_chain_unregister(&nh->head, n);
-}
-
-EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister);
-
-/**
- *     raw_notifier_call_chain - Call functions in a raw notifier chain
- *     @nh: Pointer to head of the raw notifier chain
- *     @val: Value passed unmodified to notifier function
- *     @v: Pointer passed unmodified to notifier function
- *
- *     Calls each function in a notifier chain in turn.  The functions
- *     run in an undefined context.
- *     All locking must be provided by the caller.
- *
- *     If the return value of the notifier can be and'ed
- *     with %NOTIFY_STOP_MASK then raw_notifier_call_chain()
- *     will return immediately, with the return value of
- *     the notifier function which halted execution.
- *     Otherwise the return value is the return value
- *     of the last notifier function called.
- */
-
-int raw_notifier_call_chain(struct raw_notifier_head *nh,
-               unsigned long val, void *v)
-{
-       return notifier_call_chain(&nh->head, val, v);
-}
-
-EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
-
-/*
- *     SRCU notifier chain routines.    Registration and unregistration
- *     use a mutex, and call_chain is synchronized by SRCU (no locks).
- */
-
-/**
- *     srcu_notifier_chain_register - Add notifier to an SRCU notifier chain
- *     @nh: Pointer to head of the SRCU notifier chain
- *     @n: New entry in notifier chain
- *
- *     Adds a notifier to an SRCU notifier chain.
- *     Must be called in process context.
- *
- *     Currently always returns zero.
- */
-
-int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
-               struct notifier_block *n)
-{
-       int ret;
-
-       /*
-        * This code gets used during boot-up, when task switching is
-        * not yet working and interrupts must remain disabled.  At
-        * such times we must not call mutex_lock().
-        */
-       if (unlikely(system_state == SYSTEM_BOOTING))
-               return notifier_chain_register(&nh->head, n);
-
-       mutex_lock(&nh->mutex);
-       ret = notifier_chain_register(&nh->head, n);
-       mutex_unlock(&nh->mutex);
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(srcu_notifier_chain_register);
-
-/**
- *     srcu_notifier_chain_unregister - Remove notifier from an SRCU notifier chain
- *     @nh: Pointer to head of the SRCU notifier chain
- *     @n: Entry to remove from notifier chain
- *
- *     Removes a notifier from an SRCU notifier chain.
- *     Must be called from process context.
- *
- *     Returns zero on success or %-ENOENT on failure.
- */
-int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh,
-               struct notifier_block *n)
-{
-       int ret;
-
-       /*
-        * This code gets used during boot-up, when task switching is
-        * not yet working and interrupts must remain disabled.  At
-        * such times we must not call mutex_lock().
-        */
-       if (unlikely(system_state == SYSTEM_BOOTING))
-               return notifier_chain_unregister(&nh->head, n);
-
-       mutex_lock(&nh->mutex);
-       ret = notifier_chain_unregister(&nh->head, n);
-       mutex_unlock(&nh->mutex);
-       synchronize_srcu(&nh->srcu);
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(srcu_notifier_chain_unregister);
-
-/**
- *     srcu_notifier_call_chain - Call functions in an SRCU notifier chain
- *     @nh: Pointer to head of the SRCU notifier chain
- *     @val: Value passed unmodified to notifier function
- *     @v: Pointer passed unmodified to notifier function
- *
- *     Calls each function in a notifier chain in turn.  The functions
- *     run in a process context, so they are allowed to block.
- *
- *     If the return value of the notifier can be and'ed
- *     with %NOTIFY_STOP_MASK then srcu_notifier_call_chain()
- *     will return immediately, with the return value of
- *     the notifier function which halted execution.
- *     Otherwise the return value is the return value
- *     of the last notifier function called.
- */
-
-int srcu_notifier_call_chain(struct srcu_notifier_head *nh,
-               unsigned long val, void *v)
-{
-       int ret;
-       int idx;
-
-       idx = srcu_read_lock(&nh->srcu);
-       ret = notifier_call_chain(&nh->head, val, v);
-       srcu_read_unlock(&nh->srcu, idx);
-       return ret;
-}
-
-EXPORT_SYMBOL_GPL(srcu_notifier_call_chain);
-
-/**
- *     srcu_init_notifier_head - Initialize an SRCU notifier head
- *     @nh: Pointer to head of the srcu notifier chain
- *
- *     Unlike other sorts of notifier heads, SRCU notifier heads require
- *     dynamic initialization.  Be sure to call this routine before
- *     calling any of the other SRCU notifier routines for this head.
- *
- *     If an SRCU notifier head is deallocated, it must first be cleaned
- *     up by calling srcu_cleanup_notifier_head().  Otherwise the head's
- *     per-cpu data (used by the SRCU mechanism) will leak.
- */
-
-void srcu_init_notifier_head(struct srcu_notifier_head *nh)
-{
-       mutex_init(&nh->mutex);
-       if (init_srcu_struct(&nh->srcu) < 0)
-               BUG();
-       nh->head = NULL;
-}
-
-EXPORT_SYMBOL_GPL(srcu_init_notifier_head);
-
-/**
- *     register_reboot_notifier - Register function to be called at reboot time
- *     @nb: Info about notifier function to be called
- *
- *     Registers a function with the list of functions
- *     to be called at reboot time.
- *
- *     Currently always returns zero, as blocking_notifier_chain_register()
- *     always returns zero.
- */
-int register_reboot_notifier(struct notifier_block * nb)
-{
-       return blocking_notifier_chain_register(&reboot_notifier_list, nb);
-}
-
-EXPORT_SYMBOL(register_reboot_notifier);
-
-/**
- *     unregister_reboot_notifier - Unregister previously registered reboot notifier
- *     @nb: Hook to be unregistered
- *
- *     Unregisters a previously registered reboot
- *     notifier function.
- *
- *     Returns zero on success, or %-ENOENT on failure.
- */
-int unregister_reboot_notifier(struct notifier_block * nb)
-{
-       return blocking_notifier_chain_unregister(&reboot_notifier_list, nb);
-}
-
-EXPORT_SYMBOL(unregister_reboot_notifier);
+void (*pm_power_off_prepare)(void);
 
 static int set_one_prio(struct task_struct *p, int niceval, int error)
 {
@@ -598,7 +138,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
        int error = -EINVAL;
        struct pid *pgrp;
 
-       if (which > 2 || which < 0)
+       if (which > PRIO_USER || which < PRIO_PROCESS)
                goto out;
 
        /* normalize: avoid signed division (rounding problems) */
@@ -612,7 +152,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
        switch (which) {
                case PRIO_PROCESS:
                        if (who)
-                               p = find_task_by_pid(who);
+                               p = find_task_by_vpid(who);
                        else
                                p = current;
                        if (p)
@@ -620,7 +160,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
                        break;
                case PRIO_PGRP:
                        if (who)
-                               pgrp = find_pid(who);
+                               pgrp = find_vpid(who);
                        else
                                pgrp = task_pgrp(current);
                        do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
@@ -662,14 +202,14 @@ asmlinkage long sys_getpriority(int which, int who)
        long niceval, retval = -ESRCH;
        struct pid *pgrp;
 
-       if (which > 2 || which < 0)
+       if (which > PRIO_USER || which < PRIO_PROCESS)
                return -EINVAL;
 
        read_lock(&tasklist_lock);
        switch (which) {
                case PRIO_PROCESS:
                        if (who)
-                               p = find_task_by_pid(who);
+                               p = find_task_by_vpid(who);
                        else
                                p = current;
                        if (p) {
@@ -680,7 +220,7 @@ asmlinkage long sys_getpriority(int which, int who)
                        break;
                case PRIO_PGRP:
                        if (who)
-                               pgrp = find_pid(who);
+                               pgrp = find_vpid(who);
                        else
                                pgrp = task_pgrp(current);
                        do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
@@ -733,6 +273,7 @@ static void kernel_restart_prepare(char *cmd)
        blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
        system_state = SYSTEM_RESTART;
        device_shutdown();
+       sysdev_shutdown();
 }
 
 /**
@@ -789,6 +330,7 @@ void kernel_shutdown_prepare(enum system_states state)
 void kernel_halt(void)
 {
        kernel_shutdown_prepare(SYSTEM_HALT);
+       sysdev_shutdown();
        printk(KERN_EMERG "System halted.\n");
        machine_halt();
 }
@@ -803,6 +345,10 @@ EXPORT_SYMBOL_GPL(kernel_halt);
 void kernel_power_off(void)
 {
        kernel_shutdown_prepare(SYSTEM_POWER_OFF);
+       if (pm_power_off_prepare)
+               pm_power_off_prepare();
+       disable_nonboot_cpus();
+       sysdev_shutdown();
        printk(KERN_EMERG "Power down.\n");
        machine_power_off();
 }
@@ -878,10 +424,10 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
                unlock_kernel();
                return -EINVAL;
 
-#ifdef CONFIG_SOFTWARE_SUSPEND
+#ifdef CONFIG_HIBERNATION
        case LINUX_REBOOT_CMD_SW_SUSPEND:
                {
-                       int ret = pm_suspend(PM_SUSPEND_DISK);
+                       int ret = hibernate();
                        unlock_kernel();
                        return ret;
                }
@@ -963,7 +509,7 @@ asmlinkage long sys_setregid(gid_t rgid, gid_t egid)
                        return -EPERM;
        }
        if (new_egid != old_egid) {
-               current->mm->dumpable = suid_dumpable;
+               set_dumpable(current->mm, suid_dumpable);
                smp_wmb();
        }
        if (rgid != (gid_t) -1 ||
@@ -993,13 +539,13 @@ asmlinkage long sys_setgid(gid_t gid)
 
        if (capable(CAP_SETGID)) {
                if (old_egid != gid) {
-                       current->mm->dumpable = suid_dumpable;
+                       set_dumpable(current->mm, suid_dumpable);
                        smp_wmb();
                }
                current->gid = current->egid = current->sgid = current->fsgid = gid;
        } else if ((gid == current->gid) || (gid == current->sgid)) {
                if (old_egid != gid) {
-                       current->mm->dumpable = suid_dumpable;
+                       set_dumpable(current->mm, suid_dumpable);
                        smp_wmb();
                }
                current->egid = current->fsgid = gid;
@@ -1016,13 +562,13 @@ static int set_user(uid_t new_ruid, int dumpclear)
 {
        struct user_struct *new_user;
 
-       new_user = alloc_uid(new_ruid);
+       new_user = alloc_uid(current->nsproxy->user_ns, new_ruid);
        if (!new_user)
                return -EAGAIN;
 
        if (atomic_read(&new_user->processes) >=
                                current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
-                       new_user != &root_user) {
+                       new_user != current->nsproxy->user_ns->root_user) {
                free_uid(new_user);
                return -EAGAIN;
        }
@@ -1030,7 +576,7 @@ static int set_user(uid_t new_ruid, int dumpclear)
        switch_uid(new_user);
 
        if (dumpclear) {
-               current->mm->dumpable = suid_dumpable;
+               set_dumpable(current->mm, suid_dumpable);
                smp_wmb();
        }
        current->uid = new_ruid;
@@ -1086,7 +632,7 @@ asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)
                return -EAGAIN;
 
        if (new_euid != old_euid) {
-               current->mm->dumpable = suid_dumpable;
+               set_dumpable(current->mm, suid_dumpable);
                smp_wmb();
        }
        current->fsuid = current->euid = new_euid;
@@ -1136,7 +682,7 @@ asmlinkage long sys_setuid(uid_t uid)
                return -EPERM;
 
        if (old_euid != uid) {
-               current->mm->dumpable = suid_dumpable;
+               set_dumpable(current->mm, suid_dumpable);
                smp_wmb();
        }
        current->fsuid = current->euid = uid;
@@ -1181,7 +727,7 @@ asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)
        }
        if (euid != (uid_t) -1) {
                if (euid != current->euid) {
-                       current->mm->dumpable = suid_dumpable;
+                       set_dumpable(current->mm, suid_dumpable);
                        smp_wmb();
                }
                current->euid = euid;
@@ -1231,7 +777,7 @@ asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
        }
        if (egid != (gid_t) -1) {
                if (egid != current->egid) {
-                       current->mm->dumpable = suid_dumpable;
+                       set_dumpable(current->mm, suid_dumpable);
                        smp_wmb();
                }
                current->egid = egid;
@@ -1277,7 +823,7 @@ asmlinkage long sys_setfsuid(uid_t uid)
            uid == current->suid || uid == current->fsuid || 
            capable(CAP_SETUID)) {
                if (uid != old_fsuid) {
-                       current->mm->dumpable = suid_dumpable;
+                       set_dumpable(current->mm, suid_dumpable);
                        smp_wmb();
                }
                current->fsuid = uid;
@@ -1292,7 +838,7 @@ asmlinkage long sys_setfsuid(uid_t uid)
 }
 
 /*
- * Samma på svenska..
+ * Samma på svenska..
  */
 asmlinkage long sys_setfsgid(gid_t gid)
 {
@@ -1306,7 +852,7 @@ asmlinkage long sys_setfsgid(gid_t gid)
            gid == current->sgid || gid == current->fsgid || 
            capable(CAP_SETGID)) {
                if (gid != old_fsgid) {
-                       current->mm->dumpable = suid_dumpable;
+                       set_dumpable(current->mm, suid_dumpable);
                        smp_wmb();
                }
                current->fsgid = gid;
@@ -1366,15 +912,15 @@ asmlinkage long sys_times(struct tms __user * tbuf)
  * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
  * LBT 04.03.94
  */
-
 asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
 {
        struct task_struct *p;
        struct task_struct *group_leader = current->group_leader;
        int err = -EINVAL;
+       struct pid_namespace *ns;
 
        if (!pid)
-               pid = group_leader->pid;
+               pid = task_pid_vnr(group_leader);
        if (!pgid)
                pgid = pid;
        if (pgid < 0)
@@ -1383,10 +929,12 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
        /* From this point forward we keep holding onto the tasklist lock
         * so that our parent does not change from under us. -DaveM
         */
+       ns = current->nsproxy->pid_ns;
+
        write_lock_irq(&tasklist_lock);
 
        err = -ESRCH;
-       p = find_task_by_pid(pid);
+       p = find_task_by_pid_ns(pid, ns);
        if (!p)
                goto out;
 
@@ -1394,7 +942,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
        if (!thread_group_leader(p))
                goto out;
 
-       if (p->real_parent == group_leader) {
+       if (p->real_parent->tgid == group_leader->tgid) {
                err = -EPERM;
                if (task_session(p) != task_session(group_leader))
                        goto out;
@@ -1412,9 +960,9 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
                goto out;
 
        if (pgid != pid) {
-               struct task_struct *g =
-                       find_task_by_pid_type(PIDTYPE_PGID, pgid);
+               struct task_struct *g;
 
+               g = find_task_by_pid_type_ns(PIDTYPE_PGID, pgid, ns);
                if (!g || task_session(g) != task_session(group_leader))
                        goto out;
        }
@@ -1423,10 +971,13 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
        if (err)
                goto out;
 
-       if (process_group(p) != pgid) {
+       if (task_pgrp_nr_ns(p, ns) != pgid) {
+               struct pid *pid;
+
                detach_pid(p, PIDTYPE_PGID);
-               p->signal->pgrp = pgid;
-               attach_pid(p, PIDTYPE_PGID, pgid);
+               pid = find_vpid(pgid);
+               attach_pid(p, PIDTYPE_PGID, pid);
+               set_task_pgrp(p, pid_nr(pid));
        }
 
        err = 0;
@@ -1439,19 +990,21 @@ out:
 asmlinkage long sys_getpgid(pid_t pid)
 {
        if (!pid)
-               return process_group(current);
+               return task_pgrp_vnr(current);
        else {
                int retval;
                struct task_struct *p;
+               struct pid_namespace *ns;
 
-               read_lock(&tasklist_lock);
-               p = find_task_by_pid(pid);
+               ns = current->nsproxy->pid_ns;
 
+               read_lock(&tasklist_lock);
+               p = find_task_by_pid_ns(pid, ns);
                retval = -ESRCH;
                if (p) {
                        retval = security_task_getpgid(p);
                        if (!retval)
-                               retval = process_group(p);
+                               retval = task_pgrp_nr_ns(p, ns);
                }
                read_unlock(&tasklist_lock);
                return retval;
@@ -1463,7 +1016,7 @@ asmlinkage long sys_getpgid(pid_t pid)
 asmlinkage long sys_getpgrp(void)
 {
        /* SMP - assuming writes are word atomic this is fine */
-       return process_group(current);
+       return task_pgrp_vnr(current);
 }
 
 #endif
@@ -1471,19 +1024,21 @@ asmlinkage long sys_getpgrp(void)
 asmlinkage long sys_getsid(pid_t pid)
 {
        if (!pid)
-               return process_session(current);
+               return task_session_vnr(current);
        else {
                int retval;
                struct task_struct *p;
+               struct pid_namespace *ns;
 
-               read_lock(&tasklist_lock);
-               p = find_task_by_pid(pid);
+               ns = current->nsproxy->pid_ns;
 
+               read_lock(&tasklist_lock);
+               p = find_task_by_pid_ns(pid, ns);
                retval = -ESRCH;
                if (p) {
                        retval = security_task_getsid(p);
                        if (!retval)
-                               retval = process_session(p);
+                               retval = task_session_nr_ns(p, ns);
                }
                read_unlock(&tasklist_lock);
                return retval;
@@ -1510,7 +1065,8 @@ asmlinkage long sys_setsid(void)
         * session id and so the check will always fail and make it so
         * init cannot successfully call setsid.
         */
-       if (session > 1 && find_task_by_pid_type(PIDTYPE_PGID, session))
+       if (session > 1 && find_task_by_pid_type_ns(PIDTYPE_PGID,
+                               session, &init_pid_ns))
                goto out;
 
        group_leader->signal->leader = 1;
@@ -1520,7 +1076,7 @@ asmlinkage long sys_setsid(void)
        group_leader->signal->tty = NULL;
        spin_unlock(&group_leader->sighand->siglock);
 
-       err = process_group(group_leader);
+       err = task_pgrp_vnr(group_leader);
 out:
        write_unlock_irq(&tasklist_lock);
        return err;
@@ -1923,6 +1479,16 @@ asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
        if (retval)
                return retval;
 
+       if (resource == RLIMIT_CPU && new_rlim.rlim_cur == 0) {
+               /*
+                * The caller is asking for an immediate RLIMIT_CPU
+                * expiry.  But we use the zero value to mean "it was
+                * never set".  So let's cheat and make it one second
+                * instead
+                */
+               new_rlim.rlim_cur = 1;
+       }
+
        task_lock(current->group_leader);
        *old_rlim = new_rlim;
        task_unlock(current->group_leader);
@@ -1944,15 +1510,6 @@ asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)
                unsigned long rlim_cur = new_rlim.rlim_cur;
                cputime_t cputime;
 
-               if (rlim_cur == 0) {
-                       /*
-                        * The caller is asking for an immediate RLIMIT_CPU
-                        * expiry.  But we use the zero value to mean "it was
-                        * never set".  So let's cheat and make it one second
-                        * instead
-                        */
-                       rlim_cur = 1;
-               }
                cputime = secs_to_cputime(rlim_cur);
                read_lock(&tasklist_lock);
                spin_lock_irq(&current->sighand->siglock);
@@ -2021,6 +1578,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
                        r->ru_nivcsw = p->signal->cnivcsw;
                        r->ru_minflt = p->signal->cmin_flt;
                        r->ru_majflt = p->signal->cmaj_flt;
+                       r->ru_inblock = p->signal->cinblock;
+                       r->ru_oublock = p->signal->coublock;
 
                        if (who == RUSAGE_CHILDREN)
                                break;
@@ -2032,6 +1591,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
                        r->ru_nivcsw += p->signal->nivcsw;
                        r->ru_minflt += p->signal->min_flt;
                        r->ru_majflt += p->signal->maj_flt;
+                       r->ru_inblock += p->signal->inblock;
+                       r->ru_oublock += p->signal->oublock;
                        t = p;
                        do {
                                utime = cputime_add(utime, t->utime);
@@ -2040,6 +1601,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
                                r->ru_nivcsw += t->nivcsw;
                                r->ru_minflt += t->min_flt;
                                r->ru_majflt += t->maj_flt;
+                               r->ru_inblock += task_io_get_inblock(t);
+                               r->ru_oublock += task_io_get_oublock(t);
                                t = next_thread(t);
                        } while (t != p);
                        break;
@@ -2096,14 +1659,14 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                        error = put_user(current->pdeath_signal, (int __user *)arg2);
                        break;
                case PR_GET_DUMPABLE:
-                       error = current->mm->dumpable;
+                       error = get_dumpable(current->mm);
                        break;
                case PR_SET_DUMPABLE:
                        if (arg2 < 0 || arg2 > 1) {
                                error = -EINVAL;
                                break;
                        }
-                       current->mm->dumpable = arg2;
+                       set_dumpable(current->mm, arg2);
                        break;
 
                case PR_SET_UNALIGN:
@@ -2172,6 +1735,13 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
                        error = SET_ENDIAN(current, arg2);
                        break;
 
+               case PR_GET_SECCOMP:
+                       error = prctl_get_seccomp();
+                       break;
+               case PR_SET_SECCOMP:
+                       error = prctl_set_seccomp(arg2);
+                       break;
+
                default:
                        error = -EINVAL;
                        break;
@@ -2180,7 +1750,7 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3,
 }
 
 asmlinkage long sys_getcpu(unsigned __user *cpup, unsigned __user *nodep,
-                          struct getcpu_cache __user *cache)
+                          struct getcpu_cache __user *unused)
 {
        int err = 0;
        int cpu = raw_smp_processor_id();
@@ -2188,23 +1758,63 @@ asmlinkage long sys_getcpu(unsigned __user *cpup, unsigned __user *nodep,
                err |= put_user(cpu, cpup);
        if (nodep)
                err |= put_user(cpu_to_node(cpu), nodep);
-       if (cache) {
-               /*
-                * The cache is not needed for this implementation,
-                * but make sure user programs pass something
-                * valid. vsyscall implementations can instead make
-                * good use of the cache. Only use t0 and t1 because
-                * these are available in both 32bit and 64bit ABI (no
-                * need for a compat_getcpu). 32bit has enough
-                * padding
-                */
-               unsigned long t0, t1;
-               get_user(t0, &cache->blob[0]);
-               get_user(t1, &cache->blob[1]);
-               t0++;
-               t1++;
-               put_user(t0, &cache->blob[0]);
-               put_user(t1, &cache->blob[1]);
-       }
        return err ? -EFAULT : 0;
 }
+
+char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
+
+static void argv_cleanup(char **argv, char **envp)
+{
+       argv_free(argv);
+}
+
+/**
+ * orderly_poweroff - Trigger an orderly system poweroff
+ * @force: force poweroff if command execution fails
+ *
+ * This may be called from any context to trigger a system shutdown.
+ * If the orderly shutdown fails, it will force an immediate shutdown.
+ */
+int orderly_poweroff(bool force)
+{
+       int argc;
+       char **argv = argv_split(GFP_ATOMIC, poweroff_cmd, &argc);
+       static char *envp[] = {
+               "HOME=/",
+               "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
+               NULL
+       };
+       int ret = -ENOMEM;
+       struct subprocess_info *info;
+
+       if (argv == NULL) {
+               printk(KERN_WARNING "%s failed to allocate memory for \"%s\"\n",
+                      __func__, poweroff_cmd);
+               goto out;
+       }
+
+       info = call_usermodehelper_setup(argv[0], argv, envp);
+       if (info == NULL) {
+               argv_free(argv);
+               goto out;
+       }
+
+       call_usermodehelper_setcleanup(info, argv_cleanup);
+
+       ret = call_usermodehelper_exec(info, UMH_NO_WAIT);
+
+  out:
+       if (ret && force) {
+               printk(KERN_WARNING "Failed to start orderly shutdown: "
+                      "forcing the issue\n");
+
+               /* I guess this should try to kick off some daemon to
+                  sync and poweroff asap.  Or not even bother syncing
+                  if we're doing an emergency shutdown? */
+               emergency_sync();
+               kernel_power_off();
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(orderly_poweroff);