blob: 4541ac44b35f0e39b831b3eba2e5669d29dd9f89 [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>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080011#include <linux/uaccess.h>
Ingo Molnar589ee622017-02-04 00:16:44 +010012#include <linux/mm_types.h>
Martin Schwidefsky050eef32010-08-24 09:26:21 +020013#include <asm/tlbflush.h>
David Howellsa0616cd2012-03-28 18:30:02 +010014#include <asm/ctl_reg.h>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020015
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010016static inline int init_new_context(struct task_struct *tsk,
17 struct mm_struct *mm)
18{
Martin Schwidefsky8ecb1a52016-03-08 11:54:14 +010019 spin_lock_init(&mm->context.pgtable_lock);
Martin Schwidefsky3446c132016-02-15 14:46:49 +010020 INIT_LIST_HEAD(&mm->context.pgtable_list);
Martin Schwidefsky8ecb1a52016-03-08 11:54:14 +010021 spin_lock_init(&mm->context.gmap_lock);
Martin Schwidefsky3446c132016-02-15 14:46:49 +010022 INIT_LIST_HEAD(&mm->context.gmap_list);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020023 cpumask_clear(&mm->context.cpu_attach_mask);
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020024 atomic_set(&mm->context.flush_count, 0);
Martin Schwidefsky44b6cc82016-06-13 10:36:00 +020025 mm->context.gmap_asce = 0;
Martin Schwidefsky050eef32010-08-24 09:26:21 +020026 mm->context.flush_mm = 0;
Martin Schwidefsky0b46e0a2015-04-15 13:23:26 +020027#ifdef CONFIG_PGSTE
Martin Schwidefsky23fefe12017-06-07 14:10:24 +020028 mm->context.alloc_pgste = page_table_allocate_pgste ||
29 test_thread_flag(TIF_PGSTE) ||
30 current->mm->context.alloc_pgste;
Martin Schwidefsky3eabaee2013-07-26 15:04:02 +020031 mm->context.has_pgste = 0;
Dominik Dingel693ffc02014-01-14 18:11:14 +010032 mm->context.use_skey = 0;
Claudio Imbrendaaa824e12017-04-20 10:03:46 +020033 mm->context.use_cmma = 0;
Martin Schwidefsky0b46e0a2015-04-15 13:23:26 +020034#endif
Gerald Schaefer723cacb2016-04-15 16:38:40 +020035 switch (mm->context.asce_limit) {
36 case 1UL << 42:
37 /*
38 * forked 3-level task, fall through to set new asce with new
39 * mm->pgd
40 */
41 case 0:
Martin Schwidefsky3446c132016-02-15 14:46:49 +010042 /* context created by exec, set asce limit to 4TB */
Martin Schwidefsky3446c132016-02-15 14:46:49 +010043 mm->context.asce_limit = STACK_TOP_MAX;
Gerald Schaefer723cacb2016-04-15 16:38:40 +020044 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
45 _ASCE_USER_BITS | _ASCE_TYPE_REGION3;
46 break;
47 case 1UL << 53:
48 /* forked 4-level task, set new asce with new mm->pgd */
49 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
50 _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
51 break;
52 case 1UL << 31:
53 /* forked 2-level compat task, set new asce with new mm->pgd */
54 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
55 _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT;
56 /* pgd_alloc() did not increase mm->nr_pmds */
Martin Schwidefsky3446c132016-02-15 14:46:49 +010057 mm_inc_nr_pmds(mm);
58 }
Martin Schwidefsky6252d702008-02-09 18:24:37 +010059 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010060 return 0;
61}
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define destroy_context(mm) do { } while (0)
64
Martin Schwidefskybeef5602014-04-14 15:11:26 +020065static inline void set_user_asce(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Gerald Schaefer723cacb2016-04-15 16:38:40 +020067 S390_lowcore.user_asce = mm->context.asce;
Martin Schwidefskyf8b13502014-06-02 14:53:57 +020068 if (current->thread.mm_segment.ar4)
69 __ctl_load(S390_lowcore.user_asce, 7, 7);
Heiko Carstens606aa4a2017-02-17 08:12:30 +010070 set_cpu_flag(CIF_ASCE_PRIMARY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Martin Schwidefskybeef5602014-04-14 15:11:26 +020073static inline void clear_user_asce(void)
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020074{
75 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
Heiko Carstens457f2182014-03-21 10:42:25 +010076
Martin Schwidefskybeef5602014-04-14 15:11:26 +020077 __ctl_load(S390_lowcore.user_asce, 1, 1);
Heiko Carstens457f2182014-03-21 10:42:25 +010078 __ctl_load(S390_lowcore.user_asce, 7, 7);
79}
80
Martin Schwidefskybeef5602014-04-14 15:11:26 +020081static inline void load_kernel_asce(void)
Heiko Carstens457f2182014-03-21 10:42:25 +010082{
83 unsigned long asce;
84
85 __ctl_store(asce, 1, 1);
86 if (asce != S390_lowcore.kernel_asce)
87 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
Heiko Carstens606aa4a2017-02-17 08:12:30 +010088 set_cpu_flag(CIF_ASCE_PRIMARY);
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020089}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010092 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020094 int cpu = smp_processor_id();
95
Gerald Schaefer723cacb2016-04-15 16:38:40 +020096 S390_lowcore.user_asce = next->context.asce;
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020097 if (prev == next)
98 return;
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020099 cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
100 cpumask_set_cpu(cpu, mm_cpumask(next));
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200101 /* Clear old ASCE by loading the kernel ASCE. */
102 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
103 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
Martin Schwidefsky64f31d52016-05-25 09:45:26 +0200104 cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +0200105}
106
107#define finish_arch_post_lock_switch finish_arch_post_lock_switch
108static inline void finish_arch_post_lock_switch(void)
109{
110 struct task_struct *tsk = current;
111 struct mm_struct *mm = tsk->mm;
112
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200113 load_kernel_asce();
114 if (mm) {
115 preempt_disable();
Martin Schwidefsky64f31d52016-05-25 09:45:26 +0200116 while (atomic_read(&mm->context.flush_count))
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200117 cpu_relax();
Martin Schwidefsky53e857f2012-09-10 13:00:09 +0200118
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200119 if (mm->context.flush_mm)
120 __tlb_flush_mm(mm);
121 preempt_enable();
122 }
123 set_fs(current->thread.mm_segment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200126#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define deactivate_mm(tsk,mm) do { } while (0)
128
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800129static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 struct mm_struct *next)
131{
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200132 switch_mm(prev, next, current);
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200133 set_user_asce(next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Martin Schwidefsky0f6f2812012-07-26 08:53:06 +0200136static inline void arch_dup_mmap(struct mm_struct *oldmm,
137 struct mm_struct *mm)
138{
Martin Schwidefsky0f6f2812012-07-26 08:53:06 +0200139}
140
141static inline void arch_exit_mmap(struct mm_struct *mm)
142{
143}
144
Dave Hansen62e88b12014-11-18 10:23:50 -0800145static inline void arch_unmap(struct mm_struct *mm,
146 struct vm_area_struct *vma,
147 unsigned long start, unsigned long end)
148{
149}
150
151static inline void arch_bprm_mm_init(struct mm_struct *mm,
152 struct vm_area_struct *vma)
153{
154}
155
Dave Hansen1b2ee122016-02-12 13:02:21 -0800156static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
Dave Hansend61172b2016-02-12 13:02:24 -0800157 bool write, bool execute, bool foreign)
Dave Hansen33a709b2016-02-12 13:02:19 -0800158{
159 /* by default, allow everything */
160 return true;
161}
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100162#endif /* __S390_MMU_CONTEXT_H */