tlb.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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(struct mmu_gather *tlb)
  52. {
  53. if (!tlb->need_flush)
  54. return;
  55. flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end);
  56. init_tlb_gather(tlb);
  57. }
  58. /* tlb_finish_mmu
  59. * Called at the end of the shootdown operation to free up any resources
  60. * that were required.
  61. */
  62. static inline void
  63. tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
  64. {
  65. tlb_flush_mmu(tlb);
  66. /* keep the page table cache within bounds */
  67. check_pgt_cache();
  68. }
  69. /* tlb_remove_page
  70. * Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)),
  71. * while handling the additional races in SMP caused by other CPUs
  72. * caching valid mappings in their TLBs.
  73. */
  74. static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  75. {
  76. tlb->need_flush = 1;
  77. free_page_and_swap_cache(page);
  78. return 1; /* avoid calling tlb_flush_mmu */
  79. }
  80. static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  81. {
  82. __tlb_remove_page(tlb, page);
  83. }
  84. /**
  85. * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
  86. *
  87. * Record the fact that pte's were really umapped in ->need_flush, so we can
  88. * later optimise away the tlb invalidate. This helps when userspace is
  89. * unmapping already-unmapped pages, which happens quite a lot.
  90. */
  91. #define tlb_remove_tlb_entry(tlb, ptep, address) \
  92. do { \
  93. tlb->need_flush = 1; \
  94. __tlb_remove_tlb_entry(tlb, ptep, address); \
  95. } while (0)
  96. #define pte_free_tlb(tlb, ptep, addr) __pte_free_tlb(tlb, ptep, addr)
  97. #define pud_free_tlb(tlb, pudp, addr) __pud_free_tlb(tlb, pudp, addr)
  98. #define pmd_free_tlb(tlb, pmdp, addr) __pmd_free_tlb(tlb, pmdp, addr)
  99. #define tlb_migrate_finish(mm) do {} while (0)
  100. #endif