bpf, xdp: Remove XDP_QUERY_PROG and XDP_QUERY_PROG_HW XDP commands
authorAndrii Nakryiko <andriin@fb.com>
Wed, 22 Jul 2020 06:46:02 +0000 (23:46 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 26 Jul 2020 03:37:02 +0000 (20:37 -0700)
Now that BPF program/link management is centralized in generic net_device
code, kernel code never queries program id from drivers, so
XDP_QUERY_PROG/XDP_QUERY_PROG_HW commands are unnecessary.

This patch removes all the implementations of those commands in kernel, along
the xdp_attachment_query().

This patch was compile-tested on allyesconfig.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200722064603.3350758-10-andriin@fb.com
28 files changed:
drivers/net/ethernet/amazon/ena/ena_netdev.c
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
drivers/net/ethernet/cavium/thunder/nicvf_main.c
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
drivers/net/ethernet/intel/i40e/i40e_main.c
drivers/net/ethernet/intel/ice/ice_main.c
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
drivers/net/ethernet/marvell/mvneta.c
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
drivers/net/ethernet/mellanox/mlx4/en_netdev.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/netronome/nfp/nfp_net_common.c
drivers/net/ethernet/qlogic/qede/qede_filter.c
drivers/net/ethernet/sfc/efx.c
drivers/net/ethernet/socionext/netsec.c
drivers/net/ethernet/ti/cpsw_priv.c
drivers/net/hyperv/netvsc_bpf.c
drivers/net/netdevsim/bpf.c
drivers/net/netdevsim/netdevsim.h
drivers/net/tun.c
drivers/net/veth.c
drivers/net/virtio_net.c
drivers/net/xen-netfront.c
include/linux/netdevice.h
include/net/xdp.h
net/core/dev.c
net/core/xdp.c

index 6478c1e..2a6c972 100644 (file)
@@ -576,15 +576,9 @@ static int ena_xdp_set(struct net_device *netdev, struct netdev_bpf *bpf)
  */
 static int ena_xdp(struct net_device *netdev, struct netdev_bpf *bpf)
 {
-       struct ena_adapter *adapter = netdev_priv(netdev);
-
        switch (bpf->command) {
        case XDP_SETUP_PROG:
                return ena_xdp_set(netdev, bpf);
-       case XDP_QUERY_PROG:
-               bpf->prog_id = adapter->xdp_bpf_prog ?
-                       adapter->xdp_bpf_prog->aux->id : 0;
-               break;
        default:
                return -EINVAL;
        }
index 5e3b4a3..2704a47 100644 (file)
@@ -330,10 +330,6 @@ int bnxt_xdp(struct net_device *dev, struct netdev_bpf *xdp)
        case XDP_SETUP_PROG:
                rc = bnxt_xdp_set(bp, xdp->prog);
                break;
-       case XDP_QUERY_PROG:
-               xdp->prog_id = bp->xdp_prog ? bp->xdp_prog->aux->id : 0;
-               rc = 0;
-               break;
        default:
                rc = -EINVAL;
                break;
index 2ba0ce1..1c61639 100644 (file)
@@ -1906,9 +1906,6 @@ static int nicvf_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return nicvf_xdp_setup(nic, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = nic->xdp_prog ? nic->xdp_prog->aux->id : 0;
-               return 0;
        default:
                return -EINVAL;
        }
index 9b4028c..17f6bca 100644 (file)
@@ -2077,14 +2077,9 @@ out_err:
 
 static int dpaa2_eth_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
-       struct dpaa2_eth_priv *priv = netdev_priv(dev);
-
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return setup_xdp(dev, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = priv->xdp_prog ? priv->xdp_prog->aux->id : 0;
-               break;
        default:
                return -EINVAL;
        }
index dadbfb3..d831581 100644 (file)
@@ -12923,9 +12923,6 @@ static int i40e_xdp(struct net_device *dev,
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return i40e_xdp_setup(vsi, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
-               return 0;
        case XDP_SETUP_XSK_UMEM:
                return i40e_xsk_umem_setup(vsi, xdp->xsk.umem,
                                           xdp->xsk.queue_id);
index 16a4096..231f4b6 100644 (file)
@@ -2292,9 +2292,6 @@ static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
-               return 0;
        case XDP_SETUP_XSK_UMEM:
                return ice_xsk_umem_setup(vsi, xdp->xsk.umem,
                                          xdp->xsk.queue_id);
index 4d898ff..6f32b17 100644 (file)
@@ -10190,10 +10190,6 @@ static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return ixgbe_xdp_setup(dev, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = adapter->xdp_prog ?
-                       adapter->xdp_prog->aux->id : 0;
-               return 0;
        case XDP_SETUP_XSK_UMEM:
                return ixgbe_xsk_umem_setup(adapter, xdp->xsk.umem,
                                            xdp->xsk.queue_id);
index 6e9a397..a626756 100644 (file)
@@ -4502,15 +4502,9 @@ static int ixgbevf_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
 
 static int ixgbevf_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
-       struct ixgbevf_adapter *adapter = netdev_priv(dev);
-
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return ixgbevf_xdp_setup(dev, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = adapter->xdp_prog ?
-                              adapter->xdp_prog->aux->id : 0;
-               return 0;
        default:
                return -EINVAL;
        }
index 2c9277e..6e3f9e2 100644 (file)
@@ -4442,14 +4442,9 @@ static int mvneta_xdp_setup(struct net_device *dev, struct bpf_prog *prog,
 
 static int mvneta_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
-       struct mvneta_port *pp = netdev_priv(dev);
-
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return mvneta_xdp_setup(dev, xdp->prog, xdp->extack);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = pp->xdp_prog ? pp->xdp_prog->aux->id : 0;
-               return 0;
        default:
                return -EINVAL;
        }
index 6a3f356..cd5e9d6 100644 (file)
@@ -4656,9 +4656,6 @@ static int mvpp2_xdp(struct net_device *dev, struct netdev_bpf *xdp)
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return mvpp2_xdp_setup(port, xdp);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = port->xdp_prog ? port->xdp_prog->aux->id : 0;
-               return 0;
        default:
                return -EINVAL;
        }
index 2b8608f..106513f 100644 (file)
@@ -2802,35 +2802,11 @@ unlock_out:
        return err;
 }
 
-static u32 mlx4_xdp_query(struct net_device *dev)
-{
-       struct mlx4_en_priv *priv = netdev_priv(dev);
-       struct mlx4_en_dev *mdev = priv->mdev;
-       const struct bpf_prog *xdp_prog;
-       u32 prog_id = 0;
-
-       if (!priv->tx_ring_num[TX_XDP])
-               return prog_id;
-
-       mutex_lock(&mdev->state_lock);
-       xdp_prog = rcu_dereference_protected(
-               priv->rx_ring[0]->xdp_prog,
-               lockdep_is_held(&mdev->state_lock));
-       if (xdp_prog)
-               prog_id = xdp_prog->aux->id;
-       mutex_unlock(&mdev->state_lock);
-
-       return prog_id;
-}
-
 static int mlx4_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return mlx4_xdp_set(dev, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = mlx4_xdp_query(dev);
-               return 0;
        default:
                return -EINVAL;
        }
index 9d5d8b2..aa4fb50 100644 (file)
@@ -4518,29 +4518,11 @@ unlock:
        return err;
 }
 
-static u32 mlx5e_xdp_query(struct net_device *dev)
-{
-       struct mlx5e_priv *priv = netdev_priv(dev);
-       const struct bpf_prog *xdp_prog;
-       u32 prog_id = 0;
-
-       mutex_lock(&priv->state_lock);
-       xdp_prog = priv->channels.params.xdp_prog;
-       if (xdp_prog)
-               prog_id = xdp_prog->aux->id;
-       mutex_unlock(&priv->state_lock);
-
-       return prog_id;
-}
-
 static int mlx5e_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return mlx5e_xdp_set(dev, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = mlx5e_xdp_query(dev);
-               return 0;
        case XDP_SETUP_XSK_UMEM:
                return mlx5e_xsk_setup_umem(dev, xdp->xsk.umem,
                                            xdp->xsk.queue_id);
index 4460887..39ee23e 100644 (file)
@@ -3614,10 +3614,6 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
                return nfp_net_xdp_setup_drv(nn, xdp);
        case XDP_SETUP_PROG_HW:
                return nfp_net_xdp_setup_hw(nn, xdp);
-       case XDP_QUERY_PROG:
-               return xdp_attachment_query(&nn->xdp, xdp);
-       case XDP_QUERY_PROG_HW:
-               return xdp_attachment_query(&nn->xdp_hw, xdp);
        default:
                return nfp_app_bpf(nn->app, nn, xdp);
        }
index b7d0b6c..f961f65 100644 (file)
@@ -1045,9 +1045,6 @@ int qede_xdp(struct net_device *dev, struct netdev_bpf *xdp)
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return qede_xdp_set(edev, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = edev->xdp_prog ? edev->xdp_prog->aux->id : 0;
-               return 0;
        default:
                return -EINVAL;
        }
index f16b4f2..d60acaa 100644 (file)
@@ -653,15 +653,10 @@ static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)
 static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
        struct efx_nic *efx = netdev_priv(dev);
-       struct bpf_prog *xdp_prog;
 
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return efx_xdp_setup_prog(efx, xdp->prog);
-       case XDP_QUERY_PROG:
-               xdp_prog = rtnl_dereference(efx->xdp_prog);
-               xdp->prog_id = xdp_prog ? xdp_prog->aux->id : 0;
-               return 0;
        default:
                return -EINVAL;
        }
index 0f366cc..25db667 100644 (file)
@@ -1811,9 +1811,6 @@ static int netsec_xdp(struct net_device *ndev, struct netdev_bpf *xdp)
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return netsec_xdp_setup(priv, xdp->prog, xdp->extack);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = priv->xdp_prog ? priv->xdp_prog->aux->id : 0;
-               return 0;
        default:
                return -EINVAL;
        }
index a399f36..d6d7a7d 100644 (file)
@@ -1286,9 +1286,6 @@ int cpsw_ndo_bpf(struct net_device *ndev, struct netdev_bpf *bpf)
        case XDP_SETUP_PROG:
                return cpsw_xdp_prog_setup(priv, bpf);
 
-       case XDP_QUERY_PROG:
-               return xdp_attachment_query(&priv->xdpi, bpf);
-
        default:
                return -EINVAL;
        }
index 8e41415..440486d 100644 (file)
@@ -163,16 +163,6 @@ int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog)
        return ret;
 }
 
-static u32 netvsc_xdp_query(struct netvsc_device *nvdev)
-{
-       struct bpf_prog *prog = netvsc_xdp_get(nvdev);
-
-       if (prog)
-               return prog->aux->id;
-
-       return 0;
-}
-
 int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
 {
        struct net_device_context *ndevctx = netdev_priv(dev);
@@ -182,12 +172,7 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
        int ret;
 
        if (!nvdev || nvdev->destroy) {
-               if (bpf->command == XDP_QUERY_PROG) {
-                       bpf->prog_id = 0;
-                       return 0; /* Query must always succeed */
-               } else {
-                       return -ENODEV;
-               }
+               return -ENODEV;
        }
 
        switch (bpf->command) {
@@ -208,10 +193,6 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)
 
                return ret;
 
-       case XDP_QUERY_PROG:
-               bpf->prog_id = netvsc_xdp_query(nvdev);
-               return 0;
-
        default:
                return -EINVAL;
        }
index 0b362b8..2e90512 100644 (file)
@@ -551,10 +551,6 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
        ASSERT_RTNL();
 
        switch (bpf->command) {
-       case XDP_QUERY_PROG:
-               return xdp_attachment_query(&ns->xdp, bpf);
-       case XDP_QUERY_PROG_HW:
-               return xdp_attachment_query(&ns->xdp_hw, bpf);
        case XDP_SETUP_PROG:
                err = nsim_setup_prog_checks(ns, bpf);
                if (err)
index d164052..284f709 100644 (file)
@@ -121,7 +121,7 @@ static inline void nsim_bpf_uninit(struct netdevsim *ns)
 
 static inline int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
 {
-       return bpf->command == XDP_QUERY_PROG ? 0 : -EOPNOTSUPP;
+       return -EOPNOTSUPP;
 }
 
 static inline int nsim_bpf_disable_tc(struct netdevsim *ns)
index 7adeb91..061bebe 100644 (file)
@@ -1184,26 +1184,11 @@ static int tun_xdp_set(struct net_device *dev, struct bpf_prog *prog,
        return 0;
 }
 
-static u32 tun_xdp_query(struct net_device *dev)
-{
-       struct tun_struct *tun = netdev_priv(dev);
-       const struct bpf_prog *xdp_prog;
-
-       xdp_prog = rtnl_dereference(tun->xdp_prog);
-       if (xdp_prog)
-               return xdp_prog->aux->id;
-
-       return 0;
-}
-
 static int tun_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return tun_xdp_set(dev, xdp->prog, xdp->extack);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = tun_xdp_query(dev);
-               return 0;
        default:
                return -EINVAL;
        }
index b594f03..e56cd56 100644 (file)
@@ -1198,26 +1198,11 @@ err:
        return err;
 }
 
-static u32 veth_xdp_query(struct net_device *dev)
-{
-       struct veth_priv *priv = netdev_priv(dev);
-       const struct bpf_prog *xdp_prog;
-
-       xdp_prog = priv->_xdp_prog;
-       if (xdp_prog)
-               return xdp_prog->aux->id;
-
-       return 0;
-}
-
 static int veth_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return veth_xdp_set(dev, xdp->prog, xdp->extack);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = veth_xdp_query(dev);
-               return 0;
        default:
                return -EINVAL;
        }
index ba38765..6fa8fe5 100644 (file)
@@ -2490,28 +2490,11 @@ err:
        return err;
 }
 
-static u32 virtnet_xdp_query(struct net_device *dev)
-{
-       struct virtnet_info *vi = netdev_priv(dev);
-       const struct bpf_prog *xdp_prog;
-       int i;
-
-       for (i = 0; i < vi->max_queue_pairs; i++) {
-               xdp_prog = rtnl_dereference(vi->rq[i].xdp_prog);
-               if (xdp_prog)
-                       return xdp_prog->aux->id;
-       }
-       return 0;
-}
-
 static int virtnet_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return virtnet_xdp_set(dev, xdp->prog, xdp->extack);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = virtnet_xdp_query(dev);
-               return 0;
        default:
                return -EINVAL;
        }
index a63e550..458be68 100644 (file)
@@ -1480,32 +1480,11 @@ static int xennet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
        return 0;
 }
 
-static u32 xennet_xdp_query(struct net_device *dev)
-{
-       unsigned int num_queues = dev->real_num_tx_queues;
-       struct netfront_info *np = netdev_priv(dev);
-       const struct bpf_prog *xdp_prog;
-       struct netfront_queue *queue;
-       unsigned int i;
-
-       for (i = 0; i < num_queues; ++i) {
-               queue = &np->queues[i];
-               xdp_prog = rtnl_dereference(queue->xdp_prog);
-               if (xdp_prog)
-                       return xdp_prog->aux->id;
-       }
-
-       return 0;
-}
-
 static int xennet_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 {
        switch (xdp->command) {
        case XDP_SETUP_PROG:
                return xennet_xdp_set(dev, xdp->prog, xdp->extack);
-       case XDP_QUERY_PROG:
-               xdp->prog_id = xennet_xdp_query(dev);
-               return 0;
        default:
                return -EINVAL;
        }
index 7d3c412..1046763 100644 (file)
@@ -876,8 +876,6 @@ enum bpf_netdev_command {
         */
        XDP_SETUP_PROG,
        XDP_SETUP_PROG_HW,
-       XDP_QUERY_PROG,
-       XDP_QUERY_PROG_HW,
        /* BPF program for offload callbacks, invoked at program load time. */
        BPF_OFFLOAD_MAP_ALLOC,
        BPF_OFFLOAD_MAP_FREE,
@@ -911,12 +909,6 @@ struct netdev_bpf {
                        struct bpf_prog *prog;
                        struct netlink_ext_ack *extack;
                };
-               /* XDP_QUERY_PROG, XDP_QUERY_PROG_HW */
-               struct {
-                       u32 prog_id;
-                       /* flags with which program was installed */
-                       u32 prog_flags;
-               };
                /* BPF_OFFLOAD_MAP_ALLOC, BPF_OFFLOAD_MAP_FREE */
                struct {
                        struct bpf_offloaded_map *offmap;
index dbe9c60..3814fb6 100644 (file)
@@ -240,8 +240,6 @@ struct xdp_attachment_info {
 };
 
 struct netdev_bpf;
-int xdp_attachment_query(struct xdp_attachment_info *info,
-                        struct netdev_bpf *bpf);
 bool xdp_attachment_flags_ok(struct xdp_attachment_info *info,
                             struct netdev_bpf *bpf);
 void xdp_attachment_setup(struct xdp_attachment_info *info,
index 82ce092..a2a5798 100644 (file)
@@ -5468,10 +5468,6 @@ static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp)
                }
                break;
 
-       case XDP_QUERY_PROG:
-               xdp->prog_id = old ? old->aux->id : 0;
-               break;
-
        default:
                ret = -EINVAL;
                break;
index 3c45f99..48aba93 100644 (file)
@@ -400,15 +400,6 @@ void __xdp_release_frame(void *data, struct xdp_mem_info *mem)
 }
 EXPORT_SYMBOL_GPL(__xdp_release_frame);
 
-int xdp_attachment_query(struct xdp_attachment_info *info,
-                        struct netdev_bpf *bpf)
-{
-       bpf->prog_id = info->prog ? info->prog->aux->id : 0;
-       bpf->prog_flags = info->prog ? info->flags : 0;
-       return 0;
-}
-EXPORT_SYMBOL_GPL(xdp_attachment_query);
-
 bool xdp_attachment_flags_ok(struct xdp_attachment_info *info,
                             struct netdev_bpf *bpf)
 {