blob: 8d04e6f3f79649d460376f09217c9e8fe211a850 [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;
Vasily Gorbik190f0562019-01-02 13:43:22 +010028 mm->context.compat_mm = test_thread_flag(TIF_31BIT);
Martin Schwidefsky0b46e0a2015-04-15 13:23:26 +020029#ifdef CONFIG_PGSTE
Martin Schwidefsky23fefe12017-06-07 14:10:24 +020030 mm->context.alloc_pgste = page_table_allocate_pgste ||
31 test_thread_flag(TIF_PGSTE) ||
Martin Schwidefsky53c4ab72017-11-22 17:19:32 +010032 (current->mm && current->mm->context.alloc_pgste);
Martin Schwidefsky3eabaee2013-07-26 15:04:02 +020033 mm->context.has_pgste = 0;
Janosch Frank55531b72018-02-15 16:33:47 +010034 mm->context.uses_skeys = 0;
Janosch Frankc9f0a2b2018-02-16 12:16:14 +010035 mm->context.uses_cmm = 0;
Janosch Franka9e00d82018-07-13 11:28:37 +010036 mm->context.allow_gmap_hpage_1m = 0;
Martin Schwidefsky0b46e0a2015-04-15 13:23:26 +020037#endif
Gerald Schaefer723cacb2016-04-15 16:38:40 +020038 switch (mm->context.asce_limit) {
Heiko Carstensf1c11742017-07-05 07:37:27 +020039 case _REGION2_SIZE:
Gerald Schaefer723cacb2016-04-15 16:38:40 +020040 /*
41 * forked 3-level task, fall through to set new asce with new
42 * mm->pgd
43 */
44 case 0:
Martin Schwidefsky3446c132016-02-15 14:46:49 +010045 /* context created by exec, set asce limit to 4TB */
Martin Schwidefsky3446c132016-02-15 14:46:49 +010046 mm->context.asce_limit = STACK_TOP_MAX;
Gerald Schaefer723cacb2016-04-15 16:38:40 +020047 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
48 _ASCE_USER_BITS | _ASCE_TYPE_REGION3;
49 break;
Martin Schwidefsky0b89ede2017-08-31 12:30:54 +020050 case -PAGE_SIZE:
51 /* forked 5-level task, set new asce with new_mm->pgd */
52 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
53 _ASCE_USER_BITS | _ASCE_TYPE_REGION1;
54 break;
Heiko Carstensf1c11742017-07-05 07:37:27 +020055 case _REGION1_SIZE:
Gerald Schaefer723cacb2016-04-15 16:38:40 +020056 /* forked 4-level task, set new asce with new mm->pgd */
57 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
58 _ASCE_USER_BITS | _ASCE_TYPE_REGION2;
59 break;
Heiko Carstensf1c11742017-07-05 07:37:27 +020060 case _REGION3_SIZE:
Gerald Schaefer723cacb2016-04-15 16:38:40 +020061 /* forked 2-level compat task, set new asce with new mm->pgd */
62 mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH |
63 _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT;
Martin Schwidefsky3446c132016-02-15 14:46:49 +010064 }
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 Schwidefsky0aaba412017-08-22 12:08:22 +020074 __ctl_load(S390_lowcore.user_asce, 1, 1);
75 clear_cpu_flag(CIF_ASCE_PRIMARY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Martin Schwidefskybeef5602014-04-14 15:11:26 +020078static inline void clear_user_asce(void)
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020079{
80 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
Martin Schwidefsky0aaba412017-08-22 12:08:22 +020081 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
Heiko Carstens606aa4a2017-02-17 08:12:30 +010082 set_cpu_flag(CIF_ASCE_PRIMARY);
Martin Schwidefsky02a8f3a2014-04-03 13:54:59 +020083}
84
Martin Schwidefsky0aaba412017-08-22 12:08:22 +020085mm_segment_t enable_sacf_uaccess(void);
86void disable_sacf_uaccess(mm_segment_t old_fs);
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Gerald Schaeferc1821c22007-02-05 21:18:17 +010089 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Martin Schwidefsky53e857f2012-09-10 13:00:09 +020091 int cpu = smp_processor_id();
92
Martin Schwidefsky0aaba412017-08-22 12:08:22 +020093 S390_lowcore.user_asce = next->context.asce;
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020094 cpumask_set_cpu(cpu, &next->context.cpu_attach_mask);
Martin Schwidefsky0aaba412017-08-22 12:08:22 +020095 /* Clear previous user-ASCE from CR1 and CR7 */
96 if (!test_cpu_flag(CIF_ASCE_PRIMARY)) {
97 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
98 set_cpu_flag(CIF_ASCE_PRIMARY);
99 }
100 if (test_cpu_flag(CIF_ASCE_SECONDARY)) {
101 __ctl_load(S390_lowcore.vdso_asce, 7, 7);
102 clear_cpu_flag(CIF_ASCE_SECONDARY);
103 }
Martin Schwidefskya3866202019-01-08 12:44:57 +0100104 if (prev != next)
105 cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask);
Martin Schwidefsky53e857f2012-09-10 13:00:09 +0200106}
107
108#define finish_arch_post_lock_switch finish_arch_post_lock_switch
109static inline void finish_arch_post_lock_switch(void)
110{
111 struct task_struct *tsk = current;
112 struct mm_struct *mm = tsk->mm;
113
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200114 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 Schwidefskyb3e5dc42017-08-16 14:10:01 +0200118 cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
Martin Schwidefsky60f07c82017-08-17 08:15:16 +0200119 __tlb_flush_mm_lazy(mm);
Martin Schwidefskyf8b13502014-06-02 14:53:57 +0200120 preempt_enable();
121 }
122 set_fs(current->thread.mm_segment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Martin Schwidefsky3610cce2007-10-22 12:52:47 +0200125#define enter_lazy_tlb(mm,tsk) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#define deactivate_mm(tsk,mm) do { } while (0)
127
Adrian Bunk4448aaf2005-11-08 21:34:42 -0800128static inline void activate_mm(struct mm_struct *prev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 struct mm_struct *next)
130{
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200131 switch_mm(prev, next, current);
Martin Schwidefskyb3e5dc42017-08-16 14:10:01 +0200132 cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
Martin Schwidefskybeef5602014-04-14 15:11:26 +0200133 set_user_asce(next);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100136#endif /* __S390_MMU_CONTEXT_H */