mmu_context.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * S390 version
  3. *
  4. * Derived from "include/asm-i386/mmu_context.h"
  5. */
  6. #ifndef __S390_MMU_CONTEXT_H
  7. #define __S390_MMU_CONTEXT_H
  8. #include <asm/pgalloc.h>
  9. #include <linux/uaccess.h>
  10. #include <linux/mm_types.h>
  11. #include <asm/tlbflush.h>
  12. #include <asm/ctl_reg.h>
  13. #include <asm-generic/mm_hooks.h>
  14. static inline int init_new_context(struct task_struct *tsk,
  15. struct mm_struct *mm)
  16. {
  17. spin_lock_init(&mm->context.lock);
  18. spin_lock_init(&mm->context.pgtable_lock);
  19. INIT_LIST_HEAD(&mm->context.pgtable_list);
  20. spin_lock_init(&mm->context.gmap_lock);
  21. INIT_LIST_HEAD(&mm->context.gmap_list);
  22. cpumask_clear(&mm->context.cpu_attach_mask);
  23. atomic_set(&mm->context.flush_count, 0);
  24. mm->context.gmap_asce = 0;
  25. mm->context.flush_mm = 0;
  26. #ifdef CONFIG_PGSTE
  27. mm->context.alloc_pgste = page_table_allocate_pgste ||
  28. test_thread_flag(TIF_PGSTE) ||
  29. current->mm->context.alloc_pgste;
  30. mm->context.has_pgste = 0;
  31. mm->context.use_skey = 0;
  32. mm->context.use_cmma = 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. /* pgd_alloc() did not increase mm->nr_pmds */
  61. mm_inc_nr_pmds(mm);
  62. }
  63. crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
  64. return 0;
  65. }
  66. #define destroy_context(mm) do { } while (0)
  67. static inline void set_user_asce(struct mm_struct *mm)
  68. {
  69. S390_lowcore.user_asce = mm->context.asce;
  70. if (current->thread.mm_segment.ar4)
  71. __ctl_load(S390_lowcore.user_asce, 7, 7);
  72. set_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.user_asce, 1, 1);
  78. __ctl_load(S390_lowcore.user_asce, 7, 7);
  79. }
  80. static inline void load_kernel_asce(void)
  81. {
  82. unsigned long asce;
  83. __ctl_store(asce, 1, 1);
  84. if (asce != S390_lowcore.kernel_asce)
  85. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  86. set_cpu_flag(CIF_ASCE_PRIMARY);
  87. }
  88. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  89. struct task_struct *tsk)
  90. {
  91. int cpu = smp_processor_id();
  92. S390_lowcore.user_asce = next->context.asce;
  93. if (prev == next)
  94. return;
  95. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  96. /* Clear old ASCE by loading the kernel ASCE. */
  97. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  98. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  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. load_kernel_asce();
  107. if (mm) {
  108. preempt_disable();
  109. while (atomic_read(&mm->context.flush_count))
  110. cpu_relax();
  111. cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
  112. __tlb_flush_mm_lazy(mm);
  113. preempt_enable();
  114. }
  115. set_fs(current->thread.mm_segment);
  116. }
  117. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  118. #define deactivate_mm(tsk,mm) do { } while (0)
  119. static inline void activate_mm(struct mm_struct *prev,
  120. struct mm_struct *next)
  121. {
  122. switch_mm(prev, next, current);
  123. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  124. set_user_asce(next);
  125. }
  126. #endif /* __S390_MMU_CONTEXT_H */