tlb.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /* Users of the generic TLB shootdown code must declare this storage space. */
  22. DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
  23. static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep,
  24. unsigned long address)
  25. {
  26. if (tlb->start > address)
  27. tlb->start = address;
  28. if (tlb->end < address + PAGE_SIZE)
  29. tlb->end = address + PAGE_SIZE;
  30. }
  31. static inline void init_tlb_gather(struct mmu_gather *tlb)
  32. {
  33. tlb->need_flush = 0;
  34. tlb->start = TASK_SIZE;
  35. tlb->end = 0;
  36. if (tlb->fullmm) {
  37. tlb->start = 0;
  38. tlb->end = TASK_SIZE;
  39. }
  40. }
  41. /* tlb_gather_mmu
  42. * Return a pointer to an initialized struct mmu_gather.
  43. */
  44. static inline struct mmu_gather *
  45. tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush)
  46. {
  47. struct mmu_gather *tlb = &get_cpu_var(mmu_gathers);
  48. tlb->mm = mm;
  49. tlb->fullmm = full_mm_flush;
  50. init_tlb_gather(tlb);
  51. return tlb;
  52. }
  53. extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
  54. unsigned long end);
  55. static inline void
  56. tlb_flush_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
  57. {
  58. if (!tlb->need_flush)
  59. return;
  60. flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end);
  61. init_tlb_gather(tlb);
  62. }
  63. /* tlb_finish_mmu
  64. * Called at the end of the shootdown operation to free up any resources
  65. * that were required.
  66. */
  67. static inline void
  68. tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
  69. {
  70. tlb_flush_mmu(tlb, start, end);
  71. /* keep the page table cache within bounds */
  72. check_pgt_cache();
  73. put_cpu_var(mmu_gathers);
  74. }
  75. /* tlb_remove_page
  76. * Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)),
  77. * while handling the additional races in SMP caused by other CPUs
  78. * caching valid mappings in their TLBs.
  79. */
  80. static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  81. {
  82. tlb->need_flush = 1;
  83. free_page_and_swap_cache(page);
  84. return;
  85. }
  86. /**
  87. * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
  88. *
  89. * Record the fact that pte's were really umapped in ->need_flush, so we can
  90. * later optimise away the tlb invalidate. This helps when userspace is
  91. * unmapping already-unmapped pages, which happens quite a lot.
  92. */
  93. #define tlb_remove_tlb_entry(tlb, ptep, address) \
  94. do { \
  95. tlb->need_flush = 1; \
  96. __tlb_remove_tlb_entry(tlb, ptep, address); \
  97. } while (0)
  98. #define pte_free_tlb(tlb, ptep, addr) __pte_free_tlb(tlb, ptep, addr)
  99. #define pud_free_tlb(tlb, pudp, addr) __pud_free_tlb(tlb, pudp, addr)
  100. #define pmd_free_tlb(tlb, pmdp, addr) __pmd_free_tlb(tlb, pmdp, addr)
  101. #define tlb_migrate_finish(mm) do {} while (0)
  102. #endif