tlb.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef __UM_TLB_H
  2. #define __UM_TLB_H
  3. #include <linux/pagemap.h>
  4. #include <linux/swap.h>
  5. #include <asm/percpu.h>
  6. #include <asm/pgalloc.h>
  7. #include <asm/tlbflush.h>
  8. #define tlb_start_vma(tlb, vma) do { } while (0)
  9. #define tlb_end_vma(tlb, vma) do { } while (0)
  10. #define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
  11. /* struct mmu_gather is an opaque type used by the mm code for passing around
  12. * any data needed by arch specific code for tlb_remove_page.
  13. */
  14. struct mmu_gather {
  15. struct mm_struct *mm;
  16. unsigned int need_flush; /* Really unmapped some ptes? */
  17. unsigned long start;
  18. unsigned long end;
  19. unsigned int fullmm; /* non-zero means full mm flush */
  20. };
  21. static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep,
  22. unsigned long address)
  23. {
  24. if (tlb->start > address)
  25. tlb->start = address;
  26. if (tlb->end < address + PAGE_SIZE)
  27. tlb->end = address + PAGE_SIZE;
  28. }
  29. static inline void init_tlb_gather(struct mmu_gather *tlb)
  30. {
  31. tlb->need_flush = 0;
  32. tlb->start = TASK_SIZE;
  33. tlb->end = 0;
  34. if (tlb->fullmm) {
  35. tlb->start = 0;
  36. tlb->end = TASK_SIZE;
  37. }
  38. }
  39. static inline void
  40. tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
  41. {
  42. tlb->mm = mm;
  43. tlb->start = start;
  44. tlb->end = end;
  45. tlb->fullmm = !(start | (end+1));
  46. init_tlb_gather(tlb);
  47. }
  48. extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
  49. unsigned long end);
  50. static inline void
  51. tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
  52. {
  53. flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end);
  54. }
  55. static inline void
  56. tlb_flush_mmu_free(struct mmu_gather *tlb)
  57. {
  58. init_tlb_gather(tlb);
  59. }
  60. static inline void
  61. tlb_flush_mmu(struct mmu_gather *tlb)
  62. {
  63. if (!tlb->need_flush)
  64. return;
  65. tlb_flush_mmu_tlbonly(tlb);
  66. tlb_flush_mmu_free(tlb);
  67. }
  68. /* tlb_finish_mmu
  69. * Called at the end of the shootdown operation to free up any resources
  70. * that were required.
  71. */
  72. static inline void
  73. tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
  74. {
  75. tlb_flush_mmu(tlb);
  76. /* keep the page table cache within bounds */
  77. check_pgt_cache();
  78. }
  79. /* tlb_remove_page
  80. * Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)),
  81. * while handling the additional races in SMP caused by other CPUs
  82. * caching valid mappings in their TLBs.
  83. */
  84. static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  85. {
  86. tlb->need_flush = 1;
  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. __tlb_remove_page(tlb, page);
  93. }
  94. /**
  95. * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
  96. *
  97. * Record the fact that pte's were really umapped in ->need_flush, so we can
  98. * later optimise away the tlb invalidate. This helps when userspace is
  99. * unmapping already-unmapped pages, which happens quite a lot.
  100. */
  101. #define tlb_remove_tlb_entry(tlb, ptep, address) \
  102. do { \
  103. tlb->need_flush = 1; \
  104. __tlb_remove_tlb_entry(tlb, ptep, address); \
  105. } while (0)
  106. #define pte_free_tlb(tlb, ptep, addr) __pte_free_tlb(tlb, ptep, addr)
  107. #define pud_free_tlb(tlb, pudp, addr) __pud_free_tlb(tlb, pudp, addr)
  108. #define pmd_free_tlb(tlb, pmdp, addr) __pmd_free_tlb(tlb, pmdp, addr)
  109. #define tlb_migrate_finish(mm) do {} while (0)
  110. #endif