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

Alexander Lobakin
2025-03-17T14:58:30Z

From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Date: Fri, 7 Mar 2025 15:16:48 +0100

> 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

Authentic idpf dictionary ¯\_(ツ)_/¯

>
>> + !!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).

This path (soft_reset) handles NULL => prog and prog => NULL. This
branch in particular handles errors during the soft reset, when we need
to restore the original prog and put the new one.

What you probably meant is that I don't have bpf_prog_put(old) in case
everything went well below? Breh =\

>
>> +
>> + cfg->user_config.xdp_prog = old;
>> + }
>> +
>> + return ret;
>> +}

Thanks,
Olek