Skip to content

Commit

Permalink
coredump: remove vma linked list walk
Browse files Browse the repository at this point in the history
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.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Signed-off-by: Liam R. Howlett <[email protected]>
Tested-by: Yu Zhao <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: David Howells <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: Sven Schnelle <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Matthew Wilcox (Oracle) authored and akpm00 committed Sep 27, 2022
1 parent cbd4375 commit 182ea1d
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions fs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,30 +1072,20 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
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 (gate_vma && (vma == gate_vma))
return NULL;

vma = mas_next(mas, ULONG_MAX);
if (vma)
return vma;
return gate_vma;
}

Expand All @@ -1119,9 +1109,10 @@ static void free_vma_snapshot(struct coredump_params *cprm)
*/
static bool dump_vma_snapshot(struct coredump_params *cprm)
{
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;

/*
* Once the stack expansion code is fixed to not change VMA bounds
Expand All @@ -1141,19 +1132,18 @@ static bool dump_vma_snapshot(struct coredump_params *cprm)
return false;
}

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 = cprm->vma_meta + i;

m->start = vma->vm_start;
m->end = vma->vm_end;
m->flags = vma->vm_flags;
m->dump_size = vma_dump_size(vma, cprm->mm_flags);
m->pgoff = vma->vm_pgoff;

m->file = vma->vm_file;
if (m->file)
get_file(m->file);
i++;
}

mmap_write_unlock(mm);
Expand Down

0 comments on commit 182ea1d

Please sign in to comment.