mm: introduce vma_init()
authorKirill A. Shutemov <[email protected]>
Thu, 26 Jul 2018 23:37:25 +0000 (16:37 -0700)
committerLinus Torvalds <[email protected]>
Fri, 27 Jul 2018 02:38:03 +0000 (19:38 -0700)
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/[email protected]
Signed-off-by: Kirill A. Shutemov <[email protected]>
Acked-by: Linus Torvalds <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/mm.h
kernel/fork.c

index d3a3842316b87c3f6b5d0c02b6731154b65484fc..31540f1669876027fb7b05aa8d2514ded3eadc0c 100644 (file)
@@ -452,6 +452,12 @@ struct vm_operations_struct {
                                          unsigned long addr);
 };
 
+static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
+{
+       vma->vm_mm = mm;
+       INIT_LIST_HEAD(&vma->anon_vma_chain);
+}
+
 struct mmu_gather;
 struct inode;
 
index a191c05e757d8ff348a60d25e550a0bcb85765b9..1b27babc4c780484b87757f6257cfaab3b5b6772 100644 (file)
@@ -312,10 +312,8 @@ struct vm_area_struct *vm_area_alloc(struct mm_struct *mm)
 {
        struct vm_area_struct *vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
 
-       if (vma) {
-               vma->vm_mm = mm;
-               INIT_LIST_HEAD(&vma->anon_vma_chain);
-       }
+       if (vma)
+               vma_init(vma, mm);
        return vma;
 }