tlbflush.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. * ..but the x86_64 has somewhat limited tlb flushing capabilities,
  52. * and page-granular flushes are available only on i486 and up.
  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. #endif
  91. #define flush_tlb_kernel_range(start, end) flush_tlb_all()
  92. static inline void flush_tlb_pgtables(struct mm_struct *mm,
  93. unsigned long start, unsigned long end)
  94. {
  95. /* x86_64 does not keep any page table caches in TLB */
  96. }
  97. #endif /* _X8664_TLBFLUSH_H */