Subject: Re: [RFC 05/12] nfp: add BPF to NFP code translator

From: Daniel Borkmann <[email-masked]>
Date: Wed, 01 Jun 2016 22:03:04 +0200

On 06/01/2016 06:50 PM, Jakub Kicinski wrote:
> Add translator for JITing eBPF to operations which
> can be executed on NFP's programmable engines.
>
> Signed-off-by: Jakub Kicinski <[email-masked]>
> Reviewed-by: Dinan Gunawardena <[email-masked]>
> Reviewed-by: Simon Horman <[email-masked]>
[...]
> +int
> +nfp_bpf_jit(struct bpf_prog *filter, void *prog_mem, unsigned int prog_start,
> +	    unsigned int tgt_out, unsigned int tgt_abort,
> +	    unsigned int prog_sz, struct nfp_bpf_result *res)
> +{
> +	struct nfp_prog *nfp_prog;
> +	int ret;
> +
> +	/* TODO: maybe make this dependent on bpf_jit_enable? */

Probably makes sense to leave it independent from this.

Maybe that would rather be an ethtool flag/setting?

> +	nfp_prog = kzalloc(sizeof(*nfp_prog), GFP_KERNEL);
> +	if (!nfp_prog)
> +		return -ENOMEM;
> +
> +	INIT_LIST_HEAD(&nfp_prog->insns);
> +	nfp_prog->start_off = prog_start;
> +	nfp_prog->tgt_out = tgt_out;
> +	nfp_prog->tgt_abort = tgt_abort;
> +
> +	ret = nfp_prog_prepare(nfp_prog, filter->insnsi, filter->len);
> +	if (ret)
> +		goto out;
> +
> +	nfp_bpf_optimize(nfp_prog);
> +
> +	nfp_prog->prog = prog_mem;
> +	nfp_prog->__prog_alloc_len = prog_sz;
> +
> +	ret = nfp_translate(nfp_prog);
> +	if (ret) {
> +		pr_err("Translation failed with error %d (translated: %u)\n",
> +		       ret, nfp_prog->n_translated);
> +		ret = -EINVAL;
> +	}
> +
> +	res->n_instr = nfp_prog->prog_len;
> +out:
> +	nfp_prog_free(nfp_prog);
> +
> +	return ret;
> +}
>