mmu_context.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. mm->context.compat_mm = 0;
  26. #ifdef CONFIG_PGSTE
  27. mm->context.alloc_pgste = page_table_allocate_pgste ||
  28. test_thread_flag(TIF_PGSTE) ||
  29. (current->mm && current->mm->context.alloc_pgste);
  30. mm->context.has_pgste = 0;
  31. mm->context.uses_skeys = 0;
  32. mm->context.uses_cmm = 0;
  33. mm->context.allow_gmap_hpage_1m = 0;
  34. #endif
  35. switch (mm->context.asce_limit) {
  36. case _REGION2_SIZE:
  37. /*
  38. * forked 3-level task, fall through to set new asce with new
  39. * mm->pgd
  40. */
  41. case 0:
  42. /* context created by exec, set asce limit to 4TB */
  43. mm->context.asce_limit = STACK_TOP_MAX;
  44. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  45. _ASCE_USER_BITS | _ASCE_TYPE_REGION3;
  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. }
  62. crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
  63. return 0;
  64. }
  65. #define destroy_context(mm) do { } while (0)
  66. static inline void set_user_asce(struct mm_struct *mm)
  67. {
  68. S390_lowcore.user_asce = mm->context.asce;
  69. __ctl_load(S390_lowcore.user_asce, 1, 1);
  70. clear_cpu_flag(CIF_ASCE_PRIMARY);
  71. }
  72. static inline void clear_user_asce(void)
  73. {
  74. S390_lowcore.user_asce = S390_lowcore.kernel_asce;
  75. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  76. set_cpu_flag(CIF_ASCE_PRIMARY);
  77. }
  78. mm_segment_t enable_sacf_uaccess(void);
  79. void disable_sacf_uaccess(mm_segment_t old_fs);
  80. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  81. struct task_struct *tsk)
  82. {
  83. int cpu = smp_processor_id();
  84. if (prev == next)
  85. return;
  86. S390_lowcore.user_asce = next->context.asce;
  87. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  88. /* Clear previous user-ASCE from CR1 and CR7 */
  89. if (!test_cpu_flag(CIF_ASCE_PRIMARY)) {
  90. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  91. set_cpu_flag(CIF_ASCE_PRIMARY);
  92. }
  93. if (test_cpu_flag(CIF_ASCE_SECONDARY)) {
  94. __ctl_load(S390_lowcore.vdso_asce, 7, 7);
  95. clear_cpu_flag(CIF_ASCE_SECONDARY);
  96. }
  97. cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
  98. }
  99. #define finish_arch_post_lock_switch finish_arch_post_lock_switch
  100. static inline void finish_arch_post_lock_switch(void)
  101. {
  102. struct task_struct *tsk = current;
  103. struct mm_struct *mm = tsk->mm;
  104. if (mm) {
  105. preempt_disable();
  106. while (atomic_read(&mm->context.flush_count))
  107. cpu_relax();
  108. cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
  109. __tlb_flush_mm_lazy(mm);
  110. preempt_enable();
  111. }
  112. set_fs(current->thread.mm_segment);
  113. }
  114. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  115. #define deactivate_mm(tsk,mm) do { } while (0)
  116. static inline void activate_mm(struct mm_struct *prev,
  117. struct mm_struct *next)
  118. {
  119. switch_mm(prev, next, current);
  120. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  121. set_user_asce(next);
  122. }
  123. #endif /* __S390_MMU_CONTEXT_H */