mmu_context.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef _ASM_X86_MMU_CONTEXT_H
  2. #define _ASM_X86_MMU_CONTEXT_H
  3. #include <asm/desc.h>
  4. #include <asm/atomic.h>
  5. #include <asm/pgalloc.h>
  6. #include <asm/tlbflush.h>
  7. #include <asm/paravirt.h>
  8. #ifndef CONFIG_PARAVIRT
  9. #include <asm-generic/mm_hooks.h>
  10. static inline void paravirt_activate_mm(struct mm_struct *prev,
  11. struct mm_struct *next)
  12. {
  13. }
  14. #endif /* !CONFIG_PARAVIRT */
  15. /*
  16. * Used for LDT copy/destruction.
  17. */
  18. int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  19. void destroy_context(struct mm_struct *mm);
  20. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  21. {
  22. #ifdef CONFIG_SMP
  23. if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
  24. percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
  25. #endif
  26. }
  27. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  28. struct task_struct *tsk)
  29. {
  30. unsigned cpu = smp_processor_id();
  31. if (likely(prev != next)) {
  32. /* stop flush ipis for the previous mm */
  33. cpu_clear(cpu, prev->cpu_vm_mask);
  34. #ifdef CONFIG_SMP
  35. percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
  36. percpu_write(cpu_tlbstate.active_mm, next);
  37. #endif
  38. cpu_set(cpu, next->cpu_vm_mask);
  39. /* Re-load page tables */
  40. load_cr3(next->pgd);
  41. /*
  42. * load the LDT, if the LDT is different:
  43. */
  44. if (unlikely(prev->context.ldt != next->context.ldt))
  45. load_LDT_nolock(&next->context);
  46. }
  47. #ifdef CONFIG_SMP
  48. else {
  49. percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
  50. BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
  51. if (!cpu_test_and_set(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);
  58. }
  59. }
  60. #endif
  61. }
  62. #define activate_mm(prev, next) \
  63. do { \
  64. paravirt_activate_mm((prev), (next)); \
  65. switch_mm((prev), (next), NULL); \
  66. } while (0);
  67. #ifdef CONFIG_X86_32
  68. #define deactivate_mm(tsk, mm) \
  69. do { \
  70. lazy_load_gs(0); \
  71. } while (0)
  72. #else
  73. #define deactivate_mm(tsk, mm) \
  74. do { \
  75. load_gs_index(0); \
  76. loadsegment(fs, 0); \
  77. } while (0)
  78. #endif
  79. #endif /* _ASM_X86_MMU_CONTEXT_H */