• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_MMAN_H__
3 #define __ASM_MMAN_H__
4 
5 #include <linux/compiler.h>
6 #include <linux/fs.h>
7 #include <linux/shmem_fs.h>
8 #include <linux/types.h>
9 #include <uapi/asm/mman.h>
10 
arch_calc_vm_prot_bits(unsigned long prot,unsigned long pkey __always_unused)11 static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot,
12 	unsigned long pkey __always_unused)
13 {
14 	unsigned long ret = 0;
15 
16 	if (system_supports_bti() && (prot & PROT_BTI))
17 		ret |= VM_ARM64_BTI;
18 
19 	if (system_supports_mte() && (prot & PROT_MTE))
20 		ret |= VM_MTE;
21 
22 	return ret;
23 }
24 #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey)
25 
arch_calc_vm_flag_bits(struct file * file,unsigned long flags)26 static inline unsigned long arch_calc_vm_flag_bits(struct file *file,
27 						   unsigned long flags)
28 {
29 	/*
30 	 * Only allow MTE on anonymous mappings as these are guaranteed to be
31 	 * backed by tags-capable memory. The vm_flags may be overridden by a
32 	 * filesystem supporting MTE (RAM-based).
33 	 */
34 	if (system_supports_mte()) {
35 		if ((flags & MAP_ANONYMOUS) && !(flags & MAP_HUGETLB))
36 			return VM_MTE_ALLOWED;
37 		if (shmem_file(file))
38 			return VM_MTE_ALLOWED;
39 	}
40 
41 	return 0;
42 }
43 #define arch_calc_vm_flag_bits(file, flags) arch_calc_vm_flag_bits(file, flags)
44 
arch_validate_prot(unsigned long prot,unsigned long addr __always_unused)45 static inline bool arch_validate_prot(unsigned long prot,
46 	unsigned long addr __always_unused)
47 {
48 	unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM;
49 
50 	if (system_supports_bti())
51 		supported |= PROT_BTI;
52 
53 	if (system_supports_mte())
54 		supported |= PROT_MTE;
55 
56 	return (prot & ~supported) == 0;
57 }
58 #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
59 
arch_validate_flags(unsigned long vm_flags)60 static inline bool arch_validate_flags(unsigned long vm_flags)
61 {
62 	if (!system_supports_mte())
63 		return true;
64 
65 	/* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */
66 	return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED);
67 }
68 #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
69 
70 #endif /* ! __ASM_MMAN_H__ */
71