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 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 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 ((flags & MAP_ANONYMOUS) || shmem_file(file))) 36 return VM_MTE_ALLOWED; 37 38 return 0; 39 } 40 #define arch_calc_vm_flag_bits(file, flags) arch_calc_vm_flag_bits(file, flags) 41 42 static inline bool arch_validate_prot(unsigned long prot, 43 unsigned long addr __always_unused) 44 { 45 unsigned long supported = PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM; 46 47 if (system_supports_bti()) 48 supported |= PROT_BTI; 49 50 if (system_supports_mte()) 51 supported |= PROT_MTE; 52 53 return (prot & ~supported) == 0; 54 } 55 #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr) 56 57 static inline bool arch_validate_flags(unsigned long vm_flags) 58 { 59 if (!system_supports_mte()) 60 return true; 61 62 /* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */ 63 return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED); 64 } 65 #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags) 66 67 #endif /* ! __ASM_MMAN_H__ */ 68