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 pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
42 if (vm_flags & VM_ARM64_BTI)
46 * There are two conditions required for returning a Normal Tagged
47 * memory type: (1) the user requested it via PROT_MTE passed to
48 * mmap() or mprotect() and (2) the corresponding vma supports MTE. We
49 * register (1) as VM_MTE in the vma->vm_flags and (2) as
50 * VM_MTE_ALLOWED. Note that the latter can only be set during the
51 * mmap() call since mprotect() does not accept MAP_* flags.
52 * Checking for VM_MTE only is sufficient since arch_validate_flags()
53 * does not permit (VM_MTE & !VM_MTE_ALLOWED).
55 if (vm_flags & VM_MTE)
56 prot |= PTE_ATTRINDX(MT_NORMAL_TAGGED);
58 return __pgprot(prot);
60 #define arch_vm_get_page_prot(vm_flags) arch_vm_get_page_prot(vm_flags)
62 static inline bool arch_validate_prot(unsigned long prot,
63 unsigned long addr __always_unused)
65 unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM;
67 if (system_supports_bti())
68 supported |= PROT_BTI;
70 if (system_supports_mte())
71 supported |= PROT_MTE;
73 return (prot & ~supported) == 0;
75 #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
77 static inline bool arch_validate_flags(unsigned long vm_flags)
79 if (!system_supports_mte())
82 /* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */
83 return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED);
85 #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
87 #endif /* ! __ASM_MMAN_H__ */