mmu_context.h 1.7 KB

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