tlb.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_pmds;
  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_pmds = 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_pmds < TLB_NR_PTRS))
  58. __tlb_flush_mm(tlb->mm);
  59. while (tlb->nr_ptes > 0)
  60. pte_free(tlb->array[--tlb->nr_ptes]);
  61. while (tlb->nr_pmds < TLB_NR_PTRS)
  62. pmd_free((pmd_t *) tlb->array[tlb->nr_pmds++]);
  63. }
  64. static inline void tlb_finish_mmu(struct mmu_gather *tlb,
  65. unsigned long start, unsigned long end)
  66. {
  67. tlb_flush_mmu(tlb, start, end);
  68. /* keep the page table cache within bounds */
  69. check_pgt_cache();
  70. put_cpu_var(mmu_gathers);
  71. }
  72. /*
  73. * Release the page cache reference for a pte removed by
  74. * tlb_ptep_clear_flush. In both flush modes the tlb fo a page cache page
  75. * has already been freed, so just do free_page_and_swap_cache.
  76. */
  77. static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  78. {
  79. free_page_and_swap_cache(page);
  80. }
  81. /*
  82. * pte_free_tlb frees a pte table and clears the CRSTE for the
  83. * page table from the tlb.
  84. */
  85. static inline void pte_free_tlb(struct mmu_gather *tlb, struct page *page)
  86. {
  87. if (!tlb->fullmm) {
  88. tlb->array[tlb->nr_ptes++] = page;
  89. if (tlb->nr_ptes >= tlb->nr_pmds)
  90. tlb_flush_mmu(tlb, 0, 0);
  91. } else
  92. pte_free(page);
  93. }
  94. /*
  95. * pmd_free_tlb frees a pmd table and clears the CRSTE for the
  96. * segment table entry from the tlb.
  97. */
  98. static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
  99. {
  100. #ifdef __s390x__
  101. if (!tlb->fullmm) {
  102. tlb->array[--tlb->nr_pmds] = (struct page *) pmd;
  103. if (tlb->nr_ptes >= tlb->nr_pmds)
  104. tlb_flush_mmu(tlb, 0, 0);
  105. } else
  106. pmd_free(pmd);
  107. #endif
  108. }
  109. #define pud_free_tlb(tlb, pud) do { } while (0)
  110. #define tlb_start_vma(tlb, vma) do { } while (0)
  111. #define tlb_end_vma(tlb, vma) do { } while (0)
  112. #define tlb_remove_tlb_entry(tlb, ptep, addr) do { } while (0)
  113. #define tlb_migrate_finish(mm) do { } while (0)
  114. #endif /* _S390_TLB_H */