tlbflush.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef _ASM_X86_TLBFLUSH_H
  2. #define _ASM_X86_TLBFLUSH_H
  3. #include <linux/mm.h>
  4. #include <linux/sched.h>
  5. #include <asm/processor.h>
  6. #include <asm/special_insns.h>
  7. #ifdef CONFIG_PARAVIRT
  8. #include <asm/paravirt.h>
  9. #else
  10. #define __flush_tlb() __native_flush_tlb()
  11. #define __flush_tlb_global() __native_flush_tlb_global()
  12. #define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
  13. #endif
  14. static inline void __native_flush_tlb(void)
  15. {
  16. native_write_cr3(native_read_cr3());
  17. }
  18. static inline void __native_flush_tlb_global_irq_disabled(void)
  19. {
  20. unsigned long cr4;
  21. cr4 = native_read_cr4();
  22. /* clear PGE */
  23. native_write_cr4(cr4 & ~X86_CR4_PGE);
  24. /* write old PGE again and flush TLBs */
  25. native_write_cr4(cr4);
  26. }
  27. static inline void __native_flush_tlb_global(void)
  28. {
  29. unsigned long flags;
  30. /*
  31. * Read-modify-write to CR4 - protect it from preemption and
  32. * from interrupts. (Use the raw variant because this code can
  33. * be called from deep inside debugging code.)
  34. */
  35. raw_local_irq_save(flags);
  36. __native_flush_tlb_global_irq_disabled();
  37. raw_local_irq_restore(flags);
  38. }
  39. static inline void __native_flush_tlb_single(unsigned long addr)
  40. {
  41. asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
  42. }
  43. static inline void __flush_tlb_all(void)
  44. {
  45. if (cpu_has_pge)
  46. __flush_tlb_global();
  47. else
  48. __flush_tlb();
  49. }
  50. static inline void __flush_tlb_one(unsigned long addr)
  51. {
  52. count_vm_event(NR_TLB_LOCAL_FLUSH_ONE);
  53. __flush_tlb_single(addr);
  54. }
  55. #define TLB_FLUSH_ALL -1UL
  56. /*
  57. * TLB flushing:
  58. *
  59. * - flush_tlb() flushes the current mm struct TLBs
  60. * - flush_tlb_all() flushes all processes TLBs
  61. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  62. * - flush_tlb_page(vma, vmaddr) flushes one page
  63. * - flush_tlb_range(vma, start, end) flushes a range of pages
  64. * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
  65. * - flush_tlb_others(cpumask, mm, start, end) flushes TLBs on other cpus
  66. *
  67. * ..but the i386 has somewhat limited tlb flushing capabilities,
  68. * and page-granular flushes are available only on i486 and up.
  69. */
  70. #ifndef CONFIG_SMP
  71. /* "_up" is for UniProcessor.
  72. *
  73. * This is a helper for other header functions. *Not* intended to be called
  74. * directly. All global TLB flushes need to either call this, or to bump the
  75. * vm statistics themselves.
  76. */
  77. static inline void __flush_tlb_up(void)
  78. {
  79. count_vm_event(NR_TLB_LOCAL_FLUSH_ALL);
  80. __flush_tlb();
  81. }
  82. static inline void flush_tlb_all(void)
  83. {
  84. count_vm_event(NR_TLB_LOCAL_FLUSH_ALL);
  85. __flush_tlb_all();
  86. }
  87. static inline void flush_tlb(void)
  88. {
  89. __flush_tlb_up();
  90. }
  91. static inline void local_flush_tlb(void)
  92. {
  93. __flush_tlb_up();
  94. }
  95. static inline void flush_tlb_mm(struct mm_struct *mm)
  96. {
  97. if (mm == current->active_mm)
  98. __flush_tlb_up();
  99. }
  100. static inline void flush_tlb_page(struct vm_area_struct *vma,
  101. unsigned long addr)
  102. {
  103. if (vma->vm_mm == current->active_mm)
  104. __flush_tlb_one(addr);
  105. }
  106. static inline void flush_tlb_range(struct vm_area_struct *vma,
  107. unsigned long start, unsigned long end)
  108. {
  109. if (vma->vm_mm == current->active_mm)
  110. __flush_tlb_up();
  111. }
  112. static inline void flush_tlb_mm_range(struct mm_struct *mm,
  113. unsigned long start, unsigned long end, unsigned long vmflag)
  114. {
  115. if (mm == current->active_mm)
  116. __flush_tlb_up();
  117. }
  118. static inline void native_flush_tlb_others(const struct cpumask *cpumask,
  119. struct mm_struct *mm,
  120. unsigned long start,
  121. unsigned long end)
  122. {
  123. }
  124. static inline void reset_lazy_tlbstate(void)
  125. {
  126. }
  127. static inline void flush_tlb_kernel_range(unsigned long start,
  128. unsigned long end)
  129. {
  130. flush_tlb_all();
  131. }
  132. #else /* SMP */
  133. #include <asm/smp.h>
  134. #define local_flush_tlb() __flush_tlb()
  135. #define flush_tlb_mm(mm) flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL)
  136. #define flush_tlb_range(vma, start, end) \
  137. flush_tlb_mm_range(vma->vm_mm, start, end, vma->vm_flags)
  138. extern void flush_tlb_all(void);
  139. extern void flush_tlb_current_task(void);
  140. extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
  141. extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
  142. unsigned long end, unsigned long vmflag);
  143. extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
  144. #define flush_tlb() flush_tlb_current_task()
  145. void native_flush_tlb_others(const struct cpumask *cpumask,
  146. struct mm_struct *mm,
  147. unsigned long start, unsigned long end);
  148. #define TLBSTATE_OK 1
  149. #define TLBSTATE_LAZY 2
  150. struct tlb_state {
  151. struct mm_struct *active_mm;
  152. int state;
  153. };
  154. DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);
  155. static inline void reset_lazy_tlbstate(void)
  156. {
  157. this_cpu_write(cpu_tlbstate.state, 0);
  158. this_cpu_write(cpu_tlbstate.active_mm, &init_mm);
  159. }
  160. #endif /* SMP */
  161. #ifndef CONFIG_PARAVIRT
  162. #define flush_tlb_others(mask, mm, start, end) \
  163. native_flush_tlb_others(mask, mm, start, end)
  164. #endif
  165. #endif /* _ASM_X86_TLBFLUSH_H */