blob: ca44c71e7fb396a93bcdb0483af52c9fc0900d70 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __X86_64_MMU_CONTEXT_H
2#define __X86_64_MMU_CONTEXT_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#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>
Glauber de Oliveira Costa04662712008-01-30 13:33:19 +010010#ifndef CONFIG_PARAVIRT
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020011#include <asm-generic/mm_hooks.h>
Glauber de Oliveira Costa04662712008-01-30 13:33:19 +010012#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14/*
15 * possibly do the LDT unload here?
16 */
17int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
18void destroy_context(struct mm_struct *mm);
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
21{
Brian Gerste4b59392006-01-11 22:46:09 +010022#ifdef CONFIG_SMP
Joe Perchesc4fe7602008-03-23 01:02:43 -070023 if (read_pda(mmu_state) == TLBSTATE_OK)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 write_pda(mmu_state, TLBSTATE_LAZY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#endif
Brian Gerste4b59392006-01-11 22:46:09 +010026}
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Joe Perchesc4fe7602008-03-23 01:02:43 -070028static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 struct task_struct *tsk)
30{
31 unsigned cpu = smp_processor_id();
32 if (likely(prev != next)) {
33 /* stop flush ipis for the previous mm */
Akinobu Mita3d1712c2006-03-24 03:15:11 -080034 cpu_clear(cpu, prev->cpu_vm_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#ifdef CONFIG_SMP
36 write_pda(mmu_state, TLBSTATE_OK);
37 write_pda(active_mm, next);
38#endif
Akinobu Mita3d1712c2006-03-24 03:15:11 -080039 cpu_set(cpu, next->cpu_vm_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 load_cr3(next->pgd);
41
Joe Perchesc4fe7602008-03-23 01:02:43 -070042 if (unlikely(next->context.ldt != prev->context.ldt))
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +010043 load_LDT_nolock(&next->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 }
45#ifdef CONFIG_SMP
46 else {
47 write_pda(mmu_state, TLBSTATE_OK);
48 if (read_pda(active_mm) != next)
Thomas Gleixner3abf0242008-01-30 13:30:28 +010049 BUG();
Akinobu Mita3d1712c2006-03-24 03:15:11 -080050 if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
Joe Perchesc4fe7602008-03-23 01:02:43 -070051 /* We were in lazy tlb mode and leave_mm disabled
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 * tlb flush IPI delivery. We must reload CR3
53 * to make sure to use no freed page tables.
54 */
55 load_cr3(next->pgd);
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +010056 load_LDT_nolock(&next->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 }
58 }
59#endif
60}
61
Joe Perchesc4fe7602008-03-23 01:02:43 -070062#define deactivate_mm(tsk, mm) \
63do { \
64 load_gs_index(0); \
65 asm volatile("movl %0,%%fs"::"r"(0)); \
66} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Joe Perchesc4fe7602008-03-23 01:02:43 -070068#define activate_mm(prev, next) \
69 switch_mm((prev), (next), NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71
72#endif