Commit 2dc6b100 authored by Jiong Wang's avatar Jiong Wang Committed by Alexei Starovoitov

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: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarJiong Wang <jiong.wang@netronome.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 84708c13
...@@ -942,6 +942,7 @@ EXPORT_SYMBOL_GPL(__bpf_call_base); ...@@ -942,6 +942,7 @@ EXPORT_SYMBOL_GPL(__bpf_call_base);
INSN_3(ALU, XOR, X), \ INSN_3(ALU, XOR, X), \
INSN_3(ALU, MUL, X), \ INSN_3(ALU, MUL, X), \
INSN_3(ALU, MOV, X), \ INSN_3(ALU, MOV, X), \
INSN_3(ALU, ARSH, X), \
INSN_3(ALU, DIV, X), \ INSN_3(ALU, DIV, X), \
INSN_3(ALU, MOD, X), \ INSN_3(ALU, MOD, X), \
INSN_2(ALU, NEG), \ INSN_2(ALU, NEG), \
...@@ -957,6 +958,7 @@ EXPORT_SYMBOL_GPL(__bpf_call_base); ...@@ -957,6 +958,7 @@ EXPORT_SYMBOL_GPL(__bpf_call_base);
INSN_3(ALU, XOR, K), \ INSN_3(ALU, XOR, K), \
INSN_3(ALU, MUL, K), \ INSN_3(ALU, MUL, K), \
INSN_3(ALU, MOV, K), \ INSN_3(ALU, MOV, K), \
INSN_3(ALU, ARSH, K), \
INSN_3(ALU, DIV, K), \ INSN_3(ALU, DIV, K), \
INSN_3(ALU, MOD, K), \ INSN_3(ALU, MOD, K), \
/* 64 bit ALU operations. */ \ /* 64 bit ALU operations. */ \
...@@ -1137,6 +1139,12 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack) ...@@ -1137,6 +1139,12 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)
DST = (u64) (u32) insn[0].imm | ((u64) (u32) insn[1].imm) << 32; DST = (u64) (u32) insn[0].imm | ((u64) (u32) insn[1].imm) << 32;
insn++; insn++;
CONT; CONT;
ALU_ARSH_X:
DST = (u64) (u32) ((*(s32 *) &DST) >> SRC);
CONT;
ALU_ARSH_K:
DST = (u64) (u32) ((*(s32 *) &DST) >> IMM);
CONT;
ALU64_ARSH_X: ALU64_ARSH_X:
(*(s64 *) &DST) >>= SRC; (*(s64 *) &DST) >>= SRC;
CONT; CONT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment