[PATCH v14 58/70] mm/mprotect: use maple tree navigation instead of VMA linked list

From: Liam Howlett
Date: Tue Sep 06 2022 - 15:54:02 EST


From: "Liam R. Howlett" <Liam.Howlett@xxxxxxxxxx>

Switch to navigating the VMA list with the maple tree operators in
preparation for removing the linked list.

Signed-off-by: Liam R. Howlett <Liam.Howlett@xxxxxxxxxx>
Acked-by: Vlastimil Babka <vbabka@xxxxxxx>
---
mm/mprotect.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mm/mprotect.c b/mm/mprotect.c
index 1bdac9337fb9..3c79796be65e 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -675,6 +675,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
const bool rier = (current->personality & READ_IMPLIES_EXEC) &&
(prot & PROT_READ);
struct mmu_gather tlb;
+ MA_STATE(mas, &current->mm->mm_mt, 0, 0);

start = untagged_addr(start);

@@ -706,7 +707,8 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
if ((pkey != -1) && !mm_pkey_is_allocated(current->mm, pkey))
goto out;

- vma = find_vma(current->mm, start);
+ mas_set(&mas, start);
+ vma = mas_find(&mas, ULONG_MAX);
error = -ENOMEM;
if (!vma)
goto out;
@@ -732,7 +734,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
if (start > vma->vm_start)
prev = vma;
else
- prev = vma->vm_prev;
+ prev = mas_prev(&mas, 0);

tlb_gather_mmu(&tlb, current->mm);
for (nstart = start ; ; ) {
@@ -795,7 +797,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
if (nstart >= end)
break;

- vma = prev->vm_next;
+ vma = find_vma(current->mm, prev->vm_end);
if (!vma || vma->vm_start != nstart) {
error = -ENOMEM;
break;
--
2.35.1