Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2001 Ben. Herrenschmidt (benh@kernel.crashing.org) |
| 3 | * |
| 4 | * Modifications for ppc64: |
| 5 | * Copyright (C) 2003 Dave Engebretsen <engebret@us.ibm.com> |
| 6 | * |
| 7 | * Copyright 2008 Michael Ellerman, IBM Corporation. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | */ |
| 14 | |
Stephen Rothwell | 3880ecb | 2010-06-28 21:08:29 +0000 | [diff] [blame] | 15 | #include <linux/types.h> |
Aneesh Kumar K.V | 309b315 | 2016-07-23 14:42:38 +0530 | [diff] [blame] | 16 | #include <linux/jump_label.h> |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 18 | #include <linux/string.h> |
| 19 | #include <linux/init.h> |
Ingo Molnar | 589ee62 | 2017-02-04 00:16:44 +0100 | [diff] [blame] | 20 | #include <linux/sched/mm.h> |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 21 | #include <asm/cputable.h> |
| 22 | #include <asm/code-patching.h> |
Anton Blanchard | d715e43 | 2011-11-14 12:54:47 +0000 | [diff] [blame] | 23 | #include <asm/page.h> |
| 24 | #include <asm/sections.h> |
Benjamin Herrenschmidt | 9402c68 | 2016-07-05 15:03:41 +1000 | [diff] [blame] | 25 | #include <asm/setup.h> |
Nicholas Piggin | a048a07 | 2018-05-22 09:00:00 +1000 | [diff] [blame] | 26 | #include <asm/security_features.h> |
Benjamin Herrenschmidt | 9402c68 | 2016-07-05 15:03:41 +1000 | [diff] [blame] | 27 | #include <asm/firmware.h> |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 28 | |
| 29 | struct fixup_entry { |
| 30 | unsigned long mask; |
| 31 | unsigned long value; |
| 32 | long start_off; |
| 33 | long end_off; |
Michael Ellerman | fac23fe | 2008-06-24 11:32:54 +1000 | [diff] [blame] | 34 | long alt_start_off; |
| 35 | long alt_end_off; |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 36 | }; |
| 37 | |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 38 | static unsigned int *calc_addr(struct fixup_entry *fcur, long offset) |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 39 | { |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 40 | /* |
| 41 | * We store the offset to the code as a negative offset from |
| 42 | * the start of the alt_entry, to support the VDSO. This |
| 43 | * routine converts that back into an actual address. |
| 44 | */ |
| 45 | return (unsigned int *)((unsigned long)fcur + offset); |
| 46 | } |
| 47 | |
| 48 | static int patch_alt_instruction(unsigned int *src, unsigned int *dest, |
| 49 | unsigned int *alt_start, unsigned int *alt_end) |
| 50 | { |
| 51 | unsigned int instr; |
| 52 | |
| 53 | instr = *src; |
| 54 | |
| 55 | if (instr_is_relative_branch(*src)) { |
| 56 | unsigned int *target = (unsigned int *)branch_target(src); |
| 57 | |
| 58 | /* Branch within the section doesn't need translating */ |
Michael Ellerman | b885858 | 2018-04-16 23:25:19 +1000 | [diff] [blame] | 59 | if (target < alt_start || target > alt_end) { |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 60 | instr = translate_branch(dest, src); |
| 61 | if (!instr) |
| 62 | return 1; |
| 63 | } |
| 64 | } |
| 65 | |
Christophe Leroy | 8183d99 | 2017-11-24 08:31:09 +0100 | [diff] [blame] | 66 | raw_patch_instruction(dest, instr); |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static int patch_feature_section(unsigned long value, struct fixup_entry *fcur) |
| 72 | { |
| 73 | unsigned int *start, *end, *alt_start, *alt_end, *src, *dest; |
| 74 | |
| 75 | start = calc_addr(fcur, fcur->start_off); |
| 76 | end = calc_addr(fcur, fcur->end_off); |
| 77 | alt_start = calc_addr(fcur, fcur->alt_start_off); |
| 78 | alt_end = calc_addr(fcur, fcur->alt_end_off); |
| 79 | |
| 80 | if ((alt_end - alt_start) > (end - start)) |
| 81 | return 1; |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 82 | |
| 83 | if ((value & fcur->mask) == fcur->value) |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 84 | return 0; |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 85 | |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 86 | src = alt_start; |
| 87 | dest = start; |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 88 | |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 89 | for (; src < alt_end; src++, dest++) { |
| 90 | if (patch_alt_instruction(src, dest, alt_start, alt_end)) |
| 91 | return 1; |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 92 | } |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 93 | |
| 94 | for (; dest < end; dest++) |
Christophe Leroy | 8183d99 | 2017-11-24 08:31:09 +0100 | [diff] [blame] | 95 | raw_patch_instruction(dest, PPC_INST_NOP); |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 96 | |
| 97 | return 0; |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end) |
| 101 | { |
| 102 | struct fixup_entry *fcur, *fend; |
| 103 | |
| 104 | fcur = fixup_start; |
| 105 | fend = fixup_end; |
| 106 | |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 107 | for (; fcur < fend; fcur++) { |
| 108 | if (patch_feature_section(value, fcur)) { |
Michael Ellerman | 1856c02 | 2008-07-17 14:46:00 +1000 | [diff] [blame] | 109 | WARN_ON(1); |
Michael Ellerman | 9b1a735 | 2008-06-24 11:33:02 +1000 | [diff] [blame] | 110 | printk("Unable to patch feature section at %p - %p" \ |
| 111 | " with %p - %p\n", |
| 112 | calc_addr(fcur, fcur->start_off), |
| 113 | calc_addr(fcur, fcur->end_off), |
| 114 | calc_addr(fcur, fcur->alt_start_off), |
| 115 | calc_addr(fcur, fcur->alt_end_off)); |
| 116 | } |
| 117 | } |
Michael Ellerman | 51c52e8 | 2008-06-24 11:32:36 +1000 | [diff] [blame] | 118 | } |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 119 | |
Michael Ellerman | aa8a5e0 | 2018-01-10 03:07:15 +1100 | [diff] [blame] | 120 | #ifdef CONFIG_PPC_BOOK3S_64 |
Breno Leitao | 3b30c6e | 2018-10-22 11:54:17 -0300 | [diff] [blame] | 121 | static void do_stf_entry_barrier_fixups(enum stf_barrier_type types) |
Nicholas Piggin | a048a07 | 2018-05-22 09:00:00 +1000 | [diff] [blame] | 122 | { |
| 123 | unsigned int instrs[3], *dest; |
| 124 | long *start, *end; |
| 125 | int i; |
| 126 | |
| 127 | start = PTRRELOC(&__start___stf_entry_barrier_fixup), |
| 128 | end = PTRRELOC(&__stop___stf_entry_barrier_fixup); |
| 129 | |
| 130 | instrs[0] = 0x60000000; /* nop */ |
| 131 | instrs[1] = 0x60000000; /* nop */ |
| 132 | instrs[2] = 0x60000000; /* nop */ |
| 133 | |
| 134 | i = 0; |
| 135 | if (types & STF_BARRIER_FALLBACK) { |
| 136 | instrs[i++] = 0x7d4802a6; /* mflr r10 */ |
| 137 | instrs[i++] = 0x60000000; /* branch patched below */ |
| 138 | instrs[i++] = 0x7d4803a6; /* mtlr r10 */ |
| 139 | } else if (types & STF_BARRIER_EIEIO) { |
| 140 | instrs[i++] = 0x7e0006ac; /* eieio + bit 6 hint */ |
| 141 | } else if (types & STF_BARRIER_SYNC_ORI) { |
| 142 | instrs[i++] = 0x7c0004ac; /* hwsync */ |
| 143 | instrs[i++] = 0xe94d0000; /* ld r10,0(r13) */ |
| 144 | instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */ |
| 145 | } |
| 146 | |
| 147 | for (i = 0; start < end; start++, i++) { |
| 148 | dest = (void *)start + *start; |
| 149 | |
| 150 | pr_devel("patching dest %lx\n", (unsigned long)dest); |
| 151 | |
| 152 | patch_instruction(dest, instrs[0]); |
| 153 | |
| 154 | if (types & STF_BARRIER_FALLBACK) |
| 155 | patch_branch(dest + 1, (unsigned long)&stf_barrier_fallback, |
| 156 | BRANCH_SET_LINK); |
| 157 | else |
| 158 | patch_instruction(dest + 1, instrs[1]); |
| 159 | |
| 160 | patch_instruction(dest + 2, instrs[2]); |
| 161 | } |
| 162 | |
| 163 | printk(KERN_DEBUG "stf-barrier: patched %d entry locations (%s barrier)\n", i, |
| 164 | (types == STF_BARRIER_NONE) ? "no" : |
| 165 | (types == STF_BARRIER_FALLBACK) ? "fallback" : |
| 166 | (types == STF_BARRIER_EIEIO) ? "eieio" : |
| 167 | (types == (STF_BARRIER_SYNC_ORI)) ? "hwsync" |
| 168 | : "unknown"); |
| 169 | } |
| 170 | |
Breno Leitao | 3b30c6e | 2018-10-22 11:54:17 -0300 | [diff] [blame] | 171 | static void do_stf_exit_barrier_fixups(enum stf_barrier_type types) |
Nicholas Piggin | a048a07 | 2018-05-22 09:00:00 +1000 | [diff] [blame] | 172 | { |
| 173 | unsigned int instrs[6], *dest; |
| 174 | long *start, *end; |
| 175 | int i; |
| 176 | |
| 177 | start = PTRRELOC(&__start___stf_exit_barrier_fixup), |
| 178 | end = PTRRELOC(&__stop___stf_exit_barrier_fixup); |
| 179 | |
| 180 | instrs[0] = 0x60000000; /* nop */ |
| 181 | instrs[1] = 0x60000000; /* nop */ |
| 182 | instrs[2] = 0x60000000; /* nop */ |
| 183 | instrs[3] = 0x60000000; /* nop */ |
| 184 | instrs[4] = 0x60000000; /* nop */ |
| 185 | instrs[5] = 0x60000000; /* nop */ |
| 186 | |
| 187 | i = 0; |
| 188 | if (types & STF_BARRIER_FALLBACK || types & STF_BARRIER_SYNC_ORI) { |
| 189 | if (cpu_has_feature(CPU_FTR_HVMODE)) { |
| 190 | instrs[i++] = 0x7db14ba6; /* mtspr 0x131, r13 (HSPRG1) */ |
| 191 | instrs[i++] = 0x7db04aa6; /* mfspr r13, 0x130 (HSPRG0) */ |
| 192 | } else { |
| 193 | instrs[i++] = 0x7db243a6; /* mtsprg 2,r13 */ |
| 194 | instrs[i++] = 0x7db142a6; /* mfsprg r13,1 */ |
| 195 | } |
| 196 | instrs[i++] = 0x7c0004ac; /* hwsync */ |
| 197 | instrs[i++] = 0xe9ad0000; /* ld r13,0(r13) */ |
| 198 | instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */ |
| 199 | if (cpu_has_feature(CPU_FTR_HVMODE)) { |
| 200 | instrs[i++] = 0x7db14aa6; /* mfspr r13, 0x131 (HSPRG1) */ |
| 201 | } else { |
| 202 | instrs[i++] = 0x7db242a6; /* mfsprg r13,2 */ |
| 203 | } |
| 204 | } else if (types & STF_BARRIER_EIEIO) { |
| 205 | instrs[i++] = 0x7e0006ac; /* eieio + bit 6 hint */ |
| 206 | } |
| 207 | |
| 208 | for (i = 0; start < end; start++, i++) { |
| 209 | dest = (void *)start + *start; |
| 210 | |
| 211 | pr_devel("patching dest %lx\n", (unsigned long)dest); |
| 212 | |
| 213 | patch_instruction(dest, instrs[0]); |
| 214 | patch_instruction(dest + 1, instrs[1]); |
| 215 | patch_instruction(dest + 2, instrs[2]); |
| 216 | patch_instruction(dest + 3, instrs[3]); |
| 217 | patch_instruction(dest + 4, instrs[4]); |
| 218 | patch_instruction(dest + 5, instrs[5]); |
| 219 | } |
| 220 | printk(KERN_DEBUG "stf-barrier: patched %d exit locations (%s barrier)\n", i, |
| 221 | (types == STF_BARRIER_NONE) ? "no" : |
| 222 | (types == STF_BARRIER_FALLBACK) ? "fallback" : |
| 223 | (types == STF_BARRIER_EIEIO) ? "eieio" : |
| 224 | (types == (STF_BARRIER_SYNC_ORI)) ? "hwsync" |
| 225 | : "unknown"); |
| 226 | } |
| 227 | |
| 228 | |
| 229 | void do_stf_barrier_fixups(enum stf_barrier_type types) |
| 230 | { |
| 231 | do_stf_entry_barrier_fixups(types); |
| 232 | do_stf_exit_barrier_fixups(types); |
| 233 | } |
| 234 | |
Michael Ellerman | aa8a5e0 | 2018-01-10 03:07:15 +1100 | [diff] [blame] | 235 | void do_rfi_flush_fixups(enum l1d_flush_type types) |
| 236 | { |
| 237 | unsigned int instrs[3], *dest; |
| 238 | long *start, *end; |
| 239 | int i; |
| 240 | |
| 241 | start = PTRRELOC(&__start___rfi_flush_fixup), |
| 242 | end = PTRRELOC(&__stop___rfi_flush_fixup); |
| 243 | |
| 244 | instrs[0] = 0x60000000; /* nop */ |
| 245 | instrs[1] = 0x60000000; /* nop */ |
| 246 | instrs[2] = 0x60000000; /* nop */ |
| 247 | |
| 248 | if (types & L1D_FLUSH_FALLBACK) |
| 249 | /* b .+16 to fallback flush */ |
| 250 | instrs[0] = 0x48000010; |
| 251 | |
| 252 | i = 0; |
| 253 | if (types & L1D_FLUSH_ORI) { |
| 254 | instrs[i++] = 0x63ff0000; /* ori 31,31,0 speculation barrier */ |
| 255 | instrs[i++] = 0x63de0000; /* ori 30,30,0 L1d flush*/ |
| 256 | } |
| 257 | |
| 258 | if (types & L1D_FLUSH_MTTRIG) |
| 259 | instrs[i++] = 0x7c12dba6; /* mtspr TRIG2,r0 (SPR #882) */ |
| 260 | |
| 261 | for (i = 0; start < end; start++, i++) { |
| 262 | dest = (void *)start + *start; |
| 263 | |
| 264 | pr_devel("patching dest %lx\n", (unsigned long)dest); |
| 265 | |
| 266 | patch_instruction(dest, instrs[0]); |
| 267 | patch_instruction(dest + 1, instrs[1]); |
| 268 | patch_instruction(dest + 2, instrs[2]); |
| 269 | } |
| 270 | |
Mauricio Faria de Oliveira | 0063d61 | 2018-03-14 19:40:41 -0300 | [diff] [blame] | 271 | printk(KERN_DEBUG "rfi-flush: patched %d locations (%s flush)\n", i, |
| 272 | (types == L1D_FLUSH_NONE) ? "no" : |
| 273 | (types == L1D_FLUSH_FALLBACK) ? "fallback displacement" : |
| 274 | (types & L1D_FLUSH_ORI) ? (types & L1D_FLUSH_MTTRIG) |
| 275 | ? "ori+mttrig type" |
| 276 | : "ori type" : |
| 277 | (types & L1D_FLUSH_MTTRIG) ? "mttrig type" |
| 278 | : "unknown"); |
Michael Ellerman | aa8a5e0 | 2018-01-10 03:07:15 +1100 | [diff] [blame] | 279 | } |
Michal Suchanek | 2eea7f0 | 2018-04-24 14:15:55 +1000 | [diff] [blame] | 280 | |
Michal Suchanek | 815069c | 2018-04-24 14:15:56 +1000 | [diff] [blame] | 281 | void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_end) |
Michal Suchanek | 2eea7f0 | 2018-04-24 14:15:55 +1000 | [diff] [blame] | 282 | { |
| 283 | unsigned int instr, *dest; |
| 284 | long *start, *end; |
| 285 | int i; |
| 286 | |
Michal Suchanek | 815069c | 2018-04-24 14:15:56 +1000 | [diff] [blame] | 287 | start = fixup_start; |
| 288 | end = fixup_end; |
Michal Suchanek | 2eea7f0 | 2018-04-24 14:15:55 +1000 | [diff] [blame] | 289 | |
| 290 | instr = 0x60000000; /* nop */ |
| 291 | |
| 292 | if (enable) { |
| 293 | pr_info("barrier-nospec: using ORI speculation barrier\n"); |
| 294 | instr = 0x63ff0000; /* ori 31,31,0 speculation barrier */ |
| 295 | } |
| 296 | |
| 297 | for (i = 0; start < end; start++, i++) { |
| 298 | dest = (void *)start + *start; |
| 299 | |
| 300 | pr_devel("patching dest %lx\n", (unsigned long)dest); |
| 301 | patch_instruction(dest, instr); |
| 302 | } |
| 303 | |
| 304 | printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i); |
| 305 | } |
| 306 | |
Michael Ellerman | 179ab1c | 2018-07-28 09:06:34 +1000 | [diff] [blame] | 307 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
| 308 | |
| 309 | #ifdef CONFIG_PPC_BARRIER_NOSPEC |
Michal Suchanek | 815069c | 2018-04-24 14:15:56 +1000 | [diff] [blame] | 310 | void do_barrier_nospec_fixups(bool enable) |
| 311 | { |
| 312 | void *start, *end; |
| 313 | |
| 314 | start = PTRRELOC(&__start___barrier_nospec_fixup), |
| 315 | end = PTRRELOC(&__stop___barrier_nospec_fixup); |
| 316 | |
| 317 | do_barrier_nospec_fixups_range(enable, start, end); |
| 318 | } |
Michael Ellerman | 179ab1c | 2018-07-28 09:06:34 +1000 | [diff] [blame] | 319 | #endif /* CONFIG_PPC_BARRIER_NOSPEC */ |
Michael Ellerman | aa8a5e0 | 2018-01-10 03:07:15 +1100 | [diff] [blame] | 320 | |
Diana Craciun | ebcd1bf | 2018-07-28 09:06:37 +1000 | [diff] [blame] | 321 | #ifdef CONFIG_PPC_FSL_BOOK3E |
| 322 | void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_end) |
| 323 | { |
| 324 | unsigned int instr[2], *dest; |
| 325 | long *start, *end; |
| 326 | int i; |
| 327 | |
| 328 | start = fixup_start; |
| 329 | end = fixup_end; |
| 330 | |
| 331 | instr[0] = PPC_INST_NOP; |
| 332 | instr[1] = PPC_INST_NOP; |
| 333 | |
| 334 | if (enable) { |
| 335 | pr_info("barrier-nospec: using isync; sync as speculation barrier\n"); |
| 336 | instr[0] = PPC_INST_ISYNC; |
| 337 | instr[1] = PPC_INST_SYNC; |
| 338 | } |
| 339 | |
| 340 | for (i = 0; start < end; start++, i++) { |
| 341 | dest = (void *)start + *start; |
| 342 | |
| 343 | pr_devel("patching dest %lx\n", (unsigned long)dest); |
| 344 | patch_instruction(dest, instr[0]); |
| 345 | patch_instruction(dest + 1, instr[1]); |
| 346 | } |
| 347 | |
| 348 | printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i); |
| 349 | } |
Diana Craciun | 76a5eaa | 2018-12-12 16:03:00 +0200 | [diff] [blame^] | 350 | |
| 351 | static void patch_btb_flush_section(long *curr) |
| 352 | { |
| 353 | unsigned int *start, *end; |
| 354 | |
| 355 | start = (void *)curr + *curr; |
| 356 | end = (void *)curr + *(curr + 1); |
| 357 | for (; start < end; start++) { |
| 358 | pr_devel("patching dest %lx\n", (unsigned long)start); |
| 359 | patch_instruction(start, PPC_INST_NOP); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | void do_btb_flush_fixups(void) |
| 364 | { |
| 365 | long *start, *end; |
| 366 | |
| 367 | start = PTRRELOC(&__start__btb_flush_fixup); |
| 368 | end = PTRRELOC(&__stop__btb_flush_fixup); |
| 369 | |
| 370 | for (; start < end; start += 2) |
| 371 | patch_btb_flush_section(start); |
| 372 | } |
Diana Craciun | ebcd1bf | 2018-07-28 09:06:37 +1000 | [diff] [blame] | 373 | #endif /* CONFIG_PPC_FSL_BOOK3E */ |
| 374 | |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 375 | void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end) |
| 376 | { |
Benjamin Herrenschmidt | 3d98ffb | 2010-02-26 18:29:17 +1100 | [diff] [blame] | 377 | long *start, *end; |
| 378 | unsigned int *dest; |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 379 | |
| 380 | if (!(value & CPU_FTR_LWSYNC)) |
| 381 | return ; |
| 382 | |
| 383 | start = fixup_start; |
| 384 | end = fixup_end; |
| 385 | |
| 386 | for (; start < end; start++) { |
| 387 | dest = (void *)start + *start; |
Christophe Leroy | 8183d99 | 2017-11-24 08:31:09 +0100 | [diff] [blame] | 388 | raw_patch_instruction(dest, PPC_INST_LWSYNC); |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Benjamin Herrenschmidt | 9402c68 | 2016-07-05 15:03:41 +1000 | [diff] [blame] | 392 | static void do_final_fixups(void) |
Anton Blanchard | d715e43 | 2011-11-14 12:54:47 +0000 | [diff] [blame] | 393 | { |
| 394 | #if defined(CONFIG_PPC64) && defined(CONFIG_RELOCATABLE) |
| 395 | int *src, *dest; |
| 396 | unsigned long length; |
| 397 | |
| 398 | if (PHYSICAL_START == 0) |
| 399 | return; |
| 400 | |
| 401 | src = (int *)(KERNELBASE + PHYSICAL_START); |
| 402 | dest = (int *)KERNELBASE; |
| 403 | length = (__end_interrupts - _stext) / sizeof(int); |
| 404 | |
| 405 | while (length--) { |
Christophe Leroy | 8183d99 | 2017-11-24 08:31:09 +0100 | [diff] [blame] | 406 | raw_patch_instruction(dest, *src); |
Anton Blanchard | d715e43 | 2011-11-14 12:54:47 +0000 | [diff] [blame] | 407 | src++; |
| 408 | dest++; |
| 409 | } |
| 410 | #endif |
| 411 | } |
| 412 | |
Michael Ellerman | a28e46f | 2016-07-26 22:29:18 +1000 | [diff] [blame] | 413 | static unsigned long __initdata saved_cpu_features; |
| 414 | static unsigned int __initdata saved_mmu_features; |
| 415 | #ifdef CONFIG_PPC64 |
| 416 | static unsigned long __initdata saved_firmware_features; |
| 417 | #endif |
| 418 | |
| 419 | void __init apply_feature_fixups(void) |
Benjamin Herrenschmidt | 9402c68 | 2016-07-05 15:03:41 +1000 | [diff] [blame] | 420 | { |
Benjamin Herrenschmidt | 2c0f995 | 2016-08-02 15:53:01 +1000 | [diff] [blame] | 421 | struct cpu_spec *spec = PTRRELOC(*PTRRELOC(&cur_cpu_spec)); |
Benjamin Herrenschmidt | 9402c68 | 2016-07-05 15:03:41 +1000 | [diff] [blame] | 422 | |
Michael Ellerman | a28e46f | 2016-07-26 22:29:18 +1000 | [diff] [blame] | 423 | *PTRRELOC(&saved_cpu_features) = spec->cpu_features; |
| 424 | *PTRRELOC(&saved_mmu_features) = spec->mmu_features; |
| 425 | |
Benjamin Herrenschmidt | 9402c68 | 2016-07-05 15:03:41 +1000 | [diff] [blame] | 426 | /* |
| 427 | * Apply the CPU-specific and firmware specific fixups to kernel text |
| 428 | * (nop out sections not relevant to this CPU or this firmware). |
| 429 | */ |
| 430 | do_feature_fixups(spec->cpu_features, |
| 431 | PTRRELOC(&__start___ftr_fixup), |
| 432 | PTRRELOC(&__stop___ftr_fixup)); |
| 433 | |
| 434 | do_feature_fixups(spec->mmu_features, |
| 435 | PTRRELOC(&__start___mmu_ftr_fixup), |
| 436 | PTRRELOC(&__stop___mmu_ftr_fixup)); |
| 437 | |
| 438 | do_lwsync_fixups(spec->cpu_features, |
| 439 | PTRRELOC(&__start___lwsync_fixup), |
| 440 | PTRRELOC(&__stop___lwsync_fixup)); |
| 441 | |
| 442 | #ifdef CONFIG_PPC64 |
Michael Ellerman | a28e46f | 2016-07-26 22:29:18 +1000 | [diff] [blame] | 443 | saved_firmware_features = powerpc_firmware_features; |
Benjamin Herrenschmidt | 9402c68 | 2016-07-05 15:03:41 +1000 | [diff] [blame] | 444 | do_feature_fixups(powerpc_firmware_features, |
| 445 | &__start___fw_ftr_fixup, &__stop___fw_ftr_fixup); |
| 446 | #endif |
| 447 | do_final_fixups(); |
Benjamin Herrenschmidt | 97f6e0c | 2016-08-10 17:27:34 +1000 | [diff] [blame] | 448 | } |
Aneesh Kumar K.V | 309b315 | 2016-07-23 14:42:38 +0530 | [diff] [blame] | 449 | |
Benjamin Herrenschmidt | 97f6e0c | 2016-08-10 17:27:34 +1000 | [diff] [blame] | 450 | void __init setup_feature_keys(void) |
| 451 | { |
Aneesh Kumar K.V | 309b315 | 2016-07-23 14:42:38 +0530 | [diff] [blame] | 452 | /* |
| 453 | * Initialise jump label. This causes all the cpu/mmu_has_feature() |
| 454 | * checks to take on their correct polarity based on the current set of |
| 455 | * CPU/MMU features. |
| 456 | */ |
| 457 | jump_label_init(); |
Kevin Hao | 4db7327 | 2016-07-23 14:42:41 +0530 | [diff] [blame] | 458 | cpu_feature_keys_init(); |
Kevin Hao | c12e6f2 | 2016-07-23 14:42:42 +0530 | [diff] [blame] | 459 | mmu_feature_keys_init(); |
Benjamin Herrenschmidt | 9402c68 | 2016-07-05 15:03:41 +1000 | [diff] [blame] | 460 | } |
| 461 | |
Michael Ellerman | a28e46f | 2016-07-26 22:29:18 +1000 | [diff] [blame] | 462 | static int __init check_features(void) |
| 463 | { |
| 464 | WARN(saved_cpu_features != cur_cpu_spec->cpu_features, |
| 465 | "CPU features changed after feature patching!\n"); |
| 466 | WARN(saved_mmu_features != cur_cpu_spec->mmu_features, |
| 467 | "MMU features changed after feature patching!\n"); |
| 468 | #ifdef CONFIG_PPC64 |
| 469 | WARN(saved_firmware_features != powerpc_firmware_features, |
| 470 | "Firmware features changed after feature patching!\n"); |
| 471 | #endif |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | late_initcall(check_features); |
| 476 | |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 477 | #ifdef CONFIG_FTR_FIXUP_SELFTEST |
| 478 | |
| 479 | #define check(x) \ |
| 480 | if (!(x)) printk("feature-fixups: test failed at line %d\n", __LINE__); |
| 481 | |
| 482 | /* This must be after the text it fixes up, vmlinux.lds.S enforces that atm */ |
| 483 | static struct fixup_entry fixup; |
| 484 | |
| 485 | static long calc_offset(struct fixup_entry *entry, unsigned int *p) |
| 486 | { |
| 487 | return (unsigned long)p - (unsigned long)entry; |
| 488 | } |
| 489 | |
Anton Blanchard | e51df2c | 2014-08-20 08:55:18 +1000 | [diff] [blame] | 490 | static void test_basic_patching(void) |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 491 | { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 492 | extern unsigned int ftr_fixup_test1[]; |
| 493 | extern unsigned int end_ftr_fixup_test1[]; |
| 494 | extern unsigned int ftr_fixup_test1_orig[]; |
| 495 | extern unsigned int ftr_fixup_test1_expected[]; |
Michael Ellerman | cad0e39 | 2018-04-17 00:39:03 +1000 | [diff] [blame] | 496 | int size = 4 * (end_ftr_fixup_test1 - ftr_fixup_test1); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 497 | |
| 498 | fixup.value = fixup.mask = 8; |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 499 | fixup.start_off = calc_offset(&fixup, ftr_fixup_test1 + 1); |
| 500 | fixup.end_off = calc_offset(&fixup, ftr_fixup_test1 + 2); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 501 | fixup.alt_start_off = fixup.alt_end_off = 0; |
| 502 | |
| 503 | /* Sanity check */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 504 | check(memcmp(ftr_fixup_test1, ftr_fixup_test1_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 505 | |
| 506 | /* Check we don't patch if the value matches */ |
| 507 | patch_feature_section(8, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 508 | check(memcmp(ftr_fixup_test1, ftr_fixup_test1_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 509 | |
| 510 | /* Check we do patch if the value doesn't match */ |
| 511 | patch_feature_section(0, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 512 | check(memcmp(ftr_fixup_test1, ftr_fixup_test1_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 513 | |
| 514 | /* Check we do patch if the mask doesn't match */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 515 | memcpy(ftr_fixup_test1, ftr_fixup_test1_orig, size); |
| 516 | check(memcmp(ftr_fixup_test1, ftr_fixup_test1_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 517 | patch_feature_section(~8, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 518 | check(memcmp(ftr_fixup_test1, ftr_fixup_test1_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | static void test_alternative_patching(void) |
| 522 | { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 523 | extern unsigned int ftr_fixup_test2[]; |
| 524 | extern unsigned int end_ftr_fixup_test2[]; |
| 525 | extern unsigned int ftr_fixup_test2_orig[]; |
| 526 | extern unsigned int ftr_fixup_test2_alt[]; |
| 527 | extern unsigned int ftr_fixup_test2_expected[]; |
Michael Ellerman | cad0e39 | 2018-04-17 00:39:03 +1000 | [diff] [blame] | 528 | int size = 4 * (end_ftr_fixup_test2 - ftr_fixup_test2); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 529 | |
| 530 | fixup.value = fixup.mask = 0xF; |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 531 | fixup.start_off = calc_offset(&fixup, ftr_fixup_test2 + 1); |
| 532 | fixup.end_off = calc_offset(&fixup, ftr_fixup_test2 + 2); |
| 533 | fixup.alt_start_off = calc_offset(&fixup, ftr_fixup_test2_alt); |
| 534 | fixup.alt_end_off = calc_offset(&fixup, ftr_fixup_test2_alt + 1); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 535 | |
| 536 | /* Sanity check */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 537 | check(memcmp(ftr_fixup_test2, ftr_fixup_test2_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 538 | |
| 539 | /* Check we don't patch if the value matches */ |
| 540 | patch_feature_section(0xF, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 541 | check(memcmp(ftr_fixup_test2, ftr_fixup_test2_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 542 | |
| 543 | /* Check we do patch if the value doesn't match */ |
| 544 | patch_feature_section(0, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 545 | check(memcmp(ftr_fixup_test2, ftr_fixup_test2_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 546 | |
| 547 | /* Check we do patch if the mask doesn't match */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 548 | memcpy(ftr_fixup_test2, ftr_fixup_test2_orig, size); |
| 549 | check(memcmp(ftr_fixup_test2, ftr_fixup_test2_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 550 | patch_feature_section(~0xF, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 551 | check(memcmp(ftr_fixup_test2, ftr_fixup_test2_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | static void test_alternative_case_too_big(void) |
| 555 | { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 556 | extern unsigned int ftr_fixup_test3[]; |
| 557 | extern unsigned int end_ftr_fixup_test3[]; |
| 558 | extern unsigned int ftr_fixup_test3_orig[]; |
| 559 | extern unsigned int ftr_fixup_test3_alt[]; |
Michael Ellerman | cad0e39 | 2018-04-17 00:39:03 +1000 | [diff] [blame] | 560 | int size = 4 * (end_ftr_fixup_test3 - ftr_fixup_test3); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 561 | |
| 562 | fixup.value = fixup.mask = 0xC; |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 563 | fixup.start_off = calc_offset(&fixup, ftr_fixup_test3 + 1); |
| 564 | fixup.end_off = calc_offset(&fixup, ftr_fixup_test3 + 2); |
| 565 | fixup.alt_start_off = calc_offset(&fixup, ftr_fixup_test3_alt); |
| 566 | fixup.alt_end_off = calc_offset(&fixup, ftr_fixup_test3_alt + 2); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 567 | |
| 568 | /* Sanity check */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 569 | check(memcmp(ftr_fixup_test3, ftr_fixup_test3_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 570 | |
| 571 | /* Expect nothing to be patched, and the error returned to us */ |
| 572 | check(patch_feature_section(0xF, &fixup) == 1); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 573 | check(memcmp(ftr_fixup_test3, ftr_fixup_test3_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 574 | check(patch_feature_section(0, &fixup) == 1); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 575 | check(memcmp(ftr_fixup_test3, ftr_fixup_test3_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 576 | check(patch_feature_section(~0xF, &fixup) == 1); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 577 | check(memcmp(ftr_fixup_test3, ftr_fixup_test3_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static void test_alternative_case_too_small(void) |
| 581 | { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 582 | extern unsigned int ftr_fixup_test4[]; |
| 583 | extern unsigned int end_ftr_fixup_test4[]; |
| 584 | extern unsigned int ftr_fixup_test4_orig[]; |
| 585 | extern unsigned int ftr_fixup_test4_alt[]; |
| 586 | extern unsigned int ftr_fixup_test4_expected[]; |
Michael Ellerman | cad0e39 | 2018-04-17 00:39:03 +1000 | [diff] [blame] | 587 | int size = 4 * (end_ftr_fixup_test4 - ftr_fixup_test4); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 588 | unsigned long flag; |
| 589 | |
| 590 | /* Check a high-bit flag */ |
| 591 | flag = 1UL << ((sizeof(unsigned long) - 1) * 8); |
| 592 | fixup.value = fixup.mask = flag; |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 593 | fixup.start_off = calc_offset(&fixup, ftr_fixup_test4 + 1); |
| 594 | fixup.end_off = calc_offset(&fixup, ftr_fixup_test4 + 5); |
| 595 | fixup.alt_start_off = calc_offset(&fixup, ftr_fixup_test4_alt); |
| 596 | fixup.alt_end_off = calc_offset(&fixup, ftr_fixup_test4_alt + 2); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 597 | |
| 598 | /* Sanity check */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 599 | check(memcmp(ftr_fixup_test4, ftr_fixup_test4_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 600 | |
| 601 | /* Check we don't patch if the value matches */ |
| 602 | patch_feature_section(flag, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 603 | check(memcmp(ftr_fixup_test4, ftr_fixup_test4_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 604 | |
| 605 | /* Check we do patch if the value doesn't match */ |
| 606 | patch_feature_section(0, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 607 | check(memcmp(ftr_fixup_test4, ftr_fixup_test4_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 608 | |
| 609 | /* Check we do patch if the mask doesn't match */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 610 | memcpy(ftr_fixup_test4, ftr_fixup_test4_orig, size); |
| 611 | check(memcmp(ftr_fixup_test4, ftr_fixup_test4_orig, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 612 | patch_feature_section(~flag, &fixup); |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 613 | check(memcmp(ftr_fixup_test4, ftr_fixup_test4_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static void test_alternative_case_with_branch(void) |
| 617 | { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 618 | extern unsigned int ftr_fixup_test5[]; |
| 619 | extern unsigned int end_ftr_fixup_test5[]; |
| 620 | extern unsigned int ftr_fixup_test5_expected[]; |
Michael Ellerman | cad0e39 | 2018-04-17 00:39:03 +1000 | [diff] [blame] | 621 | int size = 4 * (end_ftr_fixup_test5 - ftr_fixup_test5); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 622 | |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 623 | check(memcmp(ftr_fixup_test5, ftr_fixup_test5_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static void test_alternative_case_with_external_branch(void) |
| 627 | { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 628 | extern unsigned int ftr_fixup_test6[]; |
| 629 | extern unsigned int end_ftr_fixup_test6[]; |
| 630 | extern unsigned int ftr_fixup_test6_expected[]; |
Michael Ellerman | cad0e39 | 2018-04-17 00:39:03 +1000 | [diff] [blame] | 631 | int size = 4 * (end_ftr_fixup_test6 - ftr_fixup_test6); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 632 | |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 633 | check(memcmp(ftr_fixup_test6, ftr_fixup_test6_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 634 | } |
| 635 | |
Michael Ellerman | 6158fae | 2018-04-17 00:39:05 +1000 | [diff] [blame] | 636 | static void test_alternative_case_with_branch_to_end(void) |
| 637 | { |
| 638 | extern unsigned int ftr_fixup_test7[]; |
| 639 | extern unsigned int end_ftr_fixup_test7[]; |
| 640 | extern unsigned int ftr_fixup_test7_expected[]; |
| 641 | int size = 4 * (end_ftr_fixup_test7 - ftr_fixup_test7); |
| 642 | |
| 643 | check(memcmp(ftr_fixup_test7, ftr_fixup_test7_expected, size) == 0); |
| 644 | } |
| 645 | |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 646 | static void test_cpu_macros(void) |
| 647 | { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 648 | extern u8 ftr_fixup_test_FTR_macros[]; |
| 649 | extern u8 ftr_fixup_test_FTR_macros_expected[]; |
| 650 | unsigned long size = ftr_fixup_test_FTR_macros_expected - |
| 651 | ftr_fixup_test_FTR_macros; |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 652 | |
| 653 | /* The fixups have already been done for us during boot */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 654 | check(memcmp(ftr_fixup_test_FTR_macros, |
| 655 | ftr_fixup_test_FTR_macros_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | static void test_fw_macros(void) |
| 659 | { |
| 660 | #ifdef CONFIG_PPC64 |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 661 | extern u8 ftr_fixup_test_FW_FTR_macros[]; |
| 662 | extern u8 ftr_fixup_test_FW_FTR_macros_expected[]; |
| 663 | unsigned long size = ftr_fixup_test_FW_FTR_macros_expected - |
| 664 | ftr_fixup_test_FW_FTR_macros; |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 665 | |
| 666 | /* The fixups have already been done for us during boot */ |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 667 | check(memcmp(ftr_fixup_test_FW_FTR_macros, |
| 668 | ftr_fixup_test_FW_FTR_macros_expected, size) == 0); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 669 | #endif |
| 670 | } |
| 671 | |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 672 | static void test_lwsync_macros(void) |
| 673 | { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 674 | extern u8 lwsync_fixup_test[]; |
| 675 | extern u8 end_lwsync_fixup_test[]; |
| 676 | extern u8 lwsync_fixup_test_expected_LWSYNC[]; |
| 677 | extern u8 lwsync_fixup_test_expected_SYNC[]; |
| 678 | unsigned long size = end_lwsync_fixup_test - |
| 679 | lwsync_fixup_test; |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 680 | |
| 681 | /* The fixups have already been done for us during boot */ |
| 682 | if (cur_cpu_spec->cpu_features & CPU_FTR_LWSYNC) { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 683 | check(memcmp(lwsync_fixup_test, |
| 684 | lwsync_fixup_test_expected_LWSYNC, size) == 0); |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 685 | } else { |
Daniel Axtens | c69a48c | 2017-07-12 14:36:07 -0700 | [diff] [blame] | 686 | check(memcmp(lwsync_fixup_test, |
| 687 | lwsync_fixup_test_expected_SYNC, size) == 0); |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 691 | static int __init test_feature_fixups(void) |
| 692 | { |
| 693 | printk(KERN_DEBUG "Running feature fixup self-tests ...\n"); |
| 694 | |
| 695 | test_basic_patching(); |
| 696 | test_alternative_patching(); |
| 697 | test_alternative_case_too_big(); |
| 698 | test_alternative_case_too_small(); |
| 699 | test_alternative_case_with_branch(); |
| 700 | test_alternative_case_with_external_branch(); |
Michael Ellerman | 6158fae | 2018-04-17 00:39:05 +1000 | [diff] [blame] | 701 | test_alternative_case_with_branch_to_end(); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 702 | test_cpu_macros(); |
| 703 | test_fw_macros(); |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 704 | test_lwsync_macros(); |
Michael Ellerman | 362e770 | 2008-06-24 11:33:03 +1000 | [diff] [blame] | 705 | |
| 706 | return 0; |
| 707 | } |
| 708 | late_initcall(test_feature_fixups); |
| 709 | |
| 710 | #endif /* CONFIG_FTR_FIXUP_SELFTEST */ |