Skip to content

Commit 2dc6b10

Browse files
Jiong WangAlexei Starovoitov
authored andcommitted
bpf: interpreter support BPF_ALU | BPF_ARSH
This patch implements interpreting BPF_ALU | BPF_ARSH. Do arithmetic right shift on low 32-bit sub-register, and zero the high 32 bits. Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Jiong Wang <jiong.wang@netronome.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 84708c1 commit 2dc6b10

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

kernel/bpf/core.c

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -933,32 +933,34 @@ EXPORT_SYMBOL_GPL(__bpf_call_base);
933933
#define BPF_INSN_MAP(INSN_2, INSN_3) \
934934
/* 32 bit ALU operations. */ \
935935
/* Register based. */ \
936-
INSN_3(ALU, ADD, X), \
937-
INSN_3(ALU, SUB, X), \
938-
INSN_3(ALU, AND, X), \
939-
INSN_3(ALU, OR, X), \
940-
INSN_3(ALU, LSH, X), \
941-
INSN_3(ALU, RSH, X), \
942-
INSN_3(ALU, XOR, X), \
943-
INSN_3(ALU, MUL, X), \
944-
INSN_3(ALU, MOV, X), \
945-
INSN_3(ALU, DIV, X), \
946-
INSN_3(ALU, MOD, X), \
936+
INSN_3(ALU, ADD, X), \
937+
INSN_3(ALU, SUB, X), \
938+
INSN_3(ALU, AND, X), \
939+
INSN_3(ALU, OR, X), \
940+
INSN_3(ALU, LSH, X), \
941+
INSN_3(ALU, RSH, X), \
942+
INSN_3(ALU, XOR, X), \
943+
INSN_3(ALU, MUL, X), \
944+
INSN_3(ALU, MOV, X), \
945+
INSN_3(ALU, ARSH, X), \
946+
INSN_3(ALU, DIV, X), \
947+
INSN_3(ALU, MOD, X), \
947948
INSN_2(ALU, NEG), \
948949
INSN_3(ALU, END, TO_BE), \
949950
INSN_3(ALU, END, TO_LE), \
950951
/* Immediate based. */ \
951-
INSN_3(ALU, ADD, K), \
952-
INSN_3(ALU, SUB, K), \
953-
INSN_3(ALU, AND, K), \
954-
INSN_3(ALU, OR, K), \
955-
INSN_3(ALU, LSH, K), \
956-
INSN_3(ALU, RSH, K), \
957-
INSN_3(ALU, XOR, K), \
958-
INSN_3(ALU, MUL, K), \
959-
INSN_3(ALU, MOV, K), \
960-
INSN_3(ALU, DIV, K), \
961-
INSN_3(ALU, MOD, K), \
952+
INSN_3(ALU, ADD, K), \
953+
INSN_3(ALU, SUB, K), \
954+
INSN_3(ALU, AND, K), \
955+
INSN_3(ALU, OR, K), \
956+
INSN_3(ALU, LSH, K), \
957+
INSN_3(ALU, RSH, K), \
958+
INSN_3(ALU, XOR, K), \
959+
INSN_3(ALU, MUL, K), \
960+
INSN_3(ALU, MOV, K), \
961+
INSN_3(ALU, ARSH, K), \
962+
INSN_3(ALU, DIV, K), \
963+
INSN_3(ALU, MOD, K), \
962964
/* 64 bit ALU operations. */ \
963965
/* Register based. */ \
964966
INSN_3(ALU64, ADD, X), \
@@ -1137,6 +1139,12 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)
11371139
DST = (u64) (u32) insn[0].imm | ((u64) (u32) insn[1].imm) << 32;
11381140
insn++;
11391141
CONT;
1142+
ALU_ARSH_X:
1143+
DST = (u64) (u32) ((*(s32 *) &DST) >> SRC);
1144+
CONT;
1145+
ALU_ARSH_K:
1146+
DST = (u64) (u32) ((*(s32 *) &DST) >> IMM);
1147+
CONT;
11401148
ALU64_ARSH_X:
11411149
(*(s64 *) &DST) >>= SRC;
11421150
CONT;

0 commit comments

Comments
 (0)