tlbflush.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef _S390_TLBFLUSH_H
  2. #define _S390_TLBFLUSH_H
  3. #include <linux/mm.h>
  4. #include <asm/processor.h>
  5. #include <asm/pgalloc.h>
  6. /*
  7. * Flush all tlb entries on the local cpu.
  8. */
  9. static inline void __tlb_flush_local(void)
  10. {
  11. asm volatile("ptlb" : : : "memory");
  12. }
  13. #ifdef CONFIG_SMP
  14. /*
  15. * Flush all tlb entries on all cpus.
  16. */
  17. void smp_ptlb_all(void);
  18. static inline void __tlb_flush_global(void)
  19. {
  20. register unsigned long reg2 asm("2");
  21. register unsigned long reg3 asm("3");
  22. register unsigned long reg4 asm("4");
  23. long dummy;
  24. #ifndef __s390x__
  25. if (!MACHINE_HAS_CSP) {
  26. smp_ptlb_all();
  27. return;
  28. }
  29. #endif /* __s390x__ */
  30. dummy = 0;
  31. reg2 = reg3 = 0;
  32. reg4 = ((unsigned long) &dummy) + 1;
  33. asm volatile(
  34. " csp %0,%2"
  35. : : "d" (reg2), "d" (reg3), "d" (reg4), "m" (dummy) : "cc" );
  36. }
  37. static inline void __tlb_flush_full(struct mm_struct *mm)
  38. {
  39. cpumask_t local_cpumask;
  40. preempt_disable();
  41. /*
  42. * If the process only ran on the local cpu, do a local flush.
  43. */
  44. local_cpumask = cpumask_of_cpu(smp_processor_id());
  45. if (cpus_equal(mm->cpu_vm_mask, local_cpumask))
  46. __tlb_flush_local();
  47. else
  48. __tlb_flush_global();
  49. preempt_enable();
  50. }
  51. #else
  52. #define __tlb_flush_full(mm) __tlb_flush_local()
  53. #endif
  54. /*
  55. * Flush all tlb entries of a page table on all cpus.
  56. */
  57. static inline void __tlb_flush_idte(unsigned long asce)
  58. {
  59. asm volatile(
  60. " .insn rrf,0xb98e0000,0,%0,%1,0"
  61. : : "a" (2048), "a" (asce) : "cc" );
  62. }
  63. static inline void __tlb_flush_mm(struct mm_struct * mm)
  64. {
  65. if (unlikely(cpus_empty(mm->cpu_vm_mask)))
  66. return;
  67. /*
  68. * If the machine has IDTE we prefer to do a per mm flush
  69. * on all cpus instead of doing a local flush if the mm
  70. * only ran on the local cpu.
  71. */
  72. if (MACHINE_HAS_IDTE) {
  73. if (mm->context.noexec)
  74. __tlb_flush_idte((unsigned long)
  75. get_shadow_table(mm->pgd) |
  76. mm->context.asce_bits);
  77. __tlb_flush_idte((unsigned long) mm->pgd |
  78. mm->context.asce_bits);
  79. return;
  80. }
  81. __tlb_flush_full(mm);
  82. }
  83. static inline void __tlb_flush_mm_cond(struct mm_struct * mm)
  84. {
  85. if (atomic_read(&mm->mm_users) <= 1 && mm == current->active_mm)
  86. __tlb_flush_mm(mm);
  87. }
  88. /*
  89. * TLB flushing:
  90. * flush_tlb() - flushes the current mm struct TLBs
  91. * flush_tlb_all() - flushes all processes TLBs
  92. * flush_tlb_mm(mm) - flushes the specified mm context TLB's
  93. * flush_tlb_page(vma, vmaddr) - flushes one page
  94. * flush_tlb_range(vma, start, end) - flushes a range of pages
  95. * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
  96. */
  97. /*
  98. * flush_tlb_mm goes together with ptep_set_wrprotect for the
  99. * copy_page_range operation and flush_tlb_range is related to
  100. * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
  101. * ptep_get_and_clear do not flush the TLBs directly if the mm has
  102. * only one user. At the end of the update the flush_tlb_mm and
  103. * flush_tlb_range functions need to do the flush.
  104. */
  105. #define flush_tlb() do { } while (0)
  106. #define flush_tlb_all() do { } while (0)
  107. #define flush_tlb_page(vma, addr) do { } while (0)
  108. static inline void flush_tlb_mm(struct mm_struct *mm)
  109. {
  110. __tlb_flush_mm_cond(mm);
  111. }
  112. static inline void flush_tlb_range(struct vm_area_struct *vma,
  113. unsigned long start, unsigned long end)
  114. {
  115. __tlb_flush_mm_cond(vma->vm_mm);
  116. }
  117. static inline void flush_tlb_kernel_range(unsigned long start,
  118. unsigned long end)
  119. {
  120. __tlb_flush_mm(&init_mm);
  121. }
  122. #endif /* _S390_TLBFLUSH_H */