H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_MMU_CONTEXT_32_H |
| 2 | #define _ASM_X86_MMU_CONTEXT_32_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) |
| 5 | { |
| 6 | #ifdef CONFIG_SMP |
Jan Beulich | cfc3198 | 2008-12-16 11:46:58 +0000 | [diff] [blame] | 7 | if (x86_read_percpu(cpu_tlbstate.state) == TLBSTATE_OK) |
| 8 | x86_write_percpu(cpu_tlbstate.state, TLBSTATE_LAZY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #endif |
| 10 | } |
| 11 | |
| 12 | static 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 Beulich | cfc3198 | 2008-12-16 11:46:58 +0000 | [diff] [blame] | 22 | x86_write_percpu(cpu_tlbstate.state, TLBSTATE_OK); |
| 23 | x86_write_percpu(cpu_tlbstate.active_mm, next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #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 Fitzhardinge | e5e3a04 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 34 | load_LDT_nolock(&next->context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | #ifdef CONFIG_SMP |
| 37 | else { |
Jan Beulich | cfc3198 | 2008-12-16 11:46:58 +0000 | [diff] [blame] | 38 | x86_write_percpu(cpu_tlbstate.state, TLBSTATE_OK); |
| 39 | BUG_ON(x86_read_percpu(cpu_tlbstate.active_mm) != next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) { |
Joe Perches | 55464da | 2008-03-23 01:02:42 -0700 | [diff] [blame] | 42 | /* We were in lazy tlb mode and leave_mm disabled |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | * tlb flush IPI delivery. We must reload %cr3. |
| 44 | */ |
| 45 | load_cr3(next->pgd); |
Jeremy Fitzhardinge | e5e3a04 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 46 | load_LDT_nolock(&next->context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | #endif |
| 50 | } |
| 51 | |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 52 | #define deactivate_mm(tsk, mm) \ |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 53 | asm("movl %0,%%gs": :"r" (0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 55 | #endif /* _ASM_X86_MMU_CONTEXT_32_H */ |