blob: 39846100682a3e9c11ab9ffc4223d4734844cd1d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _S390_TLBFLUSH_H
2#define _S390_TLBFLUSH_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/mm.h>
Gerald Schaefer53492b12008-04-30 13:38:46 +02005#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <asm/processor.h>
Gerald Schaeferc1821c22007-02-05 21:18:17 +01007#include <asm/pgalloc.h>
Heiko Carstens4ccccc52016-05-14 10:46:33 +02008#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10/*
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020011 * Flush all TLB entries on the local CPU.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020013static inline void __tlb_flush_local(void)
14{
15 asm volatile("ptlb" : : : "memory");
16}
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18/*
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020019 * Flush TLB entries for a specific ASCE on all CPUs
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020021static 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 Schwidefsky1b948d62014-04-03 13:55:01 +020029#ifdef CONFIG_SMP
Heiko Carstensa8061702008-04-17 07:46:26 +020030void smp_ptlb_all(void);
31
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020032/*
33 * Flush all TLB entries on all CPUs.
34 */
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020035static inline void __tlb_flush_global(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Heiko Carstens4ccccc52016-05-14 10:46:33 +020037 unsigned int dummy = 0;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020038
Heiko Carstens4ccccc52016-05-14 10:46:33 +020039 csp(&dummy, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020042/*
43 * Flush TLB entries for a specific mm on all CPUs (in case gmap is used
44 * this implicates multiple ASCEs!).
45 */
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020046static inline void __tlb_flush_full(struct mm_struct *mm)
47{
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020048 preempt_disable();
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020049 atomic_inc(&mm->context.flush_count);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020050 if (cpumask_equal(mm_cpumask(mm), cpumask_of(smp_processor_id()))) {
51 /* Local TLB flush */
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020052 __tlb_flush_local();
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020053 } else {
54 /* Global TLB flush */
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020055 __tlb_flush_global();
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020056 /* Reset TLB flush mask */
Martin Schwidefskyd5dcafe2016-06-10 10:56:44 +020057 cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020058 }
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020059 atomic_dec(&mm->context.flush_count);
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020060 preempt_enable();
61}
Martin Schwidefsky374b8f42008-04-17 07:45:58 +020062
Martin Schwidefsky44b6cc82016-06-13 10:36:00 +020063static inline void __tlb_flush_mm(struct mm_struct *mm)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020064{
Martin Schwidefsky44b6cc82016-06-13 10:36:00 +020065 unsigned long gmap_asce;
66
67 /*
68 * If the machine has IDTE we prefer to do a per mm flush
69 * on all cpus instead of doing a local flush if the mm
70 * only ran on the local cpu.
71 */
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020072 preempt_disable();
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020073 atomic_inc(&mm->context.flush_count);
Martin Schwidefsky44b6cc82016-06-13 10:36:00 +020074 gmap_asce = READ_ONCE(mm->context.gmap_asce);
75 if (MACHINE_HAS_IDTE && gmap_asce != -1UL) {
76 if (gmap_asce)
77 __tlb_flush_idte(gmap_asce);
78 __tlb_flush_idte(mm->context.asce);
79 } else {
80 __tlb_flush_full(mm);
81 }
Martin Schwidefskyd5dcafe2016-06-10 10:56:44 +020082 /* Reset TLB flush mask */
83 cpumask_copy(mm_cpumask(mm), &mm->context.cpu_attach_mask);
Martin Schwidefsky64f31d52016-05-25 09:45:26 +020084 atomic_dec(&mm->context.flush_count);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020085 preempt_enable();
Martin Schwidefskyba8a9222007-10-22 12:52:44 +020086}
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020088static inline void __tlb_flush_kernel(void)
89{
90 if (MACHINE_HAS_IDTE)
Gerald Schaefer723cacb2016-04-15 16:38:40 +020091 __tlb_flush_idte(init_mm.context.asce);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +020092 else
93 __tlb_flush_global();
94}
95#else
96#define __tlb_flush_global() __tlb_flush_local()
97#define __tlb_flush_full(mm) __tlb_flush_local()
98
99/*
100 * Flush TLB entries for a specific ASCE on all CPUs.
101 */
Martin Schwidefsky44b6cc82016-06-13 10:36:00 +0200102static inline void __tlb_flush_mm(struct mm_struct *mm)
Martin Schwidefsky1b948d62014-04-03 13:55:01 +0200103{
Martin Schwidefskyd5dcafe2016-06-10 10:56:44 +0200104 __tlb_flush_local();
Martin Schwidefsky1b948d62014-04-03 13:55:01 +0200105}
106
107static inline void __tlb_flush_kernel(void)
108{
Martin Schwidefskyd5dcafe2016-06-10 10:56:44 +0200109 __tlb_flush_local();
Martin Schwidefsky1b948d62014-04-03 13:55:01 +0200110}
111#endif
112
Martin Schwidefsky5c474a12013-08-16 13:31:40 +0200113static inline void __tlb_flush_mm_lazy(struct mm_struct * mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Martin Schwidefsky050eef32010-08-24 09:26:21 +0200115 if (mm->context.flush_mm) {
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200116 __tlb_flush_mm(mm);
Martin Schwidefsky050eef32010-08-24 09:26:21 +0200117 mm->context.flush_mm = 0;
118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200121/*
122 * TLB flushing:
123 * flush_tlb() - flushes the current mm struct TLBs
124 * flush_tlb_all() - flushes all processes TLBs
125 * flush_tlb_mm(mm) - flushes the specified mm context TLB's
126 * flush_tlb_page(vma, vmaddr) - flushes one page
127 * flush_tlb_range(vma, start, end) - flushes a range of pages
128 * flush_tlb_kernel_range(start, end) - flushes a range of kernel pages
129 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200131/*
132 * flush_tlb_mm goes together with ptep_set_wrprotect for the
133 * copy_page_range operation and flush_tlb_range is related to
134 * ptep_get_and_clear for change_protection. ptep_set_wrprotect and
135 * ptep_get_and_clear do not flush the TLBs directly if the mm has
136 * only one user. At the end of the update the flush_tlb_mm and
137 * flush_tlb_range functions need to do the flush.
138 */
139#define flush_tlb() do { } while (0)
140#define flush_tlb_all() do { } while (0)
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200141#define flush_tlb_page(vma, addr) do { } while (0)
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100142
143static inline void flush_tlb_mm(struct mm_struct *mm)
144{
Martin Schwidefsky5c474a12013-08-16 13:31:40 +0200145 __tlb_flush_mm_lazy(mm);
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100146}
147
148static inline void flush_tlb_range(struct vm_area_struct *vma,
149 unsigned long start, unsigned long end)
150{
Martin Schwidefsky5c474a12013-08-16 13:31:40 +0200151 __tlb_flush_mm_lazy(vma->vm_mm);
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100152}
153
154static inline void flush_tlb_kernel_range(unsigned long start,
155 unsigned long end)
156{
Martin Schwidefsky1b948d62014-04-03 13:55:01 +0200157 __tlb_flush_kernel();
Martin Schwidefsky8ffd74a2008-01-26 14:10:59 +0100158}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#endif /* _S390_TLBFLUSH_H */