mmu_context.h 3.8 KB

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