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().
Unified · Split
| @@ -141,7 +141,7 @@ good_area: · 140 unmodified lines | |||
| 141 | if (!(vma->vm_flags & VM_WRITE)) | 141 | if (!(vma->vm_flags & VM_WRITE)) |
| 142 | goto bad_area; | 142 | goto bad_area; |
| 143 | } else { | 143 | } else { |
| 144 | if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))) | 144 | if (!vma_is_accessible(vma)) |
| 145 | goto bad_area; | 145 | goto bad_area; |
| 146 | } | 146 | } |
| 147 | 147 | ||
| @@ -125,7 +125,7 @@ good_area: · 124 unmodified lines | |||
| 125 | case 1: /* read, present */ | 125 | case 1: /* read, present */ |
| 126 | goto acc_err; | 126 | goto acc_err; |
| 127 | case 0: /* read, not present */ | 127 | case 0: /* read, not present */ |
| 128 | if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) | 128 | if (!vma_is_accessible(vma)) |
| 129 | goto acc_err; | 129 | goto acc_err; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| @@ -142,7 +142,7 @@ good_area: · 141 unmodified lines | |||
| 142 | goto bad_area; | 142 | goto bad_area; |
| 143 | } | 143 | } |
| 144 | } else { | 144 | } else { |
| 145 | if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))) | 145 | if (!vma_is_accessible(vma)) |
| 146 | goto bad_area; | 146 | goto bad_area; |
| 147 | } | 147 | } |
| 148 | } | 148 | } |
| @@ -314,7 +314,7 @@ static bool access_error(bool is_write, bool is_exec, · 313 unmodified lines | |||
| 314 | return false; | 314 | return false; |
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))) | 317 | if (unlikely(!vma_is_accessible(vma))) |
| 318 | return true; | 318 | return true; |
| 319 | /* | 319 | /* |
| 320 | * We should ideally do the vma pkey access check here. But in the | 320 | * We should ideally do the vma pkey access check here. But in the |
| @@ -355,7 +355,7 @@ static inline int access_error(int error_code, struct vm_area_struct *vma) · 354 unmodified lines | |||
| 355 | return 1; | 355 | return 1; |
| 356 | 356 | ||
| 357 | /* read, not present: */ | 357 | /* read, not present: */ |
| 358 | if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))) | 358 | if (unlikely(!vma_is_accessible(vma))) |
| 359 | return 1; | 359 | return 1; |
| 360 | 360 | ||
| 361 | return 0; | 361 | return 0; |
| @@ -1222,7 +1222,7 @@ access_error(unsigned long error_code, struct vm_area_struct *vma) · 1221 unmodified lines | |||
| 1222 | return 1; | 1222 | return 1; |
| 1223 | 1223 | ||
| 1224 | /* read, not present: */ | 1224 | /* read, not present: */ |
| 1225 | if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))) | 1225 | if (unlikely(!vma_is_accessible(vma))) |
| 1226 | return 1; | 1226 | return 1; |
| 1227 | 1227 | ||
| 1228 | return 0; | 1228 | return 0; |
| @@ -629,6 +629,12 @@ static inline bool vma_is_foreign(struct vm_area_struct *vma) · 628 unmodified lines | |||
| 629 | 629 | ||
| 630 | return false; | 630 | return false; |
| 631 | } | 631 | } |
| 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 | |||
| 632 | #ifdef CONFIG_SHMEM | 638 | #ifdef CONFIG_SHMEM |
| 633 | /* | 639 | /* |
| 634 | * The vma_is_shmem is not inline because it is used only by slow | 640 | * The vma_is_shmem is not inline because it is used only by slow |
| @@ -2799,7 +2799,7 @@ static void task_numa_work(struct callback_head *work) · 2798 unmodified lines | |||
| 2799 | * Skip inaccessible VMAs to avoid any confusion between | 2799 | * Skip inaccessible VMAs to avoid any confusion between |
| 2800 | * PROT_NONE and NUMA hinting ptes | 2800 | * PROT_NONE and NUMA hinting ptes |
| 2801 | */ | 2801 | */ |
| 2802 | if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) | 2802 | if (!vma_is_accessible(vma)) |
| 2803 | continue; | 2803 | continue; |
| 2804 | 2804 | ||
| 2805 | do { | 2805 | do { |
| @@ -1416,7 +1416,7 @@ long populate_vma_page_range(struct vm_area_struct *vma, · 1415 unmodified lines | |||
| 1416 | * We want mlock to succeed for regions that have any permissions | 1416 | * We want mlock to succeed for regions that have any permissions |
| 1417 | * other than PROT_NONE. | 1417 | * other than PROT_NONE. |
| 1418 | */ | 1418 | */ |
| 1419 | if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) | 1419 | if (vma_is_accessible(vma)) |
| 1420 | gup_flags |= FOLL_FORCE; | 1420 | gup_flags |= FOLL_FORCE; |
| 1421 | 1421 | ||
| 1422 | /* | 1422 | /* |
| @@ -3964,11 +3964,6 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf, pmd_t orig_pmd) · 3963 unmodified lines | |||
| 3964 | return VM_FAULT_FALLBACK; | 3964 | return VM_FAULT_FALLBACK; |
| 3965 | } | 3965 | } |
| 3966 | 3966 | ||
| 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 | |||
| 3972 | static vm_fault_t create_huge_pud(struct vm_fault *vmf) | 3967 | static vm_fault_t create_huge_pud(struct vm_fault *vmf) |
| 3973 | { | 3968 | { |
| 3974 | #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ | 3969 | #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ |
| @@ -678,8 +678,7 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, · 677 unmodified lines | |||
| 678 | 678 | ||
| 679 | if (flags & MPOL_MF_LAZY) { | 679 | if (flags & MPOL_MF_LAZY) { |
| 680 | /* Similar to task_numa_work, skip inaccessible VMAs */ | 680 | /* Similar to task_numa_work, skip inaccessible VMAs */ |
| 681 | if (!is_vm_hugetlb_page(vma) && | 681 | if (!is_vm_hugetlb_page(vma) && vma_is_accessible(vma) && |
| 682 | (vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)) && | ||
| 683 | !(vma->vm_flags & VM_MIXEDMAP)) | 682 | !(vma->vm_flags & VM_MIXEDMAP)) |
| 684 | change_prot_numa(vma, start, endvma); | 683 | change_prot_numa(vma, start, endvma); |
| 685 | return 1; | 684 | return 1; |
| @@ -2358,8 +2358,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address) · 2357 unmodified lines | |||
| 2358 | gap_addr = TASK_SIZE; | 2358 | gap_addr = TASK_SIZE; |
| 2359 | 2359 | ||
| 2360 | next = vma->vm_next; | 2360 | next = vma->vm_next; |
| 2361 | if (next && next->vm_start < gap_addr && | 2361 | if (next && next->vm_start < gap_addr && vma_is_accessible(next)) { |
| 2362 | (next->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) { | ||
| 2363 | if (!(next->vm_flags & VM_GROWSUP)) | 2362 | if (!(next->vm_flags & VM_GROWSUP)) |
| 2364 | return -ENOMEM; | 2363 | return -ENOMEM; |
| 2365 | /* Check that both stack segments have the same anon_vma? */ | 2364 | /* 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 | |||
| 2440 | prev = vma->vm_prev; | 2439 | prev = vma->vm_prev; |
| 2441 | /* Check that both stack segments have the same anon_vma? */ | 2440 | /* Check that both stack segments have the same anon_vma? */ |
| 2442 | if (prev && !(prev->vm_flags & VM_GROWSDOWN) && | 2441 | if (prev && !(prev->vm_flags & VM_GROWSDOWN) && |
| 2443 | (prev->vm_flags & (VM_WRITE|VM_READ|VM_EXEC))) { | 2442 | vma_is_accessible(prev)) { |
| 2444 | if (address - prev->vm_end < stack_guard_gap) | 2443 | if (address - prev->vm_end < stack_guard_gap) |
| 2445 | return -ENOMEM; | 2444 | return -ENOMEM; |
| 2446 | } | 2445 | } |