Skip to content

Commit 12a585e

Browse files
puranjaymohanAlexei Starovoitov
authored andcommitted
bpf, arm64: Fix redundant MOV and clarify stack arg comments
emit_stack_arg_store_imm() materializes the immediate into tmp and then moves tmp to the target register (x5-x7). Emit the immediate directly into the target register to avoid the redundant MOV. While here, qualify the bare "FP" in the stack-layout ASCII art as "A64_FP" so it is not confused with BPF_FP, and note that incoming stack arguments sit above the FP/LR pair pushed by the callee prologue. Suggested-by: Will Deacon <will@kernel.org> Signed-off-by: Puranjay Mohan <puranjay@kernel.org> Link: https://lore.kernel.org/r/20260528161750.1900674-2-puranjay@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 41300d0 commit 12a585e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

arch/arm64/net/bpf_jit_comp.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf)
546546
* low
547547
*
548548
* Stack args 6-8 are passed in x5-x7, args 9+ at [SP].
549-
* Incoming args 9+ are at [FP + 16], [FP + 24], ...
549+
* Incoming args 9+ are at [A64_FP + 16], [A64_FP + 24], ...
550+
* (above the saved FP/LR pair pushed in the callee prologue).
550551
*/
551552

552553
emit_kcfi(is_main_prog ? cfi_bpf_hash : cfi_bpf_subprog_hash, ctx);
@@ -1235,11 +1236,12 @@ static void emit_stack_arg_store_imm(s32 imm, s16 bpf_off, const u8 tmp, struct
12351236
{
12361237
int idx = -bpf_off / sizeof(u64) - 1;
12371238

1238-
emit_a64_mov_i(1, tmp, imm, ctx);
1239-
if (idx < NR_STACK_ARG_REGS)
1240-
emit(A64_MOV(1, stack_arg_reg[idx], tmp), ctx);
1241-
else
1239+
if (idx < NR_STACK_ARG_REGS) {
1240+
emit_a64_mov_i(1, stack_arg_reg[idx], imm, ctx);
1241+
} else {
1242+
emit_a64_mov_i(1, tmp, imm, ctx);
12421243
emit(A64_STR64I(tmp, A64_SP, (idx - NR_STACK_ARG_REGS) * sizeof(u64)), ctx);
1244+
}
12431245
}
12441246

12451247
/* JITs an eBPF instruction.

0 commit comments

Comments
 (0)