blob: f77c638bf3974063a941b5d9b8e537a2c7cfb1a4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S390 version
3 *
4 * Derived from "include/asm-i386/mmu_context.h"
5 */
6
7#ifndef __S390_MMU_CONTEXT_H
8#define __S390_MMU_CONTEXT_H
9
Gerald Schaeferc1821c22007-02-05 21:18:17 +010010#include <asm/pgalloc.h>
Martin Schwidefsky146e4b32008-02-09 18:24:35 +010011#include <asm/uaccess.h>
Martin Schwidefsky050eef32010-08-24 09:26:21 +020012#include <asm/tlbflush.h>
David Howellsa0616cd2012-03-28 18:30:02 +010013#include <asm/ctl_reg.h>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020014
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010015static inline int init_new_context(struct task_struct *tsk,
16 struct mm_struct *mm)
17{
Martin Schwidefsky3446c132016-02-15 14:46:49 +010018 spin_lock_init(&mm->context.list_lock);
19 INIT_LIST_HEAD(&mm->context.pgtable_list);
20 INIT_LIST_HEAD(&mm->context.gmap_list);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020021 cpumask_clear(&mm->context.cpu_attach_mask);
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020022 atomic_set(&mm->context.flush_count, 0);
Martin Schwidefsky050eef32010-08-24 09:26:21 +020023 mm->context.flush_mm = 0;
Martin Schwidefsky0b46e0a2015-04-15 13:23:26 +020024#ifdef CONFIG_PGSTE
25 mm->context.alloc_pgste = page_table_allocate_pgste;
Martin Schwidefsky3eabaee2013-07-26 15:04:02 +020026 mm->context.has_pgste = 0;
Dominik Dingel693ffc02014-01-14 18:11:14 +010027 mm->context.use_skey = 0;
Martin Schwidefsky0b46e0a2015-04-15 13:23:26 +020028#endif
Gerald Schaefer723cacb2016-04-15 16:38:40 +020029 switch (mm->context.asce_limit) {
30 case 1UL << 42:
31 /*
32 * forked 3-level task, fall through to set new asce with new
33 * mm->pgd
34 */
35 case 0:
Martin Schwidefsky3446c132016-02-15 14:46:49 +010036 /* context created by exec, set asce limit to 4TB */
Martin Schwidefsky3446c132016-02-15 14:46:49 +010037 mm->context.asce_limit = STACK_TOP_MAX;
Gerald Schaefer723cacb2016-04-15 16:38:40 +020038 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
39 _ASCE_USER_BITS | _ASCE_TYPE_REGION3;
40 break;
41 case 1UL << 53:
42 /* forked 4-level task, set new asce with new mm->pgd */
43 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
44 _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
45 break;
46 case 1UL << 31:
47 /* forked 2-level compat task, set new asce with new mm->pgd */
48 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
49 _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT;
50 /* pgd_alloc() did not increase mm->nr_pmds */
Martin Schwidefsky3446c132016-02-15 14:46:49 +010051 mm_inc_nr_pmds(mm);
52 }
Martin Schwidefsky6252d702008-02-09 18:24:37 +010053 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010054 return 0;
55}
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define destroy_context(mm) do { } while (0)
58
Martin Schwidefskybeef5602014-04-14 15:11:26 +020059static inline void set_user_asce(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Gerald Schaefer723cacb2016-04-15 16:38:40 +020061 S390_lowcore.user_asce = mm->context.asce;
Martin Schwidefskyf8b13502014-06-02 14:53:57 +020062 if (current->thread.mm_segment.ar4)
63 __ctl_load(S390_lowcore.user_asce, 7, 7);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020064 set_cpu_flag(CIF_ASCE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Martin Schwidefskybeef5602014-04-14 15:11:26 +020067static inline void clear_user_asce(void)
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020068{
69 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
Heiko Carstens457f2182014-03-21 10:42:25 +010070
Martin Schwidefskybeef5602014-04-14 15:11:26 +020071 __ctl_load(S390_lowcore.user_asce, 1, 1);
Heiko Carstens457f2182014-03-21 10:42:25 +010072 __ctl_load(S390_lowcore.user_asce, 7, 7);
73}
74
Martin Schwidefskybeef5602014-04-14 15:11:26 +020075static inline void load_kernel_asce(void)
Heiko Carstens457f2182014-03-21 10:42:25 +010076{
77 unsigned long asce;
78
79 __ctl_store(asce, 1, 1);
80 if (asce != S390_lowcore.kernel_asce)
81 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
Martin Schwidefskyd3a73ac2014-04-15 12:55:07 +020082 set_cpu_flag(CIF_ASCE);
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020083}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010086 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020088 int cpu = smp_processor_id();
89
Gerald Schaefer723cacb2016-04-15 16:38:40 +020090 S390_lowcore.user_asce = next->context.asce;
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020091 if (prev == next)
92 return;
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020093 cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
94 cpumask_set_cpu(cpu, mm_cpumask(next));
Martin Schwidefskybeef5602014-04-14 15:11:26 +020095 /* Clear old ASCE by loading the kernel ASCE. */
96 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
97 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020098 cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020099}
100
101#define finish_arch_post_lock_switch finish_arch_post_lock_switch
102static inline void finish_arch_post_lock_switch(void)
103{
104 struct task_struct *tsk = current;
105 struct mm_struct *mm = tsk->mm;
106
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200107 load_kernel_asce();
108 if (mm) {
109 preempt_disable();
Martin Schwidefsky64f31d52016-05-25 09:45:26 +0200110 while (atomic_read(&mm->context.flush_count))
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200111 cpu_relax();
Martin Schwidefsky53e857f2012-09-10 13:00:09 +0200112
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200113 if (mm->context.flush_mm)
114 __tlb_flush_mm(mm);
115 preempt_enable();
116 }
117 set_fs(current->thread.mm_segment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200120#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#define deactivate_mm(tsk,mm) do { } while (0)
122
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800123static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 struct mm_struct *next)
125{
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200126 switch_mm(prev, next, current);
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200127 set_user_asce(next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
Martin Schwidefsky0f6f2812012-07-26 08:53:06 +0200130static inline void arch_dup_mmap(struct mm_struct *oldmm,
131 struct mm_struct *mm)
132{
Martin Schwidefsky0f6f2812012-07-26 08:53:06 +0200133}
134
135static inline void arch_exit_mmap(struct mm_struct *mm)
136{
137}
138
Dave Hansen62e88b12014-11-18 10:23:50 -0800139static inline void arch_unmap(struct mm_struct *mm,
140 struct vm_area_struct *vma,
141 unsigned long start, unsigned long end)
142{
143}
144
145static inline void arch_bprm_mm_init(struct mm_struct *mm,
146 struct vm_area_struct *vma)
147{
148}
149
Dave Hansen1b2ee122016-02-12 13:02:21 -0800150static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
Dave Hansend61172b2016-02-12 13:02:24 -0800151 bool write, bool execute, bool foreign)
Dave Hansen33a709b2016-02-12 13:02:19 -0800152{
153 /* by default, allow everything */
154 return true;
155}
156
157static inline bool arch_pte_access_permitted(pte_t pte, bool write)
158{
159 /* by default, allow everything */
160 return true;
161}
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100162#endif /* __S390_MMU_CONTEXT_H */