aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-07-21 17:48:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-07-21 17:48:45 -0400
commit95faf6992df468f617edb788da8c21c6eed0dfa7 (patch)
tree121683c4e94117b9e41d31b0bc359c01a05412ba
parent3928d4f5ee37cdc523894f6e549e6aae521d8980 (diff)
mm: make vm_area_dup() actually copy the old vma data
.. 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 <torvalds@linux-foundation.org>
-rw-r--r--kernel/fork.c10
-rw-r--r--mm/mmap.c7
-rw-r--r--mm/nommu.c1
3 files changed, 7 insertions, 11 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 0e23deb5acfc..67253e41bfb0 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -315,7 +315,13 @@ struct vm_area_struct *vm_area_alloc(void)
315 315
316struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) 316struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)
317{ 317{
318 return kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); 318 struct vm_area_struct *new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
319
320 if (new) {
321 *new = *orig;
322 INIT_LIST_HEAD(&new->anon_vma_chain);
323 }
324 return new;
319} 325}
320 326
321void vm_area_free(struct vm_area_struct *vma) 327void vm_area_free(struct vm_area_struct *vma)
@@ -473,8 +479,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
473 tmp = vm_area_dup(mpnt); 479 tmp = vm_area_dup(mpnt);
474 if (!tmp) 480 if (!tmp)
475 goto fail_nomem; 481 goto fail_nomem;
476 *tmp = *mpnt;
477 INIT_LIST_HEAD(&tmp->anon_vma_chain);
478 retval = vma_dup_policy(mpnt, tmp); 482 retval = vma_dup_policy(mpnt, tmp);
479 if (retval) 483 if (retval)
480 goto fail_nomem_policy; 484 goto fail_nomem_policy;
diff --git a/mm/mmap.c b/mm/mmap.c
index 4286ad2dd1f5..b0ed8ce1b67e 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2624,11 +2624,6 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
2624 if (!new) 2624 if (!new)
2625 return -ENOMEM; 2625 return -ENOMEM;
2626 2626
2627 /* most fields are the same, copy all, and then fixup */
2628 *new = *vma;
2629
2630 INIT_LIST_HEAD(&new->anon_vma_chain);
2631
2632 if (new_below) 2627 if (new_below)
2633 new->vm_end = addr; 2628 new->vm_end = addr;
2634 else { 2629 else {
@@ -3205,13 +3200,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
3205 new_vma = vm_area_dup(vma); 3200 new_vma = vm_area_dup(vma);
3206 if (!new_vma) 3201 if (!new_vma)
3207 goto out; 3202 goto out;
3208 *new_vma = *vma;
3209 new_vma->vm_start = addr; 3203 new_vma->vm_start = addr;
3210 new_vma->vm_end = addr + len; 3204 new_vma->vm_end = addr + len;
3211 new_vma->vm_pgoff = pgoff; 3205 new_vma->vm_pgoff = pgoff;
3212 if (vma_dup_policy(vma, new_vma)) 3206 if (vma_dup_policy(vma, new_vma))
3213 goto out_free_vma; 3207 goto out_free_vma;
3214 INIT_LIST_HEAD(&new_vma->anon_vma_chain);
3215 if (anon_vma_clone(new_vma, vma)) 3208 if (anon_vma_clone(new_vma, vma))
3216 goto out_free_mempol; 3209 goto out_free_mempol;
3217 if (new_vma->vm_file) 3210 if (new_vma->vm_file)
diff --git a/mm/nommu.c b/mm/nommu.c
index 006e3fe65017..c2560e9cc803 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1476,7 +1476,6 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
1476 } 1476 }
1477 1477
1478 /* most fields are the same, copy all, and then fixup */ 1478 /* most fields are the same, copy all, and then fixup */
1479 *new = *vma;
1480 *region = *vma->vm_region; 1479 *region = *vma->vm_region;
1481 new->vm_region = region; 1480 new->vm_region = region;
1482 1481