mmu_context_64.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef __X86_64_MMU_CONTEXT_H
  2. #define __X86_64_MMU_CONTEXT_H
  3. #include <asm/desc.h>
  4. #include <asm/atomic.h>
  5. #include <asm/pgalloc.h>
  6. #include <asm/pda.h>
  7. #include <asm/pgtable.h>
  8. #include <asm/tlbflush.h>
  9. #include <asm-generic/mm_hooks.h>
  10. /*
  11. * possibly do the LDT unload here?
  12. */
  13. int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  14. void destroy_context(struct mm_struct *mm);
  15. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  16. {
  17. #ifdef CONFIG_SMP
  18. if (read_pda(mmu_state) == TLBSTATE_OK)
  19. write_pda(mmu_state, TLBSTATE_LAZY);
  20. #endif
  21. }
  22. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  23. struct task_struct *tsk)
  24. {
  25. unsigned cpu = smp_processor_id();
  26. if (likely(prev != next)) {
  27. /* stop flush ipis for the previous mm */
  28. cpu_clear(cpu, prev->cpu_vm_mask);
  29. #ifdef CONFIG_SMP
  30. write_pda(mmu_state, TLBSTATE_OK);
  31. write_pda(active_mm, next);
  32. #endif
  33. cpu_set(cpu, next->cpu_vm_mask);
  34. load_cr3(next->pgd);
  35. if (unlikely(next->context.ldt != prev->context.ldt))
  36. load_LDT_nolock(&next->context);
  37. }
  38. #ifdef CONFIG_SMP
  39. else {
  40. write_pda(mmu_state, TLBSTATE_OK);
  41. if (read_pda(active_mm) != next)
  42. BUG();
  43. if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
  44. /* We were in lazy tlb mode and leave_mm disabled
  45. * tlb flush IPI delivery. We must reload CR3
  46. * to make sure to use no freed page tables.
  47. */
  48. load_cr3(next->pgd);
  49. load_LDT_nolock(&next->context);
  50. }
  51. }
  52. #endif
  53. }
  54. #define deactivate_mm(tsk,mm) do { \
  55. load_gs_index(0); \
  56. asm volatile("movl %0,%%fs"::"r"(0)); \
  57. } while(0)
  58. #define activate_mm(prev, next) \
  59. switch_mm((prev),(next),NULL)
  60. #endif