mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK
authorSuren Baghdasaryan <surenb@google.com>
Thu, 26 Jan 2023 19:37:48 +0000 (11:37 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 10 Feb 2023 00:51:39 +0000 (16:51 -0800)
To simplify the usage of VM_LOCKED_CLEAR_MASK in vm_flags_clear(), replace
it with VM_LOCKED_MASK bitmask and convert all users.

Link: https://lkml.kernel.org/r/20230126193752.297968-4-surenb@google.com
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Acked-by: Mike Rapoport (IBM) <rppt@kernel.org>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arjun Roy <arjunroy@google.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: Joel Fernandes <joelaf@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Laurent Dufour <ldufour@linux.ibm.com>
Cc: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Minchan Kim <minchan@google.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Peter Oskolkov <posk@google.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Punit Agrawal <punit.agrawal@bytedance.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Soheil Hassas Yeganeh <soheil@google.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mm.h
kernel/fork.c
mm/hugetlb.c
mm/mlock.c
mm/mmap.c
mm/mremap.c

index e2df5d122b67fdd7b6d77c846a2a126f989fa478..663726ca22409533f24f4eab42447b19a00497fd 100644 (file)
@@ -421,8 +421,8 @@ extern unsigned int kobjsize(const void *objp);
 /* This mask defines which mm->def_flags a process can inherit its parent */
 #define VM_INIT_DEF_MASK       VM_NOHUGEPAGE
 
-/* This mask is used to clear all the VMA flags used by mlock */
-#define VM_LOCKED_CLEAR_MASK   (~(VM_LOCKED | VM_LOCKONFAULT))
+/* This mask represents all the VMA flag bits used by mlock */
+#define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT)
 
 /* Arch-specific flags to clear when updating VM flags on protection change */
 #ifndef VM_ARCH_CLEAR
index 9260f975b8f448dad0aabd0752480c4d7e3644e8..5e3029ea8e1ec26efc5495c559c0f58600797625 100644 (file)
@@ -659,7 +659,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
                        tmp->anon_vma = NULL;
                } else if (anon_vma_fork(tmp, mpnt))
                        goto fail_nomem_anon_vma_fork;
-               tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);
+               vm_flags_clear(tmp, VM_LOCKED_MASK);
                file = tmp->vm_file;
                if (file) {
                        struct address_space *mapping = file->f_mapping;
index 0f9df014377223adf728e767a8872a867573a53f..ab35b1cc99277dfba2a0a38fabb795a39025d10e 100644 (file)
@@ -6969,8 +6969,8 @@ static unsigned long page_table_shareable(struct vm_area_struct *svma,
        unsigned long s_end = sbase + PUD_SIZE;
 
        /* Allow segments to share if only one is marked locked */
-       unsigned long vm_flags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
-       unsigned long svm_flags = svma->vm_flags & VM_LOCKED_CLEAR_MASK;
+       unsigned long vm_flags = vma->vm_flags & ~VM_LOCKED_MASK;
+       unsigned long svm_flags = svma->vm_flags & ~VM_LOCKED_MASK;
 
        /*
         * match the virtual addresses, permission and the alignment of the
index 0336f52e03d7524c7d8cee772ee5fa9270676aed..5c4fff93cd6bc63117378ac22ea28234590670ad 100644 (file)
@@ -497,7 +497,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
                if (vma->vm_start != tmp)
                        return -ENOMEM;
 
-               newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
+               newflags = vma->vm_flags & ~VM_LOCKED_MASK;
                newflags |= flags;
                /* Here we know that  vma->vm_start <= nstart < vma->vm_end. */
                tmp = vma->vm_end;
@@ -661,7 +661,7 @@ static int apply_mlockall_flags(int flags)
        struct vm_area_struct *vma, *prev = NULL;
        vm_flags_t to_add = 0;
 
-       current->mm->def_flags &= VM_LOCKED_CLEAR_MASK;
+       current->mm->def_flags &= ~VM_LOCKED_MASK;
        if (flags & MCL_FUTURE) {
                current->mm->def_flags |= VM_LOCKED;
 
@@ -681,7 +681,7 @@ static int apply_mlockall_flags(int flags)
        for_each_vma(vmi, vma) {
                vm_flags_t newflags;
 
-               newflags = vma->vm_flags & VM_LOCKED_CLEAR_MASK;
+               newflags = vma->vm_flags & ~VM_LOCKED_MASK;
                newflags |= to_add;
 
                /* Ignore errors */
index b698a96d0511685109c055c043ae7546ff5e09e7..03d7c37c5969138d1234ef91938abf8eec9f7bc1 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2668,7 +2668,7 @@ expanded:
                if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) ||
                                        is_vm_hugetlb_page(vma) ||
                                        vma == get_gate_vma(current->mm))
-                       vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
+                       vm_flags_clear(vma, VM_LOCKED_MASK);
                else
                        mm->locked_vm += (len >> PAGE_SHIFT);
        }
@@ -3338,8 +3338,8 @@ static struct vm_area_struct *__install_special_mapping(
        vma->vm_start = addr;
        vma->vm_end = addr + len;
 
-       vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
-       vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
+       vm_flags_init(vma, (vm_flags | mm->def_flags |
+                     VM_DONTEXPAND | VM_SOFTDIRTY) & ~VM_LOCKED_MASK);
        vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
 
        vma->vm_ops = ops;
index 5c9a5790986284cbb1e5b49e4c96c65f4be932be..d70d8063c6e2013cb43729713d39fa7636ad104d 100644 (file)
@@ -687,7 +687,7 @@ static unsigned long move_vma(struct vm_area_struct *vma,
 
        if (unlikely(!err && (flags & MREMAP_DONTUNMAP))) {
                /* We always clear VM_LOCKED[ONFAULT] on the old vma */
-               vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
+               vm_flags_clear(vma, VM_LOCKED_MASK);
 
                /*
                 * anon_vma links of the old vma is no longer needed after its page