]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
kernel/fork: Convert dup_mmap to use maple tree
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 24 Jul 2020 17:32:30 +0000 (13:32 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 18 Jan 2021 15:40:26 +0000 (10:40 -0500)
Use the maple tree iterator to duplicate the mm_struct trees.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
include/linux/sched/mm.h
kernel/fork.c

index 1ae08b8462a41762fd48e299f304e0ba5152f7c0..bed5170bcd04d7850d14aad51f420cfb322e3211 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/mm_types.h>
 #include <linux/gfp.h>
 #include <linux/sync_core.h>
+#include <linux/maple_tree.h>
 
 /*
  * Routines for handling mm_structs
@@ -67,11 +68,13 @@ static inline void mmdrop(struct mm_struct *mm)
  */
 static inline void mmget(struct mm_struct *mm)
 {
+       mt_set_in_rcu(&mm->mm_mt);
        atomic_inc(&mm->mm_users);
 }
 
 static inline bool mmget_not_zero(struct mm_struct *mm)
 {
+       mt_set_in_rcu(&mm->mm_mt);
        return atomic_inc_not_zero(&mm->mm_users);
 }
 
index 88f0a95045be9099245d1c031681c8170886f610..b0e60038d8444606eb5ab00d937a6772a78d248c 100644 (file)
@@ -473,7 +473,9 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
        struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
        struct rb_node **rb_link, *rb_parent;
        int retval;
-       unsigned long charge;
+       unsigned long charge = 0;
+       MA_STATE(old_mas, &oldmm->mm_mt, 0, 0);
+       MA_STATE(mas, &mm->mm_mt, 0, 0);
        LIST_HEAD(uf);
 
        uprobe_start_dup_mmap();
@@ -507,7 +509,12 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
                goto out;
 
        prev = NULL;
-       for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
+
+       retval = mas_entry_count(&mas, oldmm->map_count);
+       if (retval)
+               goto fail_nomem;
+
+       mas_for_each(&old_mas, mpnt, ULONG_MAX) {
                struct file *file;
 
                if (mpnt->vm_flags & VM_DONTCOPY) {
@@ -521,7 +528,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
                 */
                if (fatal_signal_pending(current)) {
                        retval = -EINTR;
-                       goto out;
+                       goto loop_out;
                }
                if (mpnt->vm_flags & VM_ACCOUNT) {
                        unsigned long len = vma_pages(mpnt);
@@ -590,7 +597,9 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
                rb_parent = &tmp->vm_rb;
 
                /* Link the vma into the MT */
-               vma_store(mm, tmp);
+               mas.index = tmp->vm_start;
+               mas.last = tmp->vm_end - 1;
+               mas_store(&mas, tmp);
 
                mm->map_count++;
                if (!(tmp->vm_flags & VM_WIPEONFORK))
@@ -600,14 +609,16 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
                        tmp->vm_ops->open(tmp);
 
                if (retval)
-                       goto out;
+                       goto loop_out;
        }
        /* a new mm has just been created */
        retval = arch_dup_mmap(oldmm, mm);
+loop_out:
 out:
        mmap_write_unlock(mm);
        flush_tlb_mm(oldmm);
        mmap_write_unlock(oldmm);
+       mas_destroy(&mas);
        dup_userfaultfd_complete(&uf);
 fail_uprobe_end:
        uprobe_end_dup_mmap();
@@ -1080,6 +1091,7 @@ static inline void __mmput(struct mm_struct *mm)
 {
        VM_BUG_ON(atomic_read(&mm->mm_users));
 
+       mt_clear_in_rcu(&mm->mm_mt);
        uprobe_clear_state(mm);
        exit_aio(mm);
        ksm_exit(mm);