Skip to content

Commit c453312

Browse files
Russell Kingborkmann
Russell King
authored andcommitted
ARM: net: bpf: Improve prologue code sequence
Improve the prologue code sequence to be able to take advantage of 64-bit stores, changing the code from: push {r4, r5, r6, r7, r8, r9, fp, lr} mov fp, sp sub ip, sp, #80 ; 0x50 sub sp, sp, #600 ; 0x258 str ip, [fp, #-100] ; 0xffffff9c mov r6, #0 str r6, [fp, #-96] ; 0xffffffa0 mov r4, #0 mov r3, r4 mov r2, r0 str r4, [fp, #-104] ; 0xffffff98 str r4, [fp, #-108] ; 0xffffff94 to the tighter: push {r4, r5, r6, r7, r8, r9, fp, lr} mov fp, sp mov r3, #0 sub r2, sp, #80 ; 0x50 sub sp, sp, #600 ; 0x258 strd r2, [fp, #-100] ; 0xffffff9c mov r2, #0 strd r2, [fp, #-108] ; 0xffffff94 mov r2, r0 resulting in a saving of three instructions. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/E1ieH2g-0004ih-Rb@rmk-PC.armlinux.org.uk
1 parent c219399 commit c453312

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

arch/arm/net/bpf_jit_32.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,12 +1260,9 @@ static inline void emit_push_r64(const s8 src[], struct jit_ctx *ctx)
12601260

12611261
static void build_prologue(struct jit_ctx *ctx)
12621262
{
1263-
const s8 r0 = bpf2a32[BPF_REG_0][1];
1264-
const s8 r2 = bpf2a32[BPF_REG_1][1];
1265-
const s8 r3 = bpf2a32[BPF_REG_1][0];
1266-
const s8 r4 = bpf2a32[BPF_REG_6][1];
1267-
const s8 fplo = bpf2a32[BPF_REG_FP][1];
1268-
const s8 fphi = bpf2a32[BPF_REG_FP][0];
1263+
const s8 arm_r0 = bpf2a32[BPF_REG_0][1];
1264+
const s8 *bpf_r1 = bpf2a32[BPF_REG_1];
1265+
const s8 *bpf_fp = bpf2a32[BPF_REG_FP];
12691266
const s8 *tcc = bpf2a32[TCALL_CNT];
12701267

12711268
/* Save callee saved registers. */
@@ -1278,27 +1275,26 @@ static void build_prologue(struct jit_ctx *ctx)
12781275
emit(ARM_PUSH(CALLEE_PUSH_MASK), ctx);
12791276
emit(ARM_MOV_R(ARM_FP, ARM_SP), ctx);
12801277
#endif
1281-
/* Save frame pointer for later */
1282-
emit(ARM_SUB_I(ARM_IP, ARM_SP, SCRATCH_SIZE), ctx);
1278+
/* mov r3, #0 */
1279+
/* sub r2, sp, #SCRATCH_SIZE */
1280+
emit(ARM_MOV_I(bpf_r1[0], 0), ctx);
1281+
emit(ARM_SUB_I(bpf_r1[1], ARM_SP, SCRATCH_SIZE), ctx);
12831282

12841283
ctx->stack_size = imm8m(STACK_SIZE);
12851284

12861285
/* Set up function call stack */
12871286
emit(ARM_SUB_I(ARM_SP, ARM_SP, ctx->stack_size), ctx);
12881287

12891288
/* Set up BPF prog stack base register */
1290-
emit_a32_mov_r(fplo, ARM_IP, ctx);
1291-
emit_a32_mov_i(fphi, 0, ctx);
1289+
emit_a32_mov_r64(true, bpf_fp, bpf_r1, ctx);
12921290

1293-
/* mov r4, 0 */
1294-
emit(ARM_MOV_I(r4, 0), ctx);
1291+
/* Initialize Tail Count */
1292+
emit(ARM_MOV_I(bpf_r1[1], 0), ctx);
1293+
emit_a32_mov_r64(true, tcc, bpf_r1, ctx);
12951294

12961295
/* Move BPF_CTX to BPF_R1 */
1297-
emit(ARM_MOV_R(r3, r4), ctx);
1298-
emit(ARM_MOV_R(r2, r0), ctx);
1299-
/* Initialize Tail Count */
1300-
emit(ARM_STR_I(r4, ARM_FP, EBPF_SCRATCH_TO_ARM_FP(tcc[0])), ctx);
1301-
emit(ARM_STR_I(r4, ARM_FP, EBPF_SCRATCH_TO_ARM_FP(tcc[1])), ctx);
1296+
emit(ARM_MOV_R(bpf_r1[1], arm_r0), ctx);
1297+
13021298
/* end of prologue */
13031299
}
13041300

0 commit comments

Comments
 (0)