net: xdp: refactor XDP program queries
Subsystems (17)
v3 cover net: xdp: refactor XDP program queries
Here's yet another attempt tomove the XDP_QUERY_PROG{,_HW} code out from the drivers to generic netdev code.
I took a bit different approach with the v3. In this revision I introduced to a new netdev_xdp structure that tracks the XDP programs, and instead of sharing the xdp_prog member between DRV and SKB (again, they mutual exclusive). With this, there's no need for a special "what-mode-am-I-in" flag for SKB/DRV.
Jakub, what's your thoughts on the special handling of XDP offloading? Maybe it's just overkill? Just allocate space for the offloaded program regardless support or not? Also, please review the dev_xdp_support_offload() addition into the nfp code.
The last two patches move the attach flag checks to generic code, and removes the flags member from netdev_bpf.
Please refer to the individual commit messages for more details.
The series passes test_offload.py from selftests. Thanks to Jakub for pointing this out.
Thanks,
Björn
Björn Töpel (5):
net: xdp: refactor XDP_QUERY_PROG{,_HW} to netdev nfp, netdevsim: use dev_xdp_support_offload() function
net: xdp: remove XDP_QUERY_PROG{,_HW}
net: xdp: refactor XDP flags checking
net: xdp: remove xdp_attachment_flags_ok() and flags member
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 4 - .../net/ethernet/cavium/thunder/nicvf_main.c | 3 - .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 3 - drivers/net/ethernet/intel/i40e/i40e_main.c | 3 - drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 4 - .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 4 - .../net/ethernet/mellanox/mlx4/en_netdev.c | 24 --- .../net/ethernet/mellanox/mlx5/core/en_main.c | 18 -- .../ethernet/netronome/nfp/nfp_net_common.c | 10 - .../net/ethernet/netronome/nfp/nfp_net_main.c | 7 + .../net/ethernet/qlogic/qede/qede_filter.c | 3 - drivers/net/netdevsim/bpf.c | 7 - drivers/net/netdevsim/netdev.c | 4 + drivers/net/netdevsim/netdevsim.h | 2 +- drivers/net/tun.c | 15 -- drivers/net/veth.c | 15 -- drivers/net/virtio_net.c | 17 -- include/linux/netdevice.h | 30 +-- include/net/xdp.h | 5 - net/core/dev.c | 172 ++++++++++++------ net/core/rtnetlink.c | 31 +--- net/core/xdp.c | 22 --- 22 files changed, 147 insertions(+), 256 deletions(-)
Signature · 1 line
2.20.1
PATCH v3 1/5 net: xdp: refactor XDP_QUERY_PROG{,_HW} to netdev
From: Björn Töpel <[email protected]>
All XDP capable drivers need to implement the XDP_QUERY_PROG{,_HW} command of ndo_bpf. This commit refactors the query code up from the drivers to the netdev level.
The xdp_prog member of the struct net_device has evolved into a struct netdev_xdp. The new structure contains an array of XDP programs, which are allocated at run time. Each entry represents an XDP program for a certain mode (SKB, DRV or HW). Only netdevs that has announced support for XDP offload, using the new dev_xdp_support_offload() function, will allocate space for HW XDP programs. This means that that offloading capability can be checked in the generic path as well.
For simplicity, SKB and DRV XDP programs populate different entries, even though they cannot be enabled simultaneously.
--- include/linux/netdevice.h | 21 +++-- net/core/dev.c | 156 ++++++++++++++++++++++++++------------ net/core/rtnetlink.c | 31 +------- 3 files changed, 126 insertions(+), 82 deletions(-)
include/linux/netdevice.h +15 -6
@@ -903,6 +903,14 @@ struct netdev_bpf { }; }; +int dev_xdp_support_offload (struct net_device *dev); + +struct netdev_xdp { +struct bpf_prog __rcu **prog; +int num_progs; +bool explicit_mode; +}; + #ifdef CONFIG_XFRM_OFFLOAD struct xfrmdev_ops { int (*xdo_dev_state_add) (struct xfrm_state *x);
@@ -1921,7 +1929,7 @@ struct net_device {unsigned int num_rx_queues;unsigned int real_num_rx_queues; -struct bpf_prog __rcu *xdp_prog; +struct netdev_xdp xdp;unsigned long gro_flush_timeout;rx_handler_func_t __rcu *rx_handler;void __rcu *rx_handler_data;
@@ -2045,9 +2053,8 @@ struct net_device {static inline bool netif_elide_gro (const struct net_device *dev) { -if (!(dev->features &NETIF_F_GRO ) || dev->xdp_prog) -return true; -return false; +return !(dev->features &NETIF_F_GRO ) || + (dev->xdp.prog && dev->xdp.prog[0 ]); }#define NETDEV_ALIGN 32
@@ -3682,10 +3689,12 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, struct netdev_queue *txq, int *ret);typedef int (*bpf_op_t )(struct net_device *dev,struct netdev_bpf *bpf); +typedef u32 (*xdp_query_prog_t )(struct net_device *dev);int dev_change_xdp_fd (struct net_device *dev,struct netlink_ext_ack *extack,int fd,u32 flags); -u32 __dev_xdp_query (struct net_device *dev,bpf_op_t xdp_op, -enum bpf_netdev_command cmd); +u32 dev_xdp_query_generic (struct net_device *dev); +u32 dev_xdp_query_drv (struct net_device *dev); +u32 dev_xdp_query_hw (struct net_device *dev);int xdp_umem_query (struct net_device *dev,u16 queue_id);int __dev_forward_skb (struct net_device *dev,struct sk_buff *skb);
net/core/dev.c +107 -49
252 lines not on this page · raw message
net/core/rtnetlink.c +4 -27
@@ -1360,32 +1360,9 @@ static int rtnl_fill_link_ifmap(struct sk_buff *skb, struct net_device *dev)return 0 ; } -static u32 rtnl_xdp_prog_skb (struct net_device *dev) -{ -const struct bpf_prog *generic_xdp_prog; - -ASSERT_RTNL (); - - generic_xdp_prog =rtnl_dereference (dev->xdp_prog); -if (!generic_xdp_prog) -return 0 ; -return generic_xdp_prog->aux->id; -} - -static u32 rtnl_xdp_prog_drv (struct net_device *dev) -{ -return __dev_xdp_query (dev, dev->netdev_ops->ndo_bpf,XDP_QUERY_PROG ); -} - -static u32 rtnl_xdp_prog_hw (struct net_device *dev) -{ -return __dev_xdp_query (dev, dev->netdev_ops->ndo_bpf, -XDP_QUERY_PROG_HW ); -} -static int rtnl_xdp_report_one (struct sk_buff *skb,struct net_device *dev,u32 *prog_id,u8 *mode,u8 tgt_mode,u32 attr, -u32 (*get_prog_id)(struct net_device *dev)) +xdp_query_prog_t get_prog_id) {u32 curr_id;int err;
@@ -1421,15 +1398,15 @@ static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev) prog_id =0 ; mode =XDP_ATTACHED_NONE ; err =rtnl_xdp_report_one (skb, dev, &prog_id, &mode,XDP_ATTACHED_SKB , -IFLA_XDP_SKB_PROG_ID , rtnl_xdp_prog_skb); +IFLA_XDP_SKB_PROG_ID , dev_xdp_query_generic);if (err) goto err_cancel; err =rtnl_xdp_report_one (skb, dev, &prog_id, &mode,XDP_ATTACHED_DRV , -IFLA_XDP_DRV_PROG_ID , rtnl_xdp_prog_drv); +IFLA_XDP_DRV_PROG_ID , dev_xdp_query_drv);if (err) goto err_cancel; err =rtnl_xdp_report_one (skb, dev, &prog_id, &mode,XDP_ATTACHED_HW , -IFLA_XDP_HW_PROG_ID , rtnl_xdp_prog_hw); +IFLA_XDP_HW_PROG_ID , dev_xdp_query_hw);if (err) goto err_cancel;
Signature · 1 line
2.20.1
PATCH v3 2/5 nfp, netdevsim: use dev_xdp_support_offload() function
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Make all drivers with XDP offloading support usedev_xdp_support_offload().
--- drivers/net/ethernet/netronome/nfp/nfp_net_main.c | 7 +++++++ drivers/net/netdevsim/netdev.c | 4 ++++ 2 files changed, 11 insertions(+)
drivers/net/ethernet/netronome/nfp/nfp_net_main.c +7 -0
@@ -135,6 +135,13 @@ nfp_net_pf_alloc_vnic(struct nfp_pf *pf, bool needs_netdev,nfp_net_free (nn);return ERR_PTR (err); } +if (nn->app && nn->app->type->xdp_offload) { + err =dev_xdp_support_offload (nn->dp.netdev); +if (err) { +nfp_net_free (nn); +return ERR_PTR (err); + } + } } pf->num_vnics++;
drivers/net/netdevsim/netdev.c +4 -0
@@ -311,6 +311,10 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port)SET_NETDEV_DEV (dev, &ns->nsim_bus_dev->dev); dev->netdev_ops = &nsim_netdev_ops; + err =dev_xdp_support_offload (dev); +if (err) + goto err_free_netdev; +rtnl_lock (); err =nsim_bpf_init (ns);if (err)
Signature · 1 line
2.20.1
PATCH v3 3/5 net: xdp: remove XDP_QUERY_PROG{,_HW}
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Remove all use of XDP_QUERY_PROG{,_HW}, since it was moved to the generic code path.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 4 ---- .../net/ethernet/cavium/thunder/nicvf_main.c | 3 --- .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 3 --- drivers/net/ethernet/intel/i40e/i40e_main.c | 3 --- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 4 ---- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 4 ---- .../net/ethernet/mellanox/mlx4/en_netdev.c | 24 ------------------- .../net/ethernet/mellanox/mlx5/core/en_main.c | 18 -------------- .../ethernet/netronome/nfp/nfp_net_common.c | 4 ---- .../net/ethernet/qlogic/qede/qede_filter.c | 3 --- drivers/net/netdevsim/bpf.c | 4 ---- drivers/net/netdevsim/netdevsim.h | 2 +- drivers/net/tun.c | 15 ------------ drivers/net/veth.c | 15 ------------ drivers/net/virtio_net.c | 17 ------------- include/linux/netdevice.h | 8 ------- include/net/xdp.h | 2 -- net/core/dev.c | 5 ---- net/core/xdp.c | 9 ------- 19 files changed, 1 insertion(+), 146 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +0 -4
@@ -217,10 +217,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 ;
drivers/net/ethernet/cavium/thunder/nicvf_main.c +0 -3
@@ -1914,9 +1914,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 ; }
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +0 -3
@@ -1763,9 +1763,6 @@ static int dpaa2_eth_xdp(struct net_device *dev, struct netdev_bpf *xdp)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 ; }
drivers/net/ethernet/intel/i40e/i40e_main.c +0 -3
@@ -12302,9 +12302,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);
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +0 -4
@@ -10284,10 +10284,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);
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +0 -4
@@ -4485,10 +4485,6 @@ static int ixgbevf_xdp(struct net_device *dev, struct netdev_bpf *xdp)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 ; }
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +0 -24
@@ -2883,35 +2883,11 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog)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 ; }
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -18
@@ -4246,29 +4246,11 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog)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 ;default :return -EINVAL ; }
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +0 -4
@@ -3548,10 +3548,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); }
drivers/net/ethernet/qlogic/qede/qede_filter.c +0 -3
@@ -1118,9 +1118,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 ; }
drivers/net/netdevsim/bpf.c +0 -4
@@ -549,10 +549,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)
drivers/net/netdevsim/netdevsim.h +1 -1
@@ -108,7 +108,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)
drivers/net/tun.c +0 -15
@@ -1236,26 +1236,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 ; }
drivers/net/veth.c +0 -15
@@ -1097,26 +1097,11 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog,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 ; }
drivers/net/virtio_net.c +0 -17
@@ -2513,28 +2513,11 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,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 ; }
include/linux/netdevice.h +0 -8
@@ -864,8 +864,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,
@@ -885,12 +883,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;
include/net/xdp.h +0 -2
@@ -159,8 +159,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,
net/core/dev.c +0 -5
@@ -5156,11 +5156,6 @@ static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp)dev_disable_gro_hw (dev); }break ; - -case XDP_QUERY_PROG : - xdp->prog_id = old ? old->aux->id :0 ; -break ; -default : ret = -EINVAL ;break ;
net/core/xdp.c +0 -9
@@ -379,15 +379,6 @@ void xdp_return_buff(struct xdp_buff *xdp) }EXPORT_SYMBOL_GPL (xdp_return_buff); -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) {
Signature · 1 line
2.20.1
PATCH v3 4/5 net: xdp: refactor XDP flags checking
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Similar to query a driver for a loaded XDP program, each driver need to check the attachment flags when a program is loaded.
E.g., if an XDP program was loaded without explicit flags (fallback mode), it must be reloaded/removed without explicit flags.
This commit moves that check to generic code as well.
--- net/core/dev.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/core/dev.c +9 -1
@@ -8075,8 +8075,8 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,const struct net_device_ops *ops = dev->netdev_ops;xdp_query_prog_t query, check;struct bpf_prog *prog =NULL ; +bool offload, expl;bpf_op_t bpf_op; -bool offload;int err;ASSERT_RTNL ();
@@ -8124,6 +8124,14 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, } } + expl = dev->xdp.explicit_mode; +if (!offload &&query (dev) && !!expl ^ !!(flags &XDP_FLAGS_MODES )) { +NL_SET_ERR_MSG (extack,"program loaded with different flags" ); +if (prog) +bpf_prog_put (prog); +return -EBUSY ; + } + err =dev_xdp_install (dev, bpf_op, extack, flags, prog);if (err <0 && prog)bpf_prog_put (prog);
Signature · 1 line
2.20.1
PATCH v3 5/5 net: xdp: remove xdp_attachment_flags_ok() and flags member
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
The attachment flags check is done in the generic netdev code, so there is no need for this function anymore. Remove it and all uses of it.
Further; Passing flags from struct netdev_bpf when attaching an XDP program is no longer necessary, so let us remove that member.
--- drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 6 ------ drivers/net/netdevsim/bpf.c | 3 --- include/linux/netdevice.h | 1 - include/net/xdp.h | 3 --- net/core/dev.c | 1 - net/core/xdp.c | 13 ------------- 6 files changed, 27 deletions(-)
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +0 -6
@@ -3497,9 +3497,6 @@ static int nfp_net_xdp_setup_drv(struct nfp_net *nn, struct netdev_bpf *bpf)struct nfp_net_dp *dp;int err; -if (!xdp_attachment_flags_ok (&nn->xdp, bpf)) -return -EBUSY ; -if (!prog == !nn->dp.xdp_prog) {WRITE_ONCE (nn->dp.xdp_prog, prog);xdp_attachment_setup (&nn->xdp, bpf);
@@ -3528,9 +3525,6 @@ static int nfp_net_xdp_setup_hw(struct nfp_net *nn, struct netdev_bpf *bpf) {int err; -if (!xdp_attachment_flags_ok (&nn->xdp_hw, bpf)) -return -EBUSY ; - err =nfp_app_xdp_offload (nn->app, nn, bpf->prog, bpf->extack);if (err)return err;
drivers/net/netdevsim/bpf.c +0 -3
@@ -190,9 +190,6 @@ nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf, {int err; -if (!xdp_attachment_flags_ok (xdp, bpf)) -return -EBUSY ; -if (bpf->command ==XDP_SETUP_PROG && !ns->bpf_xdpdrv_accept) {NSIM_EA (bpf->extack,"driver XDP disabled in DebugFS" );return -EOPNOTSUPP ;
include/linux/netdevice.h +0 -1
@@ -879,7 +879,6 @@ struct netdev_bpf {union {/* XDP_SETUP_PROG */ struct { -u32 flags;struct bpf_prog *prog;struct netlink_ext_ack *extack; };
include/net/xdp.h +0 -3
@@ -155,12 +155,9 @@ xdp_data_meta_unsupported(const struct xdp_buff *xdp)struct xdp_attachment_info {struct bpf_prog *prog; -u32 flags; };struct netdev_bpf ; -bool xdp_attachment_flags_ok (struct xdp_attachment_info *info, -struct netdev_bpf *bpf);void xdp_attachment_setup (struct xdp_attachment_info *info,struct netdev_bpf *bpf);
net/core/dev.c +0 -1
@@ -8026,7 +8026,6 @@ static int dev_xdp_install(struct net_device *dev, bpf_op_t bpf_op, } xdp.extack = extack; - xdp.flags = flags; xdp.prog = prog; err =bpf_op (dev, &xdp);
net/core/xdp.c +0 -13
@@ -379,25 +379,12 @@ void xdp_return_buff(struct xdp_buff *xdp) }EXPORT_SYMBOL_GPL (xdp_return_buff); -bool xdp_attachment_flags_ok (struct xdp_attachment_info *info, -struct netdev_bpf *bpf) -{ -if (info->prog && (bpf->flags ^ info->flags) &XDP_FLAGS_MODES ) { -NL_SET_ERR_MSG (bpf->extack, -"program loaded with different flags" ); -return false; - } -return true; -} -EXPORT_SYMBOL_GPL (xdp_attachment_flags_ok); -void xdp_attachment_setup (struct xdp_attachment_info *info,struct netdev_bpf *bpf) {if (info->prog)bpf_prog_put (info->prog); info->prog = bpf->prog; - info->flags = bpf->flags; }EXPORT_SYMBOL_GPL (xdp_attachment_setup);
Signature · 1 line
2.20.1
Quoted 4 lines · Björn Töpel
Jakub, what's your thoughts on the special handling of XDP offloading? Maybe it's just overkill? Just allocate space for the offloaded program regardless support or not? Also, please review the
dev_xdp_support_offload()addition into the nfp code.
I'm not a huge fan of the new approach - it adds a conditional move, dereference and a cache line reference to the fast path :(
I think it'd be fine to allocate entries for all 3 types, but the potential of slowing down DRV may not be a good thing in a refactoring series.
Quoted 6 lines · Jakub Kicinski
Quoted 4 lines · Björn Töpel
Jakub, what's your thoughts on the special handling of XDP offloading? Maybe it's just overkill? Just allocate space for the offloaded program regardless support or not? Also, please review the
dev_xdp_support_offload()addition into the nfp code.
Quoted 7 lines
I'm not a huge fan of the new approach - it adds a conditional move, dereference and a cache line reference to the fast path :(
I think it'd be fine to allocate entries for all 3 types, but the potential of slowing down DRV may not be a good thing in a refactoring series.
Note, that currently it's "only" the XDP_SKB path that's affected, but yeah, I agree with out. And going forward, I'd like to use the netdev xdp_prog from the Intel drivers, instead of spreading/caching it all over.
I'll go back to the drawing board. Any suggestions on a how/where the program should be stored in the netdev are welcome! :-) ...or maybe just simply store the netdev_xdp flat (w/o the additional allocation step) in net_device. Three programs and the boolean (remove the num_progs).
Björn
Quoted 15 lines · Björn Töpel
Quoted 6 lines · Jakub Kicinski
Quoted 4 lines · Björn Töpel
Jakub, what's your thoughts on the special handling of XDP offloading? Maybe it's just overkill? Just allocate space for the offloaded program regardless support or not? Also, please review the
dev_xdp_support_offload()addition into the nfp code.Quoted 7 lines
I'm not a huge fan of the new approach - it adds a conditional move, dereference and a cache line reference to the fast path :(
I think it'd be fine to allocate entries for all 3 types, but the potential of slowing down DRV may not be a good thing in a refactoring series.
Quoted 8 lines
Note, that currently it's "only" the
XDP_SKBpath that's affected, but yeah, I agree with out. And going forward, I'd like to use the netdevxdp_progfrom the Intel drivers, instead of spreading/caching it all over.I'll go back to the drawing board. Any suggestions on a how/where the program should be stored in the netdev are welcome! :-) ...or maybe just simply store the
netdev_xdpflat (w/o the additional allocation step) innet_device. Three programs and the boolean (remove thenum_progs).
This seems reasonable to me (and thanks for keeping at this!).
-Toke
Quoted 15 lines · Björn Töpel
Quoted 6 lines · Jakub Kicinski
Quoted 4 lines · Björn Töpel
Jakub, what's your thoughts on the special handling of XDP offloading? Maybe it's just overkill? Just allocate space for the offloaded program regardless support or not? Also, please review the
dev_xdp_support_offload()addition into the nfp code.Quoted 7 lines
I'm not a huge fan of the new approach - it adds a conditional move, dereference and a cache line reference to the fast path :(
I think it'd be fine to allocate entries for all 3 types, but the potential of slowing down DRV may not be a good thing in a refactoring series.
Quoted 8 lines
Note, that currently it's "only" the
XDP_SKBpath that's affected, but yeah, I agree with out. And going forward, I'd like to use the netdevxdp_progfrom the Intel drivers, instead of spreading/caching it all over.I'll go back to the drawing board. Any suggestions on a how/where the program should be stored in the netdev are welcome! :-) ...or maybe just simply store the
netdev_xdpflat (w/o the additional allocation step) innet_device. Three programs and the boolean (remove thenum_progs).
Three progs? Are we planning to allow SKB and DRV at the same time? One prog and flags looked fairly reasonable to me. Flags can even be a u8. The offload prog can continue to live in the driver.
Quoted 1 line · Jakub Kicinski
Three progs? Are we planning to allow SKB and DRV at the same time?
No! :-)
Quoted 2 lines
One prog and flags looked fairly reasonable to me. Flags can even be a u8. The offload prog can continue to live in the driver.
Ok, I'll take that route (only adding a u8 flags member to net_device).
Quoted 15 lines · Björn Töpel
Quoted 6 lines · Jakub Kicinski
Quoted 4 lines · Björn Töpel
Jakub, what's your thoughts on the special handling of XDP offloading? Maybe it's just overkill? Just allocate space for the offloaded program regardless support or not? Also, please review the
dev_xdp_support_offload()addition into the nfp code.Quoted 7 lines
I'm not a huge fan of the new approach - it adds a conditional move, dereference and a cache line reference to the fast path :(
I think it'd be fine to allocate entries for all 3 types, but the potential of slowing down DRV may not be a good thing in a refactoring series.
Quoted 8 lines
Note, that currently it's "only" the
XDP_SKBpath that's affected, but yeah, I agree with out. And going forward, I'd like to use the netdevxdp_progfrom the Intel drivers, instead of spreading/caching it all over.I'll go back to the drawing board. Any suggestions on a how/where the program should be stored in the netdev are welcome! :-) ...or maybe just simply store the
netdev_xdpflat (w/o the additional allocation step) innet_device. Three programs and the boolean (remove thenum_progs).
A flat allocation does seem like the best path forward.
Thanks for keeping at this!
Signature · 1 line
Jonathan