lkml.org 
[lkml]   [2022]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC V1 31/31] mm/mmap: Define macros for vm_flags access permission combinations
Date
These macros will be useful in cleaning up the all those switch statements
in vm_get_page_prot() across all platforms.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
include/linux/mm.h | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6c0844b99b3e..b3691eeec500 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2828,6 +2828,45 @@ static inline bool range_in_vma(struct vm_area_struct *vma,
return (vma && vma->vm_start <= start && end <= vma->vm_end);
}

+/*
+ * Access permission related vm_flags combination is used to map into
+ * platform defined page protection flags. This enumeration helps in
+ * abstracting out possible indices after vm_flags is probed for all
+ * access permission i.e (VM_SHARED | VM_EXEC | VM_READ | VM_WRITE).
+ *
+ * VM_EXEC ---------------------|
+ * |
+ * VM_WRITE ---------------| |
+ * | |
+ * VM_READ -----------| | |
+ * | | |
+ * VM_SHARED ----| | | |
+ * | | | |
+ * v v v v
+ * VMFLAGS_IDX_(S|X)(R|X)(W|X)(E|X)
+ *
+ * X - Indicates that the access flag is absent
+ */
+enum vmflags_idx {
+ VMFLAGS_IDX_XXXX, /* (VM_NONE) */
+ VMFLAGS_IDX_XRXX, /* (VM_READ) */
+ VMFLAGS_IDX_XXWX, /* (VM_WRITE) */
+ VMFLAGS_IDX_XRWX, /* (VM_READ | VM_WRITE) */
+ VMFLAGS_IDX_XXXE, /* (VM_EXEC) */
+ VMFLAGS_IDX_XRXE, /* (VM_EXEC | VM_READ) */
+ VMFLAGS_IDX_XXWE, /* (VM_EXEC | VM_WRITE) */
+ VMFLAGS_IDX_XRWE, /* (VM_EXEC | VM_READ | VM_WRITE) */
+ VMFLAGS_IDX_SXXX, /* (VM_SHARED | VM_NONE) */
+ VMFLAGS_IDX_SRXX, /* (VM_SHARED | VM_READ) */
+ VMFLAGS_IDX_SXWX, /* (VM_SHARED | VM_WRITE) */
+ VMFLAGS_IDX_SRWX, /* (VM_SHARED | VM_READ | VM_WRITE) */
+ VMFLAGS_IDX_SXXE, /* (VM_SHARED | VM_EXEC) */
+ VMFLAGS_IDX_SRXE, /* (VM_SHARED | VM_EXEC | VM_READ) */
+ VMFLAGS_IDX_SXWE, /* (VM_SHARED | VM_EXEC | VM_WRITE) */
+ VMFLAGS_IDX_SRWE, /* (VM_SHARED | VM_EXEC | VM_READ | VM_WRITE) */
+ VMFLAGS_IDX_MAX
+};
+
#ifdef CONFIG_MMU
pgprot_t vm_get_page_prot(unsigned long vm_flags);
void vma_set_page_prot(struct vm_area_struct *vma);
--
2.25.1
\
 
 \ /
  Last update: 2022-01-24 14:00    [W:0.387 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site