From: Matthew Wilcox (Oracle) Date: Wed, 20 Oct 2021 18:54:18 +0000 (-0400) Subject: fixy-fixy X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=47b21587dc902192d13b3a0ae58e2c9b836618fe;p=users%2Fwilly%2Flinux.git fixy-fixy --- diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 87f4f53a3d7d..2ca7cc6c903b 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -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); } diff --git a/kernel/fork.c b/kernel/fork.c index 3b0b0e1fe164..08a3c9f3861c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -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)) diff --git a/mm/mmap.c b/mm/mmap.c index 7c011dd96e5a..83cb19763d90 100644 --- 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); }