Commit 3b9dbd5e authored by Liam R. Howlett's avatar Liam R. Howlett Committed by Andrew Morton

kernel/fork: convert forking to using the vmi iterator

Avoid using the maple tree interface directly.  This gains type safety.

Link: https://lkml.kernel.org/r/20230120162650.984577-10-Liam.Howlett@oracle.comSigned-off-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 92fed820
...@@ -585,8 +585,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, ...@@ -585,8 +585,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
int retval; int retval;
unsigned long charge = 0; unsigned long charge = 0;
LIST_HEAD(uf); LIST_HEAD(uf);
MA_STATE(old_mas, &oldmm->mm_mt, 0, 0); VMA_ITERATOR(old_vmi, oldmm, 0);
MA_STATE(mas, &mm->mm_mt, 0, 0); VMA_ITERATOR(vmi, mm, 0);
uprobe_start_dup_mmap(); uprobe_start_dup_mmap();
if (mmap_write_lock_killable(oldmm)) { if (mmap_write_lock_killable(oldmm)) {
...@@ -613,11 +613,11 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, ...@@ -613,11 +613,11 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
goto out; goto out;
khugepaged_fork(mm, oldmm); khugepaged_fork(mm, oldmm);
retval = mas_expected_entries(&mas, oldmm->map_count); retval = vma_iter_bulk_alloc(&vmi, oldmm->map_count);
if (retval) if (retval)
goto out; goto out;
mas_for_each(&old_mas, mpnt, ULONG_MAX) { for_each_vma(old_vmi, mpnt) {
struct file *file; struct file *file;
if (mpnt->vm_flags & VM_DONTCOPY) { if (mpnt->vm_flags & VM_DONTCOPY) {
...@@ -683,11 +683,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, ...@@ -683,11 +683,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
hugetlb_dup_vma_private(tmp); hugetlb_dup_vma_private(tmp);
/* Link the vma into the MT */ /* Link the vma into the MT */
mas.index = tmp->vm_start; if (vma_iter_bulk_store(&vmi, tmp))
mas.last = tmp->vm_end - 1; goto fail_nomem_vmi_store;
mas_store(&mas, tmp);
if (mas_is_err(&mas))
goto fail_nomem_mas_store;
mm->map_count++; mm->map_count++;
if (!(tmp->vm_flags & VM_WIPEONFORK)) if (!(tmp->vm_flags & VM_WIPEONFORK))
...@@ -702,7 +699,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, ...@@ -702,7 +699,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
/* a new mm has just been created */ /* a new mm has just been created */
retval = arch_dup_mmap(oldmm, mm); retval = arch_dup_mmap(oldmm, mm);
loop_out: loop_out:
mas_destroy(&mas); vma_iter_free(&vmi);
out: out:
mmap_write_unlock(mm); mmap_write_unlock(mm);
flush_tlb_mm(oldmm); flush_tlb_mm(oldmm);
...@@ -712,7 +709,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, ...@@ -712,7 +709,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
uprobe_end_dup_mmap(); uprobe_end_dup_mmap();
return retval; return retval;
fail_nomem_mas_store: fail_nomem_vmi_store:
unlink_anon_vmas(tmp); unlink_anon_vmas(tmp);
fail_nomem_anon_vma_fork: fail_nomem_anon_vma_fork:
mpol_put(vma_policy(tmp)); mpol_put(vma_policy(tmp));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment