History

mm/vma: make vma_is_accessible() available for general use

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().

Anshuman Khandual committed 6 years ago

Commit 3122e801 parent 7e96fb512 files · +17 −18Browse files

Unified · Split

12 files
  1. arch/csky/mm/fault.c +1 −1
  2. arch/m68k/mm/fault.c +1 −1
  3. arch/mips/mm/fault.c +1 −1
  4. arch/powerpc/mm/fault.c +1 −1
  5. arch/sh/mm/fault.c +1 −1
  6. arch/x86/mm/fault.c +1 −1
  7. include/linux/mm.h +6 −0
  8. kernel/sched/fair.c +1 −1
  9. mm/gup.c +1 −1
  10. mm/memory.c +0 −5
  11. mm/mempolicy.c +1 −2
  12. mm/mmap.c +2 −3
arch/csky/mm/fault.c+1−1
@@ -141,7 +141,7 @@ good_area: · 140 unmodified lines
141141 if (!(vma->vm_flags & VM_WRITE))
142142 goto bad_area;
143143 } else {
144− if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
144+ if (!vma_is_accessible(vma))
145145 goto bad_area;
146146 }
147147
arch/m68k/mm/fault.c+1−1
@@ -125,7 +125,7 @@ good_area: · 124 unmodified lines
125125 case 1: /* read, present */
126126 goto acc_err;
127127 case 0: /* read, not present */
128− if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
128+ if (!vma_is_accessible(vma))
129129 goto acc_err;
130130 }
131131
arch/mips/mm/fault.c+1−1
@@ -142,7 +142,7 @@ good_area: · 141 unmodified lines
142142 goto bad_area;
143143 }
144144 } else {
145− if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
145+ if (!vma_is_accessible(vma))
146146 goto bad_area;
147147 }
148148 }
arch/powerpc/mm/fault.c+1−1
@@ -314,7 +314,7 @@ static bool access_error(bool is_write, bool is_exec, · 313 unmodified lines
314314 return false;
315315 }
316316
317− if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
317+ if (unlikely(!vma_is_accessible(vma)))
318318 return true;
319319 /*
320320 * We should ideally do the vma pkey access check here. But in the
arch/sh/mm/fault.c+1−1
@@ -355,7 +355,7 @@ static inline int access_error(int error_code, struct vm_area_struct *vma) · 354 unmodified lines
355355 return 1;
356356
357357 /* read, not present: */
358− if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
358+ if (unlikely(!vma_is_accessible(vma)))
359359 return 1;
360360
361361 return 0;
arch/x86/mm/fault.c+1−1
@@ -1222,7 +1222,7 @@ access_error(unsigned long error_code, struct vm_area_struct *vma) · 1221 unmodified lines
12221222 return 1;
12231223
12241224 /* read, not present: */
1225− if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
1225+ if (unlikely(!vma_is_accessible(vma)))
12261226 return 1;
12271227
12281228 return 0;
include/linux/mm.h+6−0
@@ -629,6 +629,12 @@ static inline bool vma_is_foreign(struct vm_area_struct *vma) · 628 unmodified lines
629629
630630 return false;
631631 }
632+
633+static inline bool vma_is_accessible(struct vm_area_struct *vma)
634+{
635+ return vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
636+}
637+
632638 #ifdef CONFIG_SHMEM
633639 /*
634640 * The vma_is_shmem is not inline because it is used only by slow
kernel/sched/fair.c+1−1
@@ -2799,7 +2799,7 @@ static void task_numa_work(struct callback_head *work) · 2798 unmodified lines
27992799 * Skip inaccessible VMAs to avoid any confusion between
28002800 * PROT_NONE and NUMA hinting ptes
28012801 */
2802− if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
2802+ if (!vma_is_accessible(vma))
28032803 continue;
28042804
28052805 do {
mm/gup.c+1−1
@@ -1416,7 +1416,7 @@ long populate_vma_page_range(struct vm_area_struct *vma, · 1415 unmodified lines
14161416 * We want mlock to succeed for regions that have any permissions
14171417 * other than PROT_NONE.
14181418 */
1419− if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))
1419+ if (vma_is_accessible(vma))
14201420 gup_flags |= FOLL_FORCE;
14211421
14221422 /*
mm/memory.c+0−5
@@ -3964,11 +3964,6 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf, pmd_t orig_pmd) · 3963 unmodified lines
39643964 return VM_FAULT_FALLBACK;
39653965 }
39663966
3967−static inline bool vma_is_accessible(struct vm_area_struct *vma)
3968−{
3969− return vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE);
3970−}
3971−
39723967 static vm_fault_t create_huge_pud(struct vm_fault *vmf)
39733968 {
39743969 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \
mm/mempolicy.c+1−2
@@ -678,8 +678,7 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, · 677 unmodified lines
678678
679679 if (flags & MPOL_MF_LAZY) {
680680 /* Similar to task_numa_work, skip inaccessible VMAs */
681− if (!is_vm_hugetlb_page(vma) &&
682− (vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)) &&
681+ if (!is_vm_hugetlb_page(vma) && vma_is_accessible(vma) &&
683682 !(vma->vm_flags & VM_MIXEDMAP))
684683 change_prot_numa(vma, start, endvma);
685684 return 1;
mm/mmap.c+2−3
@@ -2358,8 +2358,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address) · 2357 unmodified lines
23582358 gap_addr = TASK_SIZE;
23592359
23602360 next = vma->vm_next;
2361− if (next && next->vm_start < gap_addr &&
2362− (next->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) {
2361+ if (next && next->vm_start < gap_addr && vma_is_accessible(next)) {
23632362 if (!(next->vm_flags & VM_GROWSUP))
23642363 return -ENOMEM;
23652364 /* Check that both stack segments have the same anon_vma? */
@@ -2440,7 +2439,7 @@ int expand_downwards(struct vm_area_struct *vma, · 74 unmodified lines
24402439 prev = vma->vm_prev;
24412440 /* Check that both stack segments have the same anon_vma? */
24422441 if (prev && !(prev->vm_flags & VM_GROWSDOWN) &&
2443− (prev->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) {
2442+ vma_is_accessible(prev)) {
24442443 if (address - prev->vm_end < stack_guard_gap)
24452444 return -ENOMEM;
24462445 }