mmu_context.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. INIT_LIST_HEAD(&mm->context.pgtable_list);
  19. INIT_LIST_HEAD(&mm->context.gmap_list);
  20. cpumask_clear(&mm->context.cpu_attach_mask);
  21. atomic_set(&mm->context.flush_count, 0);
  22. mm->context.gmap_asce = 0;
  23. mm->context.flush_mm = 0;
  24. #ifdef CONFIG_PGSTE
  25. mm->context.alloc_pgste = page_table_allocate_pgste ||
  26. test_thread_flag(TIF_PGSTE) ||
  27. current->mm->context.alloc_pgste;
  28. mm->context.has_pgste = 0;
  29. mm->context.use_skey = 0;
  30. mm->context.use_cmma = 0;
  31. #endif
  32. switch (mm->context.asce_limit) {
  33. case _REGION2_SIZE:
  34. /*
  35. * forked 3-level task, fall through to set new asce with new
  36. * mm->pgd
  37. */
  38. case 0:
  39. /* context created by exec, set asce limit to 4TB */
  40. mm->context.asce_limit = STACK_TOP_MAX;
  41. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  42. _ASCE_USER_BITS | _ASCE_TYPE_REGION3;
  43. break;
  44. case -PAGE_SIZE:
  45. /* forked 5-level task, set new asce with new_mm->pgd */
  46. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  47. _ASCE_USER_BITS | _ASCE_TYPE_REGION1;
  48. break;
  49. case _REGION1_SIZE:
  50. /* forked 4-level task, set new asce with new mm->pgd */
  51. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  52. _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
  53. break;
  54. case _REGION3_SIZE:
  55. /* forked 2-level compat task, set new asce with new mm->pgd */
  56. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  57. _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT;
  58. /* pgd_alloc() did not increase mm->nr_pmds */
  59. mm_inc_nr_pmds(mm);
  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. if (current->thread.mm_segment.ar4)
  69. __ctl_load(S390_lowcore.user_asce, 7, 7);
  70. set_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.user_asce, 1, 1);
  76. __ctl_load(S390_lowcore.user_asce, 7, 7);
  77. }
  78. static inline void load_kernel_asce(void)
  79. {
  80. unsigned long asce;
  81. __ctl_store(asce, 1, 1);
  82. if (asce != S390_lowcore.kernel_asce)
  83. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  84. set_cpu_flag(CIF_ASCE_PRIMARY);
  85. }
  86. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  87. struct task_struct *tsk)
  88. {
  89. int cpu = smp_processor_id();
  90. S390_lowcore.user_asce = next->context.asce;
  91. if (prev == next)
  92. return;
  93. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  94. /* Clear old ASCE by loading the kernel ASCE. */
  95. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  96. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  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. load_kernel_asce();
  105. if (mm) {
  106. preempt_disable();
  107. while (atomic_read(&mm->context.flush_count))
  108. cpu_relax();
  109. cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
  110. __tlb_flush_mm_lazy(mm);
  111. preempt_enable();
  112. }
  113. set_fs(current->thread.mm_segment);
  114. }
  115. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  116. #define deactivate_mm(tsk,mm) do { } while (0)
  117. static inline void activate_mm(struct mm_struct *prev,
  118. struct mm_struct *next)
  119. {
  120. switch_mm(prev, next, current);
  121. cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
  122. set_user_asce(next);
  123. }
  124. #endif /* __S390_MMU_CONTEXT_H */