mman.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ((flags & MAP_ANONYMOUS) || shmem_file(file)))
  38. return VM_MTE_ALLOWED;
  39. return 0;
  40. }
  41. #define arch_calc_vm_flag_bits(file, flags) arch_calc_vm_flag_bits(file, flags)
  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. if (system_supports_bti())
  47. supported |= PROT_BTI;
  48. if (system_supports_mte())
  49. supported |= PROT_MTE;
  50. return (prot & ~supported) == 0;
  51. }
  52. #define arch_validate_prot(prot, addr) arch_validate_prot(prot, addr)
  53. static inline bool arch_validate_flags(unsigned long vm_flags)
  54. {
  55. if (!system_supports_mte())
  56. return true;
  57. /* only allow VM_MTE if VM_MTE_ALLOWED has been set previously */
  58. return !(vm_flags & VM_MTE) || (vm_flags & VM_MTE_ALLOWED);
  59. }
  60. #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
  61. #endif /* !BUILD_VDSO */
  62. #endif /* ! __ASM_MMAN_H__ */