Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __ASM_MMAN_H__
0003 #define __ASM_MMAN_H__
0004 
0005 #include <linux/compiler.h>
0006 #include <linux/types.h>
0007 #include <uapi/asm/mman.h>
0008 
0009 static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot,
0010     unsigned long pkey __always_unused)
0011 {
0012     unsigned long ret = 0;
0013 
0014     if (system_supports_bti() && (prot & PROT_BTI))
0015         ret |= VM_ARM64_BTI;
0016 
0017     if (system_supports_mte() && (prot & PROT_MTE))
0018         ret |= VM_MTE;
0019 
0020     return ret;
0021 }
0022 #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey)
0023 
0024 static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags)
0025 {
0026     /*
0027      * Only allow MTE on anonymous mappings as these are guaranteed to be
0028      * backed by tags-capable memory. The vm_flags may be overridden by a
0029      * filesystem supporting MTE (RAM-based).
0030      */
0031     if (system_supports_mte() && (flags & MAP_ANONYMOUS))
0032         return VM_MTE_ALLOWED;
0033 
0034     return 0;
0035 }
0036 #define arch_calc_vm_flag_bits(flags) arch_calc_vm_flag_bits(flags)
0037 
0038 static inline bool arch_validate_prot(unsigned long prot,
0039     unsigned long addr __always_unused)
0040 {
0041     unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM;
0042 
0043     if (system_supports_bti())
0044         supported |= PROT_BTI;
0045 
0046     if (system_supports_mte())
0047         supported |= PROT_MTE;
0048 
0049     return (prot & ~supported) == 0;
0050 }
0051 #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
0052 
0053 static inline bool arch_validate_flags(unsigned long vm_flags)
0054 {
0055     if (!system_supports_mte())
0056         return true;
0057 
0058     /* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */
0059     return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED);
0060 }
0061 #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
0062 
0063 #endif /* ! __ASM_MMAN_H__ */