Skip to content

Commit 6cb4d9a

Browse files
Anshuman Khandualtorvalds
authored andcommitted
mm/vma: introduce VM_ACCESS_FLAGS
There are many places where all basic VMA access flags (read, write, exec) are initialized or checked against as a group. One such example is during page fault. Existing vma_is_accessible() wrapper already creates the notion of VMA accessibility as a group access permissions. Hence lets just create VM_ACCESS_FLAGS (VM_READ|VM_WRITE|VM_EXEC) which will not only reduce code duplication but also extend the VMA accessibility concept in general. Signed-off-by: Anshuman Khandual <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Cc: Russell King <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Mark Salter <[email protected]> Cc: Nick Hu <[email protected]> Cc: Ley Foon Tan <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Yoshinori Sato <[email protected]> Cc: Guan Xuetao <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Rob Springer <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent c62da0c commit 6cb4d9a

File tree

11 files changed

+16
-12
lines changed

11 files changed

+16
-12
lines changed

arch/arm/mm/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
189189
*/
190190
static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma)
191191
{
192-
unsigned int mask = VM_READ | VM_WRITE | VM_EXEC;
192+
unsigned int mask = VM_ACCESS_FLAGS;
193193

194194
if ((fsr & FSR_WRITE) && !(fsr & FSR_CM))
195195
mask = VM_WRITE;

arch/arm64/mm/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
445445
const struct fault_info *inf;
446446
struct mm_struct *mm = current->mm;
447447
vm_fault_t fault, major = 0;
448-
unsigned long vm_flags = VM_READ | VM_WRITE | VM_EXEC;
448+
unsigned long vm_flags = VM_ACCESS_FLAGS;
449449
unsigned int mm_flags = FAULT_FLAG_DEFAULT;
450450

451451
if (kprobe_page_fault(regs, esr))

arch/nds32/mm/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void do_page_fault(unsigned long entry, unsigned long addr,
7979
struct vm_area_struct *vma;
8080
int si_code;
8181
vm_fault_t fault;
82-
unsigned int mask = VM_READ | VM_WRITE | VM_EXEC;
82+
unsigned int mask = VM_ACCESS_FLAGS;
8383
unsigned int flags = FAULT_FLAG_DEFAULT;
8484

8585
error_code = error_code & (ITYPE_mskINST | ITYPE_mskETYPE);

arch/powerpc/mm/book3s64/pkeys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ int __execute_only_pkey(struct mm_struct *mm)
315315
static inline bool vma_is_pkey_exec_only(struct vm_area_struct *vma)
316316
{
317317
/* Do this check first since the vm_flags should be hot */
318-
if ((vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) != VM_EXEC)
318+
if ((vma->vm_flags & VM_ACCESS_FLAGS) != VM_EXEC)
319319
return false;
320320

321321
return (vma_pkey(vma) == vma->vm_mm->context.execute_only_pkey);

arch/s390/mm/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ void do_dat_exception(struct pt_regs *regs)
580580
int access;
581581
vm_fault_t fault;
582582

583-
access = VM_READ | VM_EXEC | VM_WRITE;
583+
access = VM_ACCESS_FLAGS;
584584
fault = do_exception(regs, access);
585585
if (unlikely(fault))
586586
do_fault_error(regs, access, fault);

arch/unicore32/mm/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
149149
*/
150150
static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma)
151151
{
152-
unsigned int mask = VM_READ | VM_WRITE | VM_EXEC;
152+
unsigned int mask = VM_ACCESS_FLAGS;
153153

154154
if (!(fsr ^ 0x12)) /* write? */
155155
mask = VM_WRITE;

arch/x86/mm/pkeys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int __execute_only_pkey(struct mm_struct *mm)
6363
static inline bool vma_is_pkey_exec_only(struct vm_area_struct *vma)
6464
{
6565
/* Do this check first since the vm_flags should be hot */
66-
if ((vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) != VM_EXEC)
66+
if ((vma->vm_flags & VM_ACCESS_FLAGS) != VM_EXEC)
6767
return false;
6868
if (vma_pkey(vma) != vma->vm_mm->context.execute_only_pkey)
6969
return false;

drivers/staging/gasket/gasket_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ static bool gasket_mmap_has_permissions(struct gasket_dev *gasket_dev,
689689

690690
/* Make sure that no wrong flags are set. */
691691
requested_permissions =
692-
(vma->vm_flags & (VM_WRITE | VM_READ | VM_EXEC));
692+
(vma->vm_flags & VM_ACCESS_FLAGS);
693693
if (requested_permissions & ~(bar_permissions)) {
694694
dev_dbg(gasket_dev->dev,
695695
"Attempting to map a region with requested permissions 0x%x, but region has permissions 0x%x.\n",

include/linux/mm.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ extern unsigned int kobjsize(const void *objp);
369369

370370
#define VM_STACK_FLAGS (VM_STACK | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
371371

372+
/* VMA basic access permission flags */
373+
#define VM_ACCESS_FLAGS (VM_READ | VM_WRITE | VM_EXEC)
374+
375+
372376
/*
373377
* Special vmas that are non-mergable, non-mlock()able.
374378
*/
@@ -646,7 +650,7 @@ static inline bool vma_is_foreign(struct vm_area_struct *vma)
646650

647651
static inline bool vma_is_accessible(struct vm_area_struct *vma)
648652
{
649-
return vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
653+
return vma->vm_flags & VM_ACCESS_FLAGS;
650654
}
651655

652656
#ifdef CONFIG_SHMEM

mm/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ static int anon_vma_compatible(struct vm_area_struct *a, struct vm_area_struct *
12241224
return a->vm_end == b->vm_start &&
12251225
mpol_equal(vma_policy(a), vma_policy(b)) &&
12261226
a->vm_file == b->vm_file &&
1227-
!((a->vm_flags ^ b->vm_flags) & ~(VM_READ|VM_WRITE|VM_EXEC|VM_SOFTDIRTY)) &&
1227+
!((a->vm_flags ^ b->vm_flags) & ~(VM_ACCESS_FLAGS | VM_SOFTDIRTY)) &&
12281228
b->vm_pgoff == a->vm_pgoff + ((b->vm_start - a->vm_start) >> PAGE_SHIFT);
12291229
}
12301230

0 commit comments

Comments
 (0)