mman.h 2.0 KB

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