mmu_context.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * arch/arm/include/asm/mmu_context.h
  4. *
  5. * Copyright (C) 1996 Russell King.
  6. *
  7. * Changelog:
  8. * 27-06-1996 RMK Created
  9. */
  10. #ifndef __ASM_ARM_MMU_CONTEXT_H
  11. #define __ASM_ARM_MMU_CONTEXT_H
  12. #include <linux/compiler.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm_types.h>
  15. #include <linux/preempt.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/cachetype.h>
  18. #include <asm/proc-fns.h>
  19. #include <asm/smp_plat.h>
  20. #include <asm-generic/mm_hooks.h>
  21. void __check_vmalloc_seq(struct mm_struct *mm);
  22. #ifdef CONFIG_MMU
  23. static inline void check_vmalloc_seq(struct mm_struct *mm)
  24. {
  25. if (!IS_ENABLED(CONFIG_ARM_LPAE) &&
  26. unlikely(atomic_read(&mm->context.vmalloc_seq) !=
  27. atomic_read(&init_mm.context.vmalloc_seq)))
  28. __check_vmalloc_seq(mm);
  29. }
  30. #endif
  31. #ifdef CONFIG_CPU_HAS_ASID
  32. void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk);
  33. #define init_new_context init_new_context
  34. static inline int
  35. init_new_context(struct task_struct *tsk, struct mm_struct *mm)
  36. {
  37. atomic64_set(&mm->context.id, 0);
  38. return 0;
  39. }
  40. #ifdef CONFIG_ARM_ERRATA_798181
  41. void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,
  42. cpumask_t *mask);
  43. #else /* !CONFIG_ARM_ERRATA_798181 */
  44. static inline void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,
  45. cpumask_t *mask)
  46. {
  47. }
  48. #endif /* CONFIG_ARM_ERRATA_798181 */
  49. #else /* !CONFIG_CPU_HAS_ASID */
  50. #ifdef CONFIG_MMU
  51. static inline void check_and_switch_context(struct mm_struct *mm,
  52. struct task_struct *tsk)
  53. {
  54. check_vmalloc_seq(mm);
  55. if (irqs_disabled())
  56. /*
  57. * cpu_switch_mm() needs to flush the VIVT caches. To avoid
  58. * high interrupt latencies, defer the call and continue
  59. * running with the old mm. Since we only support UP systems
  60. * on non-ASID CPUs, the old mm will remain valid until the
  61. * finish_arch_post_lock_switch() call.
  62. */
  63. mm->context.switch_pending = 1;
  64. else
  65. cpu_switch_mm(mm->pgd, mm);
  66. }
  67. #ifndef MODULE
  68. #define finish_arch_post_lock_switch \
  69. finish_arch_post_lock_switch
  70. static inline void finish_arch_post_lock_switch(void)
  71. {
  72. struct mm_struct *mm = current->mm;
  73. if (mm && mm->context.switch_pending) {
  74. /*
  75. * Preemption must be disabled during cpu_switch_mm() as we
  76. * have some stateful cache flush implementations. Check
  77. * switch_pending again in case we were preempted and the
  78. * switch to this mm was already done.
  79. */
  80. preempt_disable();
  81. if (mm->context.switch_pending) {
  82. mm->context.switch_pending = 0;
  83. cpu_switch_mm(mm->pgd, mm);
  84. }
  85. preempt_enable_no_resched();
  86. }
  87. }
  88. #endif /* !MODULE */
  89. #endif /* CONFIG_MMU */
  90. #endif /* CONFIG_CPU_HAS_ASID */
  91. #define activate_mm(prev,next) switch_mm(prev, next, NULL)
  92. /*
  93. * This is the actual mm switch as far as the scheduler
  94. * is concerned. No registers are touched. We avoid
  95. * calling the CPU specific function when the mm hasn't
  96. * actually changed.
  97. */
  98. static inline void
  99. switch_mm(struct mm_struct *prev, struct mm_struct *next,
  100. struct task_struct *tsk)
  101. {
  102. #ifdef CONFIG_MMU
  103. unsigned int cpu = smp_processor_id();
  104. /*
  105. * __sync_icache_dcache doesn't broadcast the I-cache invalidation,
  106. * so check for possible thread migration and invalidate the I-cache
  107. * if we're new to this CPU.
  108. */
  109. if (cache_ops_need_broadcast() &&
  110. !cpumask_empty(mm_cpumask(next)) &&
  111. !cpumask_test_cpu(cpu, mm_cpumask(next)))
  112. __flush_icache_all();
  113. if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
  114. check_and_switch_context(next, tsk);
  115. if (cache_is_vivt())
  116. cpumask_clear_cpu(cpu, mm_cpumask(prev));
  117. }
  118. #endif
  119. }
  120. #ifdef CONFIG_VMAP_STACK
  121. static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
  122. {
  123. if (mm != &init_mm)
  124. check_vmalloc_seq(mm);
  125. }
  126. #define enter_lazy_tlb enter_lazy_tlb
  127. #endif
  128. #include <asm-generic/mmu_context.h>
  129. #endif