blob: 7e98ce1d2c0e5ad8b2aca1c1e5d733cd839d9cc8 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_MMU_CONTEXT_32_H
2#define _ASM_X86_MMU_CONTEXT_32_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
Linus Torvalds1da177e2005-04-16 15:20:36 -07004static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
5{
6#ifdef CONFIG_SMP
Jan Beulichcfc31982008-12-16 11:46:58 +00007 if (x86_read_percpu(cpu_tlbstate.state) == TLBSTATE_OK)
8 x86_write_percpu(cpu_tlbstate.state, TLBSTATE_LAZY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#endif
10}
11
12static inline void switch_mm(struct mm_struct *prev,
13 struct mm_struct *next,
14 struct task_struct *tsk)
15{
16 int cpu = smp_processor_id();
17
18 if (likely(prev != next)) {
19 /* stop flush ipis for the previous mm */
20 cpu_clear(cpu, prev->cpu_vm_mask);
21#ifdef CONFIG_SMP
Jan Beulichcfc31982008-12-16 11:46:58 +000022 x86_write_percpu(cpu_tlbstate.state, TLBSTATE_OK);
23 x86_write_percpu(cpu_tlbstate.active_mm, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#endif
25 cpu_set(cpu, next->cpu_vm_mask);
26
27 /* Re-load page tables */
28 load_cr3(next->pgd);
29
30 /*
31 * load the LDT, if the LDT is different:
32 */
33 if (unlikely(prev->context.ldt != next->context.ldt))
Jeremy Fitzhardingee5e3a042006-12-07 02:14:01 +010034 load_LDT_nolock(&next->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 }
36#ifdef CONFIG_SMP
37 else {
Jan Beulichcfc31982008-12-16 11:46:58 +000038 x86_write_percpu(cpu_tlbstate.state, TLBSTATE_OK);
39 BUG_ON(x86_read_percpu(cpu_tlbstate.active_mm) != next);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
Joe Perches55464da2008-03-23 01:02:42 -070042 /* We were in lazy tlb mode and leave_mm disabled
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 * tlb flush IPI delivery. We must reload %cr3.
44 */
45 load_cr3(next->pgd);
Jeremy Fitzhardingee5e3a042006-12-07 02:14:01 +010046 load_LDT_nolock(&next->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 }
48 }
49#endif
50}
51
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +010052#define deactivate_mm(tsk, mm) \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010053 asm("movl %0,%%gs": :"r" (0));
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
H. Peter Anvin1965aae2008-10-22 22:26:29 -070055#endif /* _ASM_X86_MMU_CONTEXT_32_H */