Commit 6a8ef542 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: bpf: release the reference on offloaded programs

The xdp_prog member of the adapter's data path structure is used
for XDP in driver mode.  In case a XDP program is loaded with in
HW-only mode, we need to store it somewhere else.  Add a new XDP
prog pointer in the main structure and use that when we need to
know whether any XDP program is loaded, not only a driver mode
one.  Only release our reference on adapter free instead of
immediately after netdev unregister to allow offload to be disabled
first.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9f82fca9
...@@ -542,6 +542,7 @@ struct nfp_net_dp { ...@@ -542,6 +542,7 @@ struct nfp_net_dp {
* @rss_key: RSS secret key * @rss_key: RSS secret key
* @rss_itbl: RSS indirection table * @rss_itbl: RSS indirection table
* @xdp_flags: Flags with which XDP prog was loaded * @xdp_flags: Flags with which XDP prog was loaded
* @xdp_prog: XDP prog (for ctrl path, both DRV and HW modes)
* @max_r_vecs: Number of allocated interrupt vectors for RX/TX * @max_r_vecs: Number of allocated interrupt vectors for RX/TX
* @max_tx_rings: Maximum number of TX rings supported by the Firmware * @max_tx_rings: Maximum number of TX rings supported by the Firmware
* @max_rx_rings: Maximum number of RX rings supported by the Firmware * @max_rx_rings: Maximum number of RX rings supported by the Firmware
...@@ -592,6 +593,7 @@ struct nfp_net { ...@@ -592,6 +593,7 @@ struct nfp_net {
u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ]; u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ];
u32 xdp_flags; u32 xdp_flags;
struct bpf_prog *xdp_prog;
unsigned int max_tx_rings; unsigned int max_tx_rings;
unsigned int max_rx_rings; unsigned int max_rx_rings;
......
...@@ -3278,15 +3278,10 @@ static int ...@@ -3278,15 +3278,10 @@ static int
nfp_net_xdp_setup_drv(struct nfp_net *nn, struct bpf_prog *prog, nfp_net_xdp_setup_drv(struct nfp_net *nn, struct bpf_prog *prog,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct bpf_prog *old_prog = nn->dp.xdp_prog;
struct nfp_net_dp *dp; struct nfp_net_dp *dp;
int err;
if (!prog && !nn->dp.xdp_prog) if (!prog == !nn->dp.xdp_prog) {
return 0; WRITE_ONCE(nn->dp.xdp_prog, prog);
if (prog && nn->dp.xdp_prog) {
prog = xchg(&nn->dp.xdp_prog, prog);
bpf_prog_put(prog);
return 0; return 0;
} }
...@@ -3300,14 +3295,7 @@ nfp_net_xdp_setup_drv(struct nfp_net *nn, struct bpf_prog *prog, ...@@ -3300,14 +3295,7 @@ nfp_net_xdp_setup_drv(struct nfp_net *nn, struct bpf_prog *prog,
dp->rx_dma_off = prog ? XDP_PACKET_HEADROOM - nn->dp.rx_offset : 0; dp->rx_dma_off = prog ? XDP_PACKET_HEADROOM - nn->dp.rx_offset : 0;
/* We need RX reconfig to remap the buffers (BIDIR vs FROM_DEV) */ /* We need RX reconfig to remap the buffers (BIDIR vs FROM_DEV) */
err = nfp_net_ring_reconfig(nn, dp, extack); return nfp_net_ring_reconfig(nn, dp, extack);
if (err)
return err;
if (old_prog)
bpf_prog_put(old_prog);
return 0;
} }
static int static int
...@@ -3317,7 +3305,7 @@ nfp_net_xdp_setup(struct nfp_net *nn, struct bpf_prog *prog, u32 flags, ...@@ -3317,7 +3305,7 @@ nfp_net_xdp_setup(struct nfp_net *nn, struct bpf_prog *prog, u32 flags,
struct bpf_prog *offload_prog; struct bpf_prog *offload_prog;
int err; int err;
if (nn->dp.xdp_prog && (flags ^ nn->xdp_flags) & XDP_FLAGS_MODES) if (nn->xdp_prog && (flags ^ nn->xdp_flags) & XDP_FLAGS_MODES)
return -EBUSY; return -EBUSY;
offload_prog = flags & XDP_FLAGS_DRV_MODE ? NULL : prog; offload_prog = flags & XDP_FLAGS_DRV_MODE ? NULL : prog;
...@@ -3327,6 +3315,10 @@ nfp_net_xdp_setup(struct nfp_net *nn, struct bpf_prog *prog, u32 flags, ...@@ -3327,6 +3315,10 @@ nfp_net_xdp_setup(struct nfp_net *nn, struct bpf_prog *prog, u32 flags,
return err; return err;
nfp_app_xdp_offload(nn->app, nn, offload_prog); nfp_app_xdp_offload(nn->app, nn, offload_prog);
if (nn->xdp_prog)
bpf_prog_put(nn->xdp_prog);
nn->xdp_prog = prog;
nn->xdp_flags = flags; nn->xdp_flags = flags;
return 0; return 0;
...@@ -3341,8 +3333,8 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_xdp *xdp) ...@@ -3341,8 +3333,8 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_xdp *xdp)
return nfp_net_xdp_setup(nn, xdp->prog, xdp->flags, return nfp_net_xdp_setup(nn, xdp->prog, xdp->flags,
xdp->extack); xdp->extack);
case XDP_QUERY_PROG: case XDP_QUERY_PROG:
xdp->prog_attached = !!nn->dp.xdp_prog; xdp->prog_attached = !!nn->xdp_prog;
xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0; xdp->prog_id = nn->xdp_prog ? nn->xdp_prog->aux->id : 0;
return 0; return 0;
default: default:
return -EINVAL; return -EINVAL;
...@@ -3500,6 +3492,9 @@ struct nfp_net *nfp_net_alloc(struct pci_dev *pdev, bool needs_netdev, ...@@ -3500,6 +3492,9 @@ struct nfp_net *nfp_net_alloc(struct pci_dev *pdev, bool needs_netdev,
*/ */
void nfp_net_free(struct nfp_net *nn) void nfp_net_free(struct nfp_net *nn)
{ {
if (nn->xdp_prog)
bpf_prog_put(nn->xdp_prog);
if (nn->dp.netdev) if (nn->dp.netdev)
free_netdev(nn->dp.netdev); free_netdev(nn->dp.netdev);
else else
...@@ -3757,7 +3752,4 @@ void nfp_net_clean(struct nfp_net *nn) ...@@ -3757,7 +3752,4 @@ void nfp_net_clean(struct nfp_net *nn)
return; return;
unregister_netdev(nn->dp.netdev); unregister_netdev(nn->dp.netdev);
if (nn->dp.xdp_prog)
bpf_prog_put(nn->dp.xdp_prog);
} }
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