Skip to content

Commit 68b1819

Browse files
Xu Kuohaiborkmann
authored andcommitted
bpf, arm64: Support signed div/mod instructions
Add JIT for signed div/mod instructions. Signed-off-by: Xu Kuohai <xukuohai@huawei.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Tested-by: Florent Revest <revest@chromium.org> Acked-by: Florent Revest <revest@chromium.org> Link: https://lore.kernel.org/bpf/20230815154158.717901-7-xukuohai@huaweicloud.com
1 parent c32b6ee commit 68b1819

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

arch/arm64/net/bpf_jit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
#define A64_DATA2(sf, Rd, Rn, Rm, type) aarch64_insn_gen_data2(Rd, Rn, Rm, \
235235
A64_VARIANT(sf), AARCH64_INSN_DATA2_##type)
236236
#define A64_UDIV(sf, Rd, Rn, Rm) A64_DATA2(sf, Rd, Rn, Rm, UDIV)
237+
#define A64_SDIV(sf, Rd, Rn, Rm) A64_DATA2(sf, Rd, Rn, Rm, SDIV)
237238
#define A64_LSLV(sf, Rd, Rn, Rm) A64_DATA2(sf, Rd, Rn, Rm, LSLV)
238239
#define A64_LSRV(sf, Rd, Rn, Rm) A64_DATA2(sf, Rd, Rn, Rm, LSRV)
239240
#define A64_ASRV(sf, Rd, Rn, Rm) A64_DATA2(sf, Rd, Rn, Rm, ASRV)

arch/arm64/net/bpf_jit_comp.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,11 +828,17 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
828828
break;
829829
case BPF_ALU | BPF_DIV | BPF_X:
830830
case BPF_ALU64 | BPF_DIV | BPF_X:
831-
emit(A64_UDIV(is64, dst, dst, src), ctx);
831+
if (!off)
832+
emit(A64_UDIV(is64, dst, dst, src), ctx);
833+
else
834+
emit(A64_SDIV(is64, dst, dst, src), ctx);
832835
break;
833836
case BPF_ALU | BPF_MOD | BPF_X:
834837
case BPF_ALU64 | BPF_MOD | BPF_X:
835-
emit(A64_UDIV(is64, tmp, dst, src), ctx);
838+
if (!off)
839+
emit(A64_UDIV(is64, tmp, dst, src), ctx);
840+
else
841+
emit(A64_SDIV(is64, tmp, dst, src), ctx);
836842
emit(A64_MSUB(is64, dst, dst, tmp, src), ctx);
837843
break;
838844
case BPF_ALU | BPF_LSH | BPF_X:
@@ -959,12 +965,18 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
959965
case BPF_ALU | BPF_DIV | BPF_K:
960966
case BPF_ALU64 | BPF_DIV | BPF_K:
961967
emit_a64_mov_i(is64, tmp, imm, ctx);
962-
emit(A64_UDIV(is64, dst, dst, tmp), ctx);
968+
if (!off)
969+
emit(A64_UDIV(is64, dst, dst, tmp), ctx);
970+
else
971+
emit(A64_SDIV(is64, dst, dst, tmp), ctx);
963972
break;
964973
case BPF_ALU | BPF_MOD | BPF_K:
965974
case BPF_ALU64 | BPF_MOD | BPF_K:
966975
emit_a64_mov_i(is64, tmp2, imm, ctx);
967-
emit(A64_UDIV(is64, tmp, dst, tmp2), ctx);
976+
if (!off)
977+
emit(A64_UDIV(is64, tmp, dst, tmp2), ctx);
978+
else
979+
emit(A64_SDIV(is64, tmp, dst, tmp2), ctx);
968980
emit(A64_MSUB(is64, dst, dst, tmp, tmp2), ctx);
969981
break;
970982
case BPF_ALU | BPF_LSH | BPF_K:

0 commit comments

Comments
 (0)