From 55d27081ae2260dac2f43d418b62c71a4c14d1ad Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 24 Nov 2020 16:24:24 -0500 Subject: [PATCH] mmap: Don't reset mas until needed in mmap_region() Signed-off-by: Liam R. Howlett --- mm/mmap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 07c8803bc5a5f..5ede23b56f0ab 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2649,9 +2649,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr, goto expanded; } - mas_reset(&mas); - mas_set(&mas, addr); - mas.last = end - 1; cannot_expand: /* * Determine the object being mapped and call the appropriate @@ -2747,6 +2744,13 @@ cannot_expand: goto free_vma; } + /* + * mas was called for the prev vma, and that may not be the correct + * location for the vma being inserted. + */ + if (mas.max < addr) + mas_reset(&mas); + mas_set(&mas, addr); mas_walk(&mas); vma_mas_link(mm, vma, &mas, prev); /* Once vma denies write, undo our temporary denial count */ -- 2.50.1