提交 e0294b8d 编写于 作者: M Mao Minkai 提交者: guzitao

sw64: bpf: fix 32-bit bitwise operation

Sunway inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5PNI5

--------------------------------

Make sure the result of 32-bit bitwise operation is zero extended to
64 bits.
Signed-off-by: NMao Minkai <maominkai@wxiat.com>
Signed-off-by: NGu Zitao <guzitao@wxiat.com>
上级 3344c359
...@@ -745,14 +745,23 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx) ...@@ -745,14 +745,23 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
emit(SW64_BPF_SRA_REG(dst, src, dst), ctx); emit(SW64_BPF_SRA_REG(dst, src, dst), ctx);
break; break;
case BPF_ALU | BPF_AND | BPF_X: case BPF_ALU | BPF_AND | BPF_X:
emit(SW64_BPF_AND_REG(dst, src, dst), ctx);
emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
break;
case BPF_ALU64 | BPF_AND | BPF_X: case BPF_ALU64 | BPF_AND | BPF_X:
emit(SW64_BPF_AND_REG(dst, src, dst), ctx); emit(SW64_BPF_AND_REG(dst, src, dst), ctx);
break; break;
case BPF_ALU | BPF_OR | BPF_X: case BPF_ALU | BPF_OR | BPF_X:
emit(SW64_BPF_BIS_REG(dst, src, dst), ctx);
emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
break;
case BPF_ALU64 | BPF_OR | BPF_X: case BPF_ALU64 | BPF_OR | BPF_X:
emit(SW64_BPF_BIS_REG(dst, src, dst), ctx); emit(SW64_BPF_BIS_REG(dst, src, dst), ctx);
break; break;
case BPF_ALU | BPF_XOR | BPF_X: case BPF_ALU | BPF_XOR | BPF_X:
emit(SW64_BPF_XOR_REG(dst, src, dst), ctx);
emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
break;
case BPF_ALU64 | BPF_XOR | BPF_X: case BPF_ALU64 | BPF_XOR | BPF_X:
emit(SW64_BPF_XOR_REG(dst, src, dst), ctx); emit(SW64_BPF_XOR_REG(dst, src, dst), ctx);
break; break;
...@@ -936,6 +945,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx) ...@@ -936,6 +945,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
emit_sw64_ldu32(tmp1, imm, ctx); emit_sw64_ldu32(tmp1, imm, ctx);
emit(SW64_BPF_AND_REG(dst, tmp1, dst), ctx); emit(SW64_BPF_AND_REG(dst, tmp1, dst), ctx);
} }
emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
break; break;
case BPF_ALU64 | BPF_AND | BPF_K: case BPF_ALU64 | BPF_AND | BPF_K:
if (imm >= 0 && imm <= U8_MAX) { if (imm >= 0 && imm <= U8_MAX) {
...@@ -952,6 +962,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx) ...@@ -952,6 +962,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
emit_sw64_ldu32(tmp1, imm, ctx); emit_sw64_ldu32(tmp1, imm, ctx);
emit(SW64_BPF_BIS_REG(dst, tmp1, dst), ctx); emit(SW64_BPF_BIS_REG(dst, tmp1, dst), ctx);
} }
emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
break; break;
case BPF_ALU64 | BPF_OR | BPF_K: case BPF_ALU64 | BPF_OR | BPF_K:
if (imm >= 0 && imm <= U8_MAX) { if (imm >= 0 && imm <= U8_MAX) {
...@@ -968,6 +979,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx) ...@@ -968,6 +979,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
emit_sw64_ldu32(tmp1, imm, ctx); emit_sw64_ldu32(tmp1, imm, ctx);
emit(SW64_BPF_XOR_REG(dst, tmp1, dst), ctx); emit(SW64_BPF_XOR_REG(dst, tmp1, dst), ctx);
} }
emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
break; break;
case BPF_ALU64 | BPF_XOR | BPF_K: case BPF_ALU64 | BPF_XOR | BPF_K:
if (imm >= 0 && imm <= U8_MAX) { if (imm >= 0 && imm <= U8_MAX) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册