1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <uapi/asm/mman.h>
8 #include <linux/compiler.h>
10 #include <linux/hugetlb.h>
11 #include <linux/shmem_fs.h>
12 #include <linux/types.h>
14 static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot,
17 unsigned long ret = 0;
19 if (system_supports_bti() && (prot & PROT_BTI))
22 if (system_supports_mte() && (prot & PROT_MTE))
25 #ifdef CONFIG_ARCH_HAS_PKEYS
26 if (system_supports_poe()) {
27 ret |= pkey & BIT(0) ? VM_PKEY_BIT0 : 0;
28 ret |= pkey & BIT(1) ? VM_PKEY_BIT1 : 0;
29 ret |= pkey & BIT(2) ? VM_PKEY_BIT2 : 0;
35 #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey)
37 static inline unsigned long arch_calc_vm_flag_bits(struct file *file,
41 * Only allow MTE on anonymous mappings as these are guaranteed to be
42 * backed by tags-capable memory. The vm_flags may be overridden by a
43 * filesystem supporting MTE (RAM-based).
45 if (system_supports_mte()) {
46 if (flags & (MAP_ANONYMOUS | MAP_HUGETLB))
47 return VM_MTE_ALLOWED;
48 if (shmem_file(file) || is_file_hugepages(file))
49 return VM_MTE_ALLOWED;
54 #define arch_calc_vm_flag_bits(file, flags) arch_calc_vm_flag_bits(file, flags)
56 static inline bool arch_validate_prot(unsigned long prot,
57 unsigned long addr __always_unused)
59 unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM;
61 if (system_supports_bti())
62 supported |= PROT_BTI;
64 if (system_supports_mte())
65 supported |= PROT_MTE;
67 return (prot & ~supported) == 0;
69 #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
71 static inline bool arch_validate_flags(unsigned long vm_flags)
73 if (system_supports_mte()) {
75 * only allow VM_MTE if VM_MTE_ALLOWED has been set
78 if ((vm_flags & VM_MTE) && !(vm_flags & VM_MTE_ALLOWED))
82 if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) {
83 /* An executable GCS isn't a good idea. */
84 if (vm_flags & VM_EXEC)
87 /* The memory management core should prevent this */
88 VM_WARN_ON(vm_flags & VM_SHARED);
94 #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
96 #endif /* !BUILD_VDSO */
98 #endif /* ! __ASM_MMAN_H__ */