mmu_context_64.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef _ASM_X86_MMU_CONTEXT_64_H
  2. #define _ASM_X86_MMU_CONTEXT_64_H
  3. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  4. {
  5. #ifdef CONFIG_SMP
  6. if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
  7. percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
  8. #endif
  9. }
  10. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  11. struct task_struct *tsk)
  12. {
  13. unsigned cpu = smp_processor_id();
  14. if (likely(prev != next)) {
  15. /* stop flush ipis for the previous mm */
  16. cpu_clear(cpu, prev->cpu_vm_mask);
  17. #ifdef CONFIG_SMP
  18. percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
  19. percpu_write(cpu_tlbstate.active_mm, next);
  20. #endif
  21. cpu_set(cpu, next->cpu_vm_mask);
  22. load_cr3(next->pgd);
  23. if (unlikely(next->context.ldt != prev->context.ldt))
  24. load_LDT_nolock(&next->context);
  25. }
  26. #ifdef CONFIG_SMP
  27. else {
  28. percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
  29. BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
  30. if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) {
  31. /* We were in lazy tlb mode and leave_mm disabled
  32. * tlb flush IPI delivery. We must reload CR3
  33. * to make sure to use no freed page tables.
  34. */
  35. load_cr3(next->pgd);
  36. load_LDT_nolock(&next->context);
  37. }
  38. }
  39. #endif
  40. }
  41. #define deactivate_mm(tsk, mm) \
  42. do { \
  43. load_gs_index(0); \
  44. asm volatile("movl %0,%%fs"::"r"(0)); \
  45. } while (0)
  46. #endif /* _ASM_X86_MMU_CONTEXT_64_H */