mman.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __SPARC_MMAN_H__
  3. #define __SPARC_MMAN_H__
  4. #include <uapi/asm/mman.h>
  5. #ifndef __ASSEMBLY__
  6. #define arch_mmap_check(addr,len,flags) sparc_mmap_check(addr,len)
  7. int sparc_mmap_check(unsigned long addr, unsigned long len);
  8. #ifdef CONFIG_SPARC64
  9. #include <asm/adi_64.h>
  10. static inline void ipi_set_tstate_mcde(void *arg)
  11. {
  12. struct mm_struct *mm = arg;
  13. /* Set TSTATE_MCDE for the task using address map that ADI has been
  14. * enabled on if the task is running. If not, it will be set
  15. * automatically at the next context switch
  16. */
  17. if (current->mm == mm) {
  18. struct pt_regs *regs;
  19. regs = task_pt_regs(current);
  20. regs->tstate |= TSTATE_MCDE;
  21. }
  22. }
  23. #define arch_calc_vm_prot_bits(prot, pkey) sparc_calc_vm_prot_bits(prot)
  24. static inline unsigned long sparc_calc_vm_prot_bits(unsigned long prot)
  25. {
  26. if (adi_capable() && (prot & PROT_ADI)) {
  27. struct pt_regs *regs;
  28. if (!current->mm->context.adi) {
  29. regs = task_pt_regs(current);
  30. regs->tstate |= TSTATE_MCDE;
  31. current->mm->context.adi = true;
  32. on_each_cpu_mask(mm_cpumask(current->mm),
  33. ipi_set_tstate_mcde, current->mm, 0);
  34. }
  35. return VM_SPARC_ADI;
  36. } else {
  37. return 0;
  38. }
  39. }
  40. #define arch_validate_prot(prot, addr) sparc_validate_prot(prot, addr)
  41. static inline int sparc_validate_prot(unsigned long prot, unsigned long addr)
  42. {
  43. if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_ADI))
  44. return 0;
  45. return 1;
  46. }
  47. #define arch_validate_flags(vm_flags) arch_validate_flags(vm_flags)
  48. /* arch_validate_flags() - Ensure combination of flags is valid for a
  49. * VMA.
  50. */
  51. static inline bool arch_validate_flags(unsigned long vm_flags)
  52. {
  53. /* If ADI is being enabled on this VMA, check for ADI
  54. * capability on the platform and ensure VMA is suitable
  55. * for ADI
  56. */
  57. if (vm_flags & VM_SPARC_ADI) {
  58. if (!adi_capable())
  59. return false;
  60. /* ADI can not be enabled on PFN mapped pages */
  61. if (vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
  62. return false;
  63. /* Mergeable pages can become unmergeable
  64. * if ADI is enabled on them even if they
  65. * have identical data on them. This can be
  66. * because ADI enabled pages with identical
  67. * data may still not have identical ADI
  68. * tags on them. Disallow ADI on mergeable
  69. * pages.
  70. */
  71. if (vm_flags & VM_MERGEABLE)
  72. return false;
  73. }
  74. return true;
  75. }
  76. #endif /* CONFIG_SPARC64 */
  77. #endif /* __ASSEMBLY__ */
  78. #endif /* __SPARC_MMAN_H__ */