Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _S390_TLBFLUSH_H |
| 2 | #define _S390_TLBFLUSH_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/mm.h> |
Gerald Schaefer | 53492b1 | 2008-04-30 13:38:46 +0200 | [diff] [blame] | 5 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <asm/processor.h> |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 7 | #include <asm/pgalloc.h> |
Heiko Carstens | 4ccccc5 | 2016-05-14 10:46:33 +0200 | [diff] [blame] | 8 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | /* |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 11 | * Flush all TLB entries on the local CPU. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | */ |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 13 | static inline void __tlb_flush_local(void) |
| 14 | { |
| 15 | asm volatile("ptlb" : : : "memory"); |
| 16 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | /* |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 19 | * Flush TLB entries for a specific ASCE on all CPUs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 21 | static inline void __tlb_flush_idte(unsigned long asce) |
| 22 | { |
| 23 | /* Global TLB flush for the mm */ |
| 24 | asm volatile( |
| 25 | " .insn rrf,0xb98e0000,0,%0,%1,0" |
| 26 | : : "a" (2048), "a" (asce) : "cc"); |
| 27 | } |
| 28 | |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 29 | #ifdef CONFIG_SMP |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 30 | void smp_ptlb_all(void); |
| 31 | |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 32 | /* |
| 33 | * Flush all TLB entries on all CPUs. |
| 34 | */ |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 35 | static inline void __tlb_flush_global(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Heiko Carstens | 4ccccc5 | 2016-05-14 10:46:33 +0200 | [diff] [blame] | 37 | unsigned int dummy = 0; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 38 | |
Heiko Carstens | 4ccccc5 | 2016-05-14 10:46:33 +0200 | [diff] [blame] | 39 | csp(&dummy, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 42 | /* |
| 43 | * Flush TLB entries for a specific mm on all CPUs (in case gmap is used |
| 44 | * this implicates multiple ASCEs!). |
| 45 | */ |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame] | 46 | static inline void __tlb_flush_full(struct mm_struct *mm) |
| 47 | { |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame] | 48 | preempt_disable(); |
Martin Schwidefsky | 64f31d5 | 2016-05-25 09:45:26 +0200 | [diff] [blame] | 49 | atomic_inc(&mm->context.flush_count); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 50 | if (cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) { |
| 51 | /* Local TLB flush */ |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame] | 52 | __tlb_flush_local(); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 53 | } else { |
| 54 | /* Global TLB flush */ |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame] | 55 | __tlb_flush_global(); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 56 | /* Reset TLB flush mask */ |
Martin Schwidefsky | d5dcafe | 2016-06-10 10:56:44 +0200 | [diff] [blame^] | 57 | cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 58 | } |
Martin Schwidefsky | 64f31d5 | 2016-05-25 09:45:26 +0200 | [diff] [blame] | 59 | atomic_dec(&mm->context.flush_count); |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame] | 60 | preempt_enable(); |
| 61 | } |
Martin Schwidefsky | 374b8f4 | 2008-04-17 07:45:58 +0200 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* |
David Hildenbrand | f045402 | 2016-07-07 10:44:10 +0200 | [diff] [blame] | 64 | * Flush TLB entries for a specific ASCE on all CPUs. Should never be used |
| 65 | * when more than one asce (e.g. gmap) ran on this mm. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | */ |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 67 | static inline void __tlb_flush_asce(struct mm_struct *mm, unsigned long asce) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 68 | { |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 69 | preempt_disable(); |
Martin Schwidefsky | 64f31d5 | 2016-05-25 09:45:26 +0200 | [diff] [blame] | 70 | atomic_inc(&mm->context.flush_count); |
Martin Schwidefsky | d5dcafe | 2016-06-10 10:56:44 +0200 | [diff] [blame^] | 71 | if (MACHINE_HAS_IDTE) |
| 72 | __tlb_flush_idte(asce); |
| 73 | else |
| 74 | __tlb_flush_global(); |
| 75 | /* Reset TLB flush mask */ |
| 76 | cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask); |
Martin Schwidefsky | 64f31d5 | 2016-05-25 09:45:26 +0200 | [diff] [blame] | 77 | atomic_dec(&mm->context.flush_count); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 78 | preempt_enable(); |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 79 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 81 | static inline void __tlb_flush_kernel(void) |
| 82 | { |
| 83 | if (MACHINE_HAS_IDTE) |
Gerald Schaefer | 723cacb | 2016-04-15 16:38:40 +0200 | [diff] [blame] | 84 | __tlb_flush_idte(init_mm.context.asce); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 85 | else |
| 86 | __tlb_flush_global(); |
| 87 | } |
| 88 | #else |
| 89 | #define __tlb_flush_global() __tlb_flush_local() |
| 90 | #define __tlb_flush_full(mm) __tlb_flush_local() |
| 91 | |
| 92 | /* |
| 93 | * Flush TLB entries for a specific ASCE on all CPUs. |
| 94 | */ |
| 95 | static inline void __tlb_flush_asce(struct mm_struct *mm, unsigned long asce) |
| 96 | { |
Martin Schwidefsky | d5dcafe | 2016-06-10 10:56:44 +0200 | [diff] [blame^] | 97 | __tlb_flush_local(); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static inline void __tlb_flush_kernel(void) |
| 101 | { |
Martin Schwidefsky | d5dcafe | 2016-06-10 10:56:44 +0200 | [diff] [blame^] | 102 | __tlb_flush_local(); |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 103 | } |
| 104 | #endif |
| 105 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 106 | static inline void __tlb_flush_mm(struct mm_struct * mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 108 | /* |
| 109 | * If the machine has IDTE we prefer to do a per mm flush |
| 110 | * on all cpus instead of doing a local flush if the mm |
| 111 | * only ran on the local cpu. |
| 112 | */ |
Martin Schwidefsky | e5992f2 | 2011-07-24 10:48:20 +0200 | [diff] [blame] | 113 | if (MACHINE_HAS_IDTE && list_empty(&mm->context.gmap_list)) |
Gerald Schaefer | 723cacb | 2016-04-15 16:38:40 +0200 | [diff] [blame] | 114 | __tlb_flush_asce(mm, mm->context.asce); |
Martin Schwidefsky | 043d070 | 2011-05-23 10:24:23 +0200 | [diff] [blame] | 115 | else |
| 116 | __tlb_flush_full(mm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Martin Schwidefsky | 5c474a1 | 2013-08-16 13:31:40 +0200 | [diff] [blame] | 119 | static inline void __tlb_flush_mm_lazy(struct mm_struct * mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Martin Schwidefsky | 050eef3 | 2010-08-24 09:26:21 +0200 | [diff] [blame] | 121 | if (mm->context.flush_mm) { |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 122 | __tlb_flush_mm(mm); |
Martin Schwidefsky | 050eef3 | 2010-08-24 09:26:21 +0200 | [diff] [blame] | 123 | mm->context.flush_mm = 0; |
| 124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 127 | /* |
| 128 | * TLB flushing: |
| 129 | * flush_tlb() - flushes the current mm struct TLBs |
| 130 | * flush_tlb_all() - flushes all processes TLBs |
| 131 | * flush_tlb_mm(mm) - flushes the specified mm context TLB's |
| 132 | * flush_tlb_page(vma, vmaddr) - flushes one page |
| 133 | * flush_tlb_range(vma, start, end) - flushes a range of pages |
| 134 | * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages |
| 135 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 137 | /* |
| 138 | * flush_tlb_mm goes together with ptep_set_wrprotect for the |
| 139 | * copy_page_range operation and flush_tlb_range is related to |
| 140 | * ptep_get_and_clear for change_protection. ptep_set_wrprotect and |
| 141 | * ptep_get_and_clear do not flush the TLBs directly if the mm has |
| 142 | * only one user. At the end of the update the flush_tlb_mm and |
| 143 | * flush_tlb_range functions need to do the flush. |
| 144 | */ |
| 145 | #define flush_tlb() do { } while (0) |
| 146 | #define flush_tlb_all() do { } while (0) |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 147 | #define flush_tlb_page(vma, addr) do { } while (0) |
Martin Schwidefsky | 8ffd74a | 2008-01-26 14:10:59 +0100 | [diff] [blame] | 148 | |
| 149 | static inline void flush_tlb_mm(struct mm_struct *mm) |
| 150 | { |
Martin Schwidefsky | 5c474a1 | 2013-08-16 13:31:40 +0200 | [diff] [blame] | 151 | __tlb_flush_mm_lazy(mm); |
Martin Schwidefsky | 8ffd74a | 2008-01-26 14:10:59 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static inline void flush_tlb_range(struct vm_area_struct *vma, |
| 155 | unsigned long start, unsigned long end) |
| 156 | { |
Martin Schwidefsky | 5c474a1 | 2013-08-16 13:31:40 +0200 | [diff] [blame] | 157 | __tlb_flush_mm_lazy(vma->vm_mm); |
Martin Schwidefsky | 8ffd74a | 2008-01-26 14:10:59 +0100 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static inline void flush_tlb_kernel_range(unsigned long start, |
| 161 | unsigned long end) |
| 162 | { |
Martin Schwidefsky | 1b948d6 | 2014-04-03 13:55:01 +0200 | [diff] [blame] | 163 | __tlb_flush_kernel(); |
Martin Schwidefsky | 8ffd74a | 2008-01-26 14:10:59 +0100 | [diff] [blame] | 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | #endif /* _S390_TLBFLUSH_H */ |