tlb.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/tlbflush.h>
  28. struct mmu_gather {
  29. struct mm_struct *mm;
  30. struct mmu_table_batch *batch;
  31. unsigned int fullmm;
  32. unsigned long start, end;
  33. };
  34. struct mmu_table_batch {
  35. struct rcu_head rcu;
  36. unsigned int nr;
  37. void *tables[0];
  38. };
  39. #define MAX_TABLE_BATCH \
  40. ((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *))
  41. extern void tlb_table_flush(struct mmu_gather *tlb);
  42. extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
  43. static inline void tlb_gather_mmu(struct mmu_gather *tlb,
  44. struct mm_struct *mm,
  45. unsigned long start,
  46. unsigned long end)
  47. {
  48. tlb->mm = mm;
  49. tlb->start = start;
  50. tlb->end = end;
  51. tlb->fullmm = !(start | (end+1));
  52. tlb->batch = NULL;
  53. if (tlb->fullmm)
  54. __tlb_flush_mm(mm);
  55. }
  56. static inline void tlb_flush_mmu(struct mmu_gather *tlb)
  57. {
  58. __tlb_flush_mm_lazy(tlb->mm);
  59. tlb_table_flush(tlb);
  60. }
  61. static inline void tlb_finish_mmu(struct mmu_gather *tlb,
  62. unsigned long start, unsigned long end)
  63. {
  64. tlb_flush_mmu(tlb);
  65. }
  66. /*
  67. * Release the page cache reference for a pte removed by
  68. * tlb_ptep_clear_flush. In both flush modes the tlb for a page cache page
  69. * has already been freed, so just do free_page_and_swap_cache.
  70. */
  71. static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  72. {
  73. free_page_and_swap_cache(page);
  74. return 1; /* avoid calling tlb_flush_mmu */
  75. }
  76. static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  77. {
  78. free_page_and_swap_cache(page);
  79. }
  80. /*
  81. * pte_free_tlb frees a pte table and clears the CRSTE for the
  82. * page table from the tlb.
  83. */
  84. static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
  85. unsigned long address)
  86. {
  87. if (!tlb->fullmm)
  88. return page_table_free_rcu(tlb, (unsigned long *) pte);
  89. page_table_free(tlb->mm, (unsigned long *) pte);
  90. }
  91. /*
  92. * pmd_free_tlb frees a pmd table and clears the CRSTE for the
  93. * segment table entry from the tlb.
  94. * If the mm uses a two level page table the single pmd is freed
  95. * as the pgd. pmd_free_tlb checks the asce_limit against 2GB
  96. * to avoid the double free of the pmd in this case.
  97. */
  98. static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
  99. unsigned long address)
  100. {
  101. #ifdef CONFIG_64BIT
  102. if (tlb->mm->context.asce_limit <= (1UL << 31))
  103. return;
  104. if (!tlb->fullmm)
  105. return tlb_remove_table(tlb, pmd);
  106. crst_table_free(tlb->mm, (unsigned long *) pmd);
  107. #endif
  108. }
  109. /*
  110. * pud_free_tlb frees a pud table and clears the CRSTE for the
  111. * region third table entry from the tlb.
  112. * If the mm uses a three level page table the single pud is freed
  113. * as the pgd. pud_free_tlb checks the asce_limit against 4TB
  114. * to avoid the double free of the pud in this case.
  115. */
  116. static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
  117. unsigned long address)
  118. {
  119. #ifdef CONFIG_64BIT
  120. if (tlb->mm->context.asce_limit <= (1UL << 42))
  121. return;
  122. if (!tlb->fullmm)
  123. return tlb_remove_table(tlb, pud);
  124. crst_table_free(tlb->mm, (unsigned long *) pud);
  125. #endif
  126. }
  127. #define tlb_start_vma(tlb, vma) do { } while (0)
  128. #define tlb_end_vma(tlb, vma) do { } while (0)
  129. #define tlb_remove_tlb_entry(tlb, ptep, addr) do { } while (0)
  130. #define tlb_remove_pmd_tlb_entry(tlb, pmdp, addr) do { } while (0)
  131. #define tlb_migrate_finish(mm) do { } while (0)
  132. #endif /* _S390_TLB_H */