tlbflush.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef _S390_TLBFLUSH_H
  2. #define _S390_TLBFLUSH_H
  3. #include <linux/mm.h>
  4. #include <linux/sched.h>
  5. #include <asm/processor.h>
  6. #include <asm/pgalloc.h>
  7. #include <asm/pgtable.h>
  8. /*
  9. * Flush all TLB entries on the local CPU.
  10. */
  11. static inline void __tlb_flush_local(void)
  12. {
  13. asm volatile("ptlb" : : : "memory");
  14. }
  15. /*
  16. * Flush TLB entries for a specific ASCE on all CPUs
  17. */
  18. static inline void __tlb_flush_idte(unsigned long asce)
  19. {
  20. /* Global TLB flush for the mm */
  21. asm volatile(
  22. " .insn rrf,0xb98e0000,0,%0,%1,0"
  23. : : "a" (2048), "a" (asce) : "cc");
  24. }
  25. #ifdef CONFIG_SMP
  26. void smp_ptlb_all(void);
  27. /*
  28. * Flush all TLB entries on all CPUs.
  29. */
  30. static inline void __tlb_flush_global(void)
  31. {
  32. unsigned int dummy = 0;
  33. csp(&dummy, 0, 0);
  34. }
  35. /*
  36. * Flush TLB entries for a specific mm on all CPUs (in case gmap is used
  37. * this implicates multiple ASCEs!).
  38. */
  39. static inline void __tlb_flush_mm(struct mm_struct *mm)
  40. {
  41. unsigned long gmap_asce;
  42. /*
  43. * If the machine has IDTE we prefer to do a per mm flush
  44. * on all cpus instead of doing a local flush if the mm
  45. * only ran on the local cpu.
  46. */
  47. preempt_disable();
  48. atomic_inc(&mm->context.flush_count);
  49. /* Reset TLB flush mask */
  50. cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
  51. barrier();
  52. gmap_asce = READ_ONCE(mm->context.gmap_asce);
  53. if (MACHINE_HAS_IDTE && gmap_asce != -1UL) {
  54. if (gmap_asce)
  55. __tlb_flush_idte(gmap_asce);
  56. __tlb_flush_idte(mm->context.asce);
  57. } else {
  58. /* Global TLB flush */
  59. __tlb_flush_global();
  60. }
  61. atomic_dec(&mm->context.flush_count);
  62. preempt_enable();
  63. }
  64. static inline void __tlb_flush_kernel(void)
  65. {
  66. if (MACHINE_HAS_IDTE)
  67. __tlb_flush_idte(init_mm.context.asce);
  68. else
  69. __tlb_flush_global();
  70. }
  71. #else
  72. #define __tlb_flush_global() __tlb_flush_local()
  73. /*
  74. * Flush TLB entries for a specific ASCE on all CPUs.
  75. */
  76. static inline void __tlb_flush_mm(struct mm_struct *mm)
  77. {
  78. __tlb_flush_local();
  79. }
  80. static inline void __tlb_flush_kernel(void)
  81. {
  82. __tlb_flush_local();
  83. }
  84. #endif
  85. static inline void __tlb_flush_mm_lazy(struct mm_struct * mm)
  86. {
  87. spin_lock(&mm->context.lock);
  88. if (mm->context.flush_mm) {
  89. mm->context.flush_mm = 0;
  90. __tlb_flush_mm(mm);
  91. }
  92. spin_unlock(&mm->context.lock);
  93. }
  94. /*
  95. * TLB flushing:
  96. * flush_tlb() - flushes the current mm struct TLBs
  97. * flush_tlb_all() - flushes all processes TLBs
  98. * flush_tlb_mm(mm) - flushes the specified mm context TLB's
  99. * flush_tlb_page(vma, vmaddr) - flushes one page
  100. * flush_tlb_range(vma, start, end) - flushes a range of pages
  101. * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
  102. */
  103. /*
  104. * flush_tlb_mm goes together with ptep_set_wrprotect for the
  105. * copy_page_range operation and flush_tlb_range is related to
  106. * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
  107. * ptep_get_and_clear do not flush the TLBs directly if the mm has
  108. * only one user. At the end of the update the flush_tlb_mm and
  109. * flush_tlb_range functions need to do the flush.
  110. */
  111. #define flush_tlb() do { } while (0)
  112. #define flush_tlb_all() do { } while (0)
  113. #define flush_tlb_page(vma, addr) do { } while (0)
  114. static inline void flush_tlb_mm(struct mm_struct *mm)
  115. {
  116. __tlb_flush_mm_lazy(mm);
  117. }
  118. static inline void flush_tlb_range(struct vm_area_struct *vma,
  119. unsigned long start, unsigned long end)
  120. {
  121. __tlb_flush_mm_lazy(vma->vm_mm);
  122. }
  123. static inline void flush_tlb_kernel_range(unsigned long start,
  124. unsigned long end)
  125. {
  126. __tlb_flush_kernel();
  127. }
  128. #endif /* _S390_TLBFLUSH_H */