mmu_context_64.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef __SPARC64_MMU_CONTEXT_H
  2. #define __SPARC64_MMU_CONTEXT_H
  3. /* Derived heavily from Linus's Alpha/AXP ASN code... */
  4. #ifndef __ASSEMBLY__
  5. #include <linux/spinlock.h>
  6. #include <asm/system.h>
  7. #include <asm/spitfire.h>
  8. #include <asm-generic/mm_hooks.h>
  9. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  10. {
  11. }
  12. extern spinlock_t ctx_alloc_lock;
  13. extern unsigned long tlb_context_cache;
  14. extern unsigned long mmu_context_bmap[];
  15. extern void get_new_mmu_context(struct mm_struct *mm);
  16. #ifdef CONFIG_SMP
  17. extern void smp_new_mmu_context_version(void);
  18. #else
  19. #define smp_new_mmu_context_version() do { } while (0)
  20. #endif
  21. extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
  22. extern void destroy_context(struct mm_struct *mm);
  23. extern void __tsb_context_switch(unsigned long pgd_pa,
  24. struct tsb_config *tsb_base,
  25. struct tsb_config *tsb_huge,
  26. unsigned long tsb_descr_pa);
  27. static inline void tsb_context_switch(struct mm_struct *mm)
  28. {
  29. __tsb_context_switch(__pa(mm->pgd),
  30. &mm->context.tsb_block[0],
  31. #ifdef CONFIG_HUGETLB_PAGE
  32. (mm->context.tsb_block[1].tsb ?
  33. &mm->context.tsb_block[1] :
  34. NULL)
  35. #else
  36. NULL
  37. #endif
  38. , __pa(&mm->context.tsb_descr[0]));
  39. }
  40. extern void tsb_grow(struct mm_struct *mm, unsigned long tsb_index, unsigned long mm_rss);
  41. #ifdef CONFIG_SMP
  42. extern void smp_tsb_sync(struct mm_struct *mm);
  43. #else
  44. #define smp_tsb_sync(__mm) do { } while (0)
  45. #endif
  46. /* Set MMU context in the actual hardware. */
  47. #define load_secondary_context(__mm) \
  48. __asm__ __volatile__( \
  49. "\n661: stxa %0, [%1] %2\n" \
  50. " .section .sun4v_1insn_patch, \"ax\"\n" \
  51. " .word 661b\n" \
  52. " stxa %0, [%1] %3\n" \
  53. " .previous\n" \
  54. " flush %%g6\n" \
  55. : /* No outputs */ \
  56. : "r" (CTX_HWBITS((__mm)->context)), \
  57. "r" (SECONDARY_CONTEXT), "i" (ASI_DMMU), "i" (ASI_MMU))
  58. extern void __flush_tlb_mm(unsigned long, unsigned long);
  59. /* Switch the current MM context. Interrupts are disabled. */
  60. static inline void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm, struct task_struct *tsk)
  61. {
  62. unsigned long ctx_valid, flags;
  63. int cpu;
  64. if (unlikely(mm == &init_mm))
  65. return;
  66. spin_lock_irqsave(&mm->context.lock, flags);
  67. ctx_valid = CTX_VALID(mm->context);
  68. if (!ctx_valid)
  69. get_new_mmu_context(mm);
  70. /* We have to be extremely careful here or else we will miss
  71. * a TSB grow if we switch back and forth between a kernel
  72. * thread and an address space which has it's TSB size increased
  73. * on another processor.
  74. *
  75. * It is possible to play some games in order to optimize the
  76. * switch, but the safest thing to do is to unconditionally
  77. * perform the secondary context load and the TSB context switch.
  78. *
  79. * For reference the bad case is, for address space "A":
  80. *
  81. * CPU 0 CPU 1
  82. * run address space A
  83. * set cpu0's bits in cpu_vm_mask
  84. * switch to kernel thread, borrow
  85. * address space A via entry_lazy_tlb
  86. * run address space A
  87. * set cpu1's bit in cpu_vm_mask
  88. * flush_tlb_pending()
  89. * reset cpu_vm_mask to just cpu1
  90. * TSB grow
  91. * run address space A
  92. * context was valid, so skip
  93. * TSB context switch
  94. *
  95. * At that point cpu0 continues to use a stale TSB, the one from
  96. * before the TSB grow performed on cpu1. cpu1 did not cross-call
  97. * cpu0 to update it's TSB because at that point the cpu_vm_mask
  98. * only had cpu1 set in it.
  99. */
  100. load_secondary_context(mm);
  101. tsb_context_switch(mm);
  102. /* Any time a processor runs a context on an address space
  103. * for the first time, we must flush that context out of the
  104. * local TLB.
  105. */
  106. cpu = smp_processor_id();
  107. if (!ctx_valid || !cpumask_test_cpu(cpu, mm_cpumask(mm))) {
  108. cpumask_set_cpu(cpu, mm_cpumask(mm));
  109. __flush_tlb_mm(CTX_HWBITS(mm->context),
  110. SECONDARY_CONTEXT);
  111. }
  112. spin_unlock_irqrestore(&mm->context.lock, flags);
  113. }
  114. #define deactivate_mm(tsk,mm) do { } while (0)
  115. /* Activate a new MM instance for the current task. */
  116. static inline void activate_mm(struct mm_struct *active_mm, struct mm_struct *mm)
  117. {
  118. unsigned long flags;
  119. int cpu;
  120. spin_lock_irqsave(&mm->context.lock, flags);
  121. if (!CTX_VALID(mm->context))
  122. get_new_mmu_context(mm);
  123. cpu = smp_processor_id();
  124. if (!cpumask_test_cpu(cpu, mm_cpumask(mm)))
  125. cpumask_set_cpu(cpu, mm_cpumask(mm));
  126. load_secondary_context(mm);
  127. __flush_tlb_mm(CTX_HWBITS(mm->context), SECONDARY_CONTEXT);
  128. tsb_context_switch(mm);
  129. spin_unlock_irqrestore(&mm->context.lock, flags);
  130. }
  131. #endif /* !(__ASSEMBLY__) */
  132. #endif /* !(__SPARC64_MMU_CONTEXT_H) */