tlb.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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/pagemap.h>
  24. #include <linux/swap.h>
  25. #include <asm/processor.h>
  26. #include <asm/pgalloc.h>
  27. #include <asm/smp.h>
  28. #include <asm/tlbflush.h>
  29. struct mmu_gather {
  30. struct mm_struct *mm;
  31. unsigned int fullmm;
  32. unsigned int nr_ptes;
  33. unsigned int nr_pxds;
  34. unsigned int max;
  35. void **array;
  36. void *local[8];
  37. };
  38. static inline void __tlb_alloc_page(struct mmu_gather *tlb)
  39. {
  40. unsigned long addr = __get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0);
  41. if (addr) {
  42. tlb->array = (void *) addr;
  43. tlb->max = PAGE_SIZE / sizeof(void *);
  44. }
  45. }
  46. static inline void tlb_gather_mmu(struct mmu_gather *tlb,
  47. struct mm_struct *mm,
  48. unsigned int full_mm_flush)
  49. {
  50. tlb->mm = mm;
  51. tlb->max = ARRAY_SIZE(tlb->local);
  52. tlb->array = tlb->local;
  53. tlb->fullmm = full_mm_flush;
  54. if (tlb->fullmm)
  55. __tlb_flush_mm(mm);
  56. else
  57. __tlb_alloc_page(tlb);
  58. tlb->nr_ptes = 0;
  59. tlb->nr_pxds = tlb->max;
  60. }
  61. static inline void tlb_flush_mmu(struct mmu_gather *tlb)
  62. {
  63. if (!tlb->fullmm && (tlb->nr_ptes > 0 || tlb->nr_pxds < tlb->max))
  64. __tlb_flush_mm(tlb->mm);
  65. while (tlb->nr_ptes > 0)
  66. page_table_free_rcu(tlb->mm, tlb->array[--tlb->nr_ptes]);
  67. while (tlb->nr_pxds < tlb->max)
  68. crst_table_free_rcu(tlb->mm, tlb->array[tlb->nr_pxds++]);
  69. }
  70. static inline void tlb_finish_mmu(struct mmu_gather *tlb,
  71. unsigned long start, unsigned long end)
  72. {
  73. tlb_flush_mmu(tlb);
  74. rcu_table_freelist_finish();
  75. /* keep the page table cache within bounds */
  76. check_pgt_cache();
  77. if (tlb->array != tlb->local)
  78. free_pages((unsigned long) tlb->array, 0);
  79. }
  80. /*
  81. * Release the page cache reference for a pte removed by
  82. * tlb_ptep_clear_flush. In both flush modes the tlb for a page cache page
  83. * has already been freed, so just do free_page_and_swap_cache.
  84. */
  85. static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  86. {
  87. free_page_and_swap_cache(page);
  88. return 1; /* avoid calling tlb_flush_mmu */
  89. }
  90. static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  91. {
  92. free_page_and_swap_cache(page);
  93. }
  94. /*
  95. * pte_free_tlb frees a pte table and clears the CRSTE for the
  96. * page table from the tlb.
  97. */
  98. static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
  99. unsigned long address)
  100. {
  101. if (!tlb->fullmm) {
  102. tlb->array[tlb->nr_ptes++] = pte;
  103. if (tlb->nr_ptes >= tlb->nr_pxds)
  104. tlb_flush_mmu(tlb);
  105. } else
  106. page_table_free(tlb->mm, (unsigned long *) pte);
  107. }
  108. /*
  109. * pmd_free_tlb frees a pmd table and clears the CRSTE for the
  110. * segment table entry from the tlb.
  111. * If the mm uses a two level page table the single pmd is freed
  112. * as the pgd. pmd_free_tlb checks the asce_limit against 2GB
  113. * to avoid the double free of the pmd in this case.
  114. */
  115. static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
  116. unsigned long address)
  117. {
  118. #ifdef __s390x__
  119. if (tlb->mm->context.asce_limit <= (1UL << 31))
  120. return;
  121. if (!tlb->fullmm) {
  122. tlb->array[--tlb->nr_pxds] = pmd;
  123. if (tlb->nr_ptes >= tlb->nr_pxds)
  124. tlb_flush_mmu(tlb);
  125. } else
  126. crst_table_free(tlb->mm, (unsigned long *) pmd);
  127. #endif
  128. }
  129. /*
  130. * pud_free_tlb frees a pud table and clears the CRSTE for the
  131. * region third table entry from the tlb.
  132. * If the mm uses a three level page table the single pud is freed
  133. * as the pgd. pud_free_tlb checks the asce_limit against 4TB
  134. * to avoid the double free of the pud in this case.
  135. */
  136. static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
  137. unsigned long address)
  138. {
  139. #ifdef __s390x__
  140. if (tlb->mm->context.asce_limit <= (1UL << 42))
  141. return;
  142. if (!tlb->fullmm) {
  143. tlb->array[--tlb->nr_pxds] = pud;
  144. if (tlb->nr_ptes >= tlb->nr_pxds)
  145. tlb_flush_mmu(tlb);
  146. } else
  147. crst_table_free(tlb->mm, (unsigned long *) pud);
  148. #endif
  149. }
  150. #define tlb_start_vma(tlb, vma) do { } while (0)
  151. #define tlb_end_vma(tlb, vma) do { } while (0)
  152. #define tlb_remove_tlb_entry(tlb, ptep, addr) do { } while (0)
  153. #define tlb_migrate_finish(mm) do { } while (0)
  154. #endif /* _S390_TLB_H */