1 #ifndef _ASM_X86_MMU_CONTEXT_H
2 #define _ASM_X86_MMU_CONTEXT_H
5 #include <asm/atomic.h>
6 #include <asm/pgalloc.h>
7 #include <asm/tlbflush.h>
8 #include <asm/paravirt.h>
9 #ifndef CONFIG_PARAVIRT
10 #include <asm-generic/mm_hooks.h>
12 static inline void paravirt_activate_mm(struct mm_struct *prev,
13 struct mm_struct *next)
16 #endif /* !CONFIG_PARAVIRT */
19 * Used for LDT copy/destruction.
21 int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
22 void destroy_context(struct mm_struct *mm);
25 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
28 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
29 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
33 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
34 struct task_struct *tsk)
36 unsigned cpu = smp_processor_id();
38 if (likely(prev != next)) {
40 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
41 percpu_write(cpu_tlbstate.active_mm, next);
43 cpumask_set_cpu(cpu, mm_cpumask(next));
45 /* Re-load page tables */
48 /* stop flush ipis for the previous mm */
49 cpumask_clear_cpu(cpu, mm_cpumask(prev));
52 * load the LDT, if the LDT is different:
54 if (unlikely(prev->context.ldt != next->context.ldt))
55 load_LDT_nolock(&next->context);
59 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
60 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
62 if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next))) {
63 /* We were in lazy tlb mode and leave_mm disabled
64 * tlb flush IPI delivery. We must reload CR3
65 * to make sure to use no freed page tables.
68 load_LDT_nolock(&next->context);
74 #define activate_mm(prev, next) \
76 paravirt_activate_mm((prev), (next)); \
77 switch_mm((prev), (next), NULL); \
81 #define deactivate_mm(tsk, mm) \
86 #define deactivate_mm(tsk, mm) \
93 #endif /* _ASM_X86_MMU_CONTEXT_H */