]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
coredump: Remove vma linked list walk
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 26 Oct 2021 21:18:31 +0000 (17:18 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Sat, 30 Oct 2021 03:38:44 +0000 (23:38 -0400)
Use the Maple Tree iterator instead.  This is too complicated for the
VMA iterator to handle, so let's open-code it for now.  If this turns
out to be a common pattern, we can migrate it to common code.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
fs/coredump.c

index 3224dee44d30ed3206ec3881545a540d6c59db56..d0f8ebf4043c2e0e95148e881c8e7bf84258f46e 100644 (file)
@@ -1063,30 +1063,20 @@ whole:
        return vma->vm_end - vma->vm_start;
 }
 
-static struct vm_area_struct *first_vma(struct task_struct *tsk,
-                                       struct vm_area_struct *gate_vma)
-{
-       struct vm_area_struct *ret = tsk->mm->mmap;
-
-       if (ret)
-               return ret;
-       return gate_vma;
-}
-
 /*
  * Helper function for iterating across a vma list.  It ensures that the caller
  * will visit `gate_vma' prior to terminating the search.
  */
-static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
+static struct vm_area_struct *coredump_next_vma(struct ma_state *mas,
+                                      struct vm_area_struct *vma,
                                       struct vm_area_struct *gate_vma)
 {
-       struct vm_area_struct *ret;
-
-       ret = this_vma->vm_next;
-       if (ret)
-               return ret;
-       if (this_vma == gate_vma)
+       if (vma == gate_vma)
                return NULL;
+
+       vma = mas_next(mas, ULONG_MAX);
+       if (vma)
+               return vma;
        return gate_vma;
 }
 
@@ -1098,9 +1088,10 @@ int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count,
                      struct core_vma_metadata **vma_meta,
                      size_t *vma_data_size_ptr)
 {
-       struct vm_area_struct *vma, *gate_vma;
+       struct vm_area_struct *gate_vma, *vma = NULL;
        struct mm_struct *mm = current->mm;
-       int i;
+       MA_STATE(mas, &mm->mm_mt, 0, 0);
+       int i = 0;
        size_t vma_data_size = 0;
 
        /*
@@ -1120,8 +1111,7 @@ int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count,
                return -ENOMEM;
        }
 
-       for (i = 0, vma = first_vma(current, gate_vma); vma != NULL;
-                       vma = next_vma(vma, gate_vma), i++) {
+       while ((vma = coredump_next_vma(&mas, vma, gate_vma)) != NULL) {
                struct core_vma_metadata *m = (*vma_meta) + i;
 
                m->start = vma->vm_start;
@@ -1130,6 +1120,7 @@ int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count,
                m->dump_size = vma_dump_size(vma, cprm->mm_flags);
 
                vma_data_size += m->dump_size;
+               i++;
        }
 
        mmap_write_unlock(mm);