tlbflush.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef _X8664_TLBFLUSH_H
  2. #define _X8664_TLBFLUSH_H
  3. #include <linux/mm.h>
  4. #include <asm/processor.h>
  5. #define __flush_tlb() \
  6. do { \
  7. unsigned long tmpreg; \
  8. \
  9. __asm__ __volatile__( \
  10. "movq %%cr3, %0; # flush TLB \n" \
  11. "movq %0, %%cr3; \n" \
  12. : "=r" (tmpreg) \
  13. :: "memory"); \
  14. } while (0)
  15. /*
  16. * Global pages have to be flushed a bit differently. Not a real
  17. * performance problem because this does not happen often.
  18. */
  19. #define __flush_tlb_global() \
  20. do { \
  21. unsigned long tmpreg, cr4, cr4_orig; \
  22. \
  23. __asm__ __volatile__( \
  24. "movq %%cr4, %2; # turn off PGE \n" \
  25. "movq %2, %1; \n" \
  26. "andq %3, %1; \n" \
  27. "movq %1, %%cr4; \n" \
  28. "movq %%cr3, %0; # flush TLB \n" \
  29. "movq %0, %%cr3; \n" \
  30. "movq %2, %%cr4; # turn PGE back on \n" \
  31. : "=&r" (tmpreg), "=&r" (cr4), "=&r" (cr4_orig) \
  32. : "i" (~X86_CR4_PGE) \
  33. : "memory"); \
  34. } while (0)
  35. extern unsigned long pgkern_mask;
  36. #define __flush_tlb_all() __flush_tlb_global()
  37. #define __flush_tlb_one(addr) \
  38. __asm__ __volatile__("invlpg %0": :"m" (*(char *) addr))
  39. /*
  40. * TLB flushing:
  41. *
  42. * - flush_tlb() flushes the current mm struct TLBs
  43. * - flush_tlb_all() flushes all processes TLBs
  44. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  45. * - flush_tlb_page(vma, vmaddr) flushes one page
  46. * - flush_tlb_range(vma, start, end) flushes a range of pages
  47. * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
  48. * - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
  49. *
  50. * x86-64 can only flush individual pages or full VMs. For a range flush
  51. * we always do the full VM. Might be worth trying if for a small
  52. * range a few INVLPGs in a row are a win.
  53. */
  54. #ifndef CONFIG_SMP
  55. #define flush_tlb() __flush_tlb()
  56. #define flush_tlb_all() __flush_tlb_all()
  57. #define local_flush_tlb() __flush_tlb()
  58. static inline void flush_tlb_mm(struct mm_struct *mm)
  59. {
  60. if (mm == current->active_mm)
  61. __flush_tlb();
  62. }
  63. static inline void flush_tlb_page(struct vm_area_struct *vma,
  64. unsigned long addr)
  65. {
  66. if (vma->vm_mm == current->active_mm)
  67. __flush_tlb_one(addr);
  68. }
  69. static inline void flush_tlb_range(struct vm_area_struct *vma,
  70. unsigned long start, unsigned long end)
  71. {
  72. if (vma->vm_mm == current->active_mm)
  73. __flush_tlb();
  74. }
  75. #else
  76. #include <asm/smp.h>
  77. #define local_flush_tlb() \
  78. __flush_tlb()
  79. extern void flush_tlb_all(void);
  80. extern void flush_tlb_current_task(void);
  81. extern void flush_tlb_mm(struct mm_struct *);
  82. extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
  83. #define flush_tlb() flush_tlb_current_task()
  84. static inline void flush_tlb_range(struct vm_area_struct * vma, unsigned long start, unsigned long end)
  85. {
  86. flush_tlb_mm(vma->vm_mm);
  87. }
  88. #define TLBSTATE_OK 1
  89. #define TLBSTATE_LAZY 2
  90. /* Roughly an IPI every 20MB with 4k pages for freeing page table
  91. ranges. Cost is about 42k of memory for each CPU. */
  92. #define ARCH_FREE_PTE_NR 5350
  93. #endif
  94. #define flush_tlb_kernel_range(start, end) flush_tlb_all()
  95. static inline void flush_tlb_pgtables(struct mm_struct *mm,
  96. unsigned long start, unsigned long end)
  97. {
  98. /* x86_64 does not keep any page table caches in a software TLB.
  99. The CPUs do in their hardware TLBs, but they are handled
  100. by the normal TLB flushing algorithms. */
  101. }
  102. #endif /* _X8664_TLBFLUSH_H */