tlb.h 3.1 KB

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