diff mbox series

[RFC,V1,31/31] mm/mmap: Define macros for vm_flags access permission combinations

Message ID 1643029028-12710-32-git-send-email-anshuman.khandual@arm.com (mailing list archive)
State New
Headers show
Series mm/mmap: Drop protection_map[] and platform's __SXXX/__PXXX requirements | expand

Commit Message

Anshuman Khandual Jan. 24, 2022, 12:57 p.m. UTC
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(+)

Comments

Anshuman Khandual Feb. 3, 2022, 5:24 a.m. UTC | #1
On 1/24/22 6:27 PM, Anshuman Khandual wrote:
> 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
> +};

Defining platform specific vm_get_page_prot() involves a switch statement
with various vm_flags access combinations as cases. Hence I am wondering,
will it help to use these above macros, instead of existing combinations
separated with '|' flags. I can move this patch earlier in the series and
change all platform switch cases. Please do suggest. Thank you.

- Anshuman
diff mbox series

Patch

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);