Skip to content

Commit

Permalink
mm: make vm_area_dup() actually copy the old vma data
Browse files Browse the repository at this point in the history
.. and re-initialize th eanon_vma_chain head.

This removes some boiler-plate from the users, and also makes it clear
why it didn't need use the 'zalloc()' version.

Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
torvalds committed Jul 21, 2018
1 parent 3928d4f commit 95faf69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
10 changes: 7 additions & 3 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,13 @@ struct vm_area_struct *vm_area_alloc(void)

struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)
{
return kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
struct vm_area_struct *new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);

if (new) {
*new = *orig;
INIT_LIST_HEAD(&new->anon_vma_chain);
}
return new;
}

void vm_area_free(struct vm_area_struct *vma)
Expand Down Expand Up @@ -473,8 +479,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
tmp = vm_area_dup(mpnt);
if (!tmp)
goto fail_nomem;
*tmp = *mpnt;
INIT_LIST_HEAD(&tmp->anon_vma_chain);
retval = vma_dup_policy(mpnt, tmp);
if (retval)
goto fail_nomem_policy;
Expand Down
7 changes: 0 additions & 7 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2624,11 +2624,6 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
if (!new)
return -ENOMEM;

/* most fields are the same, copy all, and then fixup */
*new = *vma;

INIT_LIST_HEAD(&new->anon_vma_chain);

if (new_below)
new->vm_end = addr;
else {
Expand Down Expand Up @@ -3205,13 +3200,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
new_vma = vm_area_dup(vma);
if (!new_vma)
goto out;
*new_vma = *vma;
new_vma->vm_start = addr;
new_vma->vm_end = addr + len;
new_vma->vm_pgoff = pgoff;
if (vma_dup_policy(vma, new_vma))
goto out_free_vma;
INIT_LIST_HEAD(&new_vma->anon_vma_chain);
if (anon_vma_clone(new_vma, vma))
goto out_free_mempol;
if (new_vma->vm_file)
Expand Down
1 change: 0 additions & 1 deletion mm/nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,6 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
}

/* most fields are the same, copy all, and then fixup */
*new = *vma;
*region = *vma->vm_region;
new->vm_region = region;

Expand Down

0 comments on commit 95faf69

Please sign in to comment.