]> www.infradead.org Git - users/willy/linux.git/commitdiff
fixy-fixy
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 20 Oct 2021 18:54:18 +0000 (14:54 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 20 Oct 2021 20:00:30 +0000 (16:00 -0400)
include/linux/sched/mm.h
kernel/fork.c
mm/mmap.c

index 87f4f53a3d7dd2d3e1e24f1294421e1827d57d2d..2ca7cc6c903bc57b1303168fe3bb96964f7b726a 100644 (file)
@@ -50,6 +50,8 @@ static inline void mmdrop(struct mm_struct *mm)
                __mmdrop(mm);
 }
 
+void mm_set_in_rcu(struct mm_struct *mm);
+
 /**
  * mmget() - Pin the address space associated with a &struct mm_struct.
  * @mm: The address space to pin.
@@ -68,7 +70,8 @@ static inline void mmdrop(struct mm_struct *mm)
  */
 static inline void mmget(struct mm_struct *mm)
 {
-       mt_set_in_rcu(&mm->mm_mt);
+       if (!mt_in_rcu(&mm->mm_mt))
+               mm_set_in_rcu(mm);
        atomic_inc(&mm->mm_users);
 }
 
@@ -80,7 +83,8 @@ static inline bool mmget_not_zero(struct mm_struct *mm)
         * happens, the result would be that the maple tree nodes would remain
         * active for an extra RCU read cycle.
         */
-       mt_set_in_rcu(&mm->mm_mt);
+       if (!mt_in_rcu(&mm->mm_mt))
+               mm_set_in_rcu(mm);
        return atomic_inc_not_zero(&mm->mm_users);
 }
 
index 3b0b0e1fe1649cb67fb9ad3d460a618349e367ab..08a3c9f3861c70ead1ab0c6c09049c4d90f46c02 100644 (file)
@@ -617,11 +617,9 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
                rb_parent = &tmp->vm_rb;
 
                /* Link the vma into the MT */
-               mas_lock(&mas);
                mas.index = tmp->vm_start;
                mas.last = tmp->vm_end - 1;
                mas_store(&mas, tmp);
-               mas_unlock(&mas);
 
                mm->map_count++;
                if (!(tmp->vm_flags & VM_WIPEONFORK))
index 7c011dd96e5af47c22e3621604303e9eb80b9e30..83cb19763d90ca68991b2015084cdfb0d28036eb 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -309,6 +309,15 @@ static inline unsigned long vma_compute_gap(struct vm_area_struct *vma)
        return gap;
 }
 
+void mm_set_in_rcu(struct mm_struct *mm)
+{
+       if (!mt_in_rcu(&mm->mm_mt))
+               return;
+       mmap_write_lock(mm);
+       mm->mm_mt.ma_flags |= MT_FLAGS_USE_RCU;
+       mmap_write_unlock(mm);
+}
+
 #ifdef CONFIG_DEBUG_VM_RB
 static unsigned long vma_compute_subtree_gap(struct vm_area_struct *vma)
 {
@@ -3192,7 +3201,6 @@ void exit_mmap(struct mm_struct *mm)
        mmap_write_lock(mm);
        __mt_destroy(&mm->mm_mt);
        mmap_write_unlock(mm);
-
        vm_unacct_memory(nr_accounted);
 }