Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __X86_64_MMU_CONTEXT_H |
| 2 | #define __X86_64_MMU_CONTEXT_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <asm/desc.h> |
| 5 | #include <asm/atomic.h> |
| 6 | #include <asm/pgalloc.h> |
| 7 | #include <asm/pda.h> |
| 8 | #include <asm/pgtable.h> |
| 9 | #include <asm/tlbflush.h> |
| 10 | |
| 11 | /* |
| 12 | * possibly do the LDT unload here? |
| 13 | */ |
| 14 | int init_new_context(struct task_struct *tsk, struct mm_struct *mm); |
| 15 | void destroy_context(struct mm_struct *mm); |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) |
| 18 | { |
Brian Gerst | e4b5939 | 2006-01-11 22:46:09 +0100 | [diff] [blame] | 19 | #ifdef CONFIG_SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | if (read_pda(mmu_state) == TLBSTATE_OK) |
| 21 | write_pda(mmu_state, TLBSTATE_LAZY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #endif |
Brian Gerst | e4b5939 | 2006-01-11 22:46:09 +0100 | [diff] [blame] | 23 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | static inline void load_cr3(pgd_t *pgd) |
| 26 | { |
| 27 | asm volatile("movq %0,%%cr3" :: "r" (__pa(pgd)) : "memory"); |
| 28 | } |
| 29 | |
| 30 | static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, |
| 31 | struct task_struct *tsk) |
| 32 | { |
| 33 | unsigned cpu = smp_processor_id(); |
| 34 | if (likely(prev != next)) { |
| 35 | /* stop flush ipis for the previous mm */ |
Akinobu Mita | 3d1712c | 2006-03-24 03:15:11 -0800 | [diff] [blame] | 36 | cpu_clear(cpu, prev->cpu_vm_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #ifdef CONFIG_SMP |
| 38 | write_pda(mmu_state, TLBSTATE_OK); |
| 39 | write_pda(active_mm, next); |
| 40 | #endif |
Akinobu Mita | 3d1712c | 2006-03-24 03:15:11 -0800 | [diff] [blame] | 41 | cpu_set(cpu, next->cpu_vm_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | load_cr3(next->pgd); |
| 43 | |
| 44 | if (unlikely(next->context.ldt != prev->context.ldt)) |
| 45 | load_LDT_nolock(&next->context, cpu); |
| 46 | } |
| 47 | #ifdef CONFIG_SMP |
| 48 | else { |
| 49 | write_pda(mmu_state, TLBSTATE_OK); |
| 50 | if (read_pda(active_mm) != next) |
| 51 | out_of_line_bug(); |
Akinobu Mita | 3d1712c | 2006-03-24 03:15:11 -0800 | [diff] [blame] | 52 | if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* We were in lazy tlb mode and leave_mm disabled |
| 54 | * tlb flush IPI delivery. We must reload CR3 |
| 55 | * to make sure to use no freed page tables. |
| 56 | */ |
| 57 | load_cr3(next->pgd); |
| 58 | load_LDT_nolock(&next->context, cpu); |
| 59 | } |
| 60 | } |
| 61 | #endif |
| 62 | } |
| 63 | |
| 64 | #define deactivate_mm(tsk,mm) do { \ |
| 65 | load_gs_index(0); \ |
| 66 | asm volatile("movl %0,%%fs"::"r"(0)); \ |
| 67 | } while(0) |
| 68 | |
| 69 | #define activate_mm(prev, next) \ |
| 70 | switch_mm((prev),(next),NULL) |
| 71 | |
| 72 | |
| 73 | #endif |