Commit 2973c579 authored by Mao Minkai's avatar Mao Minkai Committed by guzitao
Browse files

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: default avatarMao Minkai <maominkai@wxiat.com>
Signed-off-by: default avatarGu Zitao <guzitao@wxiat.com>
parent 9b3064be
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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);
		break;
	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:
		emit(SW64_BPF_AND_REG(dst, src, dst), ctx);
		break;
	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:
		emit(SW64_BPF_BIS_REG(dst, src, dst), ctx);
		break;
	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:
		emit(SW64_BPF_XOR_REG(dst, src, dst), ctx);
		break;
@@ -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_BPF_AND_REG(dst, tmp1, dst), ctx);
		}
		emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
		break;
	case BPF_ALU64 | BPF_AND | BPF_K:
		if (imm >= 0 && imm <= U8_MAX) {
@@ -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_BPF_BIS_REG(dst, tmp1, dst), ctx);
		}
		emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
		break;
	case BPF_ALU64 | BPF_OR | BPF_K:
		if (imm >= 0 && imm <= U8_MAX) {
@@ -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_BPF_XOR_REG(dst, tmp1, dst), ctx);
		}
		emit(SW64_BPF_ZAP_IMM(dst, 0xf0, dst), ctx);
		break;
	case BPF_ALU64 | BPF_XOR | BPF_K:
		if (imm >= 0 && imm <= U8_MAX) {