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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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@xxxxxxxxxxxxxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>
> ---
>  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




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux