Skip to content

Commit 4488f90

Browse files
Mark Rutlandwilldeacon
Mark Rutland
authored andcommitted
arm64: insn: simplify insn group identification
The only code which needs to check for an entire instruction group is the aarch64_insn_is_steppable() helper function used by kprobes, which must not be instrumented, and only needs to check for the "Branch, exception generation and system instructions" class. Currently we have an out-of-line helper in insn.c which must be marked as __kprobes, which indexes a table with some bits extracted from the instruction. In aarch64_insn_is_steppable() we then need to compare the result with an expected enum value. It would be simpler to have a predicate for this, as with the other aarch64_insn_is_*() helpers, which would be always inlined to prevent inadvertent instrumentation, and would permit better code generation. This patch adds a predicate function for this instruction group using the existing __AARCH64_INSN_FUNCS() helpers, and removes the existing out-of-line helper. As the only class we currently care about is the branch+exception+sys class, I have only added helpers for this, and left the other classes unimplemented for now. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Joey Gouly <[email protected]> Cc: Will Deacon <[email protected]> Reviewed-by: Joey Gouly <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 9b948e7 commit 4488f90

File tree

3 files changed

+18
-50
lines changed

3 files changed

+18
-50
lines changed

arch/arm64/include/asm/insn.h

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,6 @@
1313
#include <asm/insn-def.h>
1414

1515
#ifndef __ASSEMBLY__
16-
/*
17-
* ARM Architecture Reference Manual for ARMv8 Profile-A, Issue A.a
18-
* Section C3.1 "A64 instruction index by encoding":
19-
* AArch64 main encoding table
20-
* Bit position
21-
* 28 27 26 25 Encoding Group
22-
* 0 0 - - Unallocated
23-
* 1 0 0 - Data processing, immediate
24-
* 1 0 1 - Branch, exception generation and system instructions
25-
* - 1 - 0 Loads and stores
26-
* - 1 0 1 Data processing - register
27-
* 0 1 1 1 Data processing - SIMD and floating point
28-
* 1 1 1 1 Data processing - SIMD and floating point
29-
* "-" means "don't care"
30-
*/
31-
enum aarch64_insn_encoding_class {
32-
AARCH64_INSN_CLS_UNKNOWN, /* UNALLOCATED */
33-
AARCH64_INSN_CLS_SVE, /* SVE instructions */
34-
AARCH64_INSN_CLS_DP_IMM, /* Data processing - immediate */
35-
AARCH64_INSN_CLS_DP_REG, /* Data processing - register */
36-
AARCH64_INSN_CLS_DP_FPSIMD, /* Data processing - SIMD and FP */
37-
AARCH64_INSN_CLS_LDST, /* Loads and stores */
38-
AARCH64_INSN_CLS_BR_SYS, /* Branch, exception generation and
39-
* system instructions */
40-
};
4116

4217
enum aarch64_insn_hint_cr_op {
4318
AARCH64_INSN_HINT_NOP = 0x0 << 5,
@@ -326,6 +301,23 @@ static __always_inline u32 aarch64_insn_get_##abbr##_value(void) \
326301
return (val); \
327302
}
328303

304+
/*
305+
* ARM Architecture Reference Manual for ARMv8 Profile-A, Issue A.a
306+
* Section C3.1 "A64 instruction index by encoding":
307+
* AArch64 main encoding table
308+
* Bit position
309+
* 28 27 26 25 Encoding Group
310+
* 0 0 - - Unallocated
311+
* 1 0 0 - Data processing, immediate
312+
* 1 0 1 - Branch, exception generation and system instructions
313+
* - 1 - 0 Loads and stores
314+
* - 1 0 1 Data processing - register
315+
* 0 1 1 1 Data processing - SIMD and floating point
316+
* 1 1 1 1 Data processing - SIMD and floating point
317+
* "-" means "don't care"
318+
*/
319+
__AARCH64_INSN_FUNCS(class_branch_sys, 0x1c000000, 0x14000000)
320+
329321
__AARCH64_INSN_FUNCS(adr, 0x9F000000, 0x10000000)
330322
__AARCH64_INSN_FUNCS(adrp, 0x9F000000, 0x90000000)
331323
__AARCH64_INSN_FUNCS(prfm, 0x3FC00000, 0x39800000)

arch/arm64/kernel/probes/decode-insn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static bool __kprobes aarch64_insn_is_steppable(u32 insn)
2424
* currently safe. Lastly, MSR instructions can do any number of nasty
2525
* things we can't handle during single-stepping.
2626
*/
27-
if (aarch64_get_insn_class(insn) == AARCH64_INSN_CLS_BR_SYS) {
27+
if (aarch64_insn_is_class_branch_sys(insn)) {
2828
if (aarch64_insn_is_branch(insn) ||
2929
aarch64_insn_is_msr_imm(insn) ||
3030
aarch64_insn_is_msr_reg(insn) ||

arch/arm64/lib/insn.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,6 @@
2020
#define AARCH64_INSN_N_BIT BIT(22)
2121
#define AARCH64_INSN_LSL_12 BIT(22)
2222

23-
static const int aarch64_insn_encoding_class[] = {
24-
AARCH64_INSN_CLS_UNKNOWN,
25-
AARCH64_INSN_CLS_UNKNOWN,
26-
AARCH64_INSN_CLS_SVE,
27-
AARCH64_INSN_CLS_UNKNOWN,
28-
AARCH64_INSN_CLS_LDST,
29-
AARCH64_INSN_CLS_DP_REG,
30-
AARCH64_INSN_CLS_LDST,
31-
AARCH64_INSN_CLS_DP_FPSIMD,
32-
AARCH64_INSN_CLS_DP_IMM,
33-
AARCH64_INSN_CLS_DP_IMM,
34-
AARCH64_INSN_CLS_BR_SYS,
35-
AARCH64_INSN_CLS_BR_SYS,
36-
AARCH64_INSN_CLS_LDST,
37-
AARCH64_INSN_CLS_DP_REG,
38-
AARCH64_INSN_CLS_LDST,
39-
AARCH64_INSN_CLS_DP_FPSIMD,
40-
};
41-
42-
enum aarch64_insn_encoding_class __kprobes aarch64_get_insn_class(u32 insn)
43-
{
44-
return aarch64_insn_encoding_class[(insn >> 25) & 0xf];
45-
}
46-
4723
static int __kprobes aarch64_get_imm_shift_mask(enum aarch64_insn_imm_type type,
4824
u32 *maskp, int *shiftp)
4925
{

0 commit comments

Comments
 (0)