mmu_context.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef __I386_SCHED_H
  2. #define __I386_SCHED_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. unsigned cpu = smp_processor_id();
  24. if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK)
  25. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_LAZY;
  26. #endif
  27. }
  28. static inline void switch_mm(struct mm_struct *prev,
  29. struct mm_struct *next,
  30. struct task_struct *tsk)
  31. {
  32. int cpu = smp_processor_id();
  33. if (likely(prev != next)) {
  34. /* stop flush ipis for the previous mm */
  35. cpu_clear(cpu, prev->cpu_vm_mask);
  36. #ifdef CONFIG_SMP
  37. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK;
  38. per_cpu(cpu_tlbstate, cpu).active_mm = next;
  39. #endif
  40. cpu_set(cpu, next->cpu_vm_mask);
  41. /* Re-load page tables */
  42. load_cr3(next->pgd);
  43. /*
  44. * load the LDT, if the LDT is different:
  45. */
  46. if (unlikely(prev->context.ldt != next->context.ldt))
  47. load_LDT_nolock(&next->context);
  48. }
  49. #ifdef CONFIG_SMP
  50. else {
  51. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK;
  52. BUG_ON(per_cpu(cpu_tlbstate, cpu).active_mm != next);
  53. if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
  54. /* We were in lazy tlb mode and leave_mm disabled
  55. * tlb flush IPI delivery. We must reload %cr3.
  56. */
  57. load_cr3(next->pgd);
  58. load_LDT_nolock(&next->context);
  59. }
  60. }
  61. #endif
  62. }
  63. #define deactivate_mm(tsk, mm) \
  64. asm("movl %0,%%gs": :"r" (0));
  65. #define activate_mm(prev, next) \
  66. do { \
  67. paravirt_activate_mm(prev, next); \
  68. switch_mm((prev),(next),NULL); \
  69. } while(0);
  70. #endif