blob: 43607bb12cc2b303e7e9f87d391f053ad0aae2d2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * S390 version
4 *
5 * Derived from "include/asm-i386/mmu_context.h"
6 */
7
8#ifndef __S390_MMU_CONTEXT_H
9#define __S390_MMU_CONTEXT_H
10
Gerald Schaeferc1821c22007-02-05 21:18:17 +010011#include <asm/pgalloc.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080012#include <linux/uaccess.h>
Ingo Molnar589ee622017-02-04 00:16:44 +010013#include <linux/mm_types.h>
Martin Schwidefsky050eef32010-08-24 09:26:21 +020014#include <asm/tlbflush.h>
David Howellsa0616cd2012-03-28 18:30:02 +010015#include <asm/ctl_reg.h>
Martin Schwidefsky8e58ab5c2017-08-23 12:13:51 +020016#include <asm-generic/mm_hooks.h>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020017
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010018static inline int init_new_context(struct task_struct *tsk,
19 struct mm_struct *mm)
20{
Martin Schwidefsky60f07c82017-08-17 08:15:16 +020021 spin_lock_init(&mm->context.lock);
Martin Schwidefsky3446c132016-02-15 14:46:49 +010022 INIT_LIST_HEAD(&mm->context.pgtable_list);
23 INIT_LIST_HEAD(&mm->context.gmap_list);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020024 cpumask_clear(&mm->context.cpu_attach_mask);
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020025 atomic_set(&mm->context.flush_count, 0);
Martin Schwidefsky44b6cc82016-06-13 10:36:00 +020026 mm->context.gmap_asce = 0;
Martin Schwidefsky050eef32010-08-24 09:26:21 +020027 mm->context.flush_mm = 0;
Martin Schwidefsky0b46e0a2015-04-15 13:23:26 +020028#ifdef CONFIG_PGSTE
Martin Schwidefsky23fefe12017-06-07 14:10:24 +020029 mm->context.alloc_pgste = page_table_allocate_pgste ||
30 test_thread_flag(TIF_PGSTE) ||
31 current->mm->context.alloc_pgste;
Martin Schwidefsky3eabaee2013-07-26 15:04:02 +020032 mm->context.has_pgste = 0;
Dominik Dingel693ffc02014-01-14 18:11:14 +010033 mm->context.use_skey = 0;
Claudio Imbrendaaa824e12017-04-20 10:03:46 +020034 mm->context.use_cmma = 0;
Martin Schwidefsky0b46e0a2015-04-15 13:23:26 +020035#endif
Gerald Schaefer723cacb2016-04-15 16:38:40 +020036 switch (mm->context.asce_limit) {
Heiko Carstensf1c11742017-07-05 07:37:27 +020037 case _REGION2_SIZE:
Gerald Schaefer723cacb2016-04-15 16:38:40 +020038 /*
39 * forked 3-level task, fall through to set new asce with new
40 * mm->pgd
41 */
42 case 0:
Martin Schwidefsky3446c132016-02-15 14:46:49 +010043 /* context created by exec, set asce limit to 4TB */
Martin Schwidefsky3446c132016-02-15 14:46:49 +010044 mm->context.asce_limit = STACK_TOP_MAX;
Gerald Schaefer723cacb2016-04-15 16:38:40 +020045 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
46 _ASCE_USER_BITS | _ASCE_TYPE_REGION3;
47 break;
Martin Schwidefsky0b89ede2017-08-31 12:30:54 +020048 case -PAGE_SIZE:
49 /* forked 5-level task, set new asce with new_mm->pgd */
50 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
51 _ASCE_USER_BITS | _ASCE_TYPE_REGION1;
52 break;
Heiko Carstensf1c11742017-07-05 07:37:27 +020053 case _REGION1_SIZE:
Gerald Schaefer723cacb2016-04-15 16:38:40 +020054 /* forked 4-level task, set new asce with new mm->pgd */
55 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
56 _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
57 break;
Heiko Carstensf1c11742017-07-05 07:37:27 +020058 case _REGION3_SIZE:
Gerald Schaefer723cacb2016-04-15 16:38:40 +020059 /* forked 2-level compat task, set new asce with new mm->pgd */
60 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
61 _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT;
62 /* pgd_alloc() did not increase mm->nr_pmds */
Martin Schwidefsky3446c132016-02-15 14:46:49 +010063 mm_inc_nr_pmds(mm);
64 }
Martin Schwidefsky6252d702008-02-09 18:24:37 +010065 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
Martin Schwidefsky6f457e12008-01-26 14:10:58 +010066 return 0;
67}
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#define destroy_context(mm) do { } while (0)
70
Martin Schwidefskybeef5602014-04-14 15:11:26 +020071static inline void set_user_asce(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Gerald Schaefer723cacb2016-04-15 16:38:40 +020073 S390_lowcore.user_asce = mm->context.asce;
Martin Schwidefskyf8b13502014-06-02 14:53:57 +020074 if (current->thread.mm_segment.ar4)
75 __ctl_load(S390_lowcore.user_asce, 7, 7);
Heiko Carstens606aa4a2017-02-17 08:12:30 +010076 set_cpu_flag(CIF_ASCE_PRIMARY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
Martin Schwidefskybeef5602014-04-14 15:11:26 +020079static inline void clear_user_asce(void)
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020080{
81 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
Heiko Carstens457f2182014-03-21 10:42:25 +010082
Martin Schwidefskybeef5602014-04-14 15:11:26 +020083 __ctl_load(S390_lowcore.user_asce, 1, 1);
Heiko Carstens457f2182014-03-21 10:42:25 +010084 __ctl_load(S390_lowcore.user_asce, 7, 7);
85}
86
Martin Schwidefskybeef5602014-04-14 15:11:26 +020087static inline void load_kernel_asce(void)
Heiko Carstens457f2182014-03-21 10:42:25 +010088{
89 unsigned long asce;
90
91 __ctl_store(asce, 1, 1);
92 if (asce != S390_lowcore.kernel_asce)
93 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
Heiko Carstens606aa4a2017-02-17 08:12:30 +010094 set_cpu_flag(CIF_ASCE_PRIMARY);
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020095}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010098 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Martin Schwidefsky53e857f2012-09-10 13:00:09 +0200100 int cpu = smp_processor_id();
101
Gerald Schaefer723cacb2016-04-15 16:38:40 +0200102 S390_lowcore.user_asce = next->context.asce;
Martin Schwidefsky53e857f2012-09-10 13:00:09 +0200103 if (prev == next)
104 return;
Martin Schwidefsky64f31d52016-05-25 09:45:26 +0200105 cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200106 /* Clear old ASCE by loading the kernel ASCE. */
107 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
108 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
Martin Schwidefsky64f31d52016-05-25 09:45:26 +0200109 cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +0200110}
111
112#define finish_arch_post_lock_switch finish_arch_post_lock_switch
113static inline void finish_arch_post_lock_switch(void)
114{
115 struct task_struct *tsk = current;
116 struct mm_struct *mm = tsk->mm;
117
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200118 load_kernel_asce();
119 if (mm) {
120 preempt_disable();
Martin Schwidefsky64f31d52016-05-25 09:45:26 +0200121 while (atomic_read(&mm->context.flush_count))
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200122 cpu_relax();
Martin Schwidefskyb3e5dc42017-08-16 14:10:01 +0200123 cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
Martin Schwidefsky60f07c82017-08-17 08:15:16 +0200124 __tlb_flush_mm_lazy(mm);
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200125 preempt_enable();
126 }
127 set_fs(current->thread.mm_segment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200130#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define deactivate_mm(tsk,mm) do { } while (0)
132
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800133static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 struct mm_struct *next)
135{
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200136 switch_mm(prev, next, current);
Martin Schwidefskyb3e5dc42017-08-16 14:10:01 +0200137 cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200138 set_user_asce(next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100141#endif /* __S390_MMU_CONTEXT_H */