xref: /openbmc/linux/arch/arm64/include/asm/mman.h (revision f6d73b12ca9fd3b1c29a6a725cd751b972c740cf)
18ef8f360SDave Martin /* SPDX-License-Identifier: GPL-2.0 */
28ef8f360SDave Martin #ifndef __ASM_MMAN_H__
38ef8f360SDave Martin #define __ASM_MMAN_H__
48ef8f360SDave Martin 
58ef8f360SDave Martin #include <linux/compiler.h>
6*04b7efa4SLorenzo Stoakes #include <linux/fs.h>
7*04b7efa4SLorenzo Stoakes #include <linux/shmem_fs.h>
88ef8f360SDave Martin #include <linux/types.h>
98ef8f360SDave Martin #include <uapi/asm/mman.h>
108ef8f360SDave Martin 
arch_calc_vm_prot_bits(unsigned long prot,unsigned long pkey __always_unused)118ef8f360SDave Martin static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot,
128ef8f360SDave Martin 	unsigned long pkey __always_unused)
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 
229f341931SCatalin Marinas 	return ret;
238ef8f360SDave Martin }
248ef8f360SDave Martin #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey)
258ef8f360SDave Martin 
arch_calc_vm_flag_bits(struct file * file,unsigned long flags)26*04b7efa4SLorenzo Stoakes static inline unsigned long arch_calc_vm_flag_bits(struct file *file,
27*04b7efa4SLorenzo Stoakes 						   unsigned long flags)
289f341931SCatalin Marinas {
299f341931SCatalin Marinas 	/*
309f341931SCatalin Marinas 	 * Only allow MTE on anonymous mappings as these are guaranteed to be
319f341931SCatalin Marinas 	 * backed by tags-capable memory. The vm_flags may be overridden by a
329f341931SCatalin Marinas 	 * filesystem supporting MTE (RAM-based).
339f341931SCatalin Marinas 	 */
34*04b7efa4SLorenzo Stoakes 	if (system_supports_mte() &&
35*04b7efa4SLorenzo Stoakes 	    ((flags & MAP_ANONYMOUS) || shmem_file(file)))
369f341931SCatalin Marinas 		return VM_MTE_ALLOWED;
379f341931SCatalin Marinas 
389f341931SCatalin Marinas 	return 0;
399f341931SCatalin Marinas }
40*04b7efa4SLorenzo Stoakes #define arch_calc_vm_flag_bits(file, flags) arch_calc_vm_flag_bits(file, flags)
419f341931SCatalin Marinas 
arch_validate_prot(unsigned long prot,unsigned long addr __always_unused)428ef8f360SDave Martin static inline bool arch_validate_prot(unsigned long prot,
438ef8f360SDave Martin 	unsigned long addr __always_unused)
448ef8f360SDave Martin {
458ef8f360SDave Martin 	unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM;
468ef8f360SDave Martin 
478ef8f360SDave Martin 	if (system_supports_bti())
488ef8f360SDave Martin 		supported |= PROT_BTI;
498ef8f360SDave Martin 
509f341931SCatalin Marinas 	if (system_supports_mte())
519f341931SCatalin Marinas 		supported |= PROT_MTE;
529f341931SCatalin Marinas 
538ef8f360SDave Martin 	return (prot & ~supported) == 0;
548ef8f360SDave Martin }
558ef8f360SDave Martin #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
568ef8f360SDave Martin 
arch_validate_flags(unsigned long vm_flags)5700420905SCatalin Marinas static inline bool arch_validate_flags(unsigned long vm_flags)
5800420905SCatalin Marinas {
5900420905SCatalin Marinas 	if (!system_supports_mte())
6000420905SCatalin Marinas 		return true;
6100420905SCatalin Marinas 
6200420905SCatalin Marinas 	/* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */
6300420905SCatalin Marinas 	return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED);
6400420905SCatalin Marinas }
6500420905SCatalin Marinas #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
6600420905SCatalin Marinas 
678ef8f360SDave Martin #endif /* ! __ASM_MMAN_H__ */
68