Re: [PATCH net-next 12/16] idpf: implement XDP_SETUP_PROG in ndo_bpf for splitq

Maciej Fijalkowski
2025-03-07T14:17:20Z

On Wed, Mar 05, 2025 at 05:21:28PM +0100, Alexander Lobakin wrote:
> From: Michal Kubiak <michal.kubiak@intel.com>
>
> Implement loading/removing XDP program using .ndo_bpf callback
> in the split queue mode. Reconfigure and restart the queues if needed
> (!!old_prog != !!new_prog), otherwise, just update the pointers.
>
> Signed-off-by: Michal Kubiak <michal.kubiak@intel.com>
> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
> ---
> drivers/net/ethernet/intel/idpf/idpf_txrx.h | 4 +-
> drivers/net/ethernet/intel/idpf/xdp.h | 7 ++
> drivers/net/ethernet/intel/idpf/idpf_lib.c | 1 +
> drivers/net/ethernet/intel/idpf/idpf_txrx.c | 4 +
> drivers/net/ethernet/intel/idpf/xdp.c | 114 ++++++++++++++++++++
> 5 files changed, 129 insertions(+), 1 deletion(-)
>

(...)

> +
> +/**
> + * idpf_xdp_setup_prog - handle XDP program install/remove requests
> + * @vport: vport to configure
> + * @xdp: request data (program, extack)
> + *
> + * Return: 0 on success, -errno on failure.
> + */
> +static int
> +idpf_xdp_setup_prog(struct idpf_vport *vport, const struct netdev_bpf *xdp)
> +{
> + const struct idpf_netdev_priv *np = netdev_priv(vport->netdev);
> + struct bpf_prog *old, *prog = xdp->prog;
> + struct idpf_vport_config *cfg;
> + int ret;
> +
> + cfg = vport->adapter->vport_config[vport->idx];
> + if (!vport->num_xdp_txq && vport->num_txq == cfg->max_q.max_txq) {
> + NL_SET_ERR_MSG_MOD(xdp->extack,
> + "No Tx queues available for XDP, please decrease the number of regular SQs");
> + return -ENOSPC;
> + }
> +
> + if (test_bit(IDPF_REMOVE_IN_PROG, vport->adapter->flags) ||

IN_PROG is a bit unfortunate here as it mixes with 'prog' :P

> + !!vport->xdp_prog == !!prog) {
> + if (np->state == __IDPF_VPORT_UP)
> + idpf_copy_xdp_prog_to_qs(vport, prog);
> +
> + old = xchg(&vport->xdp_prog, prog);
> + if (old)
> + bpf_prog_put(old);
> +
> + cfg->user_config.xdp_prog = prog;
> +
> + return 0;
> + }
> +
> + old = cfg->user_config.xdp_prog;
> + cfg->user_config.xdp_prog = prog;
> +
> + ret = idpf_initiate_soft_reset(vport, IDPF_SR_Q_CHANGE);
> + if (ret) {
> + NL_SET_ERR_MSG_MOD(xdp->extack,
> + "Could not reopen the vport after XDP setup");
> +
> + if (prog)
> + bpf_prog_put(prog);

aren't you missing this for prog->NULL conversion? you have this for
hot-swap case (prog->prog).

> +
> + cfg->user_config.xdp_prog = old;
> + }
> +
> + return ret;
> +}
> +
> +/**
> + * idpf_xdp - handle XDP-related requests
> + * @dev: network device to configure
> + * @xdp: request data (program, extack)
> + *
> + * Return: 0 on success, -errno on failure.
> + */
> +int idpf_xdp(struct net_device *dev, struct netdev_bpf *xdp)
> +{
> + struct idpf_vport *vport;
> + int ret;
> +
> + idpf_vport_ctrl_lock(dev);
> + vport = idpf_netdev_to_vport(dev);
> +
> + if (!idpf_is_queue_model_split(vport->txq_model))
> + goto notsupp;
> +
> + switch (xdp->command) {
> + case XDP_SETUP_PROG:
> + ret = idpf_xdp_setup_prog(vport, xdp);
> + break;
> + default:
> +notsupp:
> + ret = -EOPNOTSUPP;
> + break;
> + }
> +
> + idpf_vport_ctrl_unlock(dev);
> +
> + return ret;
> +}
> --
> 2.48.1
>