mmu_context_64.h 1.7 KB

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