blob: 50a7fc0f824a8f027376f0f38af9d820502095bf [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_TLBFLUSH_H
2#define _ASM_X86_TLBFLUSH_H
Thomas Gleixnerd291cf82008-01-30 13:30:35 +01003
4#include <linux/mm.h>
5#include <linux/sched.h>
6
7#include <asm/processor.h>
David Howellsf05e7982012-03-28 18:11:12 +01008#include <asm/special_insns.h>
Thomas Gleixnerd291cf82008-01-30 13:30:35 +01009
10#ifdef CONFIG_PARAVIRT
11#include <asm/paravirt.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +020012#else
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010013#define __flush_tlb() __native_flush_tlb()
14#define __flush_tlb_global() __native_flush_tlb_global()
15#define __flush_tlb_single(addr) __native_flush_tlb_single(addr)
Thomas Gleixner96a388d2007-10-11 11:20:03 +020016#endif
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010017
18static inline void __native_flush_tlb(void)
19{
Chris Wrightd7285c62009-04-23 10:21:38 -070020 native_write_cr3(native_read_cr3());
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010021}
22
Fenghua Yu086fc8f2012-12-20 23:44:27 -080023static inline void __native_flush_tlb_global_irq_disabled(void)
24{
25 unsigned long cr4;
26
27 cr4 = native_read_cr4();
28 /* clear PGE */
29 native_write_cr4(cr4 & ~X86_CR4_PGE);
30 /* write old PGE again and flush TLBs */
31 native_write_cr4(cr4);
32}
33
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010034static inline void __native_flush_tlb_global(void)
35{
Ingo Molnarb1979a52008-05-12 21:21:15 +020036 unsigned long flags;
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010037
Ingo Molnarb1979a52008-05-12 21:21:15 +020038 /*
39 * Read-modify-write to CR4 - protect it from preemption and
40 * from interrupts. (Use the raw variant because this code can
41 * be called from deep inside debugging code.)
42 */
43 raw_local_irq_save(flags);
44
Fenghua Yu086fc8f2012-12-20 23:44:27 -080045 __native_flush_tlb_global_irq_disabled();
Ingo Molnarb1979a52008-05-12 21:21:15 +020046
47 raw_local_irq_restore(flags);
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010048}
49
50static inline void __native_flush_tlb_single(unsigned long addr)
51{
Joe Perches94cf8de2008-03-23 01:03:45 -070052 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010053}
54
55static inline void __flush_tlb_all(void)
56{
57 if (cpu_has_pge)
58 __flush_tlb_global();
59 else
60 __flush_tlb();
61}
62
63static inline void __flush_tlb_one(unsigned long addr)
64{
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010065 __flush_tlb_single(addr);
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010066}
67
Alex Shi3e7f3db2012-05-10 18:01:59 +080068#define TLB_FLUSH_ALL -1UL
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010069
70/*
71 * TLB flushing:
72 *
73 * - flush_tlb() flushes the current mm struct TLBs
74 * - flush_tlb_all() flushes all processes TLBs
75 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
76 * - flush_tlb_page(vma, vmaddr) flushes one page
77 * - flush_tlb_range(vma, start, end) flushes a range of pages
78 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
Alex Shie7b52ff2012-06-28 09:02:17 +080079 * - flush_tlb_others(cpumask, mm, start, end) flushes TLBs on other cpus
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010080 *
81 * ..but the i386 has somewhat limited tlb flushing capabilities,
82 * and page-granular flushes are available only on i486 and up.
Thomas Gleixnerd291cf82008-01-30 13:30:35 +010083 */
84
85#ifndef CONFIG_SMP
86
87#define flush_tlb() __flush_tlb()
88#define flush_tlb_all() __flush_tlb_all()
89#define local_flush_tlb() __flush_tlb()
90
91static inline void flush_tlb_mm(struct mm_struct *mm)
92{
93 if (mm == current->active_mm)
94 __flush_tlb();
95}
96
97static inline void flush_tlb_page(struct vm_area_struct *vma,
98 unsigned long addr)
99{
100 if (vma->vm_mm == current->active_mm)
101 __flush_tlb_one(addr);
102}
103
104static inline void flush_tlb_range(struct vm_area_struct *vma,
105 unsigned long start, unsigned long end)
106{
107 if (vma->vm_mm == current->active_mm)
108 __flush_tlb();
109}
110
Alex Shi7efa1c82012-07-20 09:18:23 +0800111static inline void flush_tlb_mm_range(struct mm_struct *mm,
Alex Shi611ae8e2012-06-28 09:02:22 +0800112 unsigned long start, unsigned long end, unsigned long vmflag)
113{
Alex Shi7efa1c82012-07-20 09:18:23 +0800114 if (mm == current->active_mm)
Alex Shi611ae8e2012-06-28 09:02:22 +0800115 __flush_tlb();
116}
117
Rusty Russell4595f962009-01-10 21:58:09 -0800118static inline void native_flush_tlb_others(const struct cpumask *cpumask,
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100119 struct mm_struct *mm,
Alex Shie7b52ff2012-06-28 09:02:17 +0800120 unsigned long start,
121 unsigned long end)
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100122{
123}
124
Alex Nixon913da642008-09-03 14:30:23 +0100125static inline void reset_lazy_tlbstate(void)
126{
127}
128
Alex Shieffee4b2012-06-28 09:02:24 +0800129static inline void flush_tlb_kernel_range(unsigned long start,
130 unsigned long end)
131{
132 flush_tlb_all();
133}
134
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100135#else /* SMP */
136
137#include <asm/smp.h>
138
139#define local_flush_tlb() __flush_tlb()
140
Alex Shi611ae8e2012-06-28 09:02:22 +0800141#define flush_tlb_mm(mm) flush_tlb_mm_range(mm, 0UL, TLB_FLUSH_ALL, 0UL)
142
143#define flush_tlb_range(vma, start, end) \
144 flush_tlb_mm_range(vma->vm_mm, start, end, vma->vm_flags)
145
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100146extern void flush_tlb_all(void);
147extern void flush_tlb_current_task(void);
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100148extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
Alex Shi611ae8e2012-06-28 09:02:22 +0800149extern void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
150 unsigned long end, unsigned long vmflag);
Alex Shieffee4b2012-06-28 09:02:24 +0800151extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100152
153#define flush_tlb() flush_tlb_current_task()
154
Rusty Russell4595f962009-01-10 21:58:09 -0800155void native_flush_tlb_others(const struct cpumask *cpumask,
Alex Shie7b52ff2012-06-28 09:02:17 +0800156 struct mm_struct *mm,
157 unsigned long start, unsigned long end);
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100158
159#define TLBSTATE_OK 1
160#define TLBSTATE_LAZY 2
161
Joe Perches94cf8de2008-03-23 01:03:45 -0700162struct tlb_state {
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100163 struct mm_struct *active_mm;
164 int state;
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100165};
David Howells9b8de742009-04-21 23:00:24 +0100166DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);
Alex Nixon913da642008-09-03 14:30:23 +0100167
Alex Nixon913da642008-09-03 14:30:23 +0100168static inline void reset_lazy_tlbstate(void)
169{
Alex Shic6ae41e2012-05-11 15:35:27 +0800170 this_cpu_write(cpu_tlbstate.state, 0);
171 this_cpu_write(cpu_tlbstate.active_mm, &init_mm);
Alex Nixon913da642008-09-03 14:30:23 +0100172}
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100173
174#endif /* SMP */
175
176#ifndef CONFIG_PARAVIRT
Alex Shie7b52ff2012-06-28 09:02:17 +0800177#define flush_tlb_others(mask, mm, start, end) \
178 native_flush_tlb_others(mask, mm, start, end)
Thomas Gleixnerd291cf82008-01-30 13:30:35 +0100179#endif
180
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700181#endif /* _ASM_X86_TLBFLUSH_H */