Skip to content

Commit

Permalink
nfp: bpf: don't depend on high order allocations for program image
Browse files Browse the repository at this point in the history
The translator pre-allocates a buffer of maximal program size.
Due to HW/FW limitations the program buffer can't currently be
longer than 128Kb, so we used to kmalloc() it, and then map for
DMA directly.

Now that the late branch resolution is copying the program image
anyway, we can just kvmalloc() the buffer.  While at it, after
translation reallocate the buffer to save space.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
Jakub Kicinski authored and Daniel Borkmann committed Jan 10, 2018
1 parent 2314fe9 commit 44a12ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions drivers/net/ethernet/netronome/nfp/bpf/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,20 @@ static int nfp_bpf_ustore_calc(u64 *prog, unsigned int len)
return 0;
}

static void nfp_bpf_prog_trim(struct nfp_prog *nfp_prog)
{
void *prog;

prog = kvmalloc_array(nfp_prog->prog_len, sizeof(u64), GFP_KERNEL);
if (!prog)
return;

nfp_prog->__prog_alloc_len = nfp_prog->prog_len * sizeof(u64);
memcpy(prog, nfp_prog->prog, nfp_prog->__prog_alloc_len);
kvfree(nfp_prog->prog);
nfp_prog->prog = prog;
}

int nfp_bpf_jit(struct nfp_prog *nfp_prog)
{
int ret;
Expand All @@ -2691,6 +2705,8 @@ int nfp_bpf_jit(struct nfp_prog *nfp_prog)
return -EINVAL;
}

nfp_bpf_prog_trim(nfp_prog);

return ret;
}

Expand Down
5 changes: 3 additions & 2 deletions drivers/net/ethernet/netronome/nfp/bpf/offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <linux/jiffies.h>
#include <linux/timer.h>
#include <linux/list.h>
#include <linux/mm.h>

#include <net/pkt_cls.h>
#include <net/tc_act/tc_gact.h>
Expand Down Expand Up @@ -135,7 +136,7 @@ int nfp_bpf_translate(struct nfp_app *app, struct nfp_net *nn,
max_instr = nn_readw(nn, NFP_NET_CFG_BPF_MAX_LEN);
nfp_prog->__prog_alloc_len = max_instr * sizeof(u64);

nfp_prog->prog = kmalloc(nfp_prog->__prog_alloc_len, GFP_KERNEL);
nfp_prog->prog = kvmalloc(nfp_prog->__prog_alloc_len, GFP_KERNEL);
if (!nfp_prog->prog)
return -ENOMEM;

Expand All @@ -147,7 +148,7 @@ int nfp_bpf_destroy(struct nfp_app *app, struct nfp_net *nn,
{
struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;

kfree(nfp_prog->prog);
kvfree(nfp_prog->prog);
nfp_prog_free(nfp_prog);

return 0;
Expand Down

0 comments on commit 44a12ec

Please sign in to comment.