Skip to content

Commit 90a881f

Browse files
macris-xiaodavem330
authored andcommitted
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: Yu Xiao <[email protected]> Reviewed-by: Yinjun Zhang <[email protected]> Reviewed-by: Niklas Soderlund <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9159f10 commit 90a881f

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,21 @@ static int
182182
nfp_bpf_check_mtu(struct nfp_app *app, struct net_device *netdev, int new_mtu)
183183
{
184184
struct nfp_net *nn = netdev_priv(netdev);
185-
unsigned int max_mtu;
185+
struct nfp_bpf_vnic *bv;
186+
struct bpf_prog *prog;
186187

187188
if (~nn->dp.ctrl & NFP_NET_CFG_CTRL_BPF)
188189
return 0;
189190

190-
max_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32;
191-
if (new_mtu > max_mtu) {
192-
nn_info(nn, "BPF offload active, MTU over %u not supported\n",
193-
max_mtu);
191+
if (nn->xdp_hw.prog) {
192+
prog = nn->xdp_hw.prog;
193+
} else {
194+
bv = nn->app_priv;
195+
prog = bv->tc_prog;
196+
}
197+
198+
if (nfp_bpf_offload_check_mtu(nn, prog, new_mtu)) {
199+
nn_info(nn, "BPF offload active, potential packet access beyond hardware packet boundary");
194200
return -EBUSY;
195201
}
196202
return 0;

drivers/net/ethernet/netronome/nfp/bpf/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ bool nfp_is_subprog_start(struct nfp_insn_meta *meta);
560560
void nfp_bpf_jit_prepare(struct nfp_prog *nfp_prog);
561561
int nfp_bpf_jit(struct nfp_prog *prog);
562562
bool nfp_bpf_supported_opcode(u8 code);
563+
bool nfp_bpf_offload_check_mtu(struct nfp_net *nn, struct bpf_prog *prog,
564+
unsigned int mtu);
563565

564566
int nfp_verify_insn(struct bpf_verifier_env *env, int insn_idx,
565567
int prev_insn_idx);

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,19 +481,28 @@ int nfp_bpf_event_output(struct nfp_app_bpf *bpf, const void *data,
481481
return 0;
482482
}
483483

484+
bool nfp_bpf_offload_check_mtu(struct nfp_net *nn, struct bpf_prog *prog,
485+
unsigned int mtu)
486+
{
487+
unsigned int fw_mtu, pkt_off;
488+
489+
fw_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32;
490+
pkt_off = min(prog->aux->max_pkt_offset, mtu);
491+
492+
return fw_mtu < pkt_off;
493+
}
494+
484495
static int
485496
nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog,
486497
struct netlink_ext_ack *extack)
487498
{
488499
struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;
489-
unsigned int fw_mtu, pkt_off, max_stack, max_prog_len;
500+
unsigned int max_stack, max_prog_len;
490501
dma_addr_t dma_addr;
491502
void *img;
492503
int err;
493504

494-
fw_mtu = nn_readb(nn, NFP_NET_CFG_BPF_INL_MTU) * 64 - 32;
495-
pkt_off = min(prog->aux->max_pkt_offset, nn->dp.netdev->mtu);
496-
if (fw_mtu < pkt_off) {
505+
if (nfp_bpf_offload_check_mtu(nn, prog, nn->dp.netdev->mtu)) {
497506
NL_SET_ERR_MSG_MOD(extack, "BPF offload not supported with potential packet access beyond HW packet split boundary");
498507
return -EOPNOTSUPP;
499508
}

0 commit comments

Comments
 (0)