mmu_context_64.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 load_cr3(pgd_t *pgd)
  23. {
  24. asm volatile("movq %0,%%cr3" :: "r" (__pa(pgd)) : "memory");
  25. }
  26. static 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 */
  32. cpu_clear(cpu, prev->cpu_vm_mask);
  33. #ifdef CONFIG_SMP
  34. write_pda(mmu_state, TLBSTATE_OK);
  35. write_pda(active_mm, next);
  36. #endif
  37. cpu_set(cpu, next->cpu_vm_mask);
  38. load_cr3(next->pgd);
  39. if (unlikely(next->context.ldt != prev->context.ldt))
  40. load_LDT_nolock(&next->context, cpu);
  41. }
  42. #ifdef CONFIG_SMP
  43. else {
  44. write_pda(mmu_state, TLBSTATE_OK);
  45. if (read_pda(active_mm) != next)
  46. out_of_line_bug();
  47. if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
  48. /* We were in lazy tlb mode and leave_mm disabled
  49. * tlb flush IPI delivery. We must reload CR3
  50. * to make sure to use no freed page tables.
  51. */
  52. load_cr3(next->pgd);
  53. load_LDT_nolock(&next->context, cpu);
  54. }
  55. }
  56. #endif
  57. }
  58. #define deactivate_mm(tsk,mm) do { \
  59. load_gs_index(0); \
  60. asm volatile("movl %0,%%fs"::"r"(0)); \
  61. } while(0)
  62. #define activate_mm(prev, next) \
  63. switch_mm((prev),(next),NULL)
  64. #endif