[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 10/13] mm/vma: convert miscellaneous uses of VMA flags in core mm



Update various uses of legacy flags in vma.c and mmap.c to the new
vma_flags_t type, updating comments alongside them to be consistent.

Also update __install_special_mapping() to rearrange things slightly to
accommodate the changes.

Signed-off-by: Lorenzo Stoakes <ljs@xxxxxxxxxx>
---
 mm/mmap.c | 39 +++++++++++++++++++++------------------
 mm/vma.c  | 16 ++++++++++------
 2 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index e834ec9273e3..a8546c9250a0 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -557,8 +557,8 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
        }
 
        /*
-        * Set 'VM_NORESERVE' if we should not account for the
-        * memory use of this mapping.
+        * Set VMA_NORESERVE_BIT if we should not account for the memory use
+        * of this mapping.
         */
        if (flags & MAP_NORESERVE) {
                /* We honor MAP_NORESERVE if allowed to overcommit */
@@ -985,7 +985,7 @@ struct vm_area_struct *find_extend_vma_locked(struct 
mm_struct *mm, unsigned lon
                return NULL;
        if (expand_stack_locked(prev, addr))
                return NULL;
-       if (prev->vm_flags & VM_LOCKED)
+       if (vma_test(prev, VMA_LOCKED_BIT))
                populate_vma_page_range(prev, addr, prev->vm_end, NULL);
        return prev;
 }
@@ -1009,7 +1009,7 @@ struct vm_area_struct *find_extend_vma_locked(struct 
mm_struct *mm, unsigned lon
        start = vma->vm_start;
        if (expand_stack_locked(vma, addr))
                return NULL;
-       if (vma->vm_flags & VM_LOCKED)
+       if (vma_test(vma, VMA_LOCKED_BIT))
                populate_vma_page_range(vma, addr, start, NULL);
        return vma;
 }
@@ -1134,18 +1134,18 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, 
unsigned long, size,
         */
        vma = vma_lookup(mm, start);
 
-       if (!vma || !(vma->vm_flags & VM_SHARED)) {
+       if (!vma || !vma_test(vma, VMA_SHARED_BIT)) {
                mmap_read_unlock(mm);
                return -EINVAL;
        }
 
-       prot |= vma->vm_flags & VM_READ ? PROT_READ : 0;
-       prot |= vma->vm_flags & VM_WRITE ? PROT_WRITE : 0;
-       prot |= vma->vm_flags & VM_EXEC ? PROT_EXEC : 0;
+       prot |= vma_test(vma, VMA_READ_BIT) ? PROT_READ : 0;
+       prot |= vma_test(vma, VMA_WRITE_BIT) ? PROT_WRITE : 0;
+       prot |= vma_test(vma, VMA_EXEC_BIT) ? PROT_EXEC : 0;
 
        flags &= MAP_NONBLOCK;
        flags |= MAP_SHARED | MAP_FIXED | MAP_POPULATE;
-       if (vma->vm_flags & VM_LOCKED)
+       if (vma_test(vma, VMA_LOCKED_BIT))
                flags |= MAP_LOCKED;
 
        /* Save vm_flags used to calculate prot and flags, and recheck later. */
@@ -1271,7 +1271,7 @@ unsigned long tear_down_vmas(struct mm_struct *mm, struct 
vma_iterator *vmi,
        mmap_assert_write_locked(mm);
        vma_iter_set(vmi, vma->vm_end);
        do {
-               if (vma->vm_flags & VM_ACCOUNT)
+               if (vma_test(vma, VMA_ACCOUNT_BIT))
                        nr_accounted += vma_pages(vma);
                vma_mark_detached(vma);
                remove_vma(vma);
@@ -1420,7 +1420,7 @@ static int special_mapping_split(struct vm_area_struct 
*vma, unsigned long addr)
 {
        /*
         * Forbid splitting special mappings - kernel has expectations over
-        * the number of pages in mapping. Together with VM_DONTEXPAND
+        * the number of pages in mapping. Together with VMA_DONTEXPAND_BIT
         * the size of vma should stay the same over the special mapping's
         * lifetime.
         */
@@ -1692,7 +1692,7 @@ bool mmap_read_lock_maybe_expand(struct mm_struct *mm,
                return true;
        }
 
-       if (!(new_vma->vm_flags & VM_GROWSDOWN))
+       if (!vma_test(new_vma, VMA_GROWSDOWN_BIT))
                return false;
 
        mmap_write_lock(mm);
@@ -1742,7 +1742,7 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, 
struct mm_struct *oldmm)
                retval = vma_start_write_killable(mpnt);
                if (retval < 0)
                        goto loop_out;
-               if (mpnt->vm_flags & VM_DONTCOPY) {
+               if (vma_test(mpnt, VMA_DONTCOPY_BIT)) {
                        retval = vma_iter_clear_gfp(&vmi, mpnt->vm_start,
                                                    mpnt->vm_end, GFP_KERNEL);
                        if (retval)
@@ -1752,7 +1752,7 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, 
struct mm_struct *oldmm)
                        continue;
                }
                charge = 0;
-               if (mpnt->vm_flags & VM_ACCOUNT) {
+               if (vma_test(mpnt, VMA_ACCOUNT_BIT)) {
                        unsigned long len = vma_pages(mpnt);
 
                        if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
@@ -1770,16 +1770,19 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, 
struct mm_struct *oldmm)
                retval = dup_userfaultfd(tmp, &uf);
                if (retval)
                        goto fail_nomem_anon_vma_fork;
-               if (tmp->vm_flags & VM_WIPEONFORK) {
+
+               if (vma_test(tmp, VMA_WIPEONFORK_BIT)) {
                        /*
-                        * VM_WIPEONFORK gets a clean slate in the child.
+                        * VMA_WIPEONFORK_BIT gets a clean slate in the child.
                         * Don't prepare anon_vma until fault since we don't
                         * copy page for current vma.
                         */
                        tmp->anon_vma = NULL;
                } else if (anon_vma_fork(tmp, mpnt))
                        goto fail_nomem_anon_vma_fork;
-               vm_flags_clear(tmp, VM_LOCKED_MASK);
+
+               vma_start_write(tmp);
+               vma_clear_flags_mask(tmp, VMA_LOCKED_MASK);
                /*
                 * Copy/update hugetlb private vma information.
                 */
@@ -1812,7 +1815,7 @@ __latent_entropy int dup_mmap(struct mm_struct *mm, 
struct mm_struct *oldmm)
                        i_mmap_unlock_write(mapping);
                }
 
-               if (!(tmp->vm_flags & VM_WIPEONFORK))
+               if (!vma_test(tmp, VMA_WIPEONFORK_BIT))
                        retval = copy_page_range(tmp, mpnt);
 
                if (retval) {
diff --git a/mm/vma.c b/mm/vma.c
index b81c05e67a61..ab2ef0f04420 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -3417,23 +3417,27 @@ struct vm_area_struct *__install_special_mapping(
        vm_flags_t vm_flags, void *priv,
        const struct vm_operations_struct *ops)
 {
-       int ret;
+       vma_flags_t vma_flags = legacy_to_vma_flags(vm_flags);
        struct vm_area_struct *vma;
+       int ret;
 
        vma = vm_area_alloc(mm);
-       if (unlikely(vma == NULL))
+       if (unlikely(!vma))
                return ERR_PTR(-ENOMEM);
 
-       vma_set_range(vma, addr, addr + len, 0);
-       vm_flags |= vma_flags_to_legacy(mm->def_vma_flags) | VM_DONTEXPAND;
+       vma_flags_set_mask(&vma_flags, mm->def_vma_flags);
+       vma_flags_set(&vma_flags, VMA_DONTEXPAND_BIT);
        if (pgtable_supports_soft_dirty())
-               vm_flags |= VM_SOFTDIRTY;
-       vm_flags_init(vma, vm_flags & ~VM_LOCKED_MASK);
+               vma_flags_set(&vma_flags, VMA_SOFTDIRTY_BIT);
+       vma_flags_clear_mask(&vma_flags, VMA_LOCKED_MASK);
+       vma->flags = vma_flags;
        vma->vm_page_prot = vma_get_page_prot(vma);
 
        vma->vm_ops = ops;
        vma->vm_private_data = priv;
 
+       vma_set_range(vma, addr, addr + len, 0);
+
        ret = insert_vm_struct(mm, vma);
        if (ret)
                goto out;
-- 
2.54.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.