tlb.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifndef _S390_TLB_H
  2. #define _S390_TLB_H
  3. /*
  4. * TLB flushing on s390 is complicated. The following requirement
  5. * from the principles of operation is the most arduous:
  6. *
  7. * "A valid table entry must not be changed while it is attached
  8. * to any CPU and may be used for translation by that CPU except to
  9. * (1) invalidate the entry by using INVALIDATE PAGE TABLE ENTRY,
  10. * or INVALIDATE DAT TABLE ENTRY, (2) alter bits 56-63 of a page
  11. * table entry, or (3) make a change by means of a COMPARE AND SWAP
  12. * AND PURGE instruction that purges the TLB."
  13. *
  14. * The modification of a pte of an active mm struct therefore is
  15. * a two step process: i) invalidate the pte, ii) store the new pte.
  16. * This is true for the page protection bit as well.
  17. * The only possible optimization is to flush at the beginning of
  18. * a tlb_gather_mmu cycle if the mm_struct is currently not in use.
  19. *
  20. * Pages used for the page tables is a different story. FIXME: more
  21. */
  22. #include <linux/mm.h>
  23. #include <linux/swap.h>
  24. #include <asm/processor.h>
  25. #include <asm/pgalloc.h>
  26. #include <asm/smp.h>
  27. #include <asm/tlbflush.h>
  28. #ifndef CONFIG_SMP
  29. #define TLB_NR_PTRS 1
  30. #else
  31. #define TLB_NR_PTRS 508
  32. #endif
  33. struct mmu_gather {
  34. struct mm_struct *mm;
  35. unsigned int fullmm;
  36. unsigned int nr_ptes;
  37. unsigned int nr_pxds;
  38. void *array[TLB_NR_PTRS];
  39. };
  40. DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
  41. static inline struct mmu_gather *tlb_gather_mmu(struct mm_struct *mm,
  42. unsigned int full_mm_flush)
  43. {
  44. struct mmu_gather *tlb = &get_cpu_var(mmu_gathers);
  45. tlb->mm = mm;
  46. tlb->fullmm = full_mm_flush || (num_online_cpus() == 1) ||
  47. (atomic_read(&mm->mm_users) <= 1 && mm == current->active_mm);
  48. tlb->nr_ptes = 0;
  49. tlb->nr_pxds = TLB_NR_PTRS;
  50. if (tlb->fullmm)
  51. __tlb_flush_mm(mm);
  52. return tlb;
  53. }
  54. static inline void tlb_flush_mmu(struct mmu_gather *tlb,
  55. unsigned long start, unsigned long end)
  56. {
  57. if (!tlb->fullmm && (tlb->nr_ptes > 0 || tlb->nr_pxds < TLB_NR_PTRS))
  58. __tlb_flush_mm(tlb->mm);
  59. while (tlb->nr_ptes > 0)
  60. pte_free(tlb->mm, tlb->array[--tlb->nr_ptes]);
  61. while (tlb->nr_pxds < TLB_NR_PTRS)
  62. /* pgd_free frees the pointer as region or segment table */
  63. pgd_free(tlb->mm, tlb->array[tlb->nr_pxds++]);
  64. }
  65. static inline void tlb_finish_mmu(struct mmu_gather *tlb,
  66. unsigned long start, unsigned long end)
  67. {
  68. tlb_flush_mmu(tlb, start, end);
  69. /* keep the page table cache within bounds */
  70. check_pgt_cache();
  71. put_cpu_var(mmu_gathers);
  72. }
  73. /*
  74. * Release the page cache reference for a pte removed by
  75. * tlb_ptep_clear_flush. In both flush modes the tlb fo a page cache page
  76. * has already been freed, so just do free_page_and_swap_cache.
  77. */
  78. static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  79. {
  80. free_page_and_swap_cache(page);
  81. }
  82. /*
  83. * pte_free_tlb frees a pte table and clears the CRSTE for the
  84. * page table from the tlb.
  85. */
  86. static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte)
  87. {
  88. if (!tlb->fullmm) {
  89. tlb->array[tlb->nr_ptes++] = pte;
  90. if (tlb->nr_ptes >= tlb->nr_pxds)
  91. tlb_flush_mmu(tlb, 0, 0);
  92. } else
  93. pte_free(tlb->mm, pte);
  94. }
  95. /*
  96. * pmd_free_tlb frees a pmd table and clears the CRSTE for the
  97. * segment table entry from the tlb.
  98. * If the mm uses a two level page table the single pmd is freed
  99. * as the pgd. pmd_free_tlb checks the asce_limit against 2GB
  100. * to avoid the double free of the pmd in this case.
  101. */
  102. static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
  103. {
  104. #ifdef __s390x__
  105. if (tlb->mm->context.asce_limit <= (1UL << 31))
  106. return;
  107. if (!tlb->fullmm) {
  108. tlb->array[--tlb->nr_pxds] = pmd;
  109. if (tlb->nr_ptes >= tlb->nr_pxds)
  110. tlb_flush_mmu(tlb, 0, 0);
  111. } else
  112. pmd_free(tlb->mm, pmd);
  113. #endif
  114. }
  115. /*
  116. * pud_free_tlb frees a pud table and clears the CRSTE for the
  117. * region third table entry from the tlb.
  118. * If the mm uses a three level page table the single pud is freed
  119. * as the pgd. pud_free_tlb checks the asce_limit against 4TB
  120. * to avoid the double free of the pud in this case.
  121. */
  122. static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud)
  123. {
  124. #ifdef __s390x__
  125. if (tlb->mm->context.asce_limit <= (1UL << 42))
  126. return;
  127. if (!tlb->fullmm) {
  128. tlb->array[--tlb->nr_pxds] = pud;
  129. if (tlb->nr_ptes >= tlb->nr_pxds)
  130. tlb_flush_mmu(tlb, 0, 0);
  131. } else
  132. pud_free(tlb->mm, pud);
  133. #endif
  134. }
  135. #define tlb_start_vma(tlb, vma) do { } while (0)
  136. #define tlb_end_vma(tlb, vma) do { } while (0)
  137. #define tlb_remove_tlb_entry(tlb, ptep, addr) do { } while (0)
  138. #define tlb_migrate_finish(mm) do { } while (0)
  139. #endif /* _S390_TLB_H */