]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/x86/include/asm/tlbflush.h
1 #ifndef _ASM_X86_TLBFLUSH_H
2 #define _ASM_X86_TLBFLUSH_H
5 #include <linux/sched.h>
7 #include <asm/processor.h>
8 #include <asm/cpufeature.h>
9 #include <asm/special_insns.h>
11 #ifdef CONFIG_PARAVIRT
12 #include <asm/paravirt.h>
14 #define __flush_tlb() __native_flush_tlb()
15 #define __flush_tlb_global() __native_flush_tlb_global()
16 #define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
21 struct mm_struct
*active_mm
;
26 * Access to this CR4 shadow and to H/W CR4 is protected by
27 * disabling interrupts when modifying either one.
31 DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state
, cpu_tlbstate
);
33 /* Initialize cr4 shadow for this CPU. */
34 static inline void cr4_init_shadow(void)
36 this_cpu_write(cpu_tlbstate
.cr4
, __read_cr4());
39 /* Set in this cpu's CR4. */
40 static inline void cr4_set_bits(unsigned long mask
)
44 cr4
= this_cpu_read(cpu_tlbstate
.cr4
);
45 if ((cr4
| mask
) != cr4
) {
47 this_cpu_write(cpu_tlbstate
.cr4
, cr4
);
52 /* Clear in this cpu's CR4. */
53 static inline void cr4_clear_bits(unsigned long mask
)
57 cr4
= this_cpu_read(cpu_tlbstate
.cr4
);
58 if ((cr4
& ~mask
) != cr4
) {
60 this_cpu_write(cpu_tlbstate
.cr4
, cr4
);
65 /* Read the CR4 shadow. */
66 static inline unsigned long cr4_read_shadow(void)
68 return this_cpu_read(cpu_tlbstate
.cr4
);
72 * Save some of cr4 feature set we're using (e.g. Pentium 4MB
73 * enable and PPro Global page enable), so that any CPU's that boot
74 * up after us can get the correct flags. This should only be used
75 * during boot on the boot cpu.
77 extern unsigned long mmu_cr4_features
;
78 extern u32
*trampoline_cr4_features
;
80 static inline void cr4_set_bits_and_update_boot(unsigned long mask
)
82 mmu_cr4_features
|= mask
;
83 if (trampoline_cr4_features
)
84 *trampoline_cr4_features
= mmu_cr4_features
;
88 static inline void __native_flush_tlb(void)
90 native_write_cr3(native_read_cr3());
93 static inline void __native_flush_tlb_global_irq_disabled(void)
97 cr4
= this_cpu_read(cpu_tlbstate
.cr4
);
99 native_write_cr4(cr4
& ~X86_CR4_PGE
);
100 /* write old PGE again and flush TLBs */
101 native_write_cr4(cr4
);
104 static inline void __native_flush_tlb_global(void)
109 * Read-modify-write to CR4 - protect it from preemption and
110 * from interrupts. (Use the raw variant because this code can
111 * be called from deep inside debugging code.)
113 raw_local_irq_save(flags
);
115 __native_flush_tlb_global_irq_disabled();
117 raw_local_irq_restore(flags
);
120 static inline void __native_flush_tlb_single(unsigned long addr
)
122 asm volatile("invlpg (%0)" ::"r" (addr
) : "memory");
125 static inline void __flush_tlb_all(void)
128 __flush_tlb_global();
133 static inline void __flush_tlb_one(unsigned long addr
)
135 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ONE
);
136 __flush_tlb_single(addr
);
139 #define TLB_FLUSH_ALL -1UL
144 * - flush_tlb() flushes the current mm struct TLBs
145 * - flush_tlb_all() flushes all processes TLBs
146 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
147 * - flush_tlb_page(vma, vmaddr) flushes one page
148 * - flush_tlb_range(vma, start, end) flushes a range of pages
149 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
150 * - flush_tlb_others(cpumask, mm, start, end) flushes TLBs on other cpus
152 * ..but the i386 has somewhat limited tlb flushing capabilities,
153 * and page-granular flushes are available only on i486 and up.
158 /* "_up" is for UniProcessor.
160 * This is a helper for other header functions. *Not* intended to be called
161 * directly. All global TLB flushes need to either call this, or to bump the
162 * vm statistics themselves.
164 static inline void __flush_tlb_up(void)
166 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL
);
170 static inline void flush_tlb_all(void)
172 count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL
);
176 static inline void flush_tlb(void)
181 static inline void local_flush_tlb(void)
186 static inline void flush_tlb_mm(struct mm_struct
*mm
)
188 if (mm
== current
->active_mm
)
192 static inline void flush_tlb_page(struct vm_area_struct
*vma
,
195 if (vma
->vm_mm
== current
->active_mm
)
196 __flush_tlb_one(addr
);
199 static inline void flush_tlb_range(struct vm_area_struct
*vma
,
200 unsigned long start
, unsigned long end
)
202 if (vma
->vm_mm
== current
->active_mm
)
206 static inline void flush_tlb_mm_range(struct mm_struct
*mm
,
207 unsigned long start
, unsigned long end
, unsigned long vmflag
)
209 if (mm
== current
->active_mm
)
213 static inline void native_flush_tlb_others(const struct cpumask
*cpumask
,
214 struct mm_struct
*mm
,
220 static inline void reset_lazy_tlbstate(void)
224 static inline void flush_tlb_kernel_range(unsigned long start
,
234 #define local_flush_tlb() __flush_tlb()
236 #define flush_tlb_mm(mm) flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL)
238 #define flush_tlb_range(vma, start, end) \
239 flush_tlb_mm_range(vma->vm_mm, start, end, vma->vm_flags)
241 extern void flush_tlb_all(void);
242 extern void flush_tlb_current_task(void);
243 extern void flush_tlb_page(struct vm_area_struct
*, unsigned long);
244 extern void flush_tlb_mm_range(struct mm_struct
*mm
, unsigned long start
,
245 unsigned long end
, unsigned long vmflag
);
246 extern void flush_tlb_kernel_range(unsigned long start
, unsigned long end
);
248 #define flush_tlb() flush_tlb_current_task()
250 void native_flush_tlb_others(const struct cpumask
*cpumask
,
251 struct mm_struct
*mm
,
252 unsigned long start
, unsigned long end
);
254 #define TLBSTATE_OK 1
255 #define TLBSTATE_LAZY 2
257 static inline void reset_lazy_tlbstate(void)
259 this_cpu_write(cpu_tlbstate
.state
, 0);
260 this_cpu_write(cpu_tlbstate
.active_mm
, &init_mm
);
265 /* Not inlined due to inc_irq_stat not being defined yet */
266 #define flush_tlb_local() { \
267 inc_irq_stat(irq_tlb_count); \
271 #ifndef CONFIG_PARAVIRT
272 #define flush_tlb_others(mask, mm, start, end) \
273 native_flush_tlb_others(mask, mm, start, end)
276 #endif /* _ASM_X86_TLBFLUSH_H */