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

[PATCH 05/13] mm: prefer mm->def_vma_flags in mm logic



Currently mm->def_flags (of type vm_flags_t) is union'd with
mm->def_vma_flags (of type vma_flags_t).

As part of the effort to convert vm_flags_t usage to vma_flags_t (in order
to no longer be arbitrarily limited to a system word size for VMA flags),
prefer mm->def_vma_flags to mm->def_flags throughout the mm logic.

No functional change intended.

Signed-off-by: Lorenzo Stoakes <ljs@xxxxxxxxxx>
---
 mm/debug.c |  2 +-
 mm/mlock.c | 13 +++++++------
 mm/mmap.c  | 11 ++++++-----
 mm/vma.c   |  4 ++--
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/mm/debug.c b/mm/debug.c
index 497654b36f1a..f0a354a9496a 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -226,7 +226,7 @@ void dump_mm(const struct mm_struct *mm)
                mm->numa_next_scan, mm->numa_scan_offset, mm->numa_scan_seq,
 #endif
                atomic_read(&mm->tlb_flush_pending),
-               mm->def_flags, &mm->def_flags
+               vma_flags_to_legacy(mm->def_vma_flags), &mm->def_vma_flags
        );
 }
 EXPORT_SYMBOL(dump_mm);
diff --git a/mm/mlock.c b/mm/mlock.c
index 8c227fefa2df..9c87b3ced65f 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -699,26 +699,27 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, 
len)
 
 /*
  * Take the MCL_* flags passed into mlockall (or 0 if called from munlockall)
- * and translate into the appropriate modifications to mm->def_flags and/or the
- * flags for all current VMAs.
+ * and translate into the appropriate modifications to mm->def_vma_flags and/or
+ * the flags for all current VMAs.
  *
  * There are a couple of subtleties with this.  If mlockall() is called 
multiple
  * times with different flags, the values do not necessarily stack.  If 
mlockall
  * is called once including the MCL_FUTURE flag and then a second time without
- * it, VM_LOCKED and VM_LOCKONFAULT will be cleared from mm->def_flags.
+ * it, VM_LOCKED and VM_LOCKONFAULT will be cleared from mm->def_vma_flags.
  */
 static int apply_mlockall_flags(int flags)
 {
        VMA_ITERATOR(vmi, current->mm, 0);
+       struct mm_struct *mm = current->mm;
        struct vm_area_struct *vma, *prev = NULL;
        vm_flags_t to_add = 0;
 
-       current->mm->def_flags &= ~VM_LOCKED_MASK;
+       vma_flags_clear_mask(&mm->def_vma_flags, VMA_LOCKED_MASK);
        if (flags & MCL_FUTURE) {
-               current->mm->def_flags |= VM_LOCKED;
+               vma_flags_set(&mm->def_vma_flags, VMA_LOCKED_BIT);
 
                if (flags & MCL_ONFAULT)
-                       current->mm->def_flags |= VM_LOCKONFAULT;
+                       vma_flags_set(&mm->def_vma_flags, VMA_LOCKONFAULT_BIT);
 
                if (!(flags & MCL_CURRENT))
                        goto out;
diff --git a/mm/mmap.c b/mm/mmap.c
index 3ef603d5ff00..477f4a77361a 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -102,15 +102,16 @@ void vma_set_page_prot(struct vm_area_struct *vma)
  */
 static int check_brk_limits(unsigned long addr, unsigned long len)
 {
+       const struct mm_struct *mm = current->mm;
+       const bool is_def_locked =
+               vma_flags_test(&mm->def_vma_flags, VMA_LOCKED_BIT);
        unsigned long mapped_addr;
 
        mapped_addr = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
        if (IS_ERR_VALUE(mapped_addr))
                return mapped_addr;
 
-       return mlock_future_ok(current->mm,
-                             current->mm->def_flags & VM_LOCKED, len)
-               ? 0 : -EAGAIN;
+       return mlock_future_ok(mm, is_def_locked, len) ? 0 : -EAGAIN;
 }
 
 SYSCALL_DEFINE1(brk, unsigned long, brk)
@@ -197,7 +198,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
                goto out;
 
        mm->brk = brk;
-       if (mm->def_flags & VM_LOCKED)
+       if (vma_flags_test(&mm->def_vma_flags, VMA_LOCKED_BIT))
                populate = true;
 
 success:
@@ -1247,7 +1248,7 @@ int vm_brk_flags(unsigned long addr, unsigned long 
request, bool is_exec)
 
        vma = vma_prev(&vmi);
        ret = do_brk_flags(&vmi, vma, addr, len, vma_flags);
-       populate = ((mm->def_flags & VM_LOCKED) != 0);
+       populate = vma_flags_test(&mm->def_vma_flags, VMA_LOCKED_BIT);
        mmap_write_unlock(mm);
        userfaultfd_unmap_complete(mm, &uf);
        if (populate && !ret)
diff --git a/mm/vma.c b/mm/vma.c
index 3d1ae3cae45f..fb4341943576 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -3424,7 +3424,8 @@ struct vm_area_struct *__install_special_mapping(
        if (unlikely(vma == NULL))
                return ERR_PTR(-ENOMEM);
 
-       vm_flags |= mm->def_flags | VM_DONTEXPAND;
+       vma_set_range(vma, addr, addr + len, 0);
+       vm_flags |= vma_flags_to_legacy(mm->def_vma_flags) | VM_DONTEXPAND;
        if (pgtable_supports_soft_dirty())
                vm_flags |= VM_SOFTDIRTY;
        vm_flags_init(vma, vm_flags & ~VM_LOCKED_MASK);
@@ -3432,7 +3433,6 @@ struct vm_area_struct *__install_special_mapping(
 
        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)
-- 
2.54.0




 


Rackspace

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