tlbflush.h 3.3 KB

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