Commit 076f16bf authored by Liam R. Howlett's avatar Liam R. Howlett Committed by Andrew Morton
Browse files

mmap: use vmi version of vma_merge()

Use the vma iterator so that the iterator can be invalidated or updated to
avoid each caller doing so.

Link: https://lkml.kernel.org/r/20230120162650.984577-26-Liam.Howlett@oracle.com


Signed-off-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 0c0c5bff
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -2690,8 +2690,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
		 * vma again as we may succeed this time.
		 * vma again as we may succeed this time.
		 */
		 */
		if (unlikely(vm_flags != vma->vm_flags && prev)) {
		if (unlikely(vm_flags != vma->vm_flags && prev)) {
			merge = vma_merge(mm, prev, vma->vm_start, vma->vm_end, vma->vm_flags,
			merge = vmi_vma_merge(&vmi, mm, prev, vma->vm_start,
				NULL, vma->vm_file, vma->vm_pgoff, NULL, NULL_VM_UFFD_CTX, NULL);
				vma->vm_end, vma->vm_flags, NULL, vma->vm_file,
				vma->vm_pgoff, NULL, NULL_VM_UFFD_CTX, NULL);
			if (merge) {
			if (merge) {
				/*
				/*
				 * ->mmap() can change vma->vm_file and fput
				 * ->mmap() can change vma->vm_file and fput
@@ -3232,6 +3233,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
	struct mm_struct *mm = vma->vm_mm;
	struct mm_struct *mm = vma->vm_mm;
	struct vm_area_struct *new_vma, *prev;
	struct vm_area_struct *new_vma, *prev;
	bool faulted_in_anon_vma = true;
	bool faulted_in_anon_vma = true;
	VMA_ITERATOR(vmi, mm, addr);


	validate_mm_mt(mm);
	validate_mm_mt(mm);
	/*
	/*
@@ -3247,7 +3249,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
	if (new_vma && new_vma->vm_start < addr + len)
	if (new_vma && new_vma->vm_start < addr + len)
		return NULL;	/* should never get here */
		return NULL;	/* should never get here */


	new_vma = vma_merge(mm, prev, addr, addr + len, vma->vm_flags,
	new_vma = vmi_vma_merge(&vmi, mm, prev, addr, addr + len, vma->vm_flags,
			    vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma),
			    vma->anon_vma, vma->vm_file, pgoff, vma_policy(vma),
			    vma->vm_userfaultfd_ctx, anon_vma_name(vma));
			    vma->vm_userfaultfd_ctx, anon_vma_name(vma));
	if (new_vma) {
	if (new_vma) {