xdp: don't make drivers report attachment mode
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 12 Jul 2018 03:36:39 +0000 (20:36 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 13 Jul 2018 18:26:35 +0000 (20:26 +0200)
prog_attached of struct netdev_bpf should have been superseded
by simply setting prog_id long time ago, but we kept it around
to allow offloading drivers to communicate attachment mode (drv
vs hw).  Subsequently drivers were also allowed to report back
attachment flags (prog_flags), and since nowadays only programs
attached will XDP_FLAGS_HW_MODE can get offloaded, we can tell
the attachment mode from the flags driver reports.  Remove
prog_attached member.

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>
15 files changed:
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
drivers/net/ethernet/cavium/thunder/nicvf_main.c
drivers/net/ethernet/intel/i40e/i40e_main.c
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
drivers/net/ethernet/intel/ixgbevf/ixgbevf_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/netdevsim/bpf.c
drivers/net/tun.c
drivers/net/virtio_net.c
include/linux/netdevice.h
net/core/dev.c
net/core/rtnetlink.c

index 1f0e872d06675878c059ab54980c177937630ef6..0584d07c8c33c53a972a64d37e79984e7eb95499 100644 (file)
@@ -219,7 +219,6 @@ int bnxt_xdp(struct net_device *dev, struct netdev_bpf *xdp)
                rc = bnxt_xdp_set(bp, xdp->prog);
                break;
        case XDP_QUERY_PROG:
-               xdp->prog_attached = !!bp->xdp_prog;
                xdp->prog_id = bp->xdp_prog ? bp->xdp_prog->aux->id : 0;
                rc = 0;
                break;
index 135766c4296b737c7ffbf34026d61e3f0cf9d13d..768f584f8392732b19d6e889ed456a3c6de8e809 100644 (file)
@@ -1848,7 +1848,6 @@ static int nicvf_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
        case XDP_SETUP_PROG:
                return nicvf_xdp_setup(nic, xdp->prog);
        case XDP_QUERY_PROG:
-               xdp->prog_attached = !!nic->xdp_prog;
                xdp->prog_id = nic->xdp_prog ? nic->xdp_prog->aux->id : 0;
                return 0;
        default:
index 426b0ccb1fc6c545bf4bac920c0026dd028b3dbf..51762428b40e6ef91e567c4f60c3459cae275402 100644 (file)
@@ -11841,7 +11841,6 @@ static int i40e_xdp(struct net_device *dev,
        case XDP_SETUP_PROG:
                return i40e_xdp_setup(vsi, xdp->prog);
        case XDP_QUERY_PROG:
-               xdp->prog_attached = i40e_enabled_xdp_vsi(vsi);
                xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
                return 0;
        default:
index a8e21becb61914ffc2dfbbc74f51351e0d6ff4f8..3862fea1c923d5895df109f169f3ba8538093550 100644 (file)
@@ -9966,7 +9966,6 @@ static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
        case XDP_SETUP_PROG:
                return ixgbe_xdp_setup(dev, xdp->prog);
        case XDP_QUERY_PROG:
-               xdp->prog_attached = !!(adapter->xdp_prog);
                xdp->prog_id = adapter->xdp_prog ?
                        adapter->xdp_prog->aux->id : 0;
                return 0;
index 59416eddd8402154280890a24a7023645b24abe9..d86446d202d5ed95826db225139b095d7c7a683c 100644 (file)
@@ -4462,7 +4462,6 @@ static int ixgbevf_xdp(struct net_device *dev, struct netdev_bpf *xdp)
        case XDP_SETUP_PROG:
                return ixgbevf_xdp_setup(dev, xdp->prog);
        case XDP_QUERY_PROG:
-               xdp->prog_attached = !!(adapter->xdp_prog);
                xdp->prog_id = adapter->xdp_prog ?
                               adapter->xdp_prog->aux->id : 0;
                return 0;
index 65eb06e017e401237842503bc3aabad3780c1a2e..6785661d1a72627d7cc6895359e0ece284577d96 100644 (file)
@@ -2926,7 +2926,6 @@ static int mlx4_xdp(struct net_device *dev, struct netdev_bpf *xdp)
                return mlx4_xdp_set(dev, xdp->prog);
        case XDP_QUERY_PROG:
                xdp->prog_id = mlx4_xdp_query(dev);
-               xdp->prog_attached = !!xdp->prog_id;
                return 0;
        default:
                return -EINVAL;
index bbd2fd0b2e064126e947991ba07a024ebd1a1cb6..e4a9a0768a815946d652c4d31d35a6364319d452 100644 (file)
@@ -4192,7 +4192,6 @@ static int mlx5e_xdp(struct net_device *dev, struct netdev_bpf *xdp)
                return mlx5e_xdp_set(dev, xdp->prog);
        case XDP_QUERY_PROG:
                xdp->prog_id = mlx5e_xdp_query(dev);
-               xdp->prog_attached = !!xdp->prog_id;
                return 0;
        default:
                return -EINVAL;
index 7df5ca37bfb8b97f4435f41a1a8affbc1cef68f9..d207145986137aa17968c9bda56bee71f5ce03fe 100644 (file)
@@ -3459,9 +3459,6 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
                return nfp_net_xdp_setup(nn, xdp->prog, xdp->flags,
                                         xdp->extack);
        case XDP_QUERY_PROG:
-               xdp->prog_attached = !!nn->xdp_prog;
-               if (nn->dp.bpf_offload_xdp)
-                       xdp->prog_attached = XDP_ATTACHED_HW;
                xdp->prog_id = nn->xdp_prog ? nn->xdp_prog->aux->id : 0;
                xdp->prog_flags = nn->xdp_prog ? nn->xdp_flags : 0;
                return 0;
index b823bfe2ea4d6a6851699ef225265dbd333b0143..f9a327c821eb608eae5743250bb0dbc55bb1fc2f 100644 (file)
@@ -1116,7 +1116,6 @@ int qede_xdp(struct net_device *dev, struct netdev_bpf *xdp)
        case XDP_SETUP_PROG:
                return qede_xdp_set(edev, xdp->prog);
        case XDP_QUERY_PROG:
-               xdp->prog_attached = !!edev->xdp_prog;
                xdp->prog_id = edev->xdp_prog ? edev->xdp_prog->aux->id : 0;
                return 0;
        default:
index 75c25306d2347d34ee7f6847df1cd9e2dc866a40..712e6f918065f23154eff923de865c5f0762e8ee 100644 (file)
@@ -567,7 +567,6 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
                nsim_bpf_destroy_prog(bpf->offload.prog);
                return 0;
        case XDP_QUERY_PROG:
-               bpf->prog_attached = ns->xdp_prog_mode;
                bpf->prog_id = ns->xdp_prog ? ns->xdp_prog->aux->id : 0;
                bpf->prog_flags = ns->xdp_prog ? ns->xdp_flags : 0;
                return 0;
index a192a017cc68878360505b93df151de3d0b9b730..49a50219d0da528ae79b5812529fe7ea1ce1300e 100644 (file)
@@ -1268,7 +1268,6 @@ static int tun_xdp(struct net_device *dev, struct netdev_bpf *xdp)
                return tun_xdp_set(dev, xdp->prog, xdp->extack);
        case XDP_QUERY_PROG:
                xdp->prog_id = tun_xdp_query(dev);
-               xdp->prog_attached = !!xdp->prog_id;
                return 0;
        default:
                return -EINVAL;
index 53085c63277b4ecfa9d8651543bfb5e545fa73ee..2ff08bc103a9df8c114632ae6887226ec2dd24b6 100644 (file)
@@ -2343,7 +2343,6 @@ static int virtnet_xdp(struct net_device *dev, struct netdev_bpf *xdp)
                return virtnet_xdp_set(dev, xdp->prog, xdp->extack);
        case XDP_QUERY_PROG:
                xdp->prog_id = virtnet_xdp_query(dev);
-               xdp->prog_attached = !!xdp->prog_id;
                return 0;
        default:
                return -EINVAL;
index b683971e500d9e40f4a09b21a45b96d1c64b886b..69a664789b332496684d48e158c4582295cee9d1 100644 (file)
@@ -819,10 +819,6 @@ enum bpf_netdev_command {
         */
        XDP_SETUP_PROG,
        XDP_SETUP_PROG_HW,
-       /* Check if a bpf program is set on the device.  The callee should
-        * set @prog_attached to one of XDP_ATTACHED_* values, note that "true"
-        * is equivalent to XDP_ATTACHED_DRV.
-        */
        XDP_QUERY_PROG,
        /* BPF program for offload callbacks, invoked at program load time. */
        BPF_OFFLOAD_VERIFIER_PREP,
@@ -849,7 +845,6 @@ struct netdev_bpf {
                };
                /* XDP_QUERY_PROG */
                struct {
-                       u8 prog_attached;
                        u32 prog_id;
                        /* flags with which program was installed */
                        u32 prog_flags;
index 89825c1eccdcd56de91f76d09e3b67f9c7e58367..9fa3b3705a8e391b1ac063c92a047c73d6caf193 100644 (file)
@@ -4926,7 +4926,6 @@ static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp)
                break;
 
        case XDP_QUERY_PROG:
-               xdp->prog_attached = !!old;
                xdp->prog_id = old ? old->aux->id : 0;
                break;
 
@@ -7593,13 +7592,13 @@ void __dev_xdp_query(struct net_device *dev, bpf_op_t bpf_op,
        WARN_ON(bpf_op(dev, xdp) < 0);
 }
 
-static u8 __dev_xdp_attached(struct net_device *dev, bpf_op_t bpf_op)
+static bool __dev_xdp_attached(struct net_device *dev, bpf_op_t bpf_op)
 {
        struct netdev_bpf xdp;
 
        __dev_xdp_query(dev, bpf_op, &xdp);
 
-       return xdp.prog_attached;
+       return xdp.prog_id;
 }
 
 static int dev_xdp_install(struct net_device *dev, bpf_op_t bpf_op,
@@ -7634,7 +7633,7 @@ static void dev_xdp_uninstall(struct net_device *dev)
                return;
 
        __dev_xdp_query(dev, ndo_bpf, &xdp);
-       if (xdp.prog_attached == XDP_ATTACHED_NONE)
+       if (!xdp.prog_id)
                return;
 
        /* Program removal should always succeed */
index b40242459907d2a456b4cde3a5b3438deee8869f..02ebc056a68843daa6bf93b1d9c6270142687b7f 100644 (file)
@@ -1372,9 +1372,13 @@ static u8 rtnl_xdp_attached_mode(struct net_device *dev, u32 *prog_id)
                return XDP_ATTACHED_NONE;
 
        __dev_xdp_query(dev, ops->ndo_bpf, &xdp);
-       *prog_id = xdp.prog_id;
+       if (!xdp.prog_id)
+               return XDP_ATTACHED_NONE;
 
-       return xdp.prog_attached;
+       *prog_id = xdp.prog_id;
+       if (xdp.prog_flags & XDP_FLAGS_HW_MODE)
+               return XDP_ATTACHED_HW;
+       return XDP_ATTACHED_DRV;
 }
 
 static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)