]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
mm/vma: make vma_is_accessible() available for general use
authorAnshuman Khandual <anshuman.khandual@arm.com>
Tue, 7 Apr 2020 03:03:47 +0000 (20:03 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 7 Apr 2020 17:43:37 +0000 (10:43 -0700)
Lets move vma_is_accessible() helper to include/linux/mm.h which makes it
available for general use.  While here, this replaces all remaining open
encodings for VMA access check with vma_is_accessible().

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Guo Ren <guoren@kernel.org>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Guo Ren <guoren@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Burton <paulburton@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Nick Piggin <npiggin@gmail.com>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Will Deacon <will@kernel.org>
Link: http://lkml.kernel.org/r/1582520593-30704-3-git-send-email-anshuman.khandual@arm.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
12 files changed:
arch/csky/mm/fault.c
arch/m68k/mm/fault.c
arch/mips/mm/fault.c
arch/powerpc/mm/fault.c
arch/sh/mm/fault.c
arch/x86/mm/fault.c
include/linux/mm.h
kernel/sched/fair.c
mm/gup.c
mm/memory.c
mm/mempolicy.c
mm/mmap.c

index d3c61b83e1951121ac88556c5d66aa18336367c4..a6e8230b6fbfa7a48c581472ce65c9ba082eae00 100644 (file)
@@ -141,7 +141,7 @@ good_area:
                if (!(vma->vm_flags & VM_WRITE))
                        goto bad_area;
        } else {
-               if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
+               if (!vma_is_accessible(vma))
                        goto bad_area;
        }
 
index f7afb9897966a8d99bff239f7bca3642c958a4bb..0c4a21a685d590b4db6a7401e5a3790b12aad8e7 100644 (file)
@@ -125,7 +125,7 @@ good_area:
                case 1:         /* read, present */
                        goto acc_err;
                case 0:         /* read, not present */
-                       if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
+                       if (!vma_is_accessible(vma))
                                goto acc_err;
        }
 
index 4a0eafe3d932b1effeb5bf968087d704d27cf6e7..fb048ba2b91d4af7c2d25c60de4752b0fa0f18dc 100644 (file)
@@ -142,7 +142,7 @@ good_area:
                                goto bad_area;
                        }
                } else {
-                       if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
+                       if (!vma_is_accessible(vma))
                                goto bad_area;
                }
        }
index d15f0f0ee80630d1e88ee664b2a04b51bab0d24d..84af6c8eecf7113e2aa49d3e5864ac4eab727687 100644 (file)
@@ -314,7 +314,7 @@ static bool access_error(bool is_write, bool is_exec,
                return false;
        }
 
-       if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
+       if (unlikely(!vma_is_accessible(vma)))
                return true;
        /*
         * We should ideally do the vma pkey access check here. But in the
index 13ee4d20e6226bf4640305df486441650225a32c..5f23d790759766e1a11a6c5e8cacd0f5d0c51952 100644 (file)
@@ -355,7 +355,7 @@ static inline int access_error(int error_code, struct vm_area_struct *vma)
                return 1;
 
        /* read, not present: */
-       if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
+       if (unlikely(!vma_is_accessible(vma)))
                return 1;
 
        return 0;
index 859519f5b3423469ac735972fd26934dbab74cfe..a51df516b87bf1e174e2170b2c642406d2f28633 100644 (file)
@@ -1222,7 +1222,7 @@ access_error(unsigned long error_code, struct vm_area_struct *vma)
                return 1;
 
        /* read, not present: */
-       if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
+       if (unlikely(!vma_is_accessible(vma)))
                return 1;
 
        return 0;
index 7dd5c4ccbf85ae14299d9731fa2708f7992507b9..be49e371e4b54fd19328b3128d3d9d7f25e1303d 100644 (file)
@@ -629,6 +629,12 @@ static inline bool vma_is_foreign(struct vm_area_struct *vma)
 
        return false;
 }
+
+static inline bool vma_is_accessible(struct vm_area_struct *vma)
+{
+       return vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
+}
+
 #ifdef CONFIG_SHMEM
 /*
  * The vma_is_shmem is not inline because it is used only by slow
index d7fb20adabeb3027133b135e82547549826d9b2b..1ea3dddafe694cbb94554cc8999ad116afe9263b 100644 (file)
@@ -2799,7 +2799,7 @@ static void task_numa_work(struct callback_head *work)
                 * Skip inaccessible VMAs to avoid any confusion between
                 * PROT_NONE and NUMA hinting ptes
                 */
-               if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
+               if (!vma_is_accessible(vma))
                        continue;
 
                do {
index da3e031851443aa1f2af714c3af93906b361cb67..4d505c99462313087a2155bbbdb6174eccdc4d2b 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1416,7 +1416,7 @@ long populate_vma_page_range(struct vm_area_struct *vma,
         * We want mlock to succeed for regions that have any permissions
         * other than PROT_NONE.
         */
-       if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))
+       if (vma_is_accessible(vma))
                gup_flags |= FOLL_FORCE;
 
        /*
index 586271f3efc6206f69e0aa8226ea51debd8fee5d..d2a353c345adf9b1ac24763a021d4fc5ea7c3169 100644 (file)
@@ -3964,11 +3964,6 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf, pmd_t orig_pmd)
        return VM_FAULT_FALLBACK;
 }
 
-static inline bool vma_is_accessible(struct vm_area_struct *vma)
-{
-       return vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE);
-}
-
 static vm_fault_t create_huge_pud(struct vm_fault *vmf)
 {
 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) &&                    \
index 5fb427aed61279d066e603fb656b1b7c10e7c30f..b36926ba02e209f10704b89293ede280202bc49b 100644 (file)
@@ -678,8 +678,7 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end,
 
        if (flags & MPOL_MF_LAZY) {
                /* Similar to task_numa_work, skip inaccessible VMAs */
-               if (!is_vm_hugetlb_page(vma) &&
-                       (vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)) &&
+               if (!is_vm_hugetlb_page(vma) && vma_is_accessible(vma) &&
                        !(vma->vm_flags & VM_MIXEDMAP))
                        change_prot_numa(vma, start, endvma);
                return 1;
index 94ae18398c59d4b34011a38f2b905935ceb36ec9..aa09429d5888a7358514053ff4c7853be64f3b87 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2358,8 +2358,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
                gap_addr = TASK_SIZE;
 
        next = vma->vm_next;
-       if (next && next->vm_start < gap_addr &&
-                       (next->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) {
+       if (next && next->vm_start < gap_addr && vma_is_accessible(next)) {
                if (!(next->vm_flags & VM_GROWSUP))
                        return -ENOMEM;
                /* Check that both stack segments have the same anon_vma? */
@@ -2440,7 +2439,7 @@ int expand_downwards(struct vm_area_struct *vma,
        prev = vma->vm_prev;
        /* Check that both stack segments have the same anon_vma? */
        if (prev && !(prev->vm_flags & VM_GROWSDOWN) &&
-                       (prev->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) {
+                       vma_is_accessible(prev)) {
                if (address - prev->vm_end < stack_guard_gap)
                        return -ENOMEM;
        }