mmu_context.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef _ASM_X86_MMU_CONTEXT_H
  2. #define _ASM_X86_MMU_CONTEXT_H
  3. #include <asm/desc.h>
  4. #include <linux/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. #ifdef CONFIG_SMP
  33. percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
  34. percpu_write(cpu_tlbstate.active_mm, next);
  35. #endif
  36. cpumask_set_cpu(cpu, mm_cpumask(next));
  37. /* Re-load page tables */
  38. load_cr3(next->pgd);
  39. /* stop flush ipis for the previous mm */
  40. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  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 (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next))) {
  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 */