[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPhsuW6uVUbsf8Bj-SqgdENEvqzm-kgvm8RNSJYcTFcQq4iH9Q@mail.gmail.com>
Date: Mon, 25 Jun 2018 23:50:44 -0700
From: Song Liu <liu.song.a23@...il.com>
To: Jakub Kicinski <jakub.kicinski@...ronome.com>
Cc: Alexei Starovoitov <alexei.starovoitov@...il.com>,
Daniel Borkmann <daniel@...earbox.net>,
oss-drivers@...ronome.com, Networking <netdev@...r.kernel.org>,
Jiong Wang <jiong.wang@...ronome.com>
Subject: Re: [PATCH bpf-next 4/7] nfp: bpf: copy range info for all operands
of all ALU operations
On Sun, Jun 24, 2018 at 8:54 PM, Jakub Kicinski
<jakub.kicinski@...ronome.com> wrote:
> From: Jiong Wang <jiong.wang@...ronome.com>
>
> NFP verifier hook is coping range information of the shift amount for
> indirect shift operation so optimized shift sequences could be generated.
>
> We want to use range info to do more things. For example, to decide whether
> multiplication and divide are supported on the given range.
>
> This patch simply let NFP verifier hook to copy range info for all operands
> of all ALU operands.
>
> Signed-off-by: Jiong Wang <jiong.wang@...ronome.com>
> Reviewed-by: Jakub Kicinski <jakub.kicinski@...ronome.com>
Acked-by: Song Liu <songliubraving@...com>
> ---
> drivers/net/ethernet/netronome/nfp/bpf/main.h | 33 +++++++------------
> .../net/ethernet/netronome/nfp/bpf/offload.c | 4 ++-
> .../net/ethernet/netronome/nfp/bpf/verifier.c | 6 +++-
> 3 files changed, 20 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.h b/drivers/net/ethernet/netronome/nfp/bpf/main.h
> index 5975a19c28cb..c985d0ac61a3 100644
> --- a/drivers/net/ethernet/netronome/nfp/bpf/main.h
> +++ b/drivers/net/ethernet/netronome/nfp/bpf/main.h
> @@ -265,6 +265,8 @@ struct nfp_bpf_reg_state {
> * @arg2: arg2 for call instructions
> * @umin_src: copy of core verifier umin_value for src opearnd.
> * @umax_src: copy of core verifier umax_value for src operand.
> + * @umin_dst: copy of core verifier umin_value for dst opearnd.
> + * @umax_dst: copy of core verifier umax_value for dst operand.
> * @off: index of first generated machine instruction (in nfp_prog.prog)
> * @n: eBPF instruction number
> * @flags: eBPF instruction extra optimization flags
> @@ -300,12 +302,15 @@ struct nfp_insn_meta {
> struct bpf_reg_state arg1;
> struct nfp_bpf_reg_state arg2;
> };
> - /* We are interested in range info for some operands,
> - * for example, the shift amount which is kept in src operand.
> + /* We are interested in range info for operands of ALU
> + * operations. For example, shift amount, multiplicand and
> + * multiplier etc.
> */
> struct {
> u64 umin_src;
> u64 umax_src;
> + u64 umin_dst;
> + u64 umax_dst;
> };
> };
> unsigned int off;
> @@ -339,6 +344,11 @@ static inline u8 mbpf_mode(const struct nfp_insn_meta *meta)
> return BPF_MODE(meta->insn.code);
> }
>
> +static inline bool is_mbpf_alu(const struct nfp_insn_meta *meta)
> +{
> + return mbpf_class(meta) == BPF_ALU64 || mbpf_class(meta) == BPF_ALU;
> +}
> +
> static inline bool is_mbpf_load(const struct nfp_insn_meta *meta)
> {
> return (meta->insn.code & ~BPF_SIZE_MASK) == (BPF_LDX | BPF_MEM);
> @@ -384,25 +394,6 @@ static inline bool is_mbpf_xadd(const struct nfp_insn_meta *meta)
> return (meta->insn.code & ~BPF_SIZE_MASK) == (BPF_STX | BPF_XADD);
> }
>
> -static inline bool is_mbpf_indir_shift(const struct nfp_insn_meta *meta)
> -{
> - u8 code = meta->insn.code;
> - bool is_alu, is_shift;
> - u8 opclass, opcode;
> -
> - opclass = BPF_CLASS(code);
> - is_alu = opclass == BPF_ALU64 || opclass == BPF_ALU;
> - if (!is_alu)
> - return false;
> -
> - opcode = BPF_OP(code);
> - is_shift = opcode == BPF_LSH || opcode == BPF_RSH || opcode == BPF_ARSH;
> - if (!is_shift)
> - return false;
> -
> - return BPF_SRC(code) == BPF_X;
> -}
> -
> /**
> * struct nfp_prog - nfp BPF program
> * @bpf: backpointer to the bpf app priv structure
> diff --git a/drivers/net/ethernet/netronome/nfp/bpf/offload.c b/drivers/net/ethernet/netronome/nfp/bpf/offload.c
> index 856a0003bb75..78f44c4d95b4 100644
> --- a/drivers/net/ethernet/netronome/nfp/bpf/offload.c
> +++ b/drivers/net/ethernet/netronome/nfp/bpf/offload.c
> @@ -190,8 +190,10 @@ nfp_prog_prepare(struct nfp_prog *nfp_prog, const struct bpf_insn *prog,
>
> meta->insn = prog[i];
> meta->n = i;
> - if (is_mbpf_indir_shift(meta))
> + if (is_mbpf_alu(meta)) {
> meta->umin_src = U64_MAX;
> + meta->umin_dst = U64_MAX;
> + }
>
> list_add_tail(&meta->l, &nfp_prog->insns);
> }
> diff --git a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
> index e862b739441f..7bd9666bd8ff 100644
> --- a/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
> +++ b/drivers/net/ethernet/netronome/nfp/bpf/verifier.c
> @@ -551,12 +551,16 @@ nfp_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn_idx)
> if (is_mbpf_xadd(meta))
> return nfp_bpf_check_xadd(nfp_prog, meta, env);
>
> - if (is_mbpf_indir_shift(meta)) {
> + if (is_mbpf_alu(meta)) {
> const struct bpf_reg_state *sreg =
> cur_regs(env) + meta->insn.src_reg;
> + const struct bpf_reg_state *dreg =
> + cur_regs(env) + meta->insn.dst_reg;
>
> meta->umin_src = min(meta->umin_src, sreg->umin_value);
> meta->umax_src = max(meta->umax_src, sreg->umax_value);
> + meta->umin_dst = min(meta->umin_dst, dreg->umin_value);
> + meta->umax_dst = max(meta->umax_dst, dreg->umax_value);
> }
>
> return 0;
> --
> 2.17.1
>
Powered by blists - more mailing lists