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 | 050eef3 | 2010-08-24 09:26:21 +0200 | [diff] [blame] | 18 | atomic_set(&mm->context.attach_count, 0); |
| 19 | mm->context.flush_mm = 0; |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 20 | mm->context.asce_bits = _ASCE_TABLE_LENGTH | _ASCE_USER_BITS; |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 21 | #ifdef CONFIG_64BIT |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 22 | mm->context.asce_bits |= _ASCE_TYPE_REGION3; |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 23 | #endif |
Martin Schwidefsky | 3eabaee | 2013-07-26 15:04:02 +0200 | [diff] [blame] | 24 | mm->context.has_pgste = 0; |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 25 | mm->context.asce_limit = STACK_TOP_MAX; |
| 26 | crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm)); |
Martin Schwidefsky | 6f457e1 | 2008-01-26 14:10:58 +0100 | [diff] [blame] | 27 | return 0; |
| 28 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #define destroy_context(mm) do { } while (0) |
| 31 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame] | 32 | #ifndef CONFIG_64BIT |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 33 | #define LCTL_OPCODE "lctl" |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 34 | #else |
| 35 | #define LCTL_OPCODE "lctlg" |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 36 | #endif |
| 37 | |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame^] | 38 | static inline void update_user_asce(struct mm_struct *mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
Martin Schwidefsky | 146e4b3 | 2008-02-09 18:24:35 +0100 | [diff] [blame] | 40 | pgd_t *pgd = mm->pgd; |
| 41 | |
| 42 | S390_lowcore.user_asce = mm->context.asce_bits | __pa(pgd); |
Martin Schwidefsky | e258d71 | 2013-09-24 09:14:56 +0200 | [diff] [blame] | 43 | /* Load primary space page table origin. */ |
| 44 | asm volatile(LCTL_OPCODE" 1,1,%0\n" : : "m" (S390_lowcore.user_asce)); |
Martin Schwidefsky | 6252d70 | 2008-02-09 18:24:37 +0100 | [diff] [blame] | 45 | set_fs(current->thread.mm_segment); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame^] | 48 | static 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | 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] | 56 | struct task_struct *tsk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 58 | int cpu = smp_processor_id(); |
| 59 | |
| 60 | if (prev == next) |
| 61 | return; |
| 62 | if (atomic_inc_return(&next->context.attach_count) >> 16) { |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame^] | 63 | /* Delay update_user_asce until all TLB flushes are done. */ |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 64 | set_tsk_thread_flag(tsk, TIF_TLB_WAIT); |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame^] | 65 | /* Clear old ASCE by loading the kernel ASCE. */ |
| 66 | clear_user_asce(next); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 67 | } else { |
| 68 | cpumask_set_cpu(cpu, mm_cpumask(next)); |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame^] | 69 | update_user_asce(next); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 70 | if (next->context.flush_mm) |
| 71 | /* Flush pending TLBs */ |
| 72 | __tlb_flush_mm(next); |
| 73 | } |
Martin Schwidefsky | 050eef3 | 2010-08-24 09:26:21 +0200 | [diff] [blame] | 74 | atomic_dec(&prev->context.attach_count); |
| 75 | WARN_ON(atomic_read(&prev->context.attach_count) < 0); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | #define finish_arch_post_lock_switch finish_arch_post_lock_switch |
| 79 | static 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)); |
Martin Schwidefsky | 02a8f3a | 2014-04-03 13:54:59 +0200 | [diff] [blame^] | 92 | update_user_asce(mm); |
Martin Schwidefsky | 53e857f | 2012-09-10 13:00:09 +0200 | [diff] [blame] | 93 | if (mm->context.flush_mm) |
| 94 | __tlb_flush_mm(mm); |
| 95 | preempt_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Martin Schwidefsky | 3610cce | 2007-10-22 12:52:47 +0200 | [diff] [blame] | 98 | #define enter_lazy_tlb(mm,tsk) do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | #define deactivate_mm(tsk,mm) do { } while (0) |
| 100 | |
Adrian Bunk | 4448aaf | 2005-11-08 21:34:42 -0800 | [diff] [blame] | 101 | static inline void activate_mm(struct mm_struct *prev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | struct mm_struct *next) |
| 103 | { |
| 104 | switch_mm(prev, next, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Martin Schwidefsky | 0f6f281 | 2012-07-26 08:53:06 +0200 | [diff] [blame] | 107 | static 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 | |
| 116 | static inline void arch_exit_mmap(struct mm_struct *mm) |
| 117 | { |
| 118 | } |
| 119 | |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 120 | #endif /* __S390_MMU_CONTEXT_H */ |