mmu_context.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 <asm/tlbflush.h>
  11. #include <asm/ctl_reg.h>
  12. static inline int init_new_context(struct task_struct *tsk,
  13. struct mm_struct *mm)
  14. {
  15. spin_lock_init(&mm->context.pgtable_lock);
  16. INIT_LIST_HEAD(&mm->context.pgtable_list);
  17. spin_lock_init(&mm->context.gmap_lock);
  18. INIT_LIST_HEAD(&mm->context.gmap_list);
  19. cpumask_clear(&mm->context.cpu_attach_mask);
  20. atomic_set(&mm->context.flush_count, 0);
  21. mm->context.gmap_asce = 0;
  22. mm->context.flush_mm = 0;
  23. #ifdef CONFIG_PGSTE
  24. mm->context.alloc_pgste = page_table_allocate_pgste;
  25. mm->context.has_pgste = 0;
  26. mm->context.use_skey = 0;
  27. #endif
  28. switch (mm->context.asce_limit) {
  29. case 1UL << 42:
  30. /*
  31. * forked 3-level task, fall through to set new asce with new
  32. * mm->pgd
  33. */
  34. case 0:
  35. /* context created by exec, set asce limit to 4TB */
  36. mm->context.asce_limit = STACK_TOP_MAX;
  37. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  38. _ASCE_USER_BITS | _ASCE_TYPE_REGION3;
  39. break;
  40. case 1UL << 53:
  41. /* forked 4-level task, set new asce with new mm->pgd */
  42. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  43. _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
  44. break;
  45. case 1UL << 31:
  46. /* forked 2-level compat task, set new asce with new mm->pgd */
  47. mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
  48. _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT;
  49. /* pgd_alloc() did not increase mm->nr_pmds */
  50. mm_inc_nr_pmds(mm);
  51. }
  52. crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
  53. return 0;
  54. }
  55. #define destroy_context(mm) do { } while (0)
  56. static inline void set_user_asce(struct mm_struct *mm)
  57. {
  58. S390_lowcore.user_asce = mm->context.asce;
  59. if (current->thread.mm_segment.ar4)
  60. __ctl_load(S390_lowcore.user_asce, 7, 7);
  61. set_cpu_flag(CIF_ASCE);
  62. }
  63. static inline void clear_user_asce(void)
  64. {
  65. S390_lowcore.user_asce = S390_lowcore.kernel_asce;
  66. __ctl_load(S390_lowcore.user_asce, 1, 1);
  67. __ctl_load(S390_lowcore.user_asce, 7, 7);
  68. }
  69. static inline void load_kernel_asce(void)
  70. {
  71. unsigned long asce;
  72. __ctl_store(asce, 1, 1);
  73. if (asce != S390_lowcore.kernel_asce)
  74. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  75. set_cpu_flag(CIF_ASCE);
  76. }
  77. static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
  78. struct task_struct *tsk)
  79. {
  80. int cpu = smp_processor_id();
  81. S390_lowcore.user_asce = next->context.asce;
  82. if (prev == next)
  83. return;
  84. cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
  85. cpumask_set_cpu(cpu, mm_cpumask(next));
  86. /* Clear old ASCE by loading the kernel ASCE. */
  87. __ctl_load(S390_lowcore.kernel_asce, 1, 1);
  88. __ctl_load(S390_lowcore.kernel_asce, 7, 7);
  89. cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
  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. load_kernel_asce();
  97. if (mm) {
  98. preempt_disable();
  99. while (atomic_read(&mm->context.flush_count))
  100. cpu_relax();
  101. if (mm->context.flush_mm)
  102. __tlb_flush_mm(mm);
  103. preempt_enable();
  104. }
  105. set_fs(current->thread.mm_segment);
  106. }
  107. #define enter_lazy_tlb(mm,tsk) do { } while (0)
  108. #define deactivate_mm(tsk,mm) do { } while (0)
  109. static inline void activate_mm(struct mm_struct *prev,
  110. struct mm_struct *next)
  111. {
  112. switch_mm(prev, next, current);
  113. set_user_asce(next);
  114. }
  115. static inline void arch_dup_mmap(struct mm_struct *oldmm,
  116. struct mm_struct *mm)
  117. {
  118. }
  119. static inline void arch_exit_mmap(struct mm_struct *mm)
  120. {
  121. }
  122. static inline void arch_unmap(struct mm_struct *mm,
  123. struct vm_area_struct *vma,
  124. unsigned long start, unsigned long end)
  125. {
  126. }
  127. static inline void arch_bprm_mm_init(struct mm_struct *mm,
  128. struct vm_area_struct *vma)
  129. {
  130. }
  131. static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
  132. bool write, bool execute, bool foreign)
  133. {
  134. /* by default, allow everything */
  135. return true;
  136. }
  137. static inline bool arch_pte_access_permitted(pte_t pte, bool write)
  138. {
  139. /* by default, allow everything */
  140. return true;
  141. }
  142. #endif /* __S390_MMU_CONTEXT_H */