Skip to content

Commit 124047a

Browse files
Russell Kinggregkh
authored andcommitted
ARM: net: bpf: avoid 'bx' instruction on non-Thumb capable CPUs
commit e906248 upstream. Avoid the 'bx' instruction on CPUs that have no support for Thumb and thus do not implement this instruction by moving the generation of this opcode to a separate function that selects between: bx reg and mov pc, reg according to the capabilities of the CPU. Fixes: 39c13c2 ("arm: eBPF JIT compiler") Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 326efb4 commit 124047a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

arch/arm/net/bpf_jit_32.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,20 @@ static inline void emit_mov_i(const u8 rd, u32 val, struct jit_ctx *ctx)
285285
emit_mov_i_no8m(rd, val, ctx);
286286
}
287287

288-
static inline void emit_blx_r(u8 tgt_reg, struct jit_ctx *ctx)
288+
static void emit_bx_r(u8 tgt_reg, struct jit_ctx *ctx)
289289
{
290-
ctx->seen |= SEEN_CALL;
291-
#if __LINUX_ARM_ARCH__ < 5
292-
emit(ARM_MOV_R(ARM_LR, ARM_PC), ctx);
293-
294290
if (elf_hwcap & HWCAP_THUMB)
295291
emit(ARM_BX(tgt_reg), ctx);
296292
else
297293
emit(ARM_MOV_R(ARM_PC, tgt_reg), ctx);
294+
}
295+
296+
static inline void emit_blx_r(u8 tgt_reg, struct jit_ctx *ctx)
297+
{
298+
ctx->seen |= SEEN_CALL;
299+
#if __LINUX_ARM_ARCH__ < 5
300+
emit(ARM_MOV_R(ARM_LR, ARM_PC), ctx);
301+
emit_bx_r(tgt_reg, ctx);
298302
#else
299303
emit(ARM_BLX_R(tgt_reg), ctx);
300304
#endif
@@ -997,7 +1001,7 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx)
9971001
emit_a32_mov_i(tmp2[1], off, false, ctx);
9981002
emit(ARM_LDR_R(tmp[1], tmp[1], tmp2[1]), ctx);
9991003
emit(ARM_ADD_I(tmp[1], tmp[1], ctx->prologue_bytes), ctx);
1000-
emit(ARM_BX(tmp[1]), ctx);
1004+
emit_bx_r(tmp[1], ctx);
10011005

10021006
/* out: */
10031007
if (out_offset == -1)
@@ -1166,7 +1170,7 @@ static void build_epilogue(struct jit_ctx *ctx)
11661170
emit(ARM_POP(reg_set), ctx);
11671171
/* Return back to the callee function */
11681172
if (!(ctx->seen & SEEN_CALL))
1169-
emit(ARM_BX(ARM_LR), ctx);
1173+
emit_bx_r(ARM_LR, ctx);
11701174
#endif
11711175
}
11721176

0 commit comments

Comments
 (0)