aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c78
1 files changed, 35 insertions, 43 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 47c15840a381..989c7c202b3d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -60,6 +60,7 @@
60#include <linux/tty.h> 60#include <linux/tty.h>
61#include <linux/proc_fs.h> 61#include <linux/proc_fs.h>
62#include <linux/blkdev.h> 62#include <linux/blkdev.h>
63#include <linux/fs_struct.h>
63#include <trace/sched.h> 64#include <trace/sched.h>
64#include <linux/magic.h> 65#include <linux/magic.h>
65 66
@@ -644,6 +645,9 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
644 645
645 tsk->min_flt = tsk->maj_flt = 0; 646 tsk->min_flt = tsk->maj_flt = 0;
646 tsk->nvcsw = tsk->nivcsw = 0; 647 tsk->nvcsw = tsk->nivcsw = 0;
648#ifdef CONFIG_DETECT_HUNG_TASK
649 tsk->last_switch_count = tsk->nvcsw + tsk->nivcsw;
650#endif
647 651
648 tsk->mm = NULL; 652 tsk->mm = NULL;
649 tsk->active_mm = NULL; 653 tsk->active_mm = NULL;
@@ -681,38 +685,21 @@ fail_nomem:
681 return retval; 685 return retval;
682} 686}
683 687
684static struct fs_struct *__copy_fs_struct(struct fs_struct *old)
685{
686 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
687 /* We don't need to lock fs - think why ;-) */
688 if (fs) {
689 atomic_set(&fs->count, 1);
690 rwlock_init(&fs->lock);
691 fs->umask = old->umask;
692 read_lock(&old->lock);
693 fs->root = old->root;
694 path_get(&old->root);
695 fs->pwd = old->pwd;
696 path_get(&old->pwd);
697 read_unlock(&old->lock);
698 }
699 return fs;
700}
701
702struct fs_struct *copy_fs_struct(struct fs_struct *old)
703{
704 return __copy_fs_struct(old);
705}
706
707EXPORT_SYMBOL_GPL(copy_fs_struct);
708
709static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) 688static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
710{ 689{
690 struct fs_struct *fs = current->fs;
711 if (clone_flags & CLONE_FS) { 691 if (clone_flags & CLONE_FS) {
712 atomic_inc(&current->fs->count); 692 /* tsk->fs is already what we want */
693 write_lock(&fs->lock);
694 if (fs->in_exec) {
695 write_unlock(&fs->lock);
696 return -EAGAIN;
697 }
698 fs->users++;
699 write_unlock(&fs->lock);
713 return 0; 700 return 0;
714 } 701 }
715 tsk->fs = __copy_fs_struct(current->fs); 702 tsk->fs = copy_fs_struct(fs);
716 if (!tsk->fs) 703 if (!tsk->fs)
717 return -ENOMEM; 704 return -ENOMEM;
718 return 0; 705 return 0;
@@ -841,6 +828,8 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
841 atomic_set(&sig->live, 1); 828 atomic_set(&sig->live, 1);
842 init_waitqueue_head(&sig->wait_chldexit); 829 init_waitqueue_head(&sig->wait_chldexit);
843 sig->flags = 0; 830 sig->flags = 0;
831 if (clone_flags & CLONE_NEWPID)
832 sig->flags |= SIGNAL_UNKILLABLE;
844 sig->group_exit_code = 0; 833 sig->group_exit_code = 0;
845 sig->group_exit_task = NULL; 834 sig->group_exit_task = NULL;
846 sig->group_stop_count = 0; 835 sig->group_stop_count = 0;
@@ -1046,11 +1035,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1046 1035
1047 p->default_timer_slack_ns = current->timer_slack_ns; 1036 p->default_timer_slack_ns = current->timer_slack_ns;
1048 1037
1049#ifdef CONFIG_DETECT_SOFTLOCKUP
1050 p->last_switch_count = 0;
1051 p->last_switch_timestamp = 0;
1052#endif
1053
1054 task_io_accounting_init(&p->ioac); 1038 task_io_accounting_init(&p->ioac);
1055 acct_clear_integrals(p); 1039 acct_clear_integrals(p);
1056 1040
@@ -1125,7 +1109,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1125 goto bad_fork_cleanup_mm; 1109 goto bad_fork_cleanup_mm;
1126 if ((retval = copy_io(clone_flags, p))) 1110 if ((retval = copy_io(clone_flags, p)))
1127 goto bad_fork_cleanup_namespaces; 1111 goto bad_fork_cleanup_namespaces;
1128 retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs); 1112 retval = copy_thread(clone_flags, stack_start, stack_size, p, regs);
1129 if (retval) 1113 if (retval)
1130 goto bad_fork_cleanup_io; 1114 goto bad_fork_cleanup_io;
1131 1115
@@ -1263,8 +1247,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1263 p->signal->leader_pid = pid; 1247 p->signal->leader_pid = pid;
1264 tty_kref_put(p->signal->tty); 1248 tty_kref_put(p->signal->tty);
1265 p->signal->tty = tty_kref_get(current->signal->tty); 1249 p->signal->tty = tty_kref_get(current->signal->tty);
1266 set_task_pgrp(p, task_pgrp_nr(current));
1267 set_task_session(p, task_session_nr(current));
1268 attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); 1250 attach_pid(p, PIDTYPE_PGID, task_pgrp(current));
1269 attach_pid(p, PIDTYPE_SID, task_session(current)); 1251 attach_pid(p, PIDTYPE_SID, task_session(current));
1270 list_add_tail_rcu(&p->tasks, &init_task.tasks); 1252 list_add_tail_rcu(&p->tasks, &init_task.tasks);
@@ -1488,6 +1470,7 @@ void __init proc_caches_init(void)
1488 mm_cachep = kmem_cache_create("mm_struct", 1470 mm_cachep = kmem_cache_create("mm_struct",
1489 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN, 1471 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
1490 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL); 1472 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
1473 vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
1491 mmap_init(); 1474 mmap_init();
1492} 1475}
1493 1476
@@ -1543,12 +1526,16 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
1543{ 1526{
1544 struct fs_struct *fs = current->fs; 1527 struct fs_struct *fs = current->fs;
1545 1528
1546 if ((unshare_flags & CLONE_FS) && 1529 if (!(unshare_flags & CLONE_FS) || !fs)
1547 (fs && atomic_read(&fs->count) > 1)) { 1530 return 0;
1548 *new_fsp = __copy_fs_struct(current->fs); 1531
1549 if (!*new_fsp) 1532 /* don't need lock here; in the worst case we'll do useless copy */
1550 return -ENOMEM; 1533 if (fs->users == 1)
1551 } 1534 return 0;
1535
1536 *new_fsp = copy_fs_struct(fs);
1537 if (!*new_fsp)
1538 return -ENOMEM;
1552 1539
1553 return 0; 1540 return 0;
1554} 1541}
@@ -1664,8 +1651,13 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
1664 1651
1665 if (new_fs) { 1652 if (new_fs) {
1666 fs = current->fs; 1653 fs = current->fs;
1654 write_lock(&fs->lock);
1667 current->fs = new_fs; 1655 current->fs = new_fs;
1668 new_fs = fs; 1656 if (--fs->users)
1657 new_fs = NULL;
1658 else
1659 new_fs = fs;
1660 write_unlock(&fs->lock);
1669 } 1661 }
1670 1662
1671 if (new_mm) { 1663 if (new_mm) {
@@ -1704,7 +1696,7 @@ bad_unshare_cleanup_sigh:
1704 1696
1705bad_unshare_cleanup_fs: 1697bad_unshare_cleanup_fs:
1706 if (new_fs) 1698 if (new_fs)
1707 put_fs_struct(new_fs); 1699 free_fs_struct(new_fs);
1708 1700
1709bad_unshare_cleanup_thread: 1701bad_unshare_cleanup_thread:
1710bad_unshare_out: 1702bad_unshare_out: