Commit 0fd5a9e2 authored by Liam R. Howlett's avatar Liam R. Howlett Committed by Andrew Morton

mm: pass vma iterator through to __vma_adjust()

Pass the iterator through to be used in __vma_adjust().  The state of the
iterator needs to be correct for the operation that will occur so make the
adjustments.

Link: https://lkml.kernel.org/r/20230120162650.984577-36-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 c465be97
...@@ -525,6 +525,10 @@ inline int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, ...@@ -525,6 +525,10 @@ inline int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma,
vma_interval_tree_remove(vma, root); vma_interval_tree_remove(vma, root);
} }
/* VMA iterator points to previous, so set to start if necessary */
if (vma_iter_addr(vmi) != start)
vma_iter_set(vmi, start);
vma->vm_start = start; vma->vm_start = start;
vma->vm_end = end; vma->vm_end = end;
vma->vm_pgoff = pgoff; vma->vm_pgoff = pgoff;
...@@ -2164,13 +2168,13 @@ static void unmap_region(struct mm_struct *mm, struct maple_tree *mt, ...@@ -2164,13 +2168,13 @@ static void unmap_region(struct mm_struct *mm, struct maple_tree *mt,
/* /*
* __split_vma() bypasses sysctl_max_map_count checking. We use this where it * __split_vma() bypasses sysctl_max_map_count checking. We use this where it
* has already been checked or doesn't make sense to fail. * has already been checked or doesn't make sense to fail.
* VMA Iterator will point to the end VMA.
*/ */
int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
unsigned long addr, int new_below) unsigned long addr, int new_below)
{ {
struct vm_area_struct *new; struct vm_area_struct *new;
int err; int err;
unsigned long end = vma->vm_end;
validate_mm_mt(vma->vm_mm); validate_mm_mt(vma->vm_mm);
...@@ -2206,14 +2210,17 @@ int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, ...@@ -2206,14 +2210,17 @@ int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
new->vm_ops->open(new); new->vm_ops->open(new);
if (new_below) if (new_below)
err = vma_adjust(vma, addr, vma->vm_end, vma->vm_pgoff + err = __vma_adjust(vmi, vma, addr, vma->vm_end,
((addr - new->vm_start) >> PAGE_SHIFT), new); vma->vm_pgoff + ((addr - new->vm_start) >> PAGE_SHIFT),
new, NULL);
else else
err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new); err = __vma_adjust(vmi, vma, vma->vm_start, addr, vma->vm_pgoff,
new, NULL);
/* Success. */ /* Success. */
if (!err) { if (!err) {
vma_iter_set(vmi, end); if (new_below)
vma_next(vmi);
return 0; return 0;
} }
...@@ -2308,8 +2315,7 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, ...@@ -2308,8 +2315,7 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma,
if (error) if (error)
goto start_split_failed; goto start_split_failed;
vma_iter_set(vmi, start); vma = vma_iter_load(vmi);
vma = vma_find(vmi, end);
} }
prev = vma_prev(vmi); prev = vma_prev(vmi);
...@@ -2329,7 +2335,6 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, ...@@ -2329,7 +2335,6 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma,
if (error) if (error)
goto end_split_failed; goto end_split_failed;
vma_iter_set(vmi, end);
split = vma_prev(vmi); split = vma_prev(vmi);
error = munmap_sidetree(split, &mas_detach); error = munmap_sidetree(split, &mas_detach);
if (error) if (error)
...@@ -2573,6 +2578,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, ...@@ -2573,6 +2578,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
goto unacct_error; goto unacct_error;
} }
vma_iter_set(&vmi, addr);
vma->vm_start = addr; vma->vm_start = addr;
vma->vm_end = end; vma->vm_end = end;
vma->vm_flags = vm_flags; vma->vm_flags = vm_flags;
......
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