Skip to content

Commit 027232d

Browse files
kiryltorvalds
authored andcommitted
mm: introduce vma_init()
Not all VMAs allocated with vm_area_alloc(). Some of them allocated on stack or in data segment. The new helper can be use to initialize VMA properly regardless where it was allocated. Link: http://lkml.kernel.org/r/20180724121139.62570-2-kirill.shutemov@linux.intel.com Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 31c5bda commit 027232d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

include/linux/mm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ struct vm_operations_struct {
452452
unsigned long addr);
453453
};
454454

455+
static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
456+
{
457+
vma->vm_mm = mm;
458+
INIT_LIST_HEAD(&vma->anon_vma_chain);
459+
}
460+
455461
struct mmu_gather;
456462
struct inode;
457463

kernel/fork.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,8 @@ struct vm_area_struct *vm_area_alloc(struct mm_struct *mm)
312312
{
313313
struct vm_area_struct *vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
314314

315-
if (vma) {
316-
vma->vm_mm = mm;
317-
INIT_LIST_HEAD(&vma->anon_vma_chain);
318-
}
315+
if (vma)
316+
vma_init(vma, mm);
319317
return vma;
320318
}
321319

0 commit comments

Comments
 (0)