Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: Move aarch32 condition check functions

The functions to check condition flags for aarch32 execution is only
used to emulate aarch32 instructions. Move them from the instruction
encoding/decoding code to the trap handling files.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
Link: https://lore.kernel.org/r/20210303170536.1838032-3-jthierry@redhat.com
[will: leave aarch32_opcode_cond_checks where it is]
Signed-off-by: Will Deacon <will@kernel.org>

Signed-off-by: Will Deacon <will@kernel.org>

authored by

Julien Thierry and committed by
Will Deacon
633e5e93 5f154c4e

+100 -99
+1
arch/arm64/include/asm/insn.h
··· 502 502 503 503 typedef bool (pstate_check_t)(unsigned long); 504 504 extern pstate_check_t * const aarch32_opcode_cond_checks[16]; 505 + 505 506 #endif /* __ASSEMBLY__ */ 506 507 507 508 #endif /* __ASM_INSN_H */
-98
arch/arm64/kernel/insn.c
··· 1289 1289 return insn & CRM_MASK; 1290 1290 } 1291 1291 1292 - static bool __kprobes __check_eq(unsigned long pstate) 1293 - { 1294 - return (pstate & PSR_Z_BIT) != 0; 1295 - } 1296 - 1297 - static bool __kprobes __check_ne(unsigned long pstate) 1298 - { 1299 - return (pstate & PSR_Z_BIT) == 0; 1300 - } 1301 - 1302 - static bool __kprobes __check_cs(unsigned long pstate) 1303 - { 1304 - return (pstate & PSR_C_BIT) != 0; 1305 - } 1306 - 1307 - static bool __kprobes __check_cc(unsigned long pstate) 1308 - { 1309 - return (pstate & PSR_C_BIT) == 0; 1310 - } 1311 - 1312 - static bool __kprobes __check_mi(unsigned long pstate) 1313 - { 1314 - return (pstate & PSR_N_BIT) != 0; 1315 - } 1316 - 1317 - static bool __kprobes __check_pl(unsigned long pstate) 1318 - { 1319 - return (pstate & PSR_N_BIT) == 0; 1320 - } 1321 - 1322 - static bool __kprobes __check_vs(unsigned long pstate) 1323 - { 1324 - return (pstate & PSR_V_BIT) != 0; 1325 - } 1326 - 1327 - static bool __kprobes __check_vc(unsigned long pstate) 1328 - { 1329 - return (pstate & PSR_V_BIT) == 0; 1330 - } 1331 - 1332 - static bool __kprobes __check_hi(unsigned long pstate) 1333 - { 1334 - pstate &= ~(pstate >> 1); /* PSR_C_BIT &= ~PSR_Z_BIT */ 1335 - return (pstate & PSR_C_BIT) != 0; 1336 - } 1337 - 1338 - static bool __kprobes __check_ls(unsigned long pstate) 1339 - { 1340 - pstate &= ~(pstate >> 1); /* PSR_C_BIT &= ~PSR_Z_BIT */ 1341 - return (pstate & PSR_C_BIT) == 0; 1342 - } 1343 - 1344 - static bool __kprobes __check_ge(unsigned long pstate) 1345 - { 1346 - pstate ^= (pstate << 3); /* PSR_N_BIT ^= PSR_V_BIT */ 1347 - return (pstate & PSR_N_BIT) == 0; 1348 - } 1349 - 1350 - static bool __kprobes __check_lt(unsigned long pstate) 1351 - { 1352 - pstate ^= (pstate << 3); /* PSR_N_BIT ^= PSR_V_BIT */ 1353 - return (pstate & PSR_N_BIT) != 0; 1354 - } 1355 - 1356 - static bool __kprobes __check_gt(unsigned long pstate) 1357 - { 1358 - /*PSR_N_BIT ^= PSR_V_BIT */ 1359 - unsigned long temp = pstate ^ (pstate << 3); 1360 - 1361 - temp |= (pstate << 1); /*PSR_N_BIT |= PSR_Z_BIT */ 1362 - return (temp & PSR_N_BIT) == 0; 1363 - } 1364 - 1365 - static bool __kprobes __check_le(unsigned long pstate) 1366 - { 1367 - /*PSR_N_BIT ^= PSR_V_BIT */ 1368 - unsigned long temp = pstate ^ (pstate << 3); 1369 - 1370 - temp |= (pstate << 1); /*PSR_N_BIT |= PSR_Z_BIT */ 1371 - return (temp & PSR_N_BIT) != 0; 1372 - } 1373 - 1374 - static bool __kprobes __check_al(unsigned long pstate) 1375 - { 1376 - return true; 1377 - } 1378 - 1379 - /* 1380 - * Note that the ARMv8 ARM calls condition code 0b1111 "nv", but states that 1381 - * it behaves identically to 0b1110 ("al"). 1382 - */ 1383 - pstate_check_t * const aarch32_opcode_cond_checks[16] = { 1384 - __check_eq, __check_ne, __check_cs, __check_cc, 1385 - __check_mi, __check_pl, __check_vs, __check_vc, 1386 - __check_hi, __check_ls, __check_ge, __check_lt, 1387 - __check_gt, __check_le, __check_al, __check_al 1388 - }; 1389 - 1390 1292 static bool range_of_ones(u64 val) 1391 1293 { 1392 1294 /* Doesn't handle full ones or full zeroes */
+1
arch/arm64/kernel/probes/simulate-insn.c
··· 10 10 #include <linux/kprobes.h> 11 11 12 12 #include <asm/ptrace.h> 13 + #include <asm/traps.h> 13 14 14 15 #include "simulate-insn.h" 15 16
+98 -1
arch/arm64/kernel/traps.c
··· 36 36 #include <asm/esr.h> 37 37 #include <asm/exception.h> 38 38 #include <asm/extable.h> 39 - #include <asm/insn.h> 40 39 #include <asm/kprobes.h> 41 40 #include <asm/traps.h> 42 41 #include <asm/smp.h> ··· 43 44 #include <asm/stacktrace.h> 44 45 #include <asm/system_misc.h> 45 46 #include <asm/sysreg.h> 47 + 48 + static bool __kprobes __check_eq(unsigned long pstate) 49 + { 50 + return (pstate & PSR_Z_BIT) != 0; 51 + } 52 + 53 + static bool __kprobes __check_ne(unsigned long pstate) 54 + { 55 + return (pstate & PSR_Z_BIT) == 0; 56 + } 57 + 58 + static bool __kprobes __check_cs(unsigned long pstate) 59 + { 60 + return (pstate & PSR_C_BIT) != 0; 61 + } 62 + 63 + static bool __kprobes __check_cc(unsigned long pstate) 64 + { 65 + return (pstate & PSR_C_BIT) == 0; 66 + } 67 + 68 + static bool __kprobes __check_mi(unsigned long pstate) 69 + { 70 + return (pstate & PSR_N_BIT) != 0; 71 + } 72 + 73 + static bool __kprobes __check_pl(unsigned long pstate) 74 + { 75 + return (pstate & PSR_N_BIT) == 0; 76 + } 77 + 78 + static bool __kprobes __check_vs(unsigned long pstate) 79 + { 80 + return (pstate & PSR_V_BIT) != 0; 81 + } 82 + 83 + static bool __kprobes __check_vc(unsigned long pstate) 84 + { 85 + return (pstate & PSR_V_BIT) == 0; 86 + } 87 + 88 + static bool __kprobes __check_hi(unsigned long pstate) 89 + { 90 + pstate &= ~(pstate >> 1); /* PSR_C_BIT &= ~PSR_Z_BIT */ 91 + return (pstate & PSR_C_BIT) != 0; 92 + } 93 + 94 + static bool __kprobes __check_ls(unsigned long pstate) 95 + { 96 + pstate &= ~(pstate >> 1); /* PSR_C_BIT &= ~PSR_Z_BIT */ 97 + return (pstate & PSR_C_BIT) == 0; 98 + } 99 + 100 + static bool __kprobes __check_ge(unsigned long pstate) 101 + { 102 + pstate ^= (pstate << 3); /* PSR_N_BIT ^= PSR_V_BIT */ 103 + return (pstate & PSR_N_BIT) == 0; 104 + } 105 + 106 + static bool __kprobes __check_lt(unsigned long pstate) 107 + { 108 + pstate ^= (pstate << 3); /* PSR_N_BIT ^= PSR_V_BIT */ 109 + return (pstate & PSR_N_BIT) != 0; 110 + } 111 + 112 + static bool __kprobes __check_gt(unsigned long pstate) 113 + { 114 + /*PSR_N_BIT ^= PSR_V_BIT */ 115 + unsigned long temp = pstate ^ (pstate << 3); 116 + 117 + temp |= (pstate << 1); /*PSR_N_BIT |= PSR_Z_BIT */ 118 + return (temp & PSR_N_BIT) == 0; 119 + } 120 + 121 + static bool __kprobes __check_le(unsigned long pstate) 122 + { 123 + /*PSR_N_BIT ^= PSR_V_BIT */ 124 + unsigned long temp = pstate ^ (pstate << 3); 125 + 126 + temp |= (pstate << 1); /*PSR_N_BIT |= PSR_Z_BIT */ 127 + return (temp & PSR_N_BIT) != 0; 128 + } 129 + 130 + static bool __kprobes __check_al(unsigned long pstate) 131 + { 132 + return true; 133 + } 134 + 135 + /* 136 + * Note that the ARMv8 ARM calls condition code 0b1111 "nv", but states that 137 + * it behaves identically to 0b1110 ("al"). 138 + */ 139 + pstate_check_t * const aarch32_opcode_cond_checks[16] = { 140 + __check_eq, __check_ne, __check_cs, __check_cc, 141 + __check_mi, __check_pl, __check_vs, __check_vc, 142 + __check_hi, __check_ls, __check_ge, __check_lt, 143 + __check_gt, __check_le, __check_al, __check_al 144 + }; 46 145 47 146 static const char *handler[] = { 48 147 "Synchronous Abort",