Merge branch 'acpi-irq'
[linux-2.6-microblaze.git] / kernel / fork.c
index f811497..3b6d20d 100644 (file)
@@ -909,8 +909,6 @@ static void cleanup_lazy_tlbs(struct mm_struct *mm)
  */
 void __mmdrop(struct mm_struct *mm)
 {
-       int i;
-
        BUG_ON(mm == &init_mm);
        WARN_ON_ONCE(mm == current->mm);
 
@@ -925,9 +923,8 @@ void __mmdrop(struct mm_struct *mm)
        put_user_ns(mm->user_ns);
        mm_pasid_drop(mm);
        mm_destroy_cid(mm);
+       percpu_counter_destroy_many(mm->rss_stat, NR_MM_COUNTERS);
 
-       for (i = 0; i < NR_MM_COUNTERS; i++)
-               percpu_counter_destroy(&mm->rss_stat[i]);
        free_mm(mm);
 }
 EXPORT_SYMBOL_GPL(__mmdrop);
@@ -1260,8 +1257,6 @@ static void mm_init_uprobes_state(struct mm_struct *mm)
 static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
        struct user_namespace *user_ns)
 {
-       int i;
-
        mt_init_flags(&mm->mm_mt, MM_MT_FLAGS);
        mt_set_external_lock(&mm->mm_mt, &mm->mmap_lock);
        atomic_set(&mm->mm_users, 1);
@@ -1309,17 +1304,15 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
        if (mm_alloc_cid(mm))
                goto fail_cid;
 
-       for (i = 0; i < NR_MM_COUNTERS; i++)
-               if (percpu_counter_init(&mm->rss_stat[i], 0, GFP_KERNEL_ACCOUNT))
-                       goto fail_pcpu;
+       if (percpu_counter_init_many(mm->rss_stat, 0, GFP_KERNEL_ACCOUNT,
+                                    NR_MM_COUNTERS))
+               goto fail_pcpu;
 
        mm->user_ns = get_user_ns(user_ns);
        lru_gen_init_mm(mm);
        return mm;
 
 fail_pcpu:
-       while (i > 0)
-               percpu_counter_destroy(&mm->rss_stat[--i]);
        mm_destroy_cid(mm);
 fail_cid:
        destroy_context(mm);
@@ -1404,8 +1397,8 @@ EXPORT_SYMBOL_GPL(mmput_async);
  * This changes mm's executable file (shown as symlink /proc/[pid]/exe).
  *
  * Main users are mmput() and sys_execve(). Callers prevent concurrent
- * invocations: in mmput() nobody alive left, in execve task is single
- * threaded.
+ * invocations: in mmput() nobody alive left, in execve it happens before
+ * the new mm is made visible to anyone.
  *
  * Can only fail if new_exe_file != NULL.
  */
@@ -1440,9 +1433,7 @@ int set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
 /**
  * replace_mm_exe_file - replace a reference to the mm's executable file
  *
- * This changes mm's executable file (shown as symlink /proc/[pid]/exe),
- * dealing with concurrent invocation and without grabbing the mmap lock in
- * write mode.
+ * This changes mm's executable file (shown as symlink /proc/[pid]/exe).
  *
  * Main user is sys_prctl(PR_SET_MM_MAP/EXE_FILE).
  */
@@ -1472,22 +1463,20 @@ int replace_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
                        return ret;
        }
 
-       /* set the new file, lockless */
        ret = deny_write_access(new_exe_file);
        if (ret)
                return -EACCES;
        get_file(new_exe_file);
 
-       old_exe_file = xchg(&mm->exe_file, new_exe_file);
+       /* set the new file */
+       mmap_write_lock(mm);
+       old_exe_file = rcu_dereference_raw(mm->exe_file);
+       rcu_assign_pointer(mm->exe_file, new_exe_file);
+       mmap_write_unlock(mm);
+
        if (old_exe_file) {
-               /*
-                * Don't race with dup_mmap() getting the file and disallowing
-                * write access while someone might open the file writable.
-                */
-               mmap_read_lock(mm);
                allow_write_access(old_exe_file);
                fput(old_exe_file);
-               mmap_read_unlock(mm);
        }
        return 0;
 }