mman.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_vm_get_page_prot(vm_flags) sparc_vm_get_page_prot(vm_flags)
  41. static inline pgprot_t sparc_vm_get_page_prot(unsigned long vm_flags)
  42. {
  43. return (vm_flags & VM_SPARC_ADI) ? __pgprot(_PAGE_MCD_4V) : __pgprot(0);
  44. }
  45. #define arch_validate_prot(prot, addr) sparc_validate_prot(prot, addr)
  46. static inline int sparc_validate_prot(unsigned long prot, unsigned long addr)
  47. {
  48. if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_ADI))
  49. return 0;
  50. if (prot & PROT_ADI) {
  51. if (!adi_capable())
  52. return 0;
  53. if (addr) {
  54. struct vm_area_struct *vma;
  55. vma = find_vma(current->mm, addr);
  56. if (vma) {
  57. /* ADI can not be enabled on PFN
  58. * mapped pages
  59. */
  60. if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
  61. return 0;
  62. /* Mergeable pages can become unmergeable
  63. * if ADI is enabled on them even if they
  64. * have identical data on them. This can be
  65. * because ADI enabled pages with identical
  66. * data may still not have identical ADI
  67. * tags on them. Disallow ADI on mergeable
  68. * pages.
  69. */
  70. if (vma->vm_flags & VM_MERGEABLE)
  71. return 0;
  72. }
  73. }
  74. }
  75. return 1;
  76. }
  77. #endif /* CONFIG_SPARC64 */
  78. #endif /* __ASSEMBLY__ */
  79. #endif /* __SPARC_MMAN_H__ */