Skip to content

Commit 8c21f88

Browse files
peilin-yeborkmann
authored andcommitted
bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic()
Currently in emit_{lse,ll_sc}_atomic(), if there is an offset, we add it to the base address by doing e.g.: if (off) { emit_a64_mov_i(1, tmp, off, ctx); emit(A64_ADD(1, tmp, tmp, dst), ctx); [...] As pointed out by Xu, we can use emit_a64_add_i() (added in the previous patch) instead, which tries to combine the above into a single A64_ADD_I or A64_SUB_I when possible. Suggested-by: Xu Kuohai <[email protected]> Signed-off-by: Peilin Ye <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Xu Kuohai <[email protected]> Link: https://lore.kernel.org/bpf/9ad3034a62361d91a99af24efa03f48c4c9e13ea.1735868489.git.yepeilin@google.com
1 parent 66bb58a commit 8c21f88

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,7 @@ static int emit_lse_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
662662
u8 reg = dst;
663663

664664
if (off) {
665-
emit_a64_mov_i(1, tmp, off, ctx);
666-
emit(A64_ADD(1, tmp, tmp, dst), ctx);
665+
emit_a64_add_i(1, tmp, reg, tmp, off, ctx);
667666
reg = tmp;
668667
}
669668
if (arena) {
@@ -734,7 +733,7 @@ static int emit_ll_sc_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
734733
const s32 imm = insn->imm;
735734
const s16 off = insn->off;
736735
const bool isdw = BPF_SIZE(code) == BPF_DW;
737-
u8 reg;
736+
u8 reg = dst;
738737
s32 jmp_offset;
739738

740739
if (BPF_MODE(code) == BPF_PROBE_ATOMIC) {
@@ -743,11 +742,8 @@ static int emit_ll_sc_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
743742
return -EINVAL;
744743
}
745744

746-
if (!off) {
747-
reg = dst;
748-
} else {
749-
emit_a64_mov_i(1, tmp, off, ctx);
750-
emit(A64_ADD(1, tmp, tmp, dst), ctx);
745+
if (off) {
746+
emit_a64_add_i(1, tmp, reg, tmp, off, ctx);
751747
reg = tmp;
752748
}
753749

0 commit comments

Comments
 (0)