From 7fd58758bd618605182f7b22ff9942a947539a1c Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Fri, 24 Jul 2020 13:32:30 -0400 Subject: [PATCH] kernel/fork: Convert dup_mmap to use maple tree Use the maple tree iterator to duplicate the mm_struct trees. Signed-off-by: Liam R. Howlett --- kernel/fork.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index 8b38eebf7e106..04b480e532b2f 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -489,6 +489,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, struct rb_node **rb_link, *rb_parent; int retval; unsigned long charge; + MA_STATE(old_mas, &oldmm->mm_mt, 0, 0); LIST_HEAD(uf); uprobe_start_dup_mmap(); @@ -522,9 +523,17 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, goto out; prev = NULL; - for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) { + + mas_lock(&old_mas); + mas_for_each(&old_mas, mpnt, ULONG_MAX) { struct file *file; + if (xa_is_zero(mpnt)) + continue; + + mas_pause(&old_mas); + mas_unlock(&old_mas); + if (mpnt->vm_flags & VM_DONTCOPY) { vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mpnt)); continue; @@ -616,7 +625,11 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, if (retval) goto out; + + mas_lock(&old_mas); } + mas_unlock(&old_mas); + /* a new mm has just been created */ retval = arch_dup_mmap(oldmm, mm); out: -- 2.50.1