1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/compiler.h>
6 #include <linux/types.h>
7 #include <uapi/asm/mman.h>
9 static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot,
10 unsigned long pkey __always_unused)
12 unsigned long ret = 0;
14 if (system_supports_bti() && (prot & PROT_BTI))
17 if (system_supports_mte() && (prot & PROT_MTE))
22 #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey)
24 static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags)
27 * Only allow MTE on anonymous mappings as these are guaranteed to be
28 * backed by tags-capable memory. The vm_flags may be overridden by a
29 * filesystem supporting MTE (RAM-based).
31 if (system_supports_mte() && (flags & MAP_ANONYMOUS))
32 return VM_MTE_ALLOWED;
36 #define arch_calc_vm_flag_bits(flags) arch_calc_vm_flag_bits(flags)
38 static inline bool arch_validate_prot(unsigned long prot,
39 unsigned long addr __always_unused)
41 unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM;
43 if (system_supports_bti())
44 supported |= PROT_BTI;
46 if (system_supports_mte())
47 supported |= PROT_MTE;
49 return (prot & ~supported) == 0;
51 #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
53 static inline bool arch_validate_flags(unsigned long vm_flags)
55 if (!system_supports_mte())
58 /* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */
59 return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED);
61 #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
63 #endif /* ! __ASM_MMAN_H__ */