mman.h 1.7 KB

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