History

nfp: bpf: fix ALU32 high bits clearance bug

NFP BPF JIT compiler is doing a couple of small optimizations when jitting ALU imm instructions, some of these optimizations could save code-gen, for example: A & -1 = A A | 0 = A A ^ 0 = A However, for ALU32, high 32-bit of the 64-bit register should still be cleared according to ISA semantics.

Jiong Wang committed 7 years ago

Commit f036ebd1 parent 71c19021 file · +6 −11Browse files

Unified · Split

drivers/net/ethernet/netronome/nfp/bpf/jit.c+6−11
@@ -1291,15 +1291,10 @@ wrp_alu64_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta, · 1290 unmodified lines
1291 1291
1292static int1292static int
1293wrp_alu32_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,1293wrp_alu32_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
1294 enum alu_op alu_op, bool skip)1294 enum alu_op alu_op)
1295{1295{
1296 const struct bpf_insn *insn = &meta->insn;1296 const struct bpf_insn *insn = &meta->insn;
1297 1297
1298 if (skip) {
1299 meta->skip = true;
1300 return 0;
1301 }
1302
1303 wrp_alu_imm(nfp_prog, insn->dst_reg * 2, alu_op, insn->imm);1298 wrp_alu_imm(nfp_prog, insn->dst_reg * 2, alu_op, insn->imm);
1304 wrp_immed(nfp_prog, reg_both(insn->dst_reg * 2 + 1), 0);1299 wrp_immed(nfp_prog, reg_both(insn->dst_reg * 2 + 1), 0);
1305 1300
@@ -2309,7 +2304,7 @@ static int xor_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) · 1003 unmodified lines
2309 2304
2310static int xor_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2305static int xor_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
2311{2306{
2312 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_XOR, !meta->insn.imm);2307 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_XOR);
2313}2308}
2314 2309
2315static int and_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2310static int and_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
@@ -2319,7 +2314,7 @@ static int and_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) · 3 unmodified lines
2319 2314
2320static int and_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2315static int and_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
2321{2316{
2322 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_AND, !~meta->insn.imm);2317 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_AND);
2323}2318}
2324 2319
2325static int or_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2320static int or_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
@@ -2329,7 +2324,7 @@ static int or_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) · 3 unmodified lines
2329 2324
2330static int or_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2325static int or_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
2331{2326{
2332 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_OR, !meta->insn.imm);2327 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_OR);
2333}2328}
2334 2329
2335static int add_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2330static int add_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
@@ -2339,7 +2334,7 @@ static int add_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) · 3 unmodified lines
2339 2334
2340static int add_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2335static int add_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
2341{2336{
2342 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_ADD, !meta->insn.imm);2337 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_ADD);
2343}2338}
2344 2339
2345static int sub_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2340static int sub_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
@@ -2349,7 +2344,7 @@ static int sub_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) · 3 unmodified lines
2349 2344
2350static int sub_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2345static int sub_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
2351{2346{
2352 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_SUB, !meta->insn.imm);2347 return wrp_alu32_imm(nfp_prog, meta, ALU_OP_SUB);
2353}2348}
2354 2349
2355static int mul_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)2350static int mul_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)