tlb.h 3.0 KB

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