Commit 90a881fc authored by Yu Xiao's avatar Yu Xiao Committed by David S. Miller

nfp: bpf: relax prog rejection for mtu check through max_pkt_offset

MTU change is refused whenever the value of new MTU is bigger than
the max packet bytes that fits in NFP Cluster Target Memory (CTM).
However, an eBPF program doesn't always need to access the whole
packet data.

The maximum direct packet access (DPA) offset has always been
caculated by verifier and stored in the max_pkt_offset field of prog
aux data.
Signed-off-by: default avatarYu Xiao <yu.xiao@corigine.com>
Reviewed-by: default avatarYinjun Zhang <yinjun.zhang@corigine.com>
Reviewed-by: default avatarNiklas Soderlund <niklas.soderlund@corigine.com>
Signed-off-by: default avatarSimon Horman <simon.horman@corigine.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9159f102
...@@ -182,15 +182,21 @@ static int ...@@ -182,15 +182,21 @@ static int
nfp_bpf_check_mtu(struct nfp_app *app, struct net_device *netdev, int new_mtu) nfp_bpf_check_mtu(struct nfp_app *app, struct net_device *netdev, int new_mtu)
{ {
struct nfp_net *nn = netdev_priv(netdev); struct nfp_net *nn = netdev_priv(netdev);
unsigned int max_mtu; struct nfp_bpf_vnic *bv;
struct bpf_prog *prog;
if (~nn->dp.ctrl & NFP_NET_CFG_CTRL_BPF) if (~nn->dp.ctrl & NFP_NET_CFG_CTRL_BPF)
return 0; return 0;
max_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32; if (nn->xdp_hw.prog) {
if (new_mtu > max_mtu) { prog = nn->xdp_hw.prog;
nn_info(nn, "BPF offload active, MTU over %u not supported\n", } else {
max_mtu); bv = nn->app_priv;
prog = bv->tc_prog;
}
if (nfp_bpf_offload_check_mtu(nn, prog, new_mtu)) {
nn_info(nn, "BPF offload active, potential packet access beyond hardware packet boundary");
return -EBUSY; return -EBUSY;
} }
return 0; return 0;
......
...@@ -560,6 +560,8 @@ bool nfp_is_subprog_start(struct nfp_insn_meta *meta); ...@@ -560,6 +560,8 @@ bool nfp_is_subprog_start(struct nfp_insn_meta *meta);
void nfp_bpf_jit_prepare(struct nfp_prog *nfp_prog); void nfp_bpf_jit_prepare(struct nfp_prog *nfp_prog);
int nfp_bpf_jit(struct nfp_prog *prog); int nfp_bpf_jit(struct nfp_prog *prog);
bool nfp_bpf_supported_opcode(u8 code); bool nfp_bpf_supported_opcode(u8 code);
bool nfp_bpf_offload_check_mtu(struct nfp_net *nn, struct bpf_prog *prog,
unsigned int mtu);
int nfp_verify_insn(struct bpf_verifier_env *env, int insn_idx, int nfp_verify_insn(struct bpf_verifier_env *env, int insn_idx,
int prev_insn_idx); int prev_insn_idx);
......
...@@ -481,19 +481,28 @@ int nfp_bpf_event_output(struct nfp_app_bpf *bpf, const void *data, ...@@ -481,19 +481,28 @@ int nfp_bpf_event_output(struct nfp_app_bpf *bpf, const void *data,
return 0; return 0;
} }
bool nfp_bpf_offload_check_mtu(struct nfp_net *nn, struct bpf_prog *prog,
unsigned int mtu)
{
unsigned int fw_mtu, pkt_off;
fw_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32;
pkt_off = min(prog->aux->max_pkt_offset, mtu);
return fw_mtu < pkt_off;
}
static int static int
nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog, nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv; struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;
unsigned int fw_mtu, pkt_off, max_stack, max_prog_len; unsigned int max_stack, max_prog_len;
dma_addr_t dma_addr; dma_addr_t dma_addr;
void *img; void *img;
int err; int err;
fw_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32; if (nfp_bpf_offload_check_mtu(nn, prog, nn->dp.netdev->mtu)) {
pkt_off = min(prog->aux->max_pkt_offset, nn->dp.netdev->mtu);
if (fw_mtu < pkt_off) {
NL_SET_ERR_MSG_MOD(extack, "BPF offload not supported with potential packet access beyond HW packet split boundary"); NL_SET_ERR_MSG_MOD(extack, "BPF offload not supported with potential packet access beyond HW packet split boundary");
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment