]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/mprotect: use maple tree navigation instead of VMA linked list
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 6 Sep 2022 19:49:02 +0000 (19:49 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 27 Sep 2022 02:46:24 +0000 (19:46 -0700)
Switch to navigating the VMA list with the maple tree operators in
preparation for removing the linked list.

Link: https://lkml.kernel.org/r/20220906194824.2110408-59-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Tested-by: Yu Zhao <yuzhao@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: SeongJae Park <sj@kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mprotect.c

index 55ed4a889990fb4effd6ca044d966e39c68c76bc..461dcbd4f21a6f9aa2aa910cad8ccaa7ec6dc0ea 100644 (file)
@@ -676,6 +676,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);
 
@@ -707,7 +708,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;
@@ -733,7 +735,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 ; ; ) {
@@ -796,7 +798,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;