mmu_context.h 4.1 KB

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