mmu_context.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #define init_new_context init_new_context
  16. static inline int init_new_context(struct task_struct *tsk,
  17. struct mm_struct *mm)
  18. {
  19. unsigned long asce_type, init_entry;
  20. spin_lock_init(&mm->context.lock);
  21. INIT_LIST_HEAD(&mm->context.pgtable_list);
  22. INIT_LIST_HEAD(&mm->context.gmap_list);
  23. cpumask_clear(&mm->context.cpu_attach_mask);
  24. atomic_set(&mm->context.flush_count, 0);
  25. atomic_set(&mm->context.protected_count, 0);
  26. mm->context.gmap_asce = 0;
  27. mm->context.flush_mm = 0;
  28. #ifdef CONFIG_PGSTE
  29. mm->context.alloc_pgste = page_table_allocate_pgste ||
  30. test_thread_flag(TIF_PGSTE) ||
  31. (current->mm && current->mm->context.alloc_pgste);
  32. mm->context.has_pgste = 0;
  33. mm->context.uses_skeys = 0;
  34. mm->context.uses_cmm = 0;
  35. mm->context.allow_gmap_hpage_1m = 0;
  36. #endif
  37. switch (mm->context.asce_limit) {
  38. default:
  39. /*
  40. * context created by exec, the value of asce_limit can
  41. * only be zero in this case
  42. */
  43. VM_BUG_ON(mm->context.asce_limit);
  44. /* continue as 3-level task */
  45. mm->context.asce_limit = _REGION2_SIZE;
  46. fallthrough;
  47. case _REGION2_SIZE:
  48. /* forked 3-level task */
  49. init_entry = _REGION3_ENTRY_EMPTY;
  50. asce_type = _ASCE_TYPE_REGION3;
  51. break;
  52. case TASK_SIZE_MAX:
  53. /* forked 5-level task */
  54. init_entry = _REGION1_ENTRY_EMPTY;
  55. asce_type = _ASCE_TYPE_REGION1;
  56. break;
  57. case _REGION1_SIZE:
  58. /* forked 4-level task */
  59. init_entry = _REGION2_ENTRY_EMPTY;
  60. asce_type = _ASCE_TYPE_REGION2;
  61. break;
  62. }
  63. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  64. _ASCE_USER_BITS | asce_type;
  65. crst_table_init((unsigned long *) mm->pgd, init_entry);
  66. return 0;
  67. }
  68. static inline void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
  69. struct task_struct *tsk)
  70. {
  71. int cpu = smp_processor_id();
  72. if (next == &init_mm)
  73. S390_lowcore.user_asce = s390_invalid_asce;
  74. else
  75. S390_lowcore.user_asce = next->context.asce;
  76. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  77. /* Clear previous user-ASCE from CR7 */
  78. __ctl_load(s390_invalid_asce, 7, 7);
  79. if (prev != next)
  80. cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
  81. }
  82. #define switch_mm_irqs_off switch_mm_irqs_off
  83. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  84. struct task_struct *tsk)
  85. {
  86. unsigned long flags;
  87. local_irq_save(flags);
  88. switch_mm_irqs_off(prev, next, tsk);
  89. local_irq_restore(flags);
  90. }
  91. #define finish_arch_post_lock_switch finish_arch_post_lock_switch
  92. static inline void finish_arch_post_lock_switch(void)
  93. {
  94. struct task_struct *tsk = current;
  95. struct mm_struct *mm = tsk->mm;
  96. if (mm) {
  97. preempt_disable();
  98. while (atomic_read(&mm->context.flush_count))
  99. cpu_relax();
  100. cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
  101. __tlb_flush_mm_lazy(mm);
  102. preempt_enable();
  103. }
  104. __ctl_load(S390_lowcore.user_asce, 7, 7);
  105. }
  106. #define activate_mm activate_mm
  107. static inline void activate_mm(struct mm_struct *prev,
  108. struct mm_struct *next)
  109. {
  110. switch_mm(prev, next, current);
  111. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  112. __ctl_load(S390_lowcore.user_asce, 7, 7);
  113. }
  114. #include <asm-generic/mmu_context.h>
  115. #endif /* __S390_MMU_CONTEXT_H */