s390/mm,tlb: safeguard against speculative TLB creation
[linux-2.6-block.git] / arch / s390 / include / asm / mmu_context.h
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * 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
c1821c2e 10#include <asm/pgalloc.h>
146e4b3c 11#include <asm/uaccess.h>
050eef36 12#include <asm/tlbflush.h>
a0616cde 13#include <asm/ctl_reg.h>
d6dd61c8 14
6f457e1a
MS
15static inline int init_new_context(struct task_struct *tsk,
16 struct mm_struct *mm)
17{
050eef36
MS
18 atomic_set(&mm->context.attach_count, 0);
19 mm->context.flush_mm = 0;
146e4b3c 20 mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS;
6f457e1a 21#ifdef CONFIG_64BIT
6252d702 22 mm->context.asce_bits |= _ASCE_TYPE_REGION3;
6f457e1a 23#endif
3eabaee9 24 mm->context.has_pgste = 0;
6252d702
MS
25 mm->context.asce_limit = STACK_TOP_MAX;
26 crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm));
6f457e1a
MS
27 return 0;
28}
1da177e4
LT
29
30#define destroy_context(mm) do { } while (0)
31
f4815ac6 32#ifndef CONFIG_64BIT
c1821c2e 33#define LCTL_OPCODE "lctl"
c1821c2e
GS
34#else
35#define LCTL_OPCODE "lctlg"
c1821c2e
GS
36#endif
37
02a8f3ab 38static inline void update_user_asce(struct mm_struct *mm)
1da177e4 39{
146e4b3c
MS
40 pgd_t *pgd = mm->pgd;
41
42 S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd);
e258d719
MS
43 /* Load primary space page table origin. */
44 asm volatile(LCTL_OPCODE" 1,1,%0\n" : : "m" (S390_lowcore.user_asce));
6252d702 45 set_fs(current->thread.mm_segment);
1da177e4
LT
46}
47
02a8f3ab
MS
48static inline void clear_user_asce(struct mm_struct *mm)
49{
50 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
51 asm volatile(LCTL_OPCODE" 1,1,%0\n" : : "m" (S390_lowcore.user_asce));
52 asm volatile(LCTL_OPCODE" 7,7,%0\n" : : "m" (S390_lowcore.user_asce));
53}
54
1da177e4 55static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
c1821c2e 56 struct task_struct *tsk)
1da177e4 57{
53e857f3
MS
58 int cpu = smp_processor_id();
59
60 if (prev == next)
61 return;
62 if (atomic_inc_return(&next->context.attach_count) >> 16) {
02a8f3ab 63 /* Delay update_user_asce until all TLB flushes are done. */
53e857f3 64 set_tsk_thread_flag(tsk, TIF_TLB_WAIT);
02a8f3ab
MS
65 /* Clear old ASCE by loading the kernel ASCE. */
66 clear_user_asce(next);
53e857f3
MS
67 } else {
68 cpumask_set_cpu(cpu, mm_cpumask(next));
02a8f3ab 69 update_user_asce(next);
53e857f3
MS
70 if (next->context.flush_mm)
71 /* Flush pending TLBs */
72 __tlb_flush_mm(next);
73 }
050eef36
MS
74 atomic_dec(&prev->context.attach_count);
75 WARN_ON(atomic_read(&prev->context.attach_count) < 0);
53e857f3
MS
76}
77
78#define finish_arch_post_lock_switch finish_arch_post_lock_switch
79static inline void finish_arch_post_lock_switch(void)
80{
81 struct task_struct *tsk = current;
82 struct mm_struct *mm = tsk->mm;
83
84 if (!test_tsk_thread_flag(tsk, TIF_TLB_WAIT))
85 return;
86 preempt_disable();
87 clear_tsk_thread_flag(tsk, TIF_TLB_WAIT);
88 while (atomic_read(&mm->context.attach_count) >> 16)
89 cpu_relax();
90
91 cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
02a8f3ab 92 update_user_asce(mm);
53e857f3
MS
93 if (mm->context.flush_mm)
94 __tlb_flush_mm(mm);
95 preempt_enable();
1da177e4
LT
96}
97
3610cce8 98#define enter_lazy_tlb(mm,tsk) do { } while (0)
1da177e4
LT
99#define deactivate_mm(tsk,mm) do { } while (0)
100
4448aaf0 101static inline void activate_mm(struct mm_struct *prev,
1da177e4
LT
102 struct mm_struct *next)
103{
104 switch_mm(prev, next, current);
1da177e4
LT
105}
106
0f6f281b
MS
107static inline void arch_dup_mmap(struct mm_struct *oldmm,
108 struct mm_struct *mm)
109{
110#ifdef CONFIG_64BIT
111 if (oldmm->context.asce_limit < mm->context.asce_limit)
112 crst_table_downgrade(mm, oldmm->context.asce_limit);
113#endif
114}
115
116static inline void arch_exit_mmap(struct mm_struct *mm)
117{
118}
119
c1821c2e 120#endif /* __S390_MMU_CONTEXT_H */