mmu_context.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __X86_64_MMU_CONTEXT_H
  2. #define __X86_64_MMU_CONTEXT_H
  3. #include <linux/config.h>
  4. #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>
  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. #ifdef CONFIG_SMP
  16. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  17. {
  18. if (read_pda(mmu_state) == TLBSTATE_OK)
  19. write_pda(mmu_state, TLBSTATE_LAZY);
  20. }
  21. #else
  22. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  23. {
  24. }
  25. #endif
  26. static inline void load_cr3(pgd_t *pgd)
  27. {
  28. asm volatile("movq %0,%%cr3" :: "r" (__pa(pgd)) : "memory");
  29. }
  30. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  31. struct task_struct *tsk)
  32. {
  33. unsigned cpu = smp_processor_id();
  34. if (likely(prev != next)) {
  35. /* stop flush ipis for the previous mm */
  36. clear_bit(cpu, &prev->cpu_vm_mask);
  37. #ifdef CONFIG_SMP
  38. write_pda(mmu_state, TLBSTATE_OK);
  39. write_pda(active_mm, next);
  40. #endif
  41. set_bit(cpu, &next->cpu_vm_mask);
  42. load_cr3(next->pgd);
  43. if (unlikely(next->context.ldt != prev->context.ldt))
  44. load_LDT_nolock(&next->context, cpu);
  45. }
  46. #ifdef CONFIG_SMP
  47. else {
  48. write_pda(mmu_state, TLBSTATE_OK);
  49. if (read_pda(active_mm) != next)
  50. out_of_line_bug();
  51. if(!test_and_set_bit(cpu, &next->cpu_vm_mask)) {
  52. /* We were in lazy tlb mode and leave_mm disabled
  53. * tlb flush IPI delivery. We must reload CR3
  54. * to make sure to use no freed page tables.
  55. */
  56. load_cr3(next->pgd);
  57. load_LDT_nolock(&next->context, cpu);
  58. }
  59. }
  60. #endif
  61. }
  62. #define deactivate_mm(tsk,mm) do { \
  63. load_gs_index(0); \
  64. asm volatile("movl %0,%%fs"::"r"(0)); \
  65. } while(0)
  66. #define activate_mm(prev, next) \
  67. switch_mm((prev),(next),NULL)
  68. #endif