mmu_context.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef __I386_SCHED_H
  2. #define __I386_SCHED_H
  3. #include <linux/config.h>
  4. #include <asm/desc.h>
  5. #include <asm/atomic.h>
  6. #include <asm/pgalloc.h>
  7. #include <asm/tlbflush.h>
  8. /*
  9. * Used for LDT copy/destruction.
  10. */
  11. int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  12. void destroy_context(struct mm_struct *mm);
  13. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  14. {
  15. #ifdef CONFIG_SMP
  16. unsigned cpu = smp_processor_id();
  17. if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK)
  18. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_LAZY;
  19. #endif
  20. }
  21. static inline void switch_mm(struct mm_struct *prev,
  22. struct mm_struct *next,
  23. struct task_struct *tsk)
  24. {
  25. int cpu = smp_processor_id();
  26. if (likely(prev != next)) {
  27. /* stop flush ipis for the previous mm */
  28. cpu_clear(cpu, prev->cpu_vm_mask);
  29. #ifdef CONFIG_SMP
  30. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK;
  31. per_cpu(cpu_tlbstate, cpu).active_mm = next;
  32. #endif
  33. cpu_set(cpu, next->cpu_vm_mask);
  34. /* Re-load page tables */
  35. load_cr3(next->pgd);
  36. /*
  37. * load the LDT, if the LDT is different:
  38. */
  39. if (unlikely(prev->context.ldt != next->context.ldt))
  40. load_LDT_nolock(&next->context, cpu);
  41. }
  42. #ifdef CONFIG_SMP
  43. else {
  44. per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_OK;
  45. BUG_ON(per_cpu(cpu_tlbstate, cpu).active_mm != next);
  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. */
  50. load_cr3(next->pgd);
  51. load_LDT_nolock(&next->context, cpu);
  52. }
  53. }
  54. #endif
  55. }
  56. #define deactivate_mm(tsk, mm) \
  57. asm("movl %0,%%fs ; movl %0,%%gs": :"r" (0))
  58. #define activate_mm(prev, next) \
  59. switch_mm((prev),(next),NULL)
  60. #endif