Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 10 | #include <asm/pgalloc.h> |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 11 | #include <asm/uaccess.h> |
Martin Schwidefsky | 050eef3 | 2010-08-24 09:26:21 +0200 | [diff] [blame] | 12 | #include <asm/tlbflush.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 13 | #include <asm/ctl_reg.h> |
Jeremy Fitzhardinge | d6dd61c | 2007-05-02 19:27:14 +0200 | [diff] [blame] | 14 | |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 15 | static inline int init_new_context(struct task_struct *tsk, |
| 16 | struct mm_struct *mm) |
| 17 | { |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 18 | cpumask_clear(&mm->context.cpu_attach_mask); |
Martin Schwidefsky | 050eef3 | 2010-08-24 09:26:21 +0200 | [diff] [blame] | 19 | atomic_set(&mm->context.attach_count, 0); |
| 20 | mm->context.flush_mm = 0; |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 21 | mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS; |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 22 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 23 | mm->context.asce_bits |= _ASCE_TYPE_REGION3; |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 24 | #endif |
Martin Schwidefsky | 3eabaee | 2013-07-26 15:04:02 +0200 | [diff] [blame] | 25 | mm->context.has_pgste = 0; |
Dominik Dingel | 693ffc0 | 2014-01-14 18:11:14 +0100 | [diff] [blame^] | 26 | mm->context.use_skey = 0; |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 27 | mm->context.asce_limit = STACK_TOP_MAX; |
| 28 | crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm)); |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 29 | return 0; |
| 30 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #define destroy_context(mm) do { } while (0) |
| 33 | |
Heiko Carstens | 457f218 | 2014-03-21 10:42:25 +0100 | [diff] [blame] | 34 | static inline void update_user_asce(struct mm_struct *mm, int load_primary) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 36 | pgd_t *pgd = mm->pgd; |
| 37 | |
| 38 | S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd); |
Heiko Carstens | 457f218 | 2014-03-21 10:42:25 +0100 | [diff] [blame] | 39 | if (load_primary) |
| 40 | __ctl_load(S390_lowcore.user_asce, 1, 1); |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 41 | set_fs(current->thread.mm_segment); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Heiko Carstens | 457f218 | 2014-03-21 10:42:25 +0100 | [diff] [blame] | 44 | static inline void clear_user_asce(struct mm_struct *mm, int load_primary) |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame] | 45 | { |
| 46 | S390_lowcore.user_asce = S390_lowcore.kernel_asce; |
Heiko Carstens | 457f218 | 2014-03-21 10:42:25 +0100 | [diff] [blame] | 47 | |
| 48 | if (load_primary) |
| 49 | __ctl_load(S390_lowcore.user_asce, 1, 1); |
| 50 | __ctl_load(S390_lowcore.user_asce, 7, 7); |
| 51 | } |
| 52 | |
| 53 | static inline void update_primary_asce(struct task_struct *tsk) |
| 54 | { |
| 55 | unsigned long asce; |
| 56 | |
| 57 | __ctl_store(asce, 1, 1); |
| 58 | if (asce != S390_lowcore.kernel_asce) |
| 59 | __ctl_load(S390_lowcore.kernel_asce, 1, 1); |
| 60 | set_tsk_thread_flag(tsk, TIF_ASCE); |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame] | 61 | } |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 64 | struct task_struct *tsk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 66 | int cpu = smp_processor_id(); |
| 67 | |
Heiko Carstens | 457f218 | 2014-03-21 10:42:25 +0100 | [diff] [blame] | 68 | update_primary_asce(tsk); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 69 | if (prev == next) |
| 70 | return; |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 71 | if (MACHINE_HAS_TLB_LC) |
| 72 | cpumask_set_cpu(cpu, &next->context.cpu_attach_mask); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 73 | if (atomic_inc_return(&next->context.attach_count) >> 16) { |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame] | 74 | /* Delay update_user_asce until all TLB flushes are done. */ |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 75 | set_tsk_thread_flag(tsk, TIF_TLB_WAIT); |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame] | 76 | /* Clear old ASCE by loading the kernel ASCE. */ |
Heiko Carstens | 457f218 | 2014-03-21 10:42:25 +0100 | [diff] [blame] | 77 | clear_user_asce(next, 0); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 78 | } else { |
| 79 | cpumask_set_cpu(cpu, mm_cpumask(next)); |
Heiko Carstens | 457f218 | 2014-03-21 10:42:25 +0100 | [diff] [blame] | 80 | update_user_asce(next, 0); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 81 | if (next->context.flush_mm) |
| 82 | /* Flush pending TLBs */ |
| 83 | __tlb_flush_mm(next); |
| 84 | } |
Martin Schwidefsky | 050eef3 | 2010-08-24 09:26:21 +0200 | [diff] [blame] | 85 | atomic_dec(&prev->context.attach_count); |
| 86 | WARN_ON(atomic_read(&prev->context.attach_count) < 0); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 87 | if (MACHINE_HAS_TLB_LC) |
| 88 | cpumask_clear_cpu(cpu, &prev->context.cpu_attach_mask); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | #define finish_arch_post_lock_switch finish_arch_post_lock_switch |
| 92 | static inline void finish_arch_post_lock_switch(void) |
| 93 | { |
| 94 | struct task_struct *tsk = current; |
| 95 | struct mm_struct *mm = tsk->mm; |
| 96 | |
| 97 | if (!test_tsk_thread_flag(tsk, TIF_TLB_WAIT)) |
| 98 | return; |
| 99 | preempt_disable(); |
| 100 | clear_tsk_thread_flag(tsk, TIF_TLB_WAIT); |
| 101 | while (atomic_read(&mm->context.attach_count) >> 16) |
| 102 | cpu_relax(); |
| 103 | |
| 104 | cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm)); |
Heiko Carstens | 457f218 | 2014-03-21 10:42:25 +0100 | [diff] [blame] | 105 | update_user_asce(mm, 0); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 106 | if (mm->context.flush_mm) |
| 107 | __tlb_flush_mm(mm); |
| 108 | preempt_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 111 | #define enter_lazy_tlb(mm,tsk) do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #define deactivate_mm(tsk,mm) do { } while (0) |
| 113 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 114 | static inline void activate_mm(struct mm_struct *prev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | struct mm_struct *next) |
| 116 | { |
| 117 | switch_mm(prev, next, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Martin Schwidefsky | 0f6f281 | 2012-07-26 08:53:06 +0200 | [diff] [blame] | 120 | static inline void arch_dup_mmap(struct mm_struct *oldmm, |
| 121 | struct mm_struct *mm) |
| 122 | { |
| 123 | #ifdef CONFIG_64BIT |
| 124 | if (oldmm->context.asce_limit < mm->context.asce_limit) |
| 125 | crst_table_downgrade(mm, oldmm->context.asce_limit); |
| 126 | #endif |
| 127 | } |
| 128 | |
| 129 | static inline void arch_exit_mmap(struct mm_struct *mm) |
| 130 | { |
| 131 | } |
| 132 | |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 133 | #endif /* __S390_MMU_CONTEXT_H */ |