From: Liam R. Howlett <Liam.Howlett@Oracle.com>
Date: Wed, 17 Feb 2021 22:03:35 +0000 (-0500)
Subject: mm/mmap: Fix mmap_region() maple tree store.
X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3501edea1bee71b323c6e4d2443e1faa37641da7;p=users%2Fjedix%2Flinux-maple.git

mm/mmap: Fix mmap_region() maple tree store.

mas_set_range() before vma_mas_link() as the address may have changed
as commented above in the code.

Do the same in the error path.

This forces a reset of the mas->node to MA_START.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---

diff --git a/mm/mmap.c b/mm/mmap.c
index 24adca4cffe8..cf6ee2f9ea74 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2616,7 +2616,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
 		goto expanded;
 	}
 
-	mas_set_range(&mas, addr, end - 1);
 cannot_expand:
 	/*
 	 * Determine the object being mapped and call the appropriate
@@ -2712,11 +2711,8 @@ cannot_expand:
 			goto free_vma;
 	}
 
-	// Very likely a shorter walk.
-	mas = ma_prev;
-	mas.last = end - 1;
-	mas.index = addr;
-	mas_walk(&mas);
+	// addr may have changed.
+	mas_set_range(&mas, addr, end - 1);
 	vma_mas_link(mm, vma, &mas);
 
 	/* Once vma denies write, undo our temporary denial count */
@@ -2763,6 +2759,7 @@ unmap_and_free_vma:
 	vma->vm_file = NULL;
 
 	/* Undo any partial mapping done by a device driver. */
+	mas_set_range(&mas, addr, end - 1);
 	unmap_region(mm, vma, &mas, vma->vm_start, vma->vm_end, prev, max);
 	charged = 0;
 	if (vm_flags & VM_SHARED)