xdp: factor out common program/flags handling from drivers
Basic operations drivers perform during xdp setup and query can be moved to helpers in the core. Encapsulate program and flags into a structure and add helpers. Note that the structure is intended as the "main" program information source in the driver. Most drivers will additionally place the program pointer in their fast path or ring structures. The helpers don't have a huge impact now, but they will decrease the code duplication when programs can be installed in HW and driver at the same time. Encapsulating the basic operations in helpers will hopefully also reduce the number of changes to drivers which adopt them. Helpers could really be static inline, but they depend on definition of struct netdev_bpf which means they'd have to be placed in netdevice.h, an already 4500 line header. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:

committed by
Daniel Borkmann

parent
6b86758973
commit
05296620f6
@@ -553,8 +553,7 @@ struct nfp_net_dp {
|
||||
* @rss_cfg: RSS configuration
|
||||
* @rss_key: RSS secret key
|
||||
* @rss_itbl: RSS indirection table
|
||||
* @xdp_flags: Flags with which XDP prog was loaded
|
||||
* @xdp_prog: XDP prog (for ctrl path, both DRV and HW modes)
|
||||
* @xdp: Information about the attached XDP program
|
||||
* @max_r_vecs: Number of allocated interrupt vectors for RX/TX
|
||||
* @max_tx_rings: Maximum number of TX rings supported by the Firmware
|
||||
* @max_rx_rings: Maximum number of RX rings supported by the Firmware
|
||||
@@ -610,8 +609,7 @@ struct nfp_net {
|
||||
u8 rss_key[NFP_NET_CFG_RSS_KEY_SZ];
|
||||
u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ];
|
||||
|
||||
u32 xdp_flags;
|
||||
struct bpf_prog *xdp_prog;
|
||||
struct xdp_attachment_info xdp;
|
||||
|
||||
unsigned int max_tx_rings;
|
||||
unsigned int max_rx_rings;
|
||||
|
@@ -3417,34 +3417,29 @@ nfp_net_xdp_setup_drv(struct nfp_net *nn, struct bpf_prog *prog,
|
||||
return nfp_net_ring_reconfig(nn, dp, extack);
|
||||
}
|
||||
|
||||
static int
|
||||
nfp_net_xdp_setup(struct nfp_net *nn, struct bpf_prog *prog, u32 flags,
|
||||
struct netlink_ext_ack *extack)
|
||||
static int nfp_net_xdp_setup(struct nfp_net *nn, struct netdev_bpf *bpf)
|
||||
{
|
||||
struct bpf_prog *drv_prog, *offload_prog;
|
||||
int err;
|
||||
|
||||
if (nn->xdp_prog && (flags ^ nn->xdp_flags) & XDP_FLAGS_MODES)
|
||||
if (!xdp_attachment_flags_ok(&nn->xdp, bpf))
|
||||
return -EBUSY;
|
||||
|
||||
/* Load both when no flags set to allow easy activation of driver path
|
||||
* when program is replaced by one which can't be offloaded.
|
||||
*/
|
||||
drv_prog = flags & XDP_FLAGS_HW_MODE ? NULL : prog;
|
||||
offload_prog = flags & XDP_FLAGS_DRV_MODE ? NULL : prog;
|
||||
drv_prog = bpf->flags & XDP_FLAGS_HW_MODE ? NULL : bpf->prog;
|
||||
offload_prog = bpf->flags & XDP_FLAGS_DRV_MODE ? NULL : bpf->prog;
|
||||
|
||||
err = nfp_net_xdp_setup_drv(nn, drv_prog, extack);
|
||||
err = nfp_net_xdp_setup_drv(nn, drv_prog, bpf->extack);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = nfp_app_xdp_offload(nn->app, nn, offload_prog, extack);
|
||||
if (err && flags & XDP_FLAGS_HW_MODE)
|
||||
err = nfp_app_xdp_offload(nn->app, nn, offload_prog, bpf->extack);
|
||||
if (err && bpf->flags & XDP_FLAGS_HW_MODE)
|
||||
return err;
|
||||
|
||||
if (nn->xdp_prog)
|
||||
bpf_prog_put(nn->xdp_prog);
|
||||
nn->xdp_prog = prog;
|
||||
nn->xdp_flags = flags;
|
||||
xdp_attachment_setup(&nn->xdp, bpf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3456,12 +3451,9 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
|
||||
switch (xdp->command) {
|
||||
case XDP_SETUP_PROG:
|
||||
case XDP_SETUP_PROG_HW:
|
||||
return nfp_net_xdp_setup(nn, xdp->prog, xdp->flags,
|
||||
xdp->extack);
|
||||
return nfp_net_xdp_setup(nn, xdp);
|
||||
case XDP_QUERY_PROG:
|
||||
xdp->prog_id = nn->xdp_prog ? nn->xdp_prog->aux->id : 0;
|
||||
xdp->prog_flags = nn->xdp_prog ? nn->xdp_flags : 0;
|
||||
return 0;
|
||||
return xdp_attachment_query(&nn->xdp, xdp);
|
||||
default:
|
||||
return nfp_app_bpf(nn->app, nn, xdp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user