mmu_context.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * S390 version
  4. *
  5. * Derived from "include/asm-i386/mmu_context.h"
  6. */
  7. #ifndef __S390_MMU_CONTEXT_H
  8. #define __S390_MMU_CONTEXT_H
  9. #include <asm/pgalloc.h>
  10. #include <linux/uaccess.h>
  11. #include <linux/mm_types.h>
  12. #include <asm/tlbflush.h>
  13. #include <asm/ctl_reg.h>
  14. #include <asm-generic/mm_hooks.h>
  15. static inline int init_new_context(struct task_struct *tsk,
  16. struct mm_struct *mm)
  17. {
  18. spin_lock_init(&mm->context.lock);
  19. INIT_LIST_HEAD(&mm->context.pgtable_list);
  20. INIT_LIST_HEAD(&mm->context.gmap_list);
  21. cpumask_clear(&mm->context.cpu_attach_mask);
  22. atomic_set(&mm->context.flush_count, 0);
  23. mm->context.gmap_asce = 0;
  24. mm->context.flush_mm = 0;
  25. #ifdef CONFIG_PGSTE
  26. mm->context.alloc_pgste = page_table_allocate_pgste ||
  27. test_thread_flag(TIF_PGSTE) ||
  28. current->mm->context.alloc_pgste;
  29. mm->context.has_pgste = 0;
  30. mm->context.use_skey = 0;
  31. mm->context.use_cmma = 0;
  32. #endif
  33. switch (mm->context.asce_limit) {
  34. case _REGION2_SIZE:
  35. /*
  36. * forked 3-level task, fall through to set new asce with new
  37. * mm->pgd
  38. */
  39. case 0:
  40. /* context created by exec, set asce limit to 4TB */
  41. mm->context.asce_limit = STACK_TOP_MAX;
  42. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  43. _ASCE_USER_BITS | _ASCE_TYPE_REGION3;
  44. /* pgd_alloc() did not account this pud */
  45. mm_inc_nr_puds(mm);
  46. break;
  47. case -PAGE_SIZE:
  48. /* forked 5-level task, set new asce with new_mm->pgd */
  49. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  50. _ASCE_USER_BITS | _ASCE_TYPE_REGION1;
  51. break;
  52. case _REGION1_SIZE:
  53. /* forked 4-level task, set new asce with new mm->pgd */
  54. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  55. _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
  56. break;
  57. case _REGION3_SIZE:
  58. /* forked 2-level compat task, set new asce with new mm->pgd */
  59. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  60. _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT;
  61. /* pgd_alloc() did not account this pmd */
  62. mm_inc_nr_pmds(mm);
  63. }
  64. crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
  65. return 0;
  66. }
  67. #define destroy_context(mm) do { } while (0)
  68. static inline void set_user_asce(struct mm_struct *mm)
  69. {
  70. S390_lowcore.user_asce = mm->context.asce;
  71. __ctl_load(S390_lowcore.user_asce, 1, 1);
  72. clear_cpu_flag(CIF_ASCE_PRIMARY);
  73. }
  74. static inline void clear_user_asce(void)
  75. {
  76. S390_lowcore.user_asce = S390_lowcore.kernel_asce;
  77. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  78. set_cpu_flag(CIF_ASCE_PRIMARY);
  79. }
  80. mm_segment_t enable_sacf_uaccess(void);
  81. void disable_sacf_uaccess(mm_segment_t old_fs);
  82. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  83. struct task_struct *tsk)
  84. {
  85. int cpu = smp_processor_id();
  86. if (prev == next)
  87. return;
  88. S390_lowcore.user_asce = next->context.asce;
  89. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  90. /* Clear previous user-ASCE from CR1 and CR7 */
  91. if (!test_cpu_flag(CIF_ASCE_PRIMARY)) {
  92. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  93. set_cpu_flag(CIF_ASCE_PRIMARY);
  94. }
  95. if (test_cpu_flag(CIF_ASCE_SECONDARY)) {
  96. __ctl_load(S390_lowcore.vdso_asce, 7, 7);
  97. clear_cpu_flag(CIF_ASCE_SECONDARY);
  98. }
  99. cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
  100. }
  101. #define finish_arch_post_lock_switch finish_arch_post_lock_switch
  102. static inline void finish_arch_post_lock_switch(void)
  103. {
  104. struct task_struct *tsk = current;
  105. struct mm_struct *mm = tsk->mm;
  106. if (mm) {
  107. preempt_disable();
  108. while (atomic_read(&mm->context.flush_count))
  109. cpu_relax();
  110. cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
  111. __tlb_flush_mm_lazy(mm);
  112. preempt_enable();
  113. }
  114. set_fs(current->thread.mm_segment);
  115. }
  116. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  117. #define deactivate_mm(tsk,mm) do { } while (0)
  118. static inline void activate_mm(struct mm_struct *prev,
  119. struct mm_struct *next)
  120. {
  121. switch_mm(prev, next, current);
  122. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  123. set_user_asce(next);
  124. }
  125. #endif /* __S390_MMU_CONTEXT_H */