Skip to content

Commit 84708c1

Browse files
Jiong WangAlexei Starovoitov
authored andcommitted
nfp: bpf: implement jitting of BPF_ALU | BPF_ARSH | BPF_*
BPF_X support needs indirect shift mode, please see code comments for details. 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 f860203 commit 84708c1

File tree

1 file changed

+45
-0
lines changed
  • drivers/net/ethernet/netronome/nfp/bpf

1 file changed

+45
-0
lines changed

drivers/net/ethernet/netronome/nfp/bpf/jit.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,49 @@ static int neg_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
23822382
return 0;
23832383
}
23842384

2385+
static int __ashr_imm(struct nfp_prog *nfp_prog, u8 dst, u8 shift_amt)
2386+
{
2387+
/* Set signedness bit (MSB of result). */
2388+
emit_alu(nfp_prog, reg_none(), reg_a(dst), ALU_OP_OR, reg_imm(0));
2389+
emit_shf(nfp_prog, reg_both(dst), reg_none(), SHF_OP_ASHR, reg_b(dst),
2390+
SHF_SC_R_SHF, shift_amt);
2391+
wrp_immed(nfp_prog, reg_both(dst + 1), 0);
2392+
2393+
return 0;
2394+
}
2395+
2396+
static int ashr_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
2397+
{
2398+
const struct bpf_insn *insn = &meta->insn;
2399+
u64 umin, umax;
2400+
u8 dst, src;
2401+
2402+
dst = insn->dst_reg * 2;
2403+
umin = meta->umin_src;
2404+
umax = meta->umax_src;
2405+
if (umin == umax)
2406+
return __ashr_imm(nfp_prog, dst, umin);
2407+
2408+
src = insn->src_reg * 2;
2409+
/* NOTE: the first insn will set both indirect shift amount (source A)
2410+
* and signedness bit (MSB of result).
2411+
*/
2412+
emit_alu(nfp_prog, reg_none(), reg_a(src), ALU_OP_OR, reg_b(dst));
2413+
emit_shf_indir(nfp_prog, reg_both(dst), reg_none(), SHF_OP_ASHR,
2414+
reg_b(dst), SHF_SC_R_SHF);
2415+
wrp_immed(nfp_prog, reg_both(dst + 1), 0);
2416+
2417+
return 0;
2418+
}
2419+
2420+
static int ashr_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
2421+
{
2422+
const struct bpf_insn *insn = &meta->insn;
2423+
u8 dst = insn->dst_reg * 2;
2424+
2425+
return __ashr_imm(nfp_prog, dst, insn->imm);
2426+
}
2427+
23852428
static int shl_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
23862429
{
23872430
const struct bpf_insn *insn = &meta->insn;
@@ -3286,6 +3329,8 @@ static const instr_cb_t instr_cb[256] = {
32863329
[BPF_ALU | BPF_DIV | BPF_K] = div_imm,
32873330
[BPF_ALU | BPF_NEG] = neg_reg,
32883331
[BPF_ALU | BPF_LSH | BPF_K] = shl_imm,
3332+
[BPF_ALU | BPF_ARSH | BPF_X] = ashr_reg,
3333+
[BPF_ALU | BPF_ARSH | BPF_K] = ashr_imm,
32893334
[BPF_ALU | BPF_END | BPF_X] = end_reg32,
32903335
[BPF_LD | BPF_IMM | BPF_DW] = imm_ld8,
32913336
[BPF_LD | BPF_ABS | BPF_B] = data_ld1,

0 commit comments

Comments
 (0)