diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-07-21 18:24:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-07-21 18:24:03 -0400 |
commit | 490fc053865c9cc40f1085ef8a5504f5341f79d2 (patch) | |
tree | 95f2e6e189cdae1a5e638b7ea4e39502605eaaa8 | |
parent | 95faf6992df468f617edb788da8c21c6eed0dfa7 (diff) |
mm: make vm_area_alloc() initialize core fields
Like vm_area_dup(), it initializes the anon_vma_chain head, and the
basic mm pointer.
The rest of the fields end up being different for different users,
although the plan is to also initialize the 'vm_ops' field to a dummy
entry.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/ia64/kernel/perfmon.c | 4 | ||||
-rw-r--r-- | arch/ia64/mm/init.c | 8 | ||||
-rw-r--r-- | fs/exec.c | 4 | ||||
-rw-r--r-- | include/linux/mm.h | 2 | ||||
-rw-r--r-- | kernel/fork.c | 10 | ||||
-rw-r--r-- | mm/mmap.c | 12 | ||||
-rw-r--r-- | mm/nommu.c | 3 |
7 files changed, 17 insertions, 26 deletions
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c index e859246badca..46bff1661836 100644 --- a/arch/ia64/kernel/perfmon.c +++ b/arch/ia64/kernel/perfmon.c | |||
@@ -2278,17 +2278,15 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t | |||
2278 | DPRINT(("smpl_buf @%p\n", smpl_buf)); | 2278 | DPRINT(("smpl_buf @%p\n", smpl_buf)); |
2279 | 2279 | ||
2280 | /* allocate vma */ | 2280 | /* allocate vma */ |
2281 | vma = vm_area_alloc(); | 2281 | vma = vm_area_alloc(mm); |
2282 | if (!vma) { | 2282 | if (!vma) { |
2283 | DPRINT(("Cannot allocate vma\n")); | 2283 | DPRINT(("Cannot allocate vma\n")); |
2284 | goto error_kmem; | 2284 | goto error_kmem; |
2285 | } | 2285 | } |
2286 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
2287 | 2286 | ||
2288 | /* | 2287 | /* |
2289 | * partially initialize the vma for the sampling buffer | 2288 | * partially initialize the vma for the sampling buffer |
2290 | */ | 2289 | */ |
2291 | vma->vm_mm = mm; | ||
2292 | vma->vm_file = get_file(filp); | 2290 | vma->vm_file = get_file(filp); |
2293 | vma->vm_flags = VM_READ|VM_MAYREAD|VM_DONTEXPAND|VM_DONTDUMP; | 2291 | vma->vm_flags = VM_READ|VM_MAYREAD|VM_DONTEXPAND|VM_DONTDUMP; |
2294 | vma->vm_page_prot = PAGE_READONLY; /* XXX may need to change */ | 2292 | vma->vm_page_prot = PAGE_READONLY; /* XXX may need to change */ |
diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c index 3f2321bffb72..bdb14a369137 100644 --- a/arch/ia64/mm/init.c +++ b/arch/ia64/mm/init.c | |||
@@ -114,10 +114,8 @@ ia64_init_addr_space (void) | |||
114 | * the problem. When the process attempts to write to the register backing store | 114 | * the problem. When the process attempts to write to the register backing store |
115 | * for the first time, it will get a SEGFAULT in this case. | 115 | * for the first time, it will get a SEGFAULT in this case. |
116 | */ | 116 | */ |
117 | vma = vm_area_alloc(); | 117 | vma = vm_area_alloc(current->mm); |
118 | if (vma) { | 118 | if (vma) { |
119 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
120 | vma->vm_mm = current->mm; | ||
121 | vma->vm_start = current->thread.rbs_bot & PAGE_MASK; | 119 | vma->vm_start = current->thread.rbs_bot & PAGE_MASK; |
122 | vma->vm_end = vma->vm_start + PAGE_SIZE; | 120 | vma->vm_end = vma->vm_start + PAGE_SIZE; |
123 | vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT; | 121 | vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT; |
@@ -133,10 +131,8 @@ ia64_init_addr_space (void) | |||
133 | 131 | ||
134 | /* map NaT-page at address zero to speed up speculative dereferencing of NULL: */ | 132 | /* map NaT-page at address zero to speed up speculative dereferencing of NULL: */ |
135 | if (!(current->personality & MMAP_PAGE_ZERO)) { | 133 | if (!(current->personality & MMAP_PAGE_ZERO)) { |
136 | vma = vm_area_alloc(); | 134 | vma = vm_area_alloc(current->mm); |
137 | if (vma) { | 135 | if (vma) { |
138 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
139 | vma->vm_mm = current->mm; | ||
140 | vma->vm_end = PAGE_SIZE; | 136 | vma->vm_end = PAGE_SIZE; |
141 | vma->vm_page_prot = __pgprot(pgprot_val(PAGE_READONLY) | _PAGE_MA_NAT); | 137 | vma->vm_page_prot = __pgprot(pgprot_val(PAGE_READONLY) | _PAGE_MA_NAT); |
142 | vma->vm_flags = VM_READ | VM_MAYREAD | VM_IO | | 138 | vma->vm_flags = VM_READ | VM_MAYREAD | VM_IO | |
@@ -290,7 +290,7 @@ static int __bprm_mm_init(struct linux_binprm *bprm) | |||
290 | struct vm_area_struct *vma = NULL; | 290 | struct vm_area_struct *vma = NULL; |
291 | struct mm_struct *mm = bprm->mm; | 291 | struct mm_struct *mm = bprm->mm; |
292 | 292 | ||
293 | bprm->vma = vma = vm_area_alloc(); | 293 | bprm->vma = vma = vm_area_alloc(mm); |
294 | if (!vma) | 294 | if (!vma) |
295 | return -ENOMEM; | 295 | return -ENOMEM; |
296 | 296 | ||
@@ -298,7 +298,6 @@ static int __bprm_mm_init(struct linux_binprm *bprm) | |||
298 | err = -EINTR; | 298 | err = -EINTR; |
299 | goto err_free; | 299 | goto err_free; |
300 | } | 300 | } |
301 | vma->vm_mm = mm; | ||
302 | 301 | ||
303 | /* | 302 | /* |
304 | * Place the stack at the largest stack address the architecture | 303 | * Place the stack at the largest stack address the architecture |
@@ -311,7 +310,6 @@ static int __bprm_mm_init(struct linux_binprm *bprm) | |||
311 | vma->vm_start = vma->vm_end - PAGE_SIZE; | 310 | vma->vm_start = vma->vm_end - PAGE_SIZE; |
312 | vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP; | 311 | vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP; |
313 | vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); | 312 | vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); |
314 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
315 | 313 | ||
316 | err = insert_vm_struct(mm, vma); | 314 | err = insert_vm_struct(mm, vma); |
317 | if (err) | 315 | if (err) |
diff --git a/include/linux/mm.h b/include/linux/mm.h index de2fd86c6154..d3a3842316b8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -155,7 +155,7 @@ extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *, | |||
155 | * mmap() functions). | 155 | * mmap() functions). |
156 | */ | 156 | */ |
157 | 157 | ||
158 | struct vm_area_struct *vm_area_alloc(void); | 158 | struct vm_area_struct *vm_area_alloc(struct mm_struct *); |
159 | struct vm_area_struct *vm_area_dup(struct vm_area_struct *); | 159 | struct vm_area_struct *vm_area_dup(struct vm_area_struct *); |
160 | void vm_area_free(struct vm_area_struct *); | 160 | void vm_area_free(struct vm_area_struct *); |
161 | 161 | ||
diff --git a/kernel/fork.c b/kernel/fork.c index 67253e41bfb0..a191c05e757d 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -308,9 +308,15 @@ static struct kmem_cache *vm_area_cachep; | |||
308 | /* SLAB cache for mm_struct structures (tsk->mm) */ | 308 | /* SLAB cache for mm_struct structures (tsk->mm) */ |
309 | static struct kmem_cache *mm_cachep; | 309 | static struct kmem_cache *mm_cachep; |
310 | 310 | ||
311 | struct vm_area_struct *vm_area_alloc(void) | 311 | struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) |
312 | { | 312 | { |
313 | return kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); | 313 | struct vm_area_struct *vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); |
314 | |||
315 | if (vma) { | ||
316 | vma->vm_mm = mm; | ||
317 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
318 | } | ||
319 | return vma; | ||
314 | } | 320 | } |
315 | 321 | ||
316 | struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) | 322 | struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) |
@@ -1729,19 +1729,17 @@ unsigned long mmap_region(struct file *file, unsigned long addr, | |||
1729 | * specific mapper. the address has already been validated, but | 1729 | * specific mapper. the address has already been validated, but |
1730 | * not unmapped, but the maps are removed from the list. | 1730 | * not unmapped, but the maps are removed from the list. |
1731 | */ | 1731 | */ |
1732 | vma = vm_area_alloc(); | 1732 | vma = vm_area_alloc(mm); |
1733 | if (!vma) { | 1733 | if (!vma) { |
1734 | error = -ENOMEM; | 1734 | error = -ENOMEM; |
1735 | goto unacct_error; | 1735 | goto unacct_error; |
1736 | } | 1736 | } |
1737 | 1737 | ||
1738 | vma->vm_mm = mm; | ||
1739 | vma->vm_start = addr; | 1738 | vma->vm_start = addr; |
1740 | vma->vm_end = addr + len; | 1739 | vma->vm_end = addr + len; |
1741 | vma->vm_flags = vm_flags; | 1740 | vma->vm_flags = vm_flags; |
1742 | vma->vm_page_prot = vm_get_page_prot(vm_flags); | 1741 | vma->vm_page_prot = vm_get_page_prot(vm_flags); |
1743 | vma->vm_pgoff = pgoff; | 1742 | vma->vm_pgoff = pgoff; |
1744 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
1745 | 1743 | ||
1746 | if (file) { | 1744 | if (file) { |
1747 | if (vm_flags & VM_DENYWRITE) { | 1745 | if (vm_flags & VM_DENYWRITE) { |
@@ -2979,14 +2977,12 @@ static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long fla | |||
2979 | /* | 2977 | /* |
2980 | * create a vma struct for an anonymous mapping | 2978 | * create a vma struct for an anonymous mapping |
2981 | */ | 2979 | */ |
2982 | vma = vm_area_alloc(); | 2980 | vma = vm_area_alloc(mm); |
2983 | if (!vma) { | 2981 | if (!vma) { |
2984 | vm_unacct_memory(len >> PAGE_SHIFT); | 2982 | vm_unacct_memory(len >> PAGE_SHIFT); |
2985 | return -ENOMEM; | 2983 | return -ENOMEM; |
2986 | } | 2984 | } |
2987 | 2985 | ||
2988 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
2989 | vma->vm_mm = mm; | ||
2990 | vma->vm_start = addr; | 2986 | vma->vm_start = addr; |
2991 | vma->vm_end = addr + len; | 2987 | vma->vm_end = addr + len; |
2992 | vma->vm_pgoff = pgoff; | 2988 | vma->vm_pgoff = pgoff; |
@@ -3343,12 +3339,10 @@ static struct vm_area_struct *__install_special_mapping( | |||
3343 | int ret; | 3339 | int ret; |
3344 | struct vm_area_struct *vma; | 3340 | struct vm_area_struct *vma; |
3345 | 3341 | ||
3346 | vma = vm_area_alloc(); | 3342 | vma = vm_area_alloc(mm); |
3347 | if (unlikely(vma == NULL)) | 3343 | if (unlikely(vma == NULL)) |
3348 | return ERR_PTR(-ENOMEM); | 3344 | return ERR_PTR(-ENOMEM); |
3349 | 3345 | ||
3350 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
3351 | vma->vm_mm = mm; | ||
3352 | vma->vm_start = addr; | 3346 | vma->vm_start = addr; |
3353 | vma->vm_end = addr + len; | 3347 | vma->vm_end = addr + len; |
3354 | 3348 | ||
diff --git a/mm/nommu.c b/mm/nommu.c index c2560e9cc803..1d22fdbf7d7c 100644 --- a/mm/nommu.c +++ b/mm/nommu.c | |||
@@ -1204,7 +1204,7 @@ unsigned long do_mmap(struct file *file, | |||
1204 | if (!region) | 1204 | if (!region) |
1205 | goto error_getting_region; | 1205 | goto error_getting_region; |
1206 | 1206 | ||
1207 | vma = vm_area_alloc(); | 1207 | vma = vm_area_alloc(current->mm); |
1208 | if (!vma) | 1208 | if (!vma) |
1209 | goto error_getting_vma; | 1209 | goto error_getting_vma; |
1210 | 1210 | ||
@@ -1212,7 +1212,6 @@ unsigned long do_mmap(struct file *file, | |||
1212 | region->vm_flags = vm_flags; | 1212 | region->vm_flags = vm_flags; |
1213 | region->vm_pgoff = pgoff; | 1213 | region->vm_pgoff = pgoff; |
1214 | 1214 | ||
1215 | INIT_LIST_HEAD(&vma->anon_vma_chain); | ||
1216 | vma->vm_flags = vm_flags; | 1215 | vma->vm_flags = vm_flags; |
1217 | vma->vm_pgoff = pgoff; | 1216 | vma->vm_pgoff = pgoff; |
1218 | 1217 | ||