Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * native hashtable management. |
| 4 | * |
| 5 | * SMP scalability work: |
| 6 | * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 8 | |
| 9 | #undef DEBUG_LOW |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/spinlock.h> |
| 12 | #include <linux/bitops.h> |
Michael Ellerman | beacc6d | 2012-07-25 21:20:03 +0000 | [diff] [blame] | 13 | #include <linux/of.h> |
Nicholas Piggin | 4e287e6 | 2017-06-06 23:08:32 +1000 | [diff] [blame] | 14 | #include <linux/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/threads.h> |
| 16 | #include <linux/smp.h> |
Mike Rapoport | 65fddcf | 2020-06-08 21:32:42 -0700 | [diff] [blame] | 17 | #include <linux/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/machdep.h> |
| 20 | #include <asm/mmu.h> |
| 21 | #include <asm/mmu_context.h> |
Balbir Singh | 0428491 | 2017-04-11 15:23:25 +1000 | [diff] [blame] | 22 | #include <asm/trace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/tlb.h> |
| 24 | #include <asm/cputable.h> |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 25 | #include <asm/udbg.h> |
Luke Browning | 71bf08b | 2007-05-03 00:19:11 +1000 | [diff] [blame] | 26 | #include <asm/kexec.h> |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 27 | #include <asm/ppc-opcode.h> |
Christophe Leroy | 2c86cd1 | 2018-07-05 16:25:01 +0000 | [diff] [blame] | 28 | #include <asm/feature-fixups.h> |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 29 | |
Michael Neuling | ec249dd | 2015-05-27 16:07:16 +1000 | [diff] [blame] | 30 | #include <misc/cxl-base.h> |
Ian Munsie | 4c6d9ac | 2014-10-08 19:55:00 +1100 | [diff] [blame] | 31 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 32 | #ifdef DEBUG_LOW |
| 33 | #define DBG_LOW(fmt...) udbg_printf(fmt) |
| 34 | #else |
| 35 | #define DBG_LOW(fmt...) |
| 36 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 38 | #ifdef __BIG_ENDIAN__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #define HPTE_LOCK_BIT 3 |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 40 | #else |
| 41 | #define HPTE_LOCK_BIT (56+3) |
| 42 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
YueHaibing | d667edc | 2019-05-04 18:24:27 +0800 | [diff] [blame] | 44 | static DEFINE_RAW_SPINLOCK(native_tlbie_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 46 | static inline void tlbiel_hash_set_isa206(unsigned int set, unsigned int is) |
| 47 | { |
| 48 | unsigned long rb; |
| 49 | |
| 50 | rb = (set << PPC_BITLSHIFT(51)) | (is << PPC_BITLSHIFT(53)); |
| 51 | |
| 52 | asm volatile("tlbiel %0" : : "r" (rb)); |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * tlbiel instruction for hash, set invalidation |
| 57 | * i.e., r=1 and is=01 or is=10 or is=11 |
| 58 | */ |
Masahiro Yamada | 6d3ca7e | 2019-05-21 22:13:24 +0900 | [diff] [blame] | 59 | static __always_inline void tlbiel_hash_set_isa300(unsigned int set, unsigned int is, |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 60 | unsigned int pid, |
| 61 | unsigned int ric, unsigned int prs) |
| 62 | { |
| 63 | unsigned long rb; |
| 64 | unsigned long rs; |
| 65 | unsigned int r = 0; /* hash format */ |
| 66 | |
| 67 | rb = (set << PPC_BITLSHIFT(51)) | (is << PPC_BITLSHIFT(53)); |
| 68 | rs = ((unsigned long)pid << PPC_BITLSHIFT(31)); |
| 69 | |
| 70 | asm volatile(PPC_TLBIEL(%0, %1, %2, %3, %4) |
Nicholas Piggin | 5844cc2 | 2020-11-26 20:25:27 +1000 | [diff] [blame] | 71 | : : "r"(rb), "r"(rs), "i"(ric), "i"(prs), "i"(r) |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 72 | : "memory"); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | static void tlbiel_all_isa206(unsigned int num_sets, unsigned int is) |
| 77 | { |
| 78 | unsigned int set; |
| 79 | |
| 80 | asm volatile("ptesync": : :"memory"); |
| 81 | |
| 82 | for (set = 0; set < num_sets; set++) |
| 83 | tlbiel_hash_set_isa206(set, is); |
| 84 | |
Nicholas Piggin | 05504b4 | 2020-09-16 13:02:34 +1000 | [diff] [blame] | 85 | ppc_after_tlbiel_barrier(); |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static void tlbiel_all_isa300(unsigned int num_sets, unsigned int is) |
| 89 | { |
| 90 | unsigned int set; |
| 91 | |
| 92 | asm volatile("ptesync": : :"memory"); |
| 93 | |
| 94 | /* |
Nicholas Piggin | c0b27c5 | 2020-11-26 20:25:28 +1000 | [diff] [blame] | 95 | * Flush the partition table cache if this is HV mode. |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 96 | */ |
Nicholas Piggin | c0b27c5 | 2020-11-26 20:25:28 +1000 | [diff] [blame] | 97 | if (early_cpu_has_feature(CPU_FTR_HVMODE)) |
| 98 | tlbiel_hash_set_isa300(0, is, 0, 2, 0); |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 99 | |
| 100 | /* |
Nicholas Piggin | c0b27c5 | 2020-11-26 20:25:28 +1000 | [diff] [blame] | 101 | * Now invalidate the process table cache. UPRT=0 HPT modes (what |
| 102 | * current hardware implements) do not use the process table, but |
| 103 | * add the flushes anyway. |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 104 | * |
| 105 | * From ISA v3.0B p. 1078: |
| 106 | * The following forms are invalid. |
| 107 | * * PRS=1, R=0, and RIC!=2 (The only process-scoped |
| 108 | * HPT caching is of the Process Table.) |
| 109 | */ |
| 110 | tlbiel_hash_set_isa300(0, is, 0, 2, 1); |
| 111 | |
Nicholas Piggin | c0b27c5 | 2020-11-26 20:25:28 +1000 | [diff] [blame] | 112 | /* |
| 113 | * Then flush the sets of the TLB proper. Hash mode uses |
| 114 | * partition scoped TLB translations, which may be flushed |
| 115 | * in !HV mode. |
| 116 | */ |
| 117 | for (set = 0; set < num_sets; set++) |
| 118 | tlbiel_hash_set_isa300(set, is, 0, 0, 0); |
| 119 | |
Nicholas Piggin | 05504b4 | 2020-09-16 13:02:34 +1000 | [diff] [blame] | 120 | ppc_after_tlbiel_barrier(); |
Nicholas Piggin | bc276ec | 2018-08-27 13:03:01 +1000 | [diff] [blame] | 121 | |
Nicholas Piggin | fe7946c | 2019-06-23 20:41:51 +1000 | [diff] [blame] | 122 | asm volatile(PPC_ISA_3_0_INVALIDATE_ERAT "; isync" : : :"memory"); |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void hash__tlbiel_all(unsigned int action) |
| 126 | { |
| 127 | unsigned int is; |
| 128 | |
| 129 | switch (action) { |
| 130 | case TLB_INVAL_SCOPE_GLOBAL: |
| 131 | is = 3; |
| 132 | break; |
| 133 | case TLB_INVAL_SCOPE_LPID: |
| 134 | is = 2; |
| 135 | break; |
| 136 | default: |
| 137 | BUG(); |
| 138 | } |
| 139 | |
| 140 | if (early_cpu_has_feature(CPU_FTR_ARCH_300)) |
| 141 | tlbiel_all_isa300(POWER9_TLB_SETS_HASH, is); |
| 142 | else if (early_cpu_has_feature(CPU_FTR_ARCH_207S)) |
| 143 | tlbiel_all_isa206(POWER8_TLB_SETS, is); |
| 144 | else if (early_cpu_has_feature(CPU_FTR_ARCH_206)) |
| 145 | tlbiel_all_isa206(POWER7_TLB_SETS, is); |
| 146 | else |
| 147 | WARN(1, "%s called on pre-POWER7 CPU\n", __func__); |
Nicholas Piggin | d474827 | 2017-12-24 01:15:50 +1000 | [diff] [blame] | 148 | } |
| 149 | |
Mahesh Salgaonkar | a3961f8 | 2017-11-22 23:02:07 +0530 | [diff] [blame] | 150 | static inline unsigned long ___tlbie(unsigned long vpn, int psize, |
| 151 | int apsize, int ssize) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 152 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 153 | unsigned long va; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 154 | unsigned int penc; |
Aneesh Kumar K.V | de64095 | 2013-07-04 10:34:45 +0530 | [diff] [blame] | 155 | unsigned long sllp; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 156 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 157 | /* |
| 158 | * We need 14 to 65 bits of va for a tlibe of 4K page |
| 159 | * With vpn we ignore the lower VPN_SHIFT bits already. |
| 160 | * And top two bits are already ignored because we can |
Michael Ellerman | 027dfac | 2016-06-01 16:34:37 +1000 | [diff] [blame] | 161 | * only accomodate 76 bits in a 64 bit vpn with a VPN_SHIFT |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 162 | * of 12. |
| 163 | */ |
| 164 | va = vpn << VPN_SHIFT; |
| 165 | /* |
| 166 | * clear top 16 bits of 64bit va, non SLS segment |
| 167 | * Older versions of the architecture (2.02 and earler) require the |
| 168 | * masking of the top 16 bits. |
| 169 | */ |
Aneesh Kumar K.V | accfad7 | 2016-07-13 15:05:24 +0530 | [diff] [blame] | 170 | if (mmu_has_feature(MMU_FTR_TLBIE_CROP_VA)) |
| 171 | va &= ~(0xffffULL << 48); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 172 | |
| 173 | switch (psize) { |
| 174 | case MMU_PAGE_4K: |
Aneesh Kumar K.V | 1f6aaac | 2013-04-28 09:37:39 +0000 | [diff] [blame] | 175 | /* clear out bits after (52) [0....52.....63] */ |
| 176 | va &= ~((1ul << (64 - 52)) - 1); |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 177 | va |= ssize << 8; |
Aneesh Kumar K.V | 138ee7e | 2016-07-13 15:06:37 +0530 | [diff] [blame] | 178 | sllp = get_sllp_encoding(apsize); |
Aneesh Kumar K.V | de64095 | 2013-07-04 10:34:45 +0530 | [diff] [blame] | 179 | va |= sllp << 5; |
Michael Neuling | a32e252 | 2011-04-06 18:23:29 +0000 | [diff] [blame] | 180 | asm volatile(ASM_FTR_IFCLR("tlbie %0,0", PPC_TLBIE(%1,%0), %2) |
Paul Mackerras | 969391c | 2011-06-29 00:26:11 +0000 | [diff] [blame] | 181 | : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206) |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 182 | : "memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 183 | break; |
| 184 | default: |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 185 | /* We need 14 to 14 + i bits of va */ |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 186 | penc = mmu_psize_defs[psize].penc[apsize]; |
Aneesh Kumar K.V | 1f6aaac | 2013-04-28 09:37:39 +0000 | [diff] [blame] | 187 | va &= ~((1ul << mmu_psize_defs[apsize].shift) - 1); |
Arnd Bergmann | 19242b2 | 2006-06-15 21:15:44 +1000 | [diff] [blame] | 188 | va |= penc << 12; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 189 | va |= ssize << 8; |
Aneesh Kumar K.V | 29ef7a3 | 2014-04-21 10:37:36 +0530 | [diff] [blame] | 190 | /* |
| 191 | * AVAL bits: |
| 192 | * We don't need all the bits, but rest of the bits |
| 193 | * must be ignored by the processor. |
| 194 | * vpn cover upto 65 bits of va. (0...65) and we need |
| 195 | * 58..64 bits of va. |
| 196 | */ |
| 197 | va |= (vpn & 0xfe); /* AVAL */ |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 198 | va |= 1; /* L */ |
Michael Neuling | a32e252 | 2011-04-06 18:23:29 +0000 | [diff] [blame] | 199 | asm volatile(ASM_FTR_IFCLR("tlbie %0,1", PPC_TLBIE(%1,%0), %2) |
Paul Mackerras | 969391c | 2011-06-29 00:26:11 +0000 | [diff] [blame] | 200 | : : "r" (va), "r"(0), "i" (CPU_FTR_ARCH_206) |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 201 | : "memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 202 | break; |
| 203 | } |
Mahesh Salgaonkar | a3961f8 | 2017-11-22 23:02:07 +0530 | [diff] [blame] | 204 | return va; |
| 205 | } |
| 206 | |
Aneesh Kumar K.V | 047e657 | 2019-09-24 09:22:53 +0530 | [diff] [blame] | 207 | static inline void fixup_tlbie_vpn(unsigned long vpn, int psize, |
| 208 | int apsize, int ssize) |
Aneesh Kumar K.V | a5d4b58 | 2018-03-23 10:26:27 +0530 | [diff] [blame] | 209 | { |
Aneesh Kumar K.V | 047e657 | 2019-09-24 09:22:53 +0530 | [diff] [blame] | 210 | if (cpu_has_feature(CPU_FTR_P9_TLBIE_ERAT_BUG)) { |
| 211 | /* Radix flush for a hash guest */ |
| 212 | |
| 213 | unsigned long rb,rs,prs,r,ric; |
| 214 | |
| 215 | rb = PPC_BIT(52); /* IS = 2 */ |
| 216 | rs = 0; /* lpid = 0 */ |
| 217 | prs = 0; /* partition scoped */ |
| 218 | r = 1; /* radix format */ |
| 219 | ric = 0; /* RIC_FLSUH_TLB */ |
| 220 | |
| 221 | /* |
| 222 | * Need the extra ptesync to make sure we don't |
| 223 | * re-order the tlbie |
| 224 | */ |
| 225 | asm volatile("ptesync": : :"memory"); |
| 226 | asm volatile(PPC_TLBIE_5(%0, %4, %3, %2, %1) |
| 227 | : : "r"(rb), "i"(r), "i"(prs), |
| 228 | "i"(ric), "r"(rs) : "memory"); |
| 229 | } |
| 230 | |
| 231 | |
Aneesh Kumar K.V | 09ce98c | 2019-09-24 09:22:52 +0530 | [diff] [blame] | 232 | if (cpu_has_feature(CPU_FTR_P9_TLBIE_STQ_BUG)) { |
Aneesh Kumar K.V | a5d4b58 | 2018-03-23 10:26:27 +0530 | [diff] [blame] | 233 | /* Need the extra ptesync to ensure we don't reorder tlbie*/ |
| 234 | asm volatile("ptesync": : :"memory"); |
| 235 | ___tlbie(vpn, psize, apsize, ssize); |
| 236 | } |
| 237 | } |
| 238 | |
Mahesh Salgaonkar | a3961f8 | 2017-11-22 23:02:07 +0530 | [diff] [blame] | 239 | static inline void __tlbie(unsigned long vpn, int psize, int apsize, int ssize) |
| 240 | { |
| 241 | unsigned long rb; |
| 242 | |
| 243 | rb = ___tlbie(vpn, psize, apsize, ssize); |
| 244 | trace_tlbie(0, 0, rb, 0, 0, 0, 0); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 245 | } |
| 246 | |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 247 | static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 248 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 249 | unsigned long va; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 250 | unsigned int penc; |
Aneesh Kumar K.V | de64095 | 2013-07-04 10:34:45 +0530 | [diff] [blame] | 251 | unsigned long sllp; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 252 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 253 | /* VPN_SHIFT can be atmost 12 */ |
| 254 | va = vpn << VPN_SHIFT; |
| 255 | /* |
| 256 | * clear top 16 bits of 64 bit va, non SLS segment |
| 257 | * Older versions of the architecture (2.02 and earler) require the |
| 258 | * masking of the top 16 bits. |
| 259 | */ |
Aneesh Kumar K.V | accfad7 | 2016-07-13 15:05:24 +0530 | [diff] [blame] | 260 | if (mmu_has_feature(MMU_FTR_TLBIE_CROP_VA)) |
| 261 | va &= ~(0xffffULL << 48); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 262 | |
| 263 | switch (psize) { |
| 264 | case MMU_PAGE_4K: |
Aneesh Kumar K.V | 1f6aaac | 2013-04-28 09:37:39 +0000 | [diff] [blame] | 265 | /* clear out bits after(52) [0....52.....63] */ |
| 266 | va &= ~((1ul << (64 - 52)) - 1); |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 267 | va |= ssize << 8; |
Aneesh Kumar K.V | 138ee7e | 2016-07-13 15:06:37 +0530 | [diff] [blame] | 268 | sllp = get_sllp_encoding(apsize); |
Aneesh Kumar K.V | de64095 | 2013-07-04 10:34:45 +0530 | [diff] [blame] | 269 | va |= sllp << 5; |
Balbir Singh | f923efb | 2016-09-28 17:25:52 +1000 | [diff] [blame] | 270 | asm volatile(ASM_FTR_IFSET("tlbiel %0", "tlbiel %0,0", %1) |
| 271 | : : "r" (va), "i" (CPU_FTR_ARCH_206) |
| 272 | : "memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 273 | break; |
| 274 | default: |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 275 | /* We need 14 to 14 + i bits of va */ |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 276 | penc = mmu_psize_defs[psize].penc[apsize]; |
Aneesh Kumar K.V | 1f6aaac | 2013-04-28 09:37:39 +0000 | [diff] [blame] | 277 | va &= ~((1ul << mmu_psize_defs[apsize].shift) - 1); |
Arnd Bergmann | 19242b2 | 2006-06-15 21:15:44 +1000 | [diff] [blame] | 278 | va |= penc << 12; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 279 | va |= ssize << 8; |
Aneesh Kumar K.V | 29ef7a3 | 2014-04-21 10:37:36 +0530 | [diff] [blame] | 280 | /* |
| 281 | * AVAL bits: |
| 282 | * We don't need all the bits, but rest of the bits |
| 283 | * must be ignored by the processor. |
| 284 | * vpn cover upto 65 bits of va. (0...65) and we need |
| 285 | * 58..64 bits of va. |
| 286 | */ |
| 287 | va |= (vpn & 0xfe); |
Milton Miller | 60dbf43 | 2009-04-29 20:58:01 +0000 | [diff] [blame] | 288 | va |= 1; /* L */ |
Balbir Singh | f923efb | 2016-09-28 17:25:52 +1000 | [diff] [blame] | 289 | asm volatile(ASM_FTR_IFSET("tlbiel %0", "tlbiel %0,1", %1) |
| 290 | : : "r" (va), "i" (CPU_FTR_ARCH_206) |
| 291 | : "memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 292 | break; |
| 293 | } |
Balbir Singh | 0428491 | 2017-04-11 15:23:25 +1000 | [diff] [blame] | 294 | trace_tlbie(0, 1, va, 0, 0, 0, 0); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 295 | |
| 296 | } |
| 297 | |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 298 | static inline void tlbie(unsigned long vpn, int psize, int apsize, |
| 299 | int ssize, int local) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 300 | { |
Ian Munsie | 4c6d9ac | 2014-10-08 19:55:00 +1100 | [diff] [blame] | 301 | unsigned int use_local; |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 302 | int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 303 | |
Ian Munsie | 4c6d9ac | 2014-10-08 19:55:00 +1100 | [diff] [blame] | 304 | use_local = local && mmu_has_feature(MMU_FTR_TLBIEL) && !cxl_ctx_in_use(); |
| 305 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 306 | if (use_local) |
| 307 | use_local = mmu_psize_defs[psize].tlbiel; |
| 308 | if (lock_tlbie && !use_local) |
Thomas Gleixner | 6b9c9b8 | 2010-02-18 02:22:35 +0000 | [diff] [blame] | 309 | raw_spin_lock(&native_tlbie_lock); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 310 | asm volatile("ptesync": : :"memory"); |
| 311 | if (use_local) { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 312 | __tlbiel(vpn, psize, apsize, ssize); |
Nicholas Piggin | 05504b4 | 2020-09-16 13:02:34 +1000 | [diff] [blame] | 313 | ppc_after_tlbiel_barrier(); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 314 | } else { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 315 | __tlbie(vpn, psize, apsize, ssize); |
Aneesh Kumar K.V | 047e657 | 2019-09-24 09:22:53 +0530 | [diff] [blame] | 316 | fixup_tlbie_vpn(vpn, psize, apsize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 317 | asm volatile("eieio; tlbsync; ptesync": : :"memory"); |
| 318 | } |
| 319 | if (lock_tlbie && !use_local) |
Thomas Gleixner | 6b9c9b8 | 2010-02-18 02:22:35 +0000 | [diff] [blame] | 320 | raw_spin_unlock(&native_tlbie_lock); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 321 | } |
| 322 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 323 | static inline void native_lock_hpte(struct hash_pte *hptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 325 | unsigned long *word = (unsigned long *)&hptep->v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | while (1) { |
Anton Blanchard | 66d99b8 | 2010-02-10 01:03:06 +0000 | [diff] [blame] | 328 | if (!test_and_set_bit_lock(HPTE_LOCK_BIT, word)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | break; |
Nicholas Piggin | 4e287e6 | 2017-06-06 23:08:32 +1000 | [diff] [blame] | 330 | spin_begin(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | while(test_bit(HPTE_LOCK_BIT, word)) |
Nicholas Piggin | 4e287e6 | 2017-06-06 23:08:32 +1000 | [diff] [blame] | 332 | spin_cpu_relax(); |
| 333 | spin_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 337 | static inline void native_unlock_hpte(struct hash_pte *hptep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 339 | unsigned long *word = (unsigned long *)&hptep->v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Anton Blanchard | 66d99b8 | 2010-02-10 01:03:06 +0000 | [diff] [blame] | 341 | clear_bit_unlock(HPTE_LOCK_BIT, word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 344 | static long native_hpte_insert(unsigned long hpte_group, unsigned long vpn, |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 345 | unsigned long pa, unsigned long rflags, |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 346 | unsigned long vflags, int psize, int apsize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 348 | struct hash_pte *hptep = htab_address + hpte_group; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 349 | unsigned long hpte_v, hpte_r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | int i; |
| 351 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 352 | if (!(vflags & HPTE_V_BOLTED)) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 353 | DBG_LOW(" insert(group=%lx, vpn=%016lx, pa=%016lx," |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 354 | " rflags=%lx, vflags=%lx, psize=%d)\n", |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 355 | hpte_group, vpn, pa, rflags, vflags, psize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 356 | } |
| 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | for (i = 0; i < HPTES_PER_GROUP; i++) { |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 359 | if (! (be64_to_cpu(hptep->v) & HPTE_V_VALID)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | /* retry with lock held */ |
| 361 | native_lock_hpte(hptep); |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 362 | if (! (be64_to_cpu(hptep->v) & HPTE_V_VALID)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | break; |
| 364 | native_unlock_hpte(hptep); |
| 365 | } |
| 366 | |
| 367 | hptep++; |
| 368 | } |
| 369 | |
| 370 | if (i == HPTES_PER_GROUP) |
| 371 | return -1; |
| 372 | |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 373 | hpte_v = hpte_encode_v(vpn, psize, apsize, ssize) | vflags | HPTE_V_VALID; |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 374 | hpte_r = hpte_encode_r(pa, psize, apsize) | rflags; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 375 | |
| 376 | if (!(vflags & HPTE_V_BOLTED)) { |
| 377 | DBG_LOW(" i=%x hpte_v=%016lx, hpte_r=%016lx\n", |
| 378 | i, hpte_v, hpte_r); |
| 379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 381 | if (cpu_has_feature(CPU_FTR_ARCH_300)) { |
| 382 | hpte_r = hpte_old_to_new_r(hpte_v, hpte_r); |
| 383 | hpte_v = hpte_old_to_new_v(hpte_v); |
| 384 | } |
| 385 | |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 386 | hptep->r = cpu_to_be64(hpte_r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* Guarantee the second dword is visible before the valid bit */ |
Kumar Gala | 74a0ba6 | 2007-07-09 23:49:09 -0500 | [diff] [blame] | 388 | eieio(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | /* |
| 390 | * Now set the first dword including the valid bit |
| 391 | * NOTE: this also unlocks the hpte |
| 392 | */ |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 393 | hptep->v = cpu_to_be64(hpte_v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | __asm__ __volatile__ ("ptesync" : : : "memory"); |
| 396 | |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 397 | return i | (!!(vflags & HPTE_V_SECONDARY) << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static long native_hpte_remove(unsigned long hpte_group) |
| 401 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 402 | struct hash_pte *hptep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | int i; |
| 404 | int slot_offset; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 405 | unsigned long hpte_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 407 | DBG_LOW(" remove(group=%lx)\n", hpte_group); |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | /* pick a random entry to start at */ |
| 410 | slot_offset = mftb() & 0x7; |
| 411 | |
| 412 | for (i = 0; i < HPTES_PER_GROUP; i++) { |
| 413 | hptep = htab_address + hpte_group + slot_offset; |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 414 | hpte_v = be64_to_cpu(hptep->v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 416 | if ((hpte_v & HPTE_V_VALID) && !(hpte_v & HPTE_V_BOLTED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | /* retry with lock held */ |
| 418 | native_lock_hpte(hptep); |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 419 | hpte_v = be64_to_cpu(hptep->v); |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 420 | if ((hpte_v & HPTE_V_VALID) |
| 421 | && !(hpte_v & HPTE_V_BOLTED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | break; |
| 423 | native_unlock_hpte(hptep); |
| 424 | } |
| 425 | |
| 426 | slot_offset++; |
| 427 | slot_offset &= 0x7; |
| 428 | } |
| 429 | |
| 430 | if (i == HPTES_PER_GROUP) |
| 431 | return -1; |
| 432 | |
| 433 | /* Invalidate the hpte. NOTE: this also unlocks it */ |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 434 | hptep->v = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | return i; |
| 437 | } |
| 438 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 439 | static long native_hpte_updatepp(unsigned long slot, unsigned long newpp, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 440 | unsigned long vpn, int bpsize, |
Aneesh Kumar K.V | aefa568 | 2014-12-04 11:00:14 +0530 | [diff] [blame] | 441 | int apsize, int ssize, unsigned long flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 443 | struct hash_pte *hptep = htab_address + slot; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 444 | unsigned long hpte_v, want_v; |
Aneesh Kumar K.V | aefa568 | 2014-12-04 11:00:14 +0530 | [diff] [blame] | 445 | int ret = 0, local = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 447 | want_v = hpte_encode_avpn(vpn, bpsize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 448 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 449 | DBG_LOW(" update(vpn=%016lx, avpnv=%016lx, group=%lx, newpp=%lx)", |
| 450 | vpn, want_v & HPTE_V_AVPN, slot, newpp); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 451 | |
Aneesh Kumar K.V | a833280 | 2018-06-29 14:06:30 +0530 | [diff] [blame] | 452 | hpte_v = hpte_get_old_v(hptep); |
Aneesh Kumar K.V | 0608d69 | 2013-05-31 01:03:24 +0000 | [diff] [blame] | 453 | /* |
| 454 | * We need to invalidate the TLB always because hpte_remove doesn't do |
| 455 | * a tlb invalidate. If a hash bucket gets full, we "evict" a more/less |
| 456 | * random entry from it. When we do that we don't invalidate the TLB |
| 457 | * (hpte_remove) because we assume the old translation is still |
| 458 | * technically "valid". |
| 459 | */ |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 460 | if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 461 | DBG_LOW(" -> miss\n"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 462 | ret = -1; |
| 463 | } else { |
Aneesh Kumar K.V | 0ec2698 | 2014-11-03 20:21:34 +0530 | [diff] [blame] | 464 | native_lock_hpte(hptep); |
| 465 | /* recheck with locks held */ |
Aneesh Kumar K.V | a833280 | 2018-06-29 14:06:30 +0530 | [diff] [blame] | 466 | hpte_v = hpte_get_old_v(hptep); |
Aneesh Kumar K.V | 0ec2698 | 2014-11-03 20:21:34 +0530 | [diff] [blame] | 467 | if (unlikely(!HPTE_V_COMPARE(hpte_v, want_v) || |
| 468 | !(hpte_v & HPTE_V_VALID))) { |
| 469 | ret = -1; |
| 470 | } else { |
| 471 | DBG_LOW(" -> hit\n"); |
| 472 | /* Update the HPTE */ |
| 473 | hptep->r = cpu_to_be64((be64_to_cpu(hptep->r) & |
Aneesh Kumar K.V | 8550e2f | 2016-06-08 19:55:55 +0530 | [diff] [blame] | 474 | ~(HPTE_R_PPP | HPTE_R_N)) | |
| 475 | (newpp & (HPTE_R_PPP | HPTE_R_N | |
Aneesh Kumar K.V | 0ec2698 | 2014-11-03 20:21:34 +0530 | [diff] [blame] | 476 | HPTE_R_C))); |
| 477 | } |
| 478 | native_unlock_hpte(hptep); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 479 | } |
Aneesh Kumar K.V | aefa568 | 2014-12-04 11:00:14 +0530 | [diff] [blame] | 480 | |
| 481 | if (flags & HPTE_LOCAL_UPDATE) |
| 482 | local = 1; |
| 483 | /* |
| 484 | * Ensure it is out of the tlb too if it is not a nohpte fault |
| 485 | */ |
| 486 | if (!(flags & HPTE_NOHPTE_UPDATE)) |
| 487 | tlbie(vpn, bpsize, apsize, ssize, local); |
| 488 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 489 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Aneesh Kumar K.V | d78d5da | 2019-10-24 15:05:42 +0530 | [diff] [blame] | 492 | static long __native_hpte_find(unsigned long want_v, unsigned long slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 494 | struct hash_pte *hptep; |
Aneesh Kumar K.V | d78d5da | 2019-10-24 15:05:42 +0530 | [diff] [blame] | 495 | unsigned long hpte_v; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 496 | unsigned long i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 498 | for (i = 0; i < HPTES_PER_GROUP; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Aneesh Kumar K.V | a833280 | 2018-06-29 14:06:30 +0530 | [diff] [blame] | 500 | hptep = htab_address + slot; |
| 501 | hpte_v = hpte_get_old_v(hptep); |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 502 | if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID)) |
| 503 | /* HPTE matches */ |
| 504 | return slot; |
| 505 | ++slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | return -1; |
| 509 | } |
| 510 | |
Aneesh Kumar K.V | d78d5da | 2019-10-24 15:05:42 +0530 | [diff] [blame] | 511 | static long native_hpte_find(unsigned long vpn, int psize, int ssize) |
| 512 | { |
| 513 | unsigned long hpte_group; |
| 514 | unsigned long want_v; |
| 515 | unsigned long hash; |
| 516 | long slot; |
| 517 | |
| 518 | hash = hpt_hash(vpn, mmu_psize_defs[psize].shift, ssize); |
| 519 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
| 520 | |
| 521 | /* |
| 522 | * We try to keep bolted entries always in primary hash |
| 523 | * But in some case we can find them in secondary too. |
| 524 | */ |
| 525 | hpte_group = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 526 | slot = __native_hpte_find(want_v, hpte_group); |
| 527 | if (slot < 0) { |
| 528 | /* Try in secondary */ |
| 529 | hpte_group = (~hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 530 | slot = __native_hpte_find(want_v, hpte_group); |
| 531 | if (slot < 0) |
| 532 | return -1; |
| 533 | } |
| 534 | |
| 535 | return slot; |
| 536 | } |
| 537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | /* |
| 539 | * Update the page protection bits. Intended to be used to create |
| 540 | * guard pages for kernel data structures on pages which are bolted |
| 541 | * in the HPT. Assumes pages being operated on will not be stolen. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | * |
| 543 | * No need to lock here because we should be the only user. |
| 544 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 545 | static void native_hpte_updateboltedpp(unsigned long newpp, unsigned long ea, |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 546 | int psize, int ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 548 | unsigned long vpn; |
| 549 | unsigned long vsid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | long slot; |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 551 | struct hash_pte *hptep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 553 | vsid = get_kernel_vsid(ea, ssize); |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 554 | vpn = hpt_vpn(ea, vsid, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 556 | slot = native_hpte_find(vpn, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | if (slot == -1) |
| 558 | panic("could not find page to bolt\n"); |
| 559 | hptep = htab_address + slot; |
| 560 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 561 | /* Update the HPTE */ |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 562 | hptep->r = cpu_to_be64((be64_to_cpu(hptep->r) & |
Aneesh Kumar K.V | 8550e2f | 2016-06-08 19:55:55 +0530 | [diff] [blame] | 563 | ~(HPTE_R_PPP | HPTE_R_N)) | |
| 564 | (newpp & (HPTE_R_PPP | HPTE_R_N))); |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 565 | /* |
| 566 | * Ensure it is out of the tlb too. Bolted entries base and |
| 567 | * actual page size will be same. |
| 568 | */ |
| 569 | tlbie(vpn, psize, psize, ssize, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Anton Blanchard | 1b644f5 | 2017-06-28 11:32:35 +1000 | [diff] [blame] | 572 | /* |
| 573 | * Remove a bolted kernel entry. Memory hotplug uses this. |
| 574 | * |
| 575 | * No need to lock here because we should be the only user. |
| 576 | */ |
| 577 | static int native_hpte_removebolted(unsigned long ea, int psize, int ssize) |
| 578 | { |
| 579 | unsigned long vpn; |
| 580 | unsigned long vsid; |
| 581 | long slot; |
| 582 | struct hash_pte *hptep; |
| 583 | |
| 584 | vsid = get_kernel_vsid(ea, ssize); |
| 585 | vpn = hpt_vpn(ea, vsid, ssize); |
| 586 | |
| 587 | slot = native_hpte_find(vpn, psize, ssize); |
| 588 | if (slot == -1) |
| 589 | return -ENOENT; |
| 590 | |
| 591 | hptep = htab_address + slot; |
| 592 | |
| 593 | VM_WARN_ON(!(be64_to_cpu(hptep->v) & HPTE_V_BOLTED)); |
| 594 | |
| 595 | /* Invalidate the hpte */ |
| 596 | hptep->v = 0; |
| 597 | |
| 598 | /* Invalidate the TLB */ |
| 599 | tlbie(vpn, psize, psize, ssize, 0); |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 604 | static void native_hpte_invalidate(unsigned long slot, unsigned long vpn, |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 605 | int bpsize, int apsize, int ssize, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 607 | struct hash_pte *hptep = htab_address + slot; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 608 | unsigned long hpte_v; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 609 | unsigned long want_v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 614 | DBG_LOW(" invalidate(vpn=%016lx, hash: %lx)\n", vpn, slot); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 615 | |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 616 | want_v = hpte_encode_avpn(vpn, bpsize, ssize); |
Aneesh Kumar K.V | a833280 | 2018-06-29 14:06:30 +0530 | [diff] [blame] | 617 | hpte_v = hpte_get_old_v(hptep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Aneesh Kumar K.V | 27d8959 | 2018-06-29 14:06:31 +0530 | [diff] [blame] | 619 | if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID)) { |
| 620 | native_lock_hpte(hptep); |
| 621 | /* recheck with locks held */ |
| 622 | hpte_v = hpte_get_old_v(hptep); |
| 623 | |
| 624 | if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID)) |
| 625 | /* Invalidate the hpte. NOTE: this also unlocks it */ |
| 626 | hptep->v = 0; |
| 627 | else |
| 628 | native_unlock_hpte(hptep); |
| 629 | } |
Aneesh Kumar K.V | 0608d69 | 2013-05-31 01:03:24 +0000 | [diff] [blame] | 630 | /* |
| 631 | * We need to invalidate the TLB always because hpte_remove doesn't do |
| 632 | * a tlb invalidate. If a hash bucket gets full, we "evict" a more/less |
| 633 | * random entry from it. When we do that we don't invalidate the TLB |
| 634 | * (hpte_remove) because we assume the old translation is still |
| 635 | * technically "valid". |
| 636 | */ |
Aneesh Kumar K.V | db3d853 | 2013-06-20 14:30:13 +0530 | [diff] [blame] | 637 | tlbie(vpn, bpsize, apsize, ssize, local); |
| 638 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 639 | local_irq_restore(flags); |
| 640 | } |
| 641 | |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame] | 642 | #ifdef CONFIG_TRANSPARENT_HUGEPAGE |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 643 | static void native_hugepage_invalidate(unsigned long vsid, |
| 644 | unsigned long addr, |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 645 | unsigned char *hpte_slot_array, |
Aneesh Kumar K.V | d557b09 | 2014-11-02 21:15:28 +0530 | [diff] [blame] | 646 | int psize, int ssize, int local) |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 647 | { |
Aneesh Kumar K.V | 969b7b2 | 2014-08-13 12:32:01 +0530 | [diff] [blame] | 648 | int i; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 649 | struct hash_pte *hptep; |
| 650 | int actual_psize = MMU_PAGE_16M; |
| 651 | unsigned int max_hpte_count, valid; |
| 652 | unsigned long flags, s_addr = addr; |
| 653 | unsigned long hpte_v, want_v, shift; |
Aneesh Kumar K.V | fa1f8ae | 2014-08-13 12:31:58 +0530 | [diff] [blame] | 654 | unsigned long hidx, vpn = 0, hash, slot; |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 655 | |
| 656 | shift = mmu_psize_defs[psize].shift; |
| 657 | max_hpte_count = 1U << (PMD_SHIFT - shift); |
| 658 | |
| 659 | local_irq_save(flags); |
| 660 | for (i = 0; i < max_hpte_count; i++) { |
| 661 | valid = hpte_valid(hpte_slot_array, i); |
| 662 | if (!valid) |
| 663 | continue; |
| 664 | hidx = hpte_hash_index(hpte_slot_array, i); |
| 665 | |
| 666 | /* get the vpn */ |
| 667 | addr = s_addr + (i * (1ul << shift)); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 668 | vpn = hpt_vpn(addr, vsid, ssize); |
| 669 | hash = hpt_hash(vpn, shift, ssize); |
| 670 | if (hidx & _PTEIDX_SECONDARY) |
| 671 | hash = ~hash; |
| 672 | |
| 673 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 674 | slot += hidx & _PTEIDX_GROUP_IX; |
| 675 | |
| 676 | hptep = htab_address + slot; |
| 677 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Aneesh Kumar K.V | a833280 | 2018-06-29 14:06:30 +0530 | [diff] [blame] | 678 | hpte_v = hpte_get_old_v(hptep); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 679 | |
| 680 | /* Even if we miss, we need to invalidate the TLB */ |
Aneesh Kumar K.V | 27d8959 | 2018-06-29 14:06:31 +0530 | [diff] [blame] | 681 | if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID)) { |
| 682 | /* recheck with locks held */ |
| 683 | native_lock_hpte(hptep); |
| 684 | hpte_v = hpte_get_old_v(hptep); |
| 685 | |
| 686 | if (HPTE_V_COMPARE(hpte_v, want_v) && (hpte_v & HPTE_V_VALID)) { |
| 687 | /* |
| 688 | * Invalidate the hpte. NOTE: this also unlocks it |
| 689 | */ |
| 690 | |
| 691 | hptep->v = 0; |
| 692 | } else |
| 693 | native_unlock_hpte(hptep); |
| 694 | } |
Aneesh Kumar K.V | 969b7b2 | 2014-08-13 12:32:01 +0530 | [diff] [blame] | 695 | /* |
| 696 | * We need to do tlb invalidate for all the address, tlbie |
| 697 | * instruction compares entry_VA in tlb with the VA specified |
| 698 | * here |
| 699 | */ |
Aneesh Kumar K.V | d557b09 | 2014-11-02 21:15:28 +0530 | [diff] [blame] | 700 | tlbie(vpn, psize, actual_psize, ssize, local); |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 701 | } |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 702 | local_irq_restore(flags); |
| 703 | } |
Aneesh Kumar K.V | e34aa03 | 2015-12-01 09:06:53 +0530 | [diff] [blame] | 704 | #else |
| 705 | static void native_hugepage_invalidate(unsigned long vsid, |
| 706 | unsigned long addr, |
| 707 | unsigned char *hpte_slot_array, |
| 708 | int psize, int ssize, int local) |
| 709 | { |
| 710 | WARN(1, "%s called without THP support\n", __func__); |
| 711 | } |
| 712 | #endif |
Aneesh Kumar K.V | 1a52728 | 2013-06-20 14:30:27 +0530 | [diff] [blame] | 713 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 714 | static void hpte_decode(struct hash_pte *hpte, unsigned long slot, |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 715 | int *psize, int *apsize, int *ssize, unsigned long *vpn) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 716 | { |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 717 | unsigned long avpn, pteg, vpi; |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 718 | unsigned long hpte_v = be64_to_cpu(hpte->v); |
| 719 | unsigned long hpte_r = be64_to_cpu(hpte->r); |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 720 | unsigned long vsid, seg_off; |
Aneesh Kumar K.V | 7e74c39 | 2013-04-28 09:37:36 +0000 | [diff] [blame] | 721 | int size, a_size, shift; |
| 722 | /* Look at the 8 bit LP value */ |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 723 | unsigned int lp = (hpte_r >> LP_SHIFT) & ((1 << LP_BITS) - 1); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 724 | |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 725 | if (cpu_has_feature(CPU_FTR_ARCH_300)) { |
| 726 | hpte_v = hpte_new_to_old_v(hpte_v, hpte_r); |
| 727 | hpte_r = hpte_new_to_old_r(hpte_r); |
| 728 | } |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 729 | if (!(hpte_v & HPTE_V_LARGE)) { |
| 730 | size = MMU_PAGE_4K; |
| 731 | a_size = MMU_PAGE_4K; |
| 732 | } else { |
Paul Mackerras | 0eeede0 | 2016-09-02 17:20:43 +1000 | [diff] [blame] | 733 | size = hpte_page_sizes[lp] & 0xf; |
| 734 | a_size = hpte_page_sizes[lp] >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
Paul Mackerras | 2454c7e | 2007-05-10 15:28:44 +1000 | [diff] [blame] | 736 | /* This works for all page sizes, and for 256M and 1T segments */ |
Paul Mackerras | 6b243fc | 2016-11-11 16:55:03 +1100 | [diff] [blame] | 737 | *ssize = hpte_v >> HPTE_V_SSIZE_SHIFT; |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 738 | shift = mmu_psize_defs[size].shift; |
| 739 | |
| 740 | avpn = (HPTE_V_AVPN_VAL(hpte_v) & ~mmu_psize_defs[size].avpnm); |
| 741 | pteg = slot / HPTES_PER_GROUP; |
| 742 | if (hpte_v & HPTE_V_SECONDARY) |
| 743 | pteg = ~pteg; |
| 744 | |
| 745 | switch (*ssize) { |
| 746 | case MMU_SEGSIZE_256M: |
| 747 | /* We only have 28 - 23 bits of seg_off in avpn */ |
| 748 | seg_off = (avpn & 0x1f) << 23; |
| 749 | vsid = avpn >> 5; |
| 750 | /* We can find more bits from the pteg value */ |
| 751 | if (shift < 23) { |
| 752 | vpi = (vsid ^ pteg) & htab_hash_mask; |
| 753 | seg_off |= vpi << shift; |
| 754 | } |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 755 | *vpn = vsid << (SID_SHIFT - VPN_SHIFT) | seg_off >> VPN_SHIFT; |
Aneesh Kumar K.V | 83383b7 | 2013-07-03 13:50:03 +0530 | [diff] [blame] | 756 | break; |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 757 | case MMU_SEGSIZE_1T: |
| 758 | /* We only have 40 - 23 bits of seg_off in avpn */ |
| 759 | seg_off = (avpn & 0x1ffff) << 23; |
| 760 | vsid = avpn >> 17; |
| 761 | if (shift < 23) { |
| 762 | vpi = (vsid ^ (vsid << 25) ^ pteg) & htab_hash_mask; |
| 763 | seg_off |= vpi << shift; |
| 764 | } |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 765 | *vpn = vsid << (SID_SHIFT_1T - VPN_SHIFT) | seg_off >> VPN_SHIFT; |
Aneesh Kumar K.V | 83383b7 | 2013-07-03 13:50:03 +0530 | [diff] [blame] | 766 | break; |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 767 | default: |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 768 | *vpn = size = 0; |
Aneesh Kumar K.V | dcda287 | 2012-09-10 02:52:49 +0000 | [diff] [blame] | 769 | } |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 770 | *psize = size; |
| 771 | *apsize = a_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 774 | /* |
| 775 | * clear all mappings on kexec. All cpus are in real mode (or they will |
| 776 | * be when they isi), and we are the only one left. We rely on our kernel |
| 777 | * mapping being 0xC0's and the hardware ignoring those two real bits. |
| 778 | * |
Cyril Bur | fdf880a | 2015-10-08 11:04:26 +1100 | [diff] [blame] | 779 | * This must be called with interrupts disabled. |
| 780 | * |
| 781 | * Taking the native_tlbie_lock is unsafe here due to the possibility of |
| 782 | * lockdep being on. On pre POWER5 hardware, not taking the lock could |
| 783 | * cause deadlock. POWER5 and newer not taking the lock is fine. This only |
| 784 | * gets called during boot before secondary CPUs have come up and during |
| 785 | * crashdump and all bets are off anyway. |
| 786 | * |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 787 | * TODO: add batching support when enabled. remember, no dynamic memory here, |
Michael Ellerman | 027dfac | 2016-06-01 16:34:37 +1000 | [diff] [blame] | 788 | * although there is the control page available... |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 789 | */ |
Hari Bathini | 8119cef | 2021-07-14 18:17:58 +0530 | [diff] [blame] | 790 | static notrace void native_hpte_clear(void) |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 791 | { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 792 | unsigned long vpn = 0; |
Cyril Bur | fdf880a | 2015-10-08 11:04:26 +1100 | [diff] [blame] | 793 | unsigned long slot, slots; |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 794 | struct hash_pte *hptep = htab_address; |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 795 | unsigned long hpte_v; |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 796 | unsigned long pteg_count; |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 797 | int psize, apsize, ssize; |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 798 | |
| 799 | pteg_count = htab_hash_mask + 1; |
| 800 | |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 801 | slots = pteg_count * HPTES_PER_GROUP; |
| 802 | |
| 803 | for (slot = 0; slot < slots; slot++, hptep++) { |
| 804 | /* |
| 805 | * we could lock the pte here, but we are the only cpu |
| 806 | * running, right? and for crash dump, we probably |
| 807 | * don't want to wait for a maybe bad cpu. |
| 808 | */ |
Anton Blanchard | 12f04f2 | 2013-09-23 12:04:36 +1000 | [diff] [blame] | 809 | hpte_v = be64_to_cpu(hptep->v); |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 810 | |
R Sharada | 47f78a4 | 2006-02-22 21:43:08 +0530 | [diff] [blame] | 811 | /* |
Cyril Bur | fdf880a | 2015-10-08 11:04:26 +1100 | [diff] [blame] | 812 | * Call __tlbie() here rather than tlbie() since we can't take the |
| 813 | * native_tlbie_lock. |
R Sharada | 47f78a4 | 2006-02-22 21:43:08 +0530 | [diff] [blame] | 814 | */ |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 815 | if (hpte_v & HPTE_V_VALID) { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 816 | hpte_decode(hptep, slot, &psize, &apsize, &ssize, &vpn); |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 817 | hptep->v = 0; |
Mahesh Salgaonkar | a3961f8 | 2017-11-22 23:02:07 +0530 | [diff] [blame] | 818 | ___tlbie(vpn, psize, apsize, ssize); |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | |
R Sharada | 47f78a4 | 2006-02-22 21:43:08 +0530 | [diff] [blame] | 822 | asm volatile("eieio; tlbsync; ptesync":::"memory"); |
R Sharada | f4c82d5 | 2005-06-25 14:58:08 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 825 | /* |
| 826 | * Batched hash table flush, we batch the tlbie's to avoid taking/releasing |
| 827 | * the lock all the time |
| 828 | */ |
Benjamin Herrenschmidt | 61b1a94 | 2005-09-20 13:52:50 +1000 | [diff] [blame] | 829 | static void native_flush_hash_range(unsigned long number, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | { |
Aneesh Kumar K.V | a5d4b58 | 2018-03-23 10:26:27 +0530 | [diff] [blame] | 831 | unsigned long vpn = 0; |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 832 | unsigned long hash, index, hidx, shift, slot; |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 833 | struct hash_pte *hptep; |
David Gibson | 96e2844 | 2005-07-13 01:11:42 -0700 | [diff] [blame] | 834 | unsigned long hpte_v; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 835 | unsigned long want_v; |
| 836 | unsigned long flags; |
| 837 | real_pte_t pte; |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 838 | struct ppc64_tlb_batch *batch = this_cpu_ptr(&ppc64_tlb_batch); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 839 | unsigned long psize = batch->psize; |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 840 | int ssize = batch->ssize; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 841 | int i; |
Frederic Barrat | 88b1bf72 | 2017-03-29 19:19:42 +0200 | [diff] [blame] | 842 | unsigned int use_local; |
| 843 | |
| 844 | use_local = local && mmu_has_feature(MMU_FTR_TLBIEL) && |
| 845 | mmu_psize_defs[psize].tlbiel && !cxl_ctx_in_use(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
| 847 | local_irq_save(flags); |
| 848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | for (i = 0; i < number; i++) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 850 | vpn = batch->vpn[i]; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 851 | pte = batch->pte[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 853 | pte_iterate_hashed_subpages(pte, psize, vpn, index, shift) { |
| 854 | hash = hpt_hash(vpn, shift, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 855 | hidx = __rpte_to_hidx(pte, index); |
| 856 | if (hidx & _PTEIDX_SECONDARY) |
| 857 | hash = ~hash; |
| 858 | slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; |
| 859 | slot += hidx & _PTEIDX_GROUP_IX; |
| 860 | hptep = htab_address + slot; |
Aneesh Kumar K.V | 74f227b | 2013-04-28 09:37:34 +0000 | [diff] [blame] | 861 | want_v = hpte_encode_avpn(vpn, psize, ssize); |
Aneesh Kumar K.V | 27d8959 | 2018-06-29 14:06:31 +0530 | [diff] [blame] | 862 | hpte_v = hpte_get_old_v(hptep); |
| 863 | |
| 864 | if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) |
| 865 | continue; |
| 866 | /* lock and try again */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 867 | native_lock_hpte(hptep); |
Aneesh Kumar K.V | a833280 | 2018-06-29 14:06:30 +0530 | [diff] [blame] | 868 | hpte_v = hpte_get_old_v(hptep); |
Aneesh Kumar K.V | 27d8959 | 2018-06-29 14:06:31 +0530 | [diff] [blame] | 869 | |
| 870 | if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 871 | native_unlock_hpte(hptep); |
| 872 | else |
| 873 | hptep->v = 0; |
Aneesh Kumar K.V | 27d8959 | 2018-06-29 14:06:31 +0530 | [diff] [blame] | 874 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 875 | } pte_iterate_hashed_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Frederic Barrat | 88b1bf72 | 2017-03-29 19:19:42 +0200 | [diff] [blame] | 878 | if (use_local) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | asm volatile("ptesync":::"memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 880 | for (i = 0; i < number; i++) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 881 | vpn = batch->vpn[i]; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 882 | pte = batch->pte[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 884 | pte_iterate_hashed_subpages(pte, psize, |
| 885 | vpn, index, shift) { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 886 | __tlbiel(vpn, psize, psize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 887 | } pte_iterate_hashed_end(); |
| 888 | } |
Nicholas Piggin | 05504b4 | 2020-09-16 13:02:34 +1000 | [diff] [blame] | 889 | ppc_after_tlbiel_barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | } else { |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 891 | int lock_tlbie = !mmu_has_feature(MMU_FTR_LOCKLESS_TLBIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | if (lock_tlbie) |
Thomas Gleixner | 6b9c9b8 | 2010-02-18 02:22:35 +0000 | [diff] [blame] | 894 | raw_spin_lock(&native_tlbie_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
| 896 | asm volatile("ptesync":::"memory"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 897 | for (i = 0; i < number; i++) { |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 898 | vpn = batch->vpn[i]; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 899 | pte = batch->pte[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Aneesh Kumar K.V | 5524a27 | 2012-09-10 02:52:50 +0000 | [diff] [blame] | 901 | pte_iterate_hashed_subpages(pte, psize, |
| 902 | vpn, index, shift) { |
Aneesh Kumar K.V | b1022fb | 2013-04-28 09:37:35 +0000 | [diff] [blame] | 903 | __tlbie(vpn, psize, psize, ssize); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 904 | } pte_iterate_hashed_end(); |
| 905 | } |
Aneesh Kumar K.V | a5d4b58 | 2018-03-23 10:26:27 +0530 | [diff] [blame] | 906 | /* |
| 907 | * Just do one more with the last used values. |
| 908 | */ |
Aneesh Kumar K.V | 047e657 | 2019-09-24 09:22:53 +0530 | [diff] [blame] | 909 | fixup_tlbie_vpn(vpn, psize, psize, ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | asm volatile("eieio; tlbsync; ptesync":::"memory"); |
| 911 | |
| 912 | if (lock_tlbie) |
Thomas Gleixner | 6b9c9b8 | 2010-02-18 02:22:35 +0000 | [diff] [blame] | 913 | raw_spin_unlock(&native_tlbie_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | local_irq_restore(flags); |
| 917 | } |
| 918 | |
Michael Ellerman | 7d0daae | 2006-06-23 18:16:38 +1000 | [diff] [blame] | 919 | void __init hpte_init_native(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | { |
Benjamin Herrenschmidt | 7025776 | 2016-07-05 15:03:58 +1000 | [diff] [blame] | 921 | mmu_hash_ops.hpte_invalidate = native_hpte_invalidate; |
| 922 | mmu_hash_ops.hpte_updatepp = native_hpte_updatepp; |
| 923 | mmu_hash_ops.hpte_updateboltedpp = native_hpte_updateboltedpp; |
Anton Blanchard | 1b644f5 | 2017-06-28 11:32:35 +1000 | [diff] [blame] | 924 | mmu_hash_ops.hpte_removebolted = native_hpte_removebolted; |
Benjamin Herrenschmidt | 7025776 | 2016-07-05 15:03:58 +1000 | [diff] [blame] | 925 | mmu_hash_ops.hpte_insert = native_hpte_insert; |
| 926 | mmu_hash_ops.hpte_remove = native_hpte_remove; |
| 927 | mmu_hash_ops.hpte_clear_all = native_hpte_clear; |
| 928 | mmu_hash_ops.flush_hash_range = native_flush_hash_range; |
| 929 | mmu_hash_ops.hugepage_invalidate = native_hugepage_invalidate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | } |