x86: move load_cr3 to a common place.
[deliverable/linux.git] / include / asm-x86 / mmu_context_64.h
CommitLineData
1da177e4
LT
1#ifndef __X86_64_MMU_CONTEXT_H
2#define __X86_64_MMU_CONTEXT_H
3
1da177e4
LT
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>
d6dd61c8 10#include <asm-generic/mm_hooks.h>
1da177e4
LT
11
12/*
13 * possibly do the LDT unload here?
14 */
15int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
16void destroy_context(struct mm_struct *mm);
17
1da177e4
LT
18static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
19{
e4b5939a 20#ifdef CONFIG_SMP
1da177e4
LT
21 if (read_pda(mmu_state) == TLBSTATE_OK)
22 write_pda(mmu_state, TLBSTATE_LAZY);
1da177e4 23#endif
e4b5939a 24}
1da177e4 25
1da177e4
LT
26static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
27 struct task_struct *tsk)
28{
29 unsigned cpu = smp_processor_id();
30 if (likely(prev != next)) {
31 /* stop flush ipis for the previous mm */
3d1712c9 32 cpu_clear(cpu, prev->cpu_vm_mask);
1da177e4
LT
33#ifdef CONFIG_SMP
34 write_pda(mmu_state, TLBSTATE_OK);
35 write_pda(active_mm, next);
36#endif
3d1712c9 37 cpu_set(cpu, next->cpu_vm_mask);
1da177e4
LT
38 load_cr3(next->pgd);
39
40 if (unlikely(next->context.ldt != prev->context.ldt))
881c2975 41 load_LDT_nolock(&next->context);
1da177e4
LT
42 }
43#ifdef CONFIG_SMP
44 else {
45 write_pda(mmu_state, TLBSTATE_OK);
46 if (read_pda(active_mm) != next)
3abf024d 47 BUG();
3d1712c9 48 if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
1da177e4
LT
49 /* We were in lazy tlb mode and leave_mm disabled
50 * tlb flush IPI delivery. We must reload CR3
51 * to make sure to use no freed page tables.
52 */
53 load_cr3(next->pgd);
881c2975 54 load_LDT_nolock(&next->context);
1da177e4
LT
55 }
56 }
57#endif
58}
59
60#define deactivate_mm(tsk,mm) do { \
61 load_gs_index(0); \
62 asm volatile("movl %0,%%fs"::"r"(0)); \
63} while(0)
64
65#define activate_mm(prev, next) \
66 switch_mm((prev),(next),NULL)
67
68
69#endif
This page took 0.458826 seconds and 5 git commands to generate.