xref: /linux/arch/arm64/include/asm/mman.h (revision 4a39ac5b7d62679c07a3e3d12b0f6982377d8a7d)
18ef8f360SDave Martin /* SPDX-License-Identifier: GPL-2.0 */
28ef8f360SDave Martin #ifndef __ASM_MMAN_H__
38ef8f360SDave Martin #define __ASM_MMAN_H__
48ef8f360SDave Martin 
5*712676eaSAdhemerval Zanella #include <uapi/asm/mman.h>
6*712676eaSAdhemerval Zanella 
7*712676eaSAdhemerval Zanella #ifndef BUILD_VDSO
88ef8f360SDave Martin #include <linux/compiler.h>
98ef8f360SDave Martin #include <linux/types.h>
108ef8f360SDave Martin 
118ef8f360SDave Martin static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot,
12b3c03fe1SJoey Gouly 	unsigned long pkey)
138ef8f360SDave Martin {
149f341931SCatalin Marinas 	unsigned long ret = 0;
158ef8f360SDave Martin 
169f341931SCatalin Marinas 	if (system_supports_bti() && (prot & PROT_BTI))
179f341931SCatalin Marinas 		ret |= VM_ARM64_BTI;
189f341931SCatalin Marinas 
199f341931SCatalin Marinas 	if (system_supports_mte() && (prot & PROT_MTE))
209f341931SCatalin Marinas 		ret |= VM_MTE;
219f341931SCatalin Marinas 
22b3c03fe1SJoey Gouly #ifdef CONFIG_ARCH_HAS_PKEYS
23b3c03fe1SJoey Gouly 	if (system_supports_poe()) {
24b3c03fe1SJoey Gouly 		ret |= pkey & BIT(0) ? VM_PKEY_BIT0 : 0;
25b3c03fe1SJoey Gouly 		ret |= pkey & BIT(1) ? VM_PKEY_BIT1 : 0;
26b3c03fe1SJoey Gouly 		ret |= pkey & BIT(2) ? VM_PKEY_BIT2 : 0;
27b3c03fe1SJoey Gouly 	}
28b3c03fe1SJoey Gouly #endif
29b3c03fe1SJoey Gouly 
309f341931SCatalin Marinas 	return ret;
318ef8f360SDave Martin }
328ef8f360SDave Martin #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey)
338ef8f360SDave Martin 
349f341931SCatalin Marinas static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags)
359f341931SCatalin Marinas {
369f341931SCatalin Marinas 	/*
379f341931SCatalin Marinas 	 * Only allow MTE on anonymous mappings as these are guaranteed to be
389f341931SCatalin Marinas 	 * backed by tags-capable memory. The vm_flags may be overridden by a
399f341931SCatalin Marinas 	 * filesystem supporting MTE (RAM-based).
409f341931SCatalin Marinas 	 */
419f341931SCatalin Marinas 	if (system_supports_mte() && (flags & MAP_ANONYMOUS))
429f341931SCatalin Marinas 		return VM_MTE_ALLOWED;
439f341931SCatalin Marinas 
449f341931SCatalin Marinas 	return 0;
459f341931SCatalin Marinas }
469f341931SCatalin Marinas #define arch_calc_vm_flag_bits(flags) arch_calc_vm_flag_bits(flags)
479f341931SCatalin Marinas 
488ef8f360SDave Martin static inline bool arch_validate_prot(unsigned long prot,
498ef8f360SDave Martin 	unsigned long addr __always_unused)
508ef8f360SDave Martin {
518ef8f360SDave Martin 	unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM;
528ef8f360SDave Martin 
538ef8f360SDave Martin 	if (system_supports_bti())
548ef8f360SDave Martin 		supported |= PROT_BTI;
558ef8f360SDave Martin 
569f341931SCatalin Marinas 	if (system_supports_mte())
579f341931SCatalin Marinas 		supported |= PROT_MTE;
589f341931SCatalin Marinas 
598ef8f360SDave Martin 	return (prot & ~supported) == 0;
608ef8f360SDave Martin }
618ef8f360SDave Martin #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
628ef8f360SDave Martin 
6300420905SCatalin Marinas static inline bool arch_validate_flags(unsigned long vm_flags)
6400420905SCatalin Marinas {
6500420905SCatalin Marinas 	if (!system_supports_mte())
6600420905SCatalin Marinas 		return true;
6700420905SCatalin Marinas 
6800420905SCatalin Marinas 	/* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */
6900420905SCatalin Marinas 	return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED);
7000420905SCatalin Marinas }
7100420905SCatalin Marinas #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
7200420905SCatalin Marinas 
73*712676eaSAdhemerval Zanella #endif /* !BUILD_VDSO */
74*712676eaSAdhemerval Zanella 
758ef8f360SDave Martin #endif /* ! __ASM_MMAN_H__ */
76