xdp: Infrastructure to generalize XDP
Subsystems (15)
v3 cover xdp: Infrastructure to generalize XDP
This patch set generalizes XDP by making the hooks in drivers to be generic. This has a number of advantages:
- Allows a means to pipeline XDP programs together
- Reduces the amount of code and complexity needed in drivers to manage XDP
- Provides a more structured environment that is extensible to new features while being mostly transparent to the drivers
- Allow XDP programs to be set per device or per queue
- Moves management of BPF programs out of driver into a common infrastructure
The generic XDP infrastructure is based on an xdp_hook structure that contains callback functions and private data structure that can be populated by the user of XDP. The XDP hooks are registered either on a netdev or a napi (both maintain a list of XDP hooks). Allowing per netdev hooks makes management of XDP a lot simpler when the intent is for the hook to apply to the whole device (as is the case with XDP_BPF so far). Multiple xdp hooks may be registered on a device or napi instance, the order of execution is indicated in the priority field of the xdp_hook structure. Execution of the list contains to the end or until a program returns something other than XDP_PASS. If both napi XDP hooks and device hooks are enabled, the NAPI hooks are run first.
The xdp_hook structure contains a "hookfn" field that is the function executes a hook. The "priv" structure is private data that is provided as an argument to hookfn-- in the case of a BPF hook this is simply the bpf_prog.
Hooks may be registered by xdp_register_dev_hook or xdp_register_napi_hook, and subsequently they can be unregistered but xdp_unregister_dev_hook and xdp_unregister_napi_hook. The identifier for a hook is the pointer to the template hook that was used to register the hook. xdp_find_dev_hook and xdp_find_napi_hook will return whether a hook has been registered and optionally return the contents of the hook. xdp_bpf_check_prog is to check if the driver is okay with running the program (uses the XDP_CHECK_BPF_PROG ndo command described below).
Driver interface:
Drivers no longer deal with BPF programs for the most part, instead they call into the XDP interface.
There are two functions of interest for use in the receive data path:
- xdp_hook_run_needed_check: returns true if there is an XDP program registered on the napi instance or its device
- xdp_hook_run, xdp_hook_run_ret_last: runs the XDP programs for the hooks registered for the given napi instance or its device. The latter variant returns a pointer to the last XDP hook that was run (useful for reporting).
The ndo_xdp defines a new set of commands for this interface. A driver should implement these commands:
- XDP_MODE_ON: Initialize device to use XDP. Called when first XDP program is registered on a device (including on a NAPI instance).
- XDP_MODE_OFF: XDP is finished on the device. Called after the last XDP hook has been unregistered for a device.
- XDP_CHECK_BPF_PROG: Check if a BPF program is acceptable to a device to run.
- XDP_OFFLOAD_BPF: Offload the associated BPF program (e.g. Netronome).
A new net feature is added NETIF_F_XDP so that a driver indicates that is supports XDP.
This patch set:
- Adds the infrastructure described above include xdp.c and xdp.h files.
- Modifies mlx4, mlx5, qede, nfp, and virt_net drivers to use the new interface. That is mostly removed the management of BPF programs and changing to call the new interface.
v2:
- Eliminate use of nfhooks like lists. Just use use simple array for the hooks
- Modify more drivers that now support XDP
v3:
- Don't allow non-BPF hooks to be set
Tested:
Tested XDP_DROP and XDP_TX on mlx5. No regression or other issues noted.
Testing other drviers is TBD.
Tom Herbert (8):
xdp: Infrastructure to generalize XDP
mlx4: Changes to use generic XDP infrastructure
nfp: Changes to use generic XDP infrastructure
qede: Changes to use generic XDP infrastructure
virt_net: Changes to use generic XDP infrastructure
mlx5: Changes to use generic XDP infrastructure
bnxt: Changes to use generic XDP infrastructure
xdp: Cleanup after API changes
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 14 - drivers/net/ethernet/broadcom/bnxt/bnxt.h | 2 +- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 46 ++-- drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 92 ++----- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 27 +- drivers/net/ethernet/mellanox/mlx4/en_tx.c | 1 + drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 1 - drivers/net/ethernet/mellanox/mlx5/core/en.h | 3 +- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 108 ++------ drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 12 +- drivers/net/ethernet/netronome/nfp/nfp_bpf_jit.c | 1 + drivers/net/ethernet/netronome/nfp/nfp_net.h | 5 +- .../net/ethernet/netronome/nfp/nfp_net_common.c | 170 ++++++------ .../net/ethernet/netronome/nfp/nfp_net_ethtool.c | 12 +- drivers/net/ethernet/qlogic/qede/qede.h | 3 +- drivers/net/ethernet/qlogic/qede/qede_ethtool.c | 2 +- drivers/net/ethernet/qlogic/qede/qede_filter.c | 39 ++- drivers/net/ethernet/qlogic/qede/qede_fp.c | 36 ++- drivers/net/ethernet/qlogic/qede/qede_main.c | 23 +- drivers/net/virtio_net.c | 99 +++---- include/linux/filter.h | 11 +- include/linux/netdev_features.h | 3 +- include/linux/netdevice.h | 27 +- include/net/xdp.h | 296 ++++++++++++++++++++ include/trace/events/xdp.h | 16 +- net/core/Makefile | 2 +- net/core/dev.c | 52 ++-- net/core/filter.c | 7 +- net/core/rtnetlink.c | 14 +- net/core/xdp.c | 306 +++++++++++++++++++++ 30 files changed, 934 insertions(+), 496 deletions(-) create mode 100644 include/net/xdp.h create mode 100644 net/core/xdp.c
Signature · 1 line
2.9.3
RFC PATCH v3 1/8 xdp: Infrastructure to generalize XDP
This patch creates an infrastructure for registering and running code at XDP hooks in drivers. This extends and generalizes the original XDP/BPF interface. It abstract out management and running of BPF programs out of drivers.
An XDP hook is defined by the xdp_hook structure. A pointer to this structure is passed into the XDP register function to set up a hook. The XDP register function mallocs its own xdp_hook structure and copies the values from the xdp_hook passed in. The register function also saves the pointer value of the xdp_hook argument; this pointer is used in subsequently calls to XDP to identify the registered hook.
The interface is defined in net/xdp.h. This includes the definition of xdp_hook, functions to register and unregister hooks on a device or individual instances of napi, and xdp_hook_run that is called by drivers to run the hooks.
--- drivers/net/ethernet/netronome/nfp/nfp_bpf_jit.c | 1 + include/linux/filter.h | 10 +- include/linux/netdev_features.h | 3 +- include/linux/netdevice.h | 16 ++ include/net/xdp.h | 296 ++++++++++++++++++++++ include/trace/events/xdp.h | 31 +++ kernel/bpf/core.c | 1 + net/core/Makefile | 2 +- net/core/dev.c | 52 ++-- net/core/filter.c | 1 + net/core/rtnetlink.c | 14 +- net/core/xdp.c | 306 +++++++++++++++++++++++ 12 files changed, 698 insertions(+), 35 deletions(-) create mode 100644 include/net/xdp.h create mode 100644 net/core/xdp.c
drivers/net/ethernet/netronome/nfp/nfp_bpf_jit.c +1 -0
@@ -38,6 +38,7 @@#include <linux/filter.h> #include <linux/pkt_cls.h> #include <linux/unistd.h> +#include <net/xdp.h> #include "nfp_asm.h" #include "nfp_bpf.h"
include/linux/filter.h +3 -7
@@ -434,7 +434,7 @@ struct sk_filter {struct bpf_prog *prog; }; -#define BPF_PROG_RUN (filter, ctx) (*filter->bpf_func)(ctx, filter->insnsi) +#define BPF_PROG_RUN (filter, ctx) (*(filter)->bpf_func)(ctx, (filter)->insnsi)#define BPF_SKB_CB_LEN QDISC_CB_PRIV_LEN
@@ -443,12 +443,6 @@ struct bpf_skb_data_end {void *data_end; }; -struct xdp_buff { -void *data; -void *data_end; -void *data_hard_start; -}; -/* compute the linear packet data range [data, data_end) which * will be accessed by cls_bpf, act_bpf and lwt programs */
@@ -510,6 +504,8 @@ static inline u32 bpf_prog_run_clear_cb(const struct bpf_prog *prog,return BPF_PROG_RUN (prog, skb); } +struct xdp_buff ; + static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog,struct xdp_buff *xdp) {
include/linux/netdev_features.h +2 -1
@@ -71,8 +71,8 @@ enum {NETIF_F_HW_VLAN_STAG_RX_BIT ,/* Receive VLAN STAG HW acceleration */ NETIF_F_HW_VLAN_STAG_FILTER_BIT ,/* Receive filtering on VLAN STAGs */ NETIF_F_HW_L2FW_DOFFLOAD_BIT ,/* Allow L2 Forwarding in Hardware */ -NETIF_F_HW_TC_BIT ,/* Offload TC infrastructure */ +NETIF_F_XDP_BIT ,/* Support XDP interface */ /* * Add your fresh new feature above and remember to update
@@ -134,6 +134,7 @@ enum {#define NETIF_F_HW_VLAN_STAG_TX __NETIF_F(HW_VLAN_STAG_TX)#define NETIF_F_HW_L2FW_DOFFLOAD __NETIF_F(HW_L2FW_DOFFLOAD)#define NETIF_F_HW_TC __NETIF_F(HW_TC) +#define NETIF_F_XDP __NETIF_F(XDP)#define for_each_netdev_feature (mask_addr, bit) \ for_each_set_bit(bit, (unsigned long *)mask_addr, NETDEV_FEATURE_COUNT)
include/linux/netdevice.h +16 -0
@@ -324,6 +324,7 @@ struct napi_struct {struct sk_buff *skb;struct hrtimer timer;struct list_head dev_list; +struct xdp_hook_set __rcu *xdp_hooks;struct hlist_node napi_hash_node;unsigned int napi_id; };
@@ -822,12 +823,25 @@ enum xdp_netdev_command {* return true if a program is currently attached and running. */ XDP_QUERY_PROG, +/* Initialize device to use XDP. Called when first XDP program is +* registered on a device (including on a NAPI instance). +*/ +XDP_MODE_ON , +/* XDP is finished on the device. Called after the last XDP hook +* has been removed from a device. +*/ +XDP_MODE_OFF , +/* Check if device is okay with the proposed BPF program to be loaded */ +XDP_CHECK_BPF_PROG , +/* Offload a BPF program to the device */ + XDP_OFFLOAD_BPF, };struct netdev_xdp {enum xdp_netdev_command command;union {/* XDP_SETUP_PROG */ +/* XDP_CHECK_BPF_PROG */ struct bpf_prog *prog;/* XDP_QUERY_PROG */ bool prog_attached;
@@ -1668,6 +1682,8 @@ struct net_device {struct list_head close_list;struct list_head ptype_all;struct list_head ptype_specific; +struct xdp_hook_set __rcu *xdp_hooks; +unsigned int xdp_hook_cnt;struct {struct list_head upper;
include/net/xdp.h new file +296 -0
296 lines not on this page · raw message
include/trace/events/xdp.h +31 -0
@@ -7,6 +7,7 @@#include <linux/netdevice.h> #include <linux/filter.h> #include <linux/tracepoint.h> +#include <net/xdp.h> #define __XDP_ACT_MAP (FN ) \ FN(ABORTED) \
@@ -48,6 +49,36 @@ TRACE_EVENT(xdp_exception, __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB)) ); +/* Temporary trace function. This will be renamed to xdp_exception after all +* the calling drivers have been patched. +*/ +TRACE_EVENT (xdp_hook_exception, + + TP_PROTO(const struct net_device *dev, + const struct xdp_hook *hook, u32 act), + +TP_ARGS (dev, hook, act), + +TP_STRUCT__entry ( + __string(name, dev->name) + __array(u8, prog_tag, 8) +__field (u32, act) + ), + +TP_fast_assign ( + BUILD_BUG_ON(sizeof(__entry->prog_tag) != + sizeof(hook->tag)); + memcpy(__entry->prog_tag, hook->tag, sizeof(hook->tag)); + __assign_str(name, dev->name); + __entry->act = act; + ), + +TP_printk ("prog=%s device=%s action=%s" , +__print_hex_str (__entry->prog_tag,8 ), +__get_str (name), +__print_symbolic (__entry->act, __XDP_ACT_SYM_TAB)) +); +#endif /* _TRACE_XDP_H */ #include <trace/define_trace.h>
kernel/bpf/core.c +1 -0
@@ -1412,6 +1412,7 @@ int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,#include <linux/bpf_trace.h> EXPORT_TRACEPOINT_SYMBOL_GPL (xdp_exception); +EXPORT_TRACEPOINT_SYMBOL_GPL (xdp_hook_exception);EXPORT_TRACEPOINT_SYMBOL_GPL (bpf_prog_get_type);EXPORT_TRACEPOINT_SYMBOL_GPL (bpf_prog_put_rcu);
net/core/Makefile +1 -1
@@ -9,7 +9,7 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o obj-y += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \ neighbour.o rtnetlink.o utils.o link_watch.o filter.o \ - sock_diag.o dev_ioctl.o tso.o sock_reuseport.o + sock_diag.o dev_ioctl.o tso.o sock_reuseport.o xdp.o obj-$(CONFIG_XFRM) += flow.o obj-y += net-sysfs.o
net/core/dev.c +35 -17
89 lines not on this page · raw message
net/core/filter.c +1 -0
@@ -52,6 +52,7 @@#include <net/dst_metadata.h> #include <net/dst.h> #include <net/sock_reuseport.h> +#include <net/xdp.h> /** * sk_filter_trim_cap - run a packet through a socket filter
net/core/rtnetlink.c +5 -9
@@ -56,6 +56,7 @@#include <net/fib_rules.h> #include <net/rtnetlink.h> #include <net/net_namespace.h> +#include <net/xdp.h> struct rtnl_link {rtnl_doit_func doit;
@@ -901,7 +902,7 @@ static size_t rtnl_xdp_size(const struct net_device *dev)size_t xdp_size =nla_total_size (0 ) +/* nest IFLA_XDP */ nla_total_size (1 );/* XDP_ATTACHED */ -if (!dev->netdev_ops->ndo_xdp) +if (!(dev->features &NETIF_F_XDP ))return 0 ;else return xdp_size;
@@ -1251,20 +1252,15 @@ static int rtnl_fill_link_ifmap(struct sk_buff *skb, struct net_device *dev)static int rtnl_xdp_fill (struct sk_buff *skb,struct net_device *dev) { -struct netdev_xdp xdp_op = {};struct nlattr *xdp;int err; -if (!dev->netdev_ops->ndo_xdp) -return 0 ; xdp =nla_nest_start (skb,IFLA_XDP );if (!xdp)return -EMSGSIZE ; - xdp_op.command =XDP_QUERY_PROG ; - err = dev->netdev_ops->ndo_xdp (dev, &xdp_op); -if (err) - goto err_cancel; - err =nla_put_u8 (skb,IFLA_XDP_ATTACHED , xdp_op.prog_attached); + + err =nla_put_u8 (skb,IFLA_XDP_ATTACHED , +xdp_find_dev_hook (dev, &xdp_bpf_hook,NULL ));if (err) goto err_cancel;
net/core/xdp.c new file +306 -0
306 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH v3 2/8 mlx4: Changes to use generic XDP infrastructure
In reply to Tom HerbertChange XDP program management functional interface to correspond to new XDP API.
--- drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 92 +++++--------------------- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 27 ++++---- drivers/net/ethernet/mellanox/mlx4/en_tx.c | 1 + drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 1 - 4 files changed, 29 insertions(+), 92 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +16 -76
@@ -42,6 +42,7 @@#include <net/busy_poll.h> #include <net/vxlan.h> #include <net/devlink.h> +#include <net/xdp.h> #include <linux/mlx4/driver.h> #include <linux/mlx4/device.h>
@@ -2199,8 +2200,7 @@ int mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,struct mlx4_en_port_profile *prof, bool carry_xdp_prog) { -struct bpf_prog *xdp_prog; -int i, t; + int t;mlx4_en_copy_priv (tmp, priv, prof);
@@ -2215,22 +2215,6 @@ int mlx4_en_try_alloc_resources(struct mlx4_en_priv *priv,return -ENOMEM ; } -/* All rx_rings has the same xdp_prog. Pick the first one. */ - xdp_prog =rcu_dereference_protected ( - priv->rx_ring[0 ]->xdp_prog, -lockdep_is_held (&priv->mdev->state_lock)); - -if (xdp_prog && carry_xdp_prog) { - xdp_prog =bpf_prog_add (xdp_prog, tmp->rx_ring_num); -if (IS_ERR (xdp_prog)) { -mlx4_en_free_resources (tmp); -return PTR_ERR (xdp_prog); - } -for (i =0 ; i < tmp->rx_ring_num; i++) -rcu_assign_pointer (tmp->rx_ring[i]->xdp_prog, - xdp_prog); - } -return 0 ; }
@@ -2717,42 +2701,20 @@ static int mlx4_en_set_tx_maxrate(struct net_device *dev, int queue_index, u32 mreturn err; } -static int mlx4_xdp_set (struct net_device *dev,struct bpf_prog *prog) +static int mlx4_xdp_init (struct net_device *dev,bool enable) {struct mlx4_en_priv *priv =netdev_priv (dev);struct mlx4_en_dev *mdev = priv->mdev;struct mlx4_en_port_profile new_prof; -struct bpf_prog *old_prog;struct mlx4_en_priv *tmp;int tx_changed =0 ; -int xdp_ring_num;int port_up =0 ; -int err; -int i; +int xdp_ring_num, err; - xdp_ring_num = prog ? priv->rx_ring_num :0 ; + xdp_ring_num = enable ?ALIGN (priv->rx_ring_num,MLX4_EN_NUM_UP ) :0 ; -/* No need to reconfigure buffers when simply swapping the -* program for a new one. -*/ -if (priv->tx_ring_num[TX_XDP ] == xdp_ring_num) { -if (prog) { - prog =bpf_prog_add (prog, priv->rx_ring_num -1 ); -if (IS_ERR (prog)) -return PTR_ERR (prog); - } -mutex_lock (&mdev->state_lock); -for (i =0 ; i < priv->rx_ring_num; i++) { - old_prog =rcu_dereference_protected ( - priv->rx_ring[i]->xdp_prog, -lockdep_is_held (&mdev->state_lock)); -rcu_assign_pointer (priv->rx_ring[i]->xdp_prog, prog); -if (old_prog) -bpf_prog_put (old_prog); - } -mutex_unlock (&mdev->state_lock); +if (priv->tx_ring_num[TX_XDP ] == xdp_ring_num)return 0 ; - }if (!mlx4_en_check_xdp_mtu (dev, dev->mtu))return -EOPNOTSUPP ;
@@ -2761,14 +2723,6 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog)if (!tmp)return -ENOMEM ; -if (prog) { - prog =bpf_prog_add (prog, priv->rx_ring_num -1 ); -if (IS_ERR (prog)) { - err =PTR_ERR (prog); - goto out; - } - } -mutex_lock (&mdev->state_lock);memcpy (&new_prof, priv->prof,sizeof (struct mlx4_en_port_profile )); new_prof.tx_ring_num[TX_XDP ] = xdp_ring_num;
@@ -2781,11 +2735,8 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog) } err =mlx4_en_try_alloc_resources (priv, tmp, &new_prof, false); -if (err) { -if (prog) -bpf_prog_sub (prog, priv->rx_ring_num -1 ); +if (err) goto unlock_out; - }if (priv->port_up) { port_up =1 ;
@@ -2796,15 +2747,6 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog)if (tx_changed)netif_set_real_num_tx_queues (dev, priv->tx_ring_num[TX ]); -for (i =0 ; i < priv->rx_ring_num; i++) { - old_prog =rcu_dereference_protected ( - priv->rx_ring[i]->xdp_prog, -lockdep_is_held (&mdev->state_lock)); -rcu_assign_pointer (priv->rx_ring[i]->xdp_prog, prog); -if (old_prog) -bpf_prog_put (old_prog); - } -if (port_up) { err =mlx4_en_start_port (dev);if (err) {
@@ -2816,26 +2758,24 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog) unlock_out:mutex_unlock (&mdev->state_lock); -out:kfree (tmp);return err; } -static bool mlx4_xdp_attached (struct net_device *dev) +static int mlx4_xdp_check_bpf (struct net_device *dev,struct bpf_prog *prog) { -struct mlx4_en_priv *priv =netdev_priv (dev); - -return !!priv->tx_ring_num[TX_XDP ]; +return 0 ; }static int mlx4_xdp (struct net_device *dev,struct netdev_xdp *xdp) {switch (xdp->command) { -case XDP_SETUP_PROG : -return mlx4_xdp_set (dev, xdp->prog); -case XDP_QUERY_PROG : - xdp->prog_attached =mlx4_xdp_attached (dev); -return 0 ; +case XDP_MODE_ON : +return mlx4_xdp_init (dev, true); +case XDP_MODE_OFF : +return mlx4_xdp_init (dev, false); +case XDP_CHECK_BPF_PROG : +return mlx4_xdp_check_bpf (dev, xdp->prog);default :return -EINVAL ; }
@@ -3335,7 +3275,7 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, dev->vlan_features = dev->hw_features; - dev->hw_features |=NETIF_F_RXCSUM |NETIF_F_RXHASH ; + dev->hw_features |=NETIF_F_RXCSUM |NETIF_F_RXHASH |NETIF_F_XDP ; dev->features = dev->hw_features |NETIF_F_HIGHDMA |NETIF_F_HW_VLAN_CTAG_TX |NETIF_F_HW_VLAN_CTAG_RX |NETIF_F_HW_VLAN_CTAG_FILTER ;
drivers/net/ethernet/mellanox/mlx4/en_rx.c +12 -15
@@ -43,6 +43,7 @@#include <linux/if_vlan.h> #include <linux/vmalloc.h> #include <linux/irq.h> +#include <net/xdp.h> #if IS_ENABLED (CONFIG_IPV6 )#include <net/ip6_checksum.h>
@@ -547,13 +548,7 @@ void mlx4_en_destroy_rx_ring(struct mlx4_en_priv *priv, {struct mlx4_en_dev *mdev = priv->mdev;struct mlx4_en_rx_ring *ring = *pring; -struct bpf_prog *old_prog; - old_prog =rcu_dereference_protected ( - ring->xdp_prog, -lockdep_is_held (&mdev->state_lock)); -if (old_prog) -bpf_prog_put (old_prog);mlx4_free_hwq_res (mdev->dev, &ring->wqres, size * stride +TXBB_SIZE );vfree (ring->rx_info); ring->rx_info =NULL ;
@@ -802,7 +797,6 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budstruct mlx4_en_rx_ring *ring = priv->rx_ring[cq->ring];struct mlx4_en_rx_alloc *frags;struct mlx4_en_rx_desc *rx_desc; -struct bpf_prog *xdp_prog;int doorbell_pending;struct sk_buff *skb;int index;
@@ -813,6 +807,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budint factor = priv->cqe_factor;u64 timestamp;bool l2_tunnel; +bool run_xdp;if (unlikely (!priv->port_up))return 0 ;
@@ -820,9 +815,9 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (unlikely (budget <=0 ))return polled; -/* Protect accesses to: ring->xdp_prog, priv->mac_hash list */ +/* Protect accesses to: XDP hooks, priv->mac_hash list */ rcu_read_lock (); - xdp_prog =rcu_dereference (ring->xdp_prog); + run_xdp =xdp_hook_run_needed_check (dev, &cq->napi); doorbell_pending =0 ;/* We assume a 1:1 mapping between CQEs and Rx descriptors, so Rx
@@ -895,13 +890,14 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud l2_tunnel = (dev->hw_enc_features &NETIF_F_RXCSUM ) && (cqe->vlan_my_qpn &cpu_to_be32 (MLX4_CQE_L2_TUNNEL )); -/* A bpf program gets first chance to drop the packet. It may +/* An xdp program gets first chance to drop the packet. It may * read bytes but not past the end of the frag. */ -if (xdp_prog) { +if (run_xdp) {struct xdp_buff xdp;dma_addr_t dma;void *orig_data; +struct xdp_hook *last_hook;u32 act; dma =be64_to_cpu (rx_desc->data[0 ].addr);
@@ -914,7 +910,8 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud xdp.data_end = xdp.data + length; orig_data = xdp.data; - act =bpf_prog_run_xdp (xdp_prog, &xdp); + act =xdp_hook_run_ret_last (&cq->napi, &xdp, + &last_hook);if (xdp.data != orig_data) { length = xdp.data_end - xdp.data;
@@ -930,12 +927,12 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud length, cq->ring, &doorbell_pending))) goto consumed; -trace_xdp_exception (dev, xdp_prog, act); +trace_xdp_hook_exception (dev, last_hook, act); goto xdp_drop_no_cnt;/* Drop on xmit failure */ default : -bpf_warn_invalid_xdp_action (act); +xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_exception (dev, xdp_prog, act); +trace_xdp_hook_exception (dev, last_hook, act);case XDP_DROP : ring->xdp_drop++; xdp_drop_no_cnt:
drivers/net/ethernet/mellanox/mlx4/en_tx.c +1 -0
@@ -43,6 +43,7 @@#include <linux/ip.h> #include <linux/ipv6.h> #include <linux/moduleparam.h> +#include <net/xdp.h> #include "mlx4_en.h"
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +0 -1
@@ -348,7 +348,6 @@ struct mlx4_en_rx_ring {u8 fcs_del;void *buf;void *rx_info; -struct bpf_prog __rcu *xdp_prog;struct mlx4_en_page_cache page_cache;unsigned long bytes;unsigned long packets;
Signature · 1 line
2.9.3
RFC PATCH v3 3/8 nfp: Changes to use generic XDP infrastructure
In reply to Tom HerbertChange XDP program management functional interface to correspond to new XDP API.
--- drivers/net/ethernet/netronome/nfp/nfp_net.h | 5 +- .../net/ethernet/netronome/nfp/nfp_net_common.c | 172 ++++++++++----------- .../net/ethernet/netronome/nfp/nfp_net_ethtool.c | 12 +- 3 files changed, 87 insertions(+), 102 deletions(-)
drivers/net/ethernet/netronome/nfp/nfp_net.h +2 -3
@@ -503,14 +503,13 @@ struct nfp_net { unsigned is_vf:1; unsigned bpf_offload_skip_sw:1; unsigned bpf_offload_xdp:1; + unsigned xdp_enabled:1;u32 ctrl;u32 fl_bufsz;u32 rx_offset; -struct bpf_prog *xdp_prog; -struct nfp_net_tx_ring *tx_rings;struct nfp_net_rx_ring *rx_rings;
@@ -788,7 +787,7 @@ void nfp_net_irqs_assign(struct nfp_net *nn, struct msix_entry *irq_entries, unsigned int n);int -nfp_net_ring_reconfig (struct nfp_net *nn,struct bpf_prog **xdp_prog, +nfp_net_ring_reconfig (struct nfp_net *nn,struct nfp_net_ring_set *rx,struct nfp_net_ring_set *tx);#ifdef CONFIG_NFP_DEBUG
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +80 -92
441 lines not on this page · raw message
drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c +5 -7
@@ -201,8 +201,7 @@ static int nfp_net_set_ring_size(struct nfp_net *nn, u32 rxd_cnt, u32 txd_cnt)if (nn->txd_cnt != txd_cnt) reconfig_tx = &tx; -return nfp_net_ring_reconfig (nn, &nn->xdp_prog, - reconfig_rx, reconfig_tx); +return nfp_net_ring_reconfig (nn, reconfig_rx, reconfig_tx); } static int nfp_net_set_ringparam(struct net_device *netdev,
@@ -737,7 +736,7 @@ static void nfp_net_get_channels(struct net_device *netdev,unsigned int num_tx_rings; num_tx_rings = nn->num_tx_rings; -if (nn->xdp_prog) +if (nn->xdp_enabled) num_tx_rings -= nn->num_rx_rings; channel->max_rx =min (nn->max_rx_rings, nn->max_r_vecs);
@@ -767,15 +766,14 @@ static int nfp_net_set_num_rings(struct nfp_net *nn, unsigned int total_rx,if (nn->num_rx_rings != total_rx) reconfig_rx = ℞if (nn->num_stack_tx_rings != total_tx || - (nn->xdp_prog && reconfig_rx)) + (nn->xdp_enabled && reconfig_rx)) reconfig_tx = &tx;/* nfp_net_check_config() will catch tx.n_rings > nn->max_tx_rings */ -if (nn->xdp_prog) +if (nn->xdp_enabled) tx.n_rings += total_rx; -return nfp_net_ring_reconfig (nn, &nn->xdp_prog, - reconfig_rx, reconfig_tx); +return nfp_net_ring_reconfig (nn, reconfig_rx, reconfig_tx); } static int nfp_net_set_channels(struct net_device *netdev,
Signature · 1 line
2.9.3
RFC PATCH v3 4/8 qede: Changes to use generic XDP infrastructure
In reply to Tom HerbertChange XDP program management functional interface to correspond to new XDP API.
--- drivers/net/ethernet/qlogic/qede/qede.h | 3 +- drivers/net/ethernet/qlogic/qede/qede_ethtool.c | 2 +- drivers/net/ethernet/qlogic/qede/qede_filter.c | 39 ++++++++++--------------- drivers/net/ethernet/qlogic/qede/qede_fp.c | 36 +++++++++++++---------- drivers/net/ethernet/qlogic/qede/qede_main.c | 23 ++++----------- 5 files changed, 45 insertions(+), 58 deletions(-)
drivers/net/ethernet/qlogic/qede/qede.h +1 -2
@@ -217,10 +217,9 @@ struct qede_dev {u16 geneve_dst_port;bool wol_enabled; +bool xdp_enabled;struct qede_rdma_dev rdma_info; - -struct bpf_prog *xdp_prog; };enum QEDE_STATE {
drivers/net/ethernet/qlogic/qede/qede_ethtool.c +1 -1
@@ -342,7 +342,7 @@ static int qede_get_sset_count(struct net_device *dev, int stringset) num_stats +=QEDE_RSS_COUNT (edev) *QEDE_NUM_RQSTATS ;/* Account for XDP statistics [if needed] */ -if (edev->xdp_prog) +if (edev->xdp_enabled) num_stats +=QEDE_RSS_COUNT (edev) *QEDE_NUM_TQSTATS ;return num_stats;
drivers/net/ethernet/qlogic/qede/qede_filter.c +16 -23
@@ -426,7 +426,7 @@ int qede_set_features(struct net_device *dev, netdev_features_t features)* aggregations, so no need to actually reload. */ __qede_lock (edev); -if (edev->xdp_prog) +if (edev->xdp_enabled) args.func (edev, &args);else qede_reload (edev, &args, true);
@@ -506,29 +506,21 @@ void qede_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)schedule_delayed_work (&edev->sp_task,0 ); } -static void qede_xdp_reload_func (struct qede_dev *edev, -struct qede_reload_args *args) +static int qede_xdp_check_bpf (struct qede_dev *edev,struct bpf_prog *prog) { -struct bpf_prog *old; - - old =xchg (&edev->xdp_prog, args->u.new_prog); -if (old) -bpf_prog_put (old); -} - -static int qede_xdp_set (struct qede_dev *edev,struct bpf_prog *prog) -{ -struct qede_reload_args args; -if (prog && prog->xdp_adjust_head) {DP_ERR (edev,"Does not support bpf_xdp_adjust_head()\n" );return -EOPNOTSUPP ; } -/* If we're called, there was already a bpf reference increment */ - args.func = &qede_xdp_reload_func; - args.u.new_prog = prog; -qede_reload (edev, &args, false); +return 0 ; +} + +static int qede_xdp_init (struct qede_dev *edev,bool enable) +{ + edev->xdp_enabled = enable; + +qede_reload (edev,NULL , false);return 0 ; }
@@ -538,11 +530,12 @@ int qede_xdp(struct net_device *dev, struct netdev_xdp *xdp)struct qede_dev *edev =netdev_priv (dev);switch (xdp->command) { -case XDP_SETUP_PROG : -return qede_xdp_set (edev, xdp->prog); -case XDP_QUERY_PROG : - xdp->prog_attached = !!edev->xdp_prog; -return 0 ; +case XDP_MODE_OFF : +return qede_xdp_init (edev, true); +case XDP_MODE_ON : +return qede_xdp_init (edev, false); +case XDP_CHECK_BPF_PROG : +return qede_xdp_check_bpf (edev, xdp->prog);default :return -EINVAL ; }
drivers/net/ethernet/qlogic/qede/qede_fp.c +21 -15
@@ -41,6 +41,7 @@#include <linux/if_vlan.h> #include <net/ip6_checksum.h> #include "qede_ptp.h" +#include <net/xdp.h> #include <linux/qed/qed_if.h> #include "qede.h"
@@ -988,13 +989,14 @@ static bool qede_pkt_is_ip_fragmented(struct eth_fast_path_rx_reg_cqe *cqe,static bool qede_rx_xdp (struct qede_dev *edev,struct qede_fastpath *fp,struct qede_rx_queue *rxq, -struct bpf_prog *prog,struct sw_rx_data *bd,struct eth_fast_path_rx_reg_cqe *cqe) {u16 len =le16_to_cpu (cqe->len_on_first_bd);struct xdp_buff xdp;enum xdp_action act; +struct xdp_hook *last_hook; +bool retval = false; xdp.data =page_address (bd->data) + cqe->placement_offset; xdp.data_end = xdp.data + len;
@@ -1004,11 +1006,13 @@ static bool qede_rx_xdp(struct qede_dev *edev,* side for map helpers. */ rcu_read_lock (); - act =bpf_prog_run_xdp (prog, &xdp); -rcu_read_unlock (); -if (act ==XDP_PASS ) -return true; + act =xdp_hook_run_ret_last (&fp->napi, &xdp, &last_hook); + +if (act ==XDP_PASS ) { + retval = true; + goto out; + }/* Count number of packets not to be passed to stack */ rxq->xdp_no_pass++;
@@ -1018,8 +1022,8 @@ static bool qede_rx_xdp(struct qede_dev *edev,/* We need the replacement buffer before transmit. */ if (qede_alloc_rx_buffer (rxq, true)) {qede_recycle_rx_bd_ring (rxq,1 ); -trace_xdp_exception (edev->ndev, prog, act); -return false; +trace_xdp_hook_exception (edev->ndev, last_hook, act); + goto out; }/* Now if there's a transmission problem, we'd still have to
@@ -1029,22 +1033,25 @@ static bool qede_rx_xdp(struct qede_dev *edev,dma_unmap_page (rxq->dev, bd->mapping,PAGE_SIZE ,DMA_BIDIRECTIONAL );__free_page (bd->data); -trace_xdp_exception (edev->ndev, prog, act); +trace_xdp_hook_exception (edev->ndev, last_hook, act); }/* Regardless, we've consumed an Rx BD */ qede_rx_bd_ring_consume (rxq); -return false; + goto out;default : -bpf_warn_invalid_xdp_action (act); +xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_exception (edev->ndev, prog, act); +trace_xdp_hook_exception (edev->ndev, last_hook, act);case XDP_DROP :qede_recycle_rx_bd_ring (rxq, cqe->bd_num); } -return false; +out: +rcu_read_unlock (); + +return retval; } static struct sk_buff *qede_rx_allocate_skb(struct qede_dev *edev,
@@ -1189,7 +1196,6 @@ static int qede_rx_process_cqe(struct qede_dev *edev,struct qede_fastpath *fp, struct qede_rx_queue *rxq) { - struct bpf_prog *xdp_prog = READ_ONCE(rxq->xdp_prog); struct eth_fast_path_rx_reg_cqe *fp_cqe;u16 len, pad, bd_cons_idx, parse_flag;enum eth_rx_cqe_type cqe_type;
@@ -1227,8 +1233,8 @@ static int qede_rx_process_cqe(struct qede_dev *edev, pad = fp_cqe->placement_offset;/* Run eBPF program if one is attached */ -if (xdp_prog) -if (!qede_rx_xdp (edev, fp, rxq, xdp_prog, bd, fp_cqe)) +if (xdp_hook_run_needed_check (edev->ndev, &fp->napi)) +if (!qede_rx_xdp (edev, fp, rxq, bd, fp_cqe))return 1 ;/* If this is an error packet then drop it */
drivers/net/ethernet/qlogic/qede/qede_main.c +6 -17
@@ -581,7 +581,7 @@ static void qede_init_ndev(struct qede_dev *edev) {struct net_device *ndev = edev->ndev;struct pci_dev *pdev = edev->pdev; -u32 hw_features; +netdev_features_t hw_features;pci_set_drvdata (pdev, ndev);
@@ -601,7 +601,7 @@ static void qede_init_ndev(struct qede_dev *edev)/* user-changeble features */ hw_features =NETIF_F_GRO |NETIF_F_SG |NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM | -NETIF_F_TSO |NETIF_F_TSO6 ; +NETIF_F_TSO |NETIF_F_TSO6 |NETIF_F_XDP ;/* Encap features*/ hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
@@ -730,7 +730,7 @@ static int qede_alloc_fp_array(struct qede_dev *edev)if (!fp->rxq) goto err; -if (edev->xdp_prog) { +if (edev->xdp_enabled) { fp->xdp_tx =kzalloc (sizeof (*fp->xdp_tx),GFP_KERNEL );if (!fp->xdp_tx)
@@ -952,9 +952,7 @@ static void __qede_remove(struct pci_dev *pdev, enum qede_remove_mode mode)pci_set_drvdata (pdev,NULL ); -/* Release edev's reference to XDP's bpf if such exist */ -if (edev->xdp_prog) -bpf_prog_put (edev->xdp_prog); +free_netdev (ndev);/* Use global ops since we've freed edev */ qed_ops->common->slowpath_stop (cdev);
@@ -1114,7 +1112,7 @@ static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)int i;/* Don't perform FW aggregations in case of XDP */ -if (edev->xdp_prog) +if (edev->xdp_enabled) edev->gro_disable =1 ;if (edev->gro_disable)
@@ -1172,7 +1170,7 @@ static int qede_alloc_mem_rxq(struct qede_dev *edev, struct qede_rx_queue *rxq)/* Segment size to spilt a page in multiple equal parts, * unless XDP is used in which case we'd use the entire page. */ -if (!edev->xdp_prog) +if (!edev->xdp_enabled) rxq->rx_buf_seg_size =roundup_pow_of_two (rxq->rx_buf_size);else rxq->rx_buf_seg_size =PAGE_SIZE ;
@@ -1625,8 +1623,6 @@ static int qede_stop_queues(struct qede_dev *edev) rc =qede_stop_txq (edev, fp->xdp_tx, i);if (rc)return rc; - -bpf_prog_put (fp->rxq->xdp_prog); } }
@@ -1770,13 +1766,6 @@ static int qede_start_queues(struct qede_dev *edev, bool clear_stats) rc =qede_start_txq (edev, fp, fp->xdp_tx, i,XDP_PI );if (rc) goto out; - - fp->rxq->xdp_prog =bpf_prog_add (edev->xdp_prog,1 ); -if (IS_ERR (fp->rxq->xdp_prog)) { - rc =PTR_ERR (fp->rxq->xdp_prog); - fp->rxq->xdp_prog =NULL ; - goto out; - } }if (fp->type &QEDE_FASTPATH_TX ) {
Signature · 1 line
2.9.3
RFC PATCH v3 5/8 virt_net: Changes to use generic XDP infrastructure
In reply to Tom HerbertChange XDP program management functional interface to correspond to new XDP API.
--- drivers/net/virtio_net.c | 99 +++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 60 deletions(-)
drivers/net/virtio_net.c +39 -60
@@ -95,8 +95,6 @@ struct receive_queue {struct napi_struct napi; -struct bpf_prog __rcu *xdp_prog; -/* Chain pages by the private ptr. */ struct page *pages;
@@ -142,6 +140,9 @@ struct virtnet_info {/* Host can handle any s/g split between our header and packet data */ bool any_header_sg; +/* XDP has been enabled in device */ +bool xdp_enabled; +/* Packet virtio header size */ u8 hdr_len;
@@ -394,19 +395,19 @@ static struct sk_buff *receive_small(struct net_device *dev, void *buf, unsigned int len) {struct sk_buff *skb; -struct bpf_prog *xdp_prog;unsigned int xdp_headroom =virtnet_get_headroom (vi);unsigned int header_offset =VIRTNET_RX_PAD + xdp_headroom;unsigned int headroom = vi->hdr_len + header_offset;unsigned int buflen =SKB_DATA_ALIGN (GOOD_PACKET_LEN + headroom) +SKB_DATA_ALIGN (sizeof (struct skb_shared_info ));unsigned int delta =0 ; +struct xdp_hook *last_hook; + len -= vi->hdr_len;rcu_read_lock (); - xdp_prog =rcu_dereference (rq->xdp_prog); -if (xdp_prog) { -struct virtio_net_hdr_mrg_rxbuf *hdr = buf + header_offset; +if (xdp_hook_run_needed_check (dev, &rq->napi)) { +struct virtio_net_hdr_mrg_rxbuf *hdr = buf;struct xdp_buff xdp;void *orig_data;u32 act;
@@ -418,8 +419,7 @@ static struct sk_buff *receive_small(struct net_device *dev, xdp.data = xdp.data_hard_start + xdp_headroom; xdp.data_end = xdp.data + len; orig_data = xdp.data; - act =bpf_prog_run_xdp (xdp_prog, &xdp); - + act =xdp_hook_run_ret_last (&rq->napi, &xdp, &last_hook);switch (act) {case XDP_PASS :/* Recalculate length in case bpf program changed it */
@@ -427,13 +427,13 @@ static struct sk_buff *receive_small(struct net_device *dev,break ;case XDP_TX :if (unlikely (!virtnet_xdp_xmit (vi, rq, &xdp))) -trace_xdp_exception (vi->dev, xdp_prog, act); +trace_xdp_hook_exception (vi->dev, last_hook, act);rcu_read_unlock (); goto xdp_xmit;default : -bpf_warn_invalid_xdp_action (act); +xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_exception (vi->dev, xdp_prog, act); +trace_xdp_hook_exception (vi->dev, last_hook, act);case XDP_DROP : goto err_xdp; }
@@ -557,16 +557,15 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,struct page *page =virt_to_head_page (buf);int offset = buf -page_address (page);struct sk_buff *head_skb, *curr_skb; -struct bpf_prog *xdp_prog;unsigned int truesize; head_skb =NULL ;rcu_read_lock (); - xdp_prog =rcu_dereference (rq->xdp_prog); -if (xdp_prog) { +if (xdp_hook_run_needed_check (dev, &rq->napi)) {struct page *xdp_page;struct xdp_buff xdp; +struct xdp_hook *last_hook;void *data;u32 act;
@@ -597,7 +596,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev, xdp.data_hard_start = data -VIRTIO_XDP_HEADROOM + vi->hdr_len; xdp.data = data + vi->hdr_len; xdp.data_end = xdp.data + (len - vi->hdr_len); - act =bpf_prog_run_xdp (xdp_prog, &xdp); + act =xdp_hook_run_ret_last (&rq->napi, &xdp, &last_hook);switch (act) {case XDP_PASS :
@@ -620,16 +619,16 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,break ;case XDP_TX :if (unlikely (!virtnet_xdp_xmit (vi, rq, &xdp))) -trace_xdp_exception (vi->dev, xdp_prog, act); +trace_xdp_hook_exception (vi->dev, last_hook, act);ewma_pkt_len_add (&rq->mrg_avg_pkt_len, len);if (unlikely (xdp_page != page)) goto err_xdp;rcu_read_unlock (); goto xdp_xmit;default : -bpf_warn_invalid_xdp_action (act); +xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_exception (vi->dev, xdp_prog, act); +trace_xdp_hook_exception (vi->dev, last_hook, act);case XDP_DROP :if (unlikely (xdp_page != page))__free_pages (xdp_page,0 );
@@ -1606,7 +1605,7 @@ static int virtnet_set_channels(struct net_device *dev,* also when XDP is loaded all RX queues have XDP programs so we only * need to check a single RX queue. */ -if (vi->rq[0 ].xdp_prog) +if (vi->xdp_enabled)return -EINVAL ;get_online_cpus ();
@@ -1778,11 +1777,20 @@ static int virtnet_reset(struct virtnet_info *vi, int curr_qp, int xdp_qp)return ret; } -static int virtnet_xdp_set (struct net_device *dev,struct bpf_prog *prog) +static int virtnet_xdp_check_bpf (struct net_device *dev,struct bpf_prog *prog) +{ +if (prog && prog->xdp_adjust_head) { +netdev_warn (dev,"Does not support bpf_xdp_adjust_head()\n" ); +return -EOPNOTSUPP ; + } + +return 0 ; +} + +static int virtnet_xdp_init (struct net_device *dev,bool enable) {unsigned long int max_sz =PAGE_SIZE -sizeof (struct padded_vnet_hdr );struct virtnet_info *vi =netdev_priv (dev); -struct bpf_prog *old_prog;u16 xdp_qp =0 , curr_qp;int i, err;
@@ -1805,7 +1813,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog) } curr_qp = vi->curr_queue_pairs - vi->xdp_queue_pairs; -if (prog) +if (enable) xdp_qp = nr_cpu_ids;/* XDP requires extra queues for XDP_TX */
@@ -1815,12 +1823,6 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)return -ENOMEM ; } -if (prog) { - prog =bpf_prog_add (prog, vi->max_queue_pairs -1 ); -if (IS_ERR (prog)) -return PTR_ERR (prog); - } -/* Changing the headroom in buffers is a disruptive operation because * existing buffers must be flushed and reallocated. This will happen * when a xdp program is initially added or xdp is disabled by removing
@@ -1836,12 +1838,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)netif_set_real_num_rx_queues (dev, curr_qp + xdp_qp); -for (i =0 ; i < vi->max_queue_pairs; i++) { - old_prog =rtnl_dereference (vi->rq[i].xdp_prog); -rcu_assign_pointer (vi->rq[i].xdp_prog, prog); -if (old_prog) -bpf_prog_put (old_prog); - } + vi->xdp_enabled = enable;return 0 ;
@@ -1850,31 +1847,18 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)* error up to user space for resolution. The underlying reset hung on * us so not much we can do here. */ -if (prog) -bpf_prog_sub (prog, vi->max_queue_pairs -1 );return err; } -static bool virtnet_xdp_query (struct net_device *dev) -{ -struct virtnet_info *vi =netdev_priv (dev); -int i; - -for (i =0 ; i < vi->max_queue_pairs; i++) { -if (vi->rq[i].xdp_prog) -return true; - } -return false; -} -static int virtnet_xdp (struct net_device *dev,struct netdev_xdp *xdp) {switch (xdp->command) { -case XDP_SETUP_PROG : -return virtnet_xdp_set (dev, xdp->prog); -case XDP_QUERY_PROG : - xdp->prog_attached =virtnet_xdp_query (dev); -return 0 ; +case XDP_MODE_ON : +return virtnet_xdp_init (dev, true); +case XDP_MODE_OFF : +return virtnet_xdp_init (dev, false); +case XDP_CHECK_BPF_PROG : +return virtnet_xdp_check_bpf (dev, xdp->prog);default :return -EINVAL ; }
@@ -1955,17 +1939,11 @@ static void virtnet_free_queues(struct virtnet_info *vi)static void _free_receive_bufs (struct virtnet_info *vi) { -struct bpf_prog *old_prog;int i;for (i =0 ; i < vi->max_queue_pairs; i++) {while (vi->rq[i].pages)__free_pages (get_a_page (&vi->rq[i],GFP_KERNEL ),0 ); - - old_prog =rtnl_dereference (vi->rq[i].xdp_prog); -RCU_INIT_POINTER (vi->rq[i].xdp_prog,NULL ); -if (old_prog) -bpf_prog_put (old_prog); } }
@@ -2274,7 +2252,8 @@ static int virtnet_probe(struct virtio_device *vdev)/* Do we support "hardware" checksums? */ if (virtio_has_feature (vdev,VIRTIO_NET_F_CSUM )) {/* This opens up the world of extra features. */ - dev->hw_features |=NETIF_F_HW_CSUM |NETIF_F_SG ; + dev->hw_features |=NETIF_F_HW_CSUM |NETIF_F_SG | +NETIF_F_XDP ;if (csum) dev->features |=NETIF_F_HW_CSUM |NETIF_F_SG ;
Signature · 1 line
2.9.3
RFC PATCH v3 6/8 mlx5: Changes to use generic XDP infrastructure
In reply to Tom HerbertChange XDP program management functional interface to correspond to new XDP API.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 3 +- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 108 ++++++---------------- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 12 +-- 3 files changed, 36 insertions(+), 87 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +1 -2
@@ -381,7 +381,6 @@ struct mlx5e_rq {u16 rx_headroom;struct mlx5e_rx_am am;/* Adaptive Moderation */ -struct bpf_prog *xdp_prog;/* control */ struct mlx5_wq_ctrl wq_ctrl;
@@ -695,7 +694,7 @@ struct mlx5e_priv {/* priv data path fields - start */ struct mlx5e_sq **txq_to_sq_map;int channeltc_to_txq_map[MLX5E_MAX_NUM_CHANNELS ][MLX5E_MAX_NUM_TC ]; -struct bpf_prog *xdp_prog; +bool xdp_enabled;/* priv data path fields - end */ unsigned long state;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +29 -79
185 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +6 -6
@@ -721,18 +721,18 @@ static inline int mlx5e_xdp_handle(struct mlx5e_rq *rq,struct mlx5e_dma_info *di, void *va, u16 *rx_headroom, u32 *len) { - const struct bpf_prog *prog = READ_ONCE(rq->xdp_prog); struct xdp_buff xdp; +struct xdp_hook *last_hook;u32 act; -if (!prog) +if (!xdp_hook_run_needed_check (rq->netdev, rq->cq.napi))return false; xdp.data = va + *rx_headroom; xdp.data_end = xdp.data + *len; xdp.data_hard_start = va; - act =bpf_prog_run_xdp (prog, &xdp); + act =xdp_hook_run_ret_last (rq->cq.napi, &xdp, &last_hook);switch (act) {case XDP_PASS : *rx_headroom = xdp.data - xdp.data_hard_start;
@@ -740,12 +740,12 @@ static inline int mlx5e_xdp_handle(struct mlx5e_rq *rq,return false;case XDP_TX :if (unlikely (!mlx5e_xmit_xdp_frame (rq, di, &xdp))) -trace_xdp_exception (rq->netdev, prog, act); +trace_xdp_hook_exception (rq->netdev, last_hook, act);return true;default : -bpf_warn_invalid_xdp_action (act); +xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_exception (rq->netdev, prog, act); +trace_xdp_hook_exception (rq->netdev, last_hook, act);case XDP_DROP : rq->stats.xdp_drop++;mlx5e_page_release (rq, di, true);
Signature · 1 line
2.9.3
RFC PATCH v3 7/8 bnxt: Changes to use generic XDP infrastructure
In reply to Tom HerbertChange XDP program management functional interface to correspond to new XDP API.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 14 -------- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 2 +- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 46 +++++++++++++++------------ 3 files changed, 27 insertions(+), 35 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -14
@@ -2098,9 +2098,6 @@ static void bnxt_free_rx_rings(struct bnxt *bp)struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i];struct bnxt_ring_struct *ring; -if (rxr->xdp_prog) -bpf_prog_put (rxr->xdp_prog); -kfree (rxr->rx_tpa); rxr->rx_tpa =NULL ;
@@ -2388,15 +2385,6 @@ static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr) ring = &rxr->rx_ring_struct;bnxt_init_rxbd_pages (ring, type); -if (BNXT_RX_PAGE_MODE (bp) && bp->xdp_prog) { - rxr->xdp_prog =bpf_prog_add (bp->xdp_prog,1 ); -if (IS_ERR (rxr->xdp_prog)) { -int rc =PTR_ERR (rxr->xdp_prog); - - rxr->xdp_prog =NULL ; -return rc; - } - } prod = rxr->rx_prod;for (i =0 ; i < bp->rx_ring_size; i++) {if (bnxt_alloc_rx_data (bp, rxr, prod,GFP_KERNEL ) !=0 ) {
@@ -7198,8 +7186,6 @@ static void bnxt_remove_one(struct pci_dev *pdev)bnxt_dcb_free (bp);kfree (bp->edev); bp->edev =NULL ; -if (bp->xdp_prog) -bpf_prog_put (bp->xdp_prog);bnxt_cleanup_pci (bp);free_netdev (dev); }
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -1
@@ -1180,7 +1180,7 @@ struct bnxt {u8 num_leds;struct bnxt_led_info leds[BNXT_MAX_LED ]; -struct bpf_prog *xdp_prog; +bool xdp_enabled; };#define BNXT_RX_STATS_OFFSET (counter) \
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +26 -20
123 lines not on this page · raw message
Signature · 1 line
2.9.3
RFC PATCH v3 8/8 xdp: Cleanup after API changes
In reply to Tom HerbertThis patch:
- Change trace_xdp_hook_exception to trace_xdp_exception
- Remove XDP_SETUP_PROG and XDP_QUERY_PROG constants
- Remove bpf_warn_invalid_xdp_action
--- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 4 +-- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 4 +-- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 4 +-- .../net/ethernet/netronome/nfp/nfp_net_common.c | 8 +++--- drivers/net/ethernet/qlogic/qede/qede_fp.c | 6 ++--- drivers/net/virtio_net.c | 8 +++--- include/linux/filter.h | 1 - include/linux/netdevice.h | 15 ----------- include/trace/events/xdp.h | 29 ---------------------- kernel/bpf/core.c | 1 - net/core/filter.c | 6 ----- 11 files changed, 16 insertions(+), 70 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +2 -2
@@ -134,7 +134,7 @@ bool bnxt_rx_xdp(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, u16 cons,case XDP_TX :if (tx_avail <2 ) { -trace_xdp_hook_exception (bp->dev, last_hook, act); +trace_xdp_exception (bp->dev, last_hook, act);bnxt_reuse_rx_data (rxr, cons, page);return true; }
@@ -150,7 +150,7 @@ bool bnxt_rx_xdp(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, u16 cons,xdp_warn_invalid_action (act);/* Fall thru */ case XDP_ABORTED : -trace_xdp_hook_exception (bp->dev, last_hook, act); +trace_xdp_exception (bp->dev, last_hook, act);/* Fall thru */ case XDP_DROP :bnxt_reuse_rx_data (rxr, cons, page);
drivers/net/ethernet/mellanox/mlx4/en_rx.c +2 -2
@@ -927,12 +927,12 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud length, cq->ring, &doorbell_pending))) goto consumed; -trace_xdp_hook_exception (dev, last_hook, act); +trace_xdp_exception (dev, last_hook, act); goto xdp_drop_no_cnt;/* Drop on xmit failure */ default :xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_hook_exception (dev, last_hook, act); +trace_xdp_exception (dev, last_hook, act);case XDP_DROP : ring->xdp_drop++; xdp_drop_no_cnt:
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +2 -2
@@ -740,12 +740,12 @@ static inline int mlx5e_xdp_handle(struct mlx5e_rq *rq,return false;case XDP_TX :if (unlikely (!mlx5e_xmit_xdp_frame (rq, di, &xdp))) -trace_xdp_hook_exception (rq->netdev, last_hook, act); +trace_xdp_exception (rq->netdev, last_hook, act);return true;default :xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_hook_exception (rq->netdev, last_hook, act); +trace_xdp_exception (rq->netdev, last_hook, act);case XDP_DROP : rq->stats.xdp_drop++;mlx5e_page_release (rq, di, true);
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +3 -5
@@ -1616,15 +1616,13 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget)if (unlikely (!nfp_net_tx_xdp_buf (nn, rx_ring, tx_ring, rxbuf, pkt_off, pkt_len))) -trace_xdp_hook_exception (nn->netdev, - last_hook, - act); +trace_xdp_exception (nn->netdev, + last_hook, act);continue ;default :xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_hook_exception (nn->netdev, last_hook, - act); +trace_xdp_exception (nn->netdev, last_hook, act);case XDP_DROP :nfp_net_rx_give_one (rx_ring, rxbuf->frag, rxbuf->dma_addr);
drivers/net/ethernet/qlogic/qede/qede_fp.c +3 -3
@@ -1022,7 +1022,7 @@ static bool qede_rx_xdp(struct qede_dev *edev,/* We need the replacement buffer before transmit. */ if (qede_alloc_rx_buffer (rxq, true)) {qede_recycle_rx_bd_ring (rxq,1 ); -trace_xdp_hook_exception (edev->ndev, last_hook, act); +trace_xdp_exception (edev->ndev, last_hook, act); goto out; }
@@ -1033,7 +1033,7 @@ static bool qede_rx_xdp(struct qede_dev *edev,dma_unmap_page (rxq->dev, bd->mapping,PAGE_SIZE ,DMA_BIDIRECTIONAL );__free_page (bd->data); -trace_xdp_hook_exception (edev->ndev, last_hook, act); +trace_xdp_exception (edev->ndev, last_hook, act); }/* Regardless, we've consumed an Rx BD */
@@ -1043,7 +1043,7 @@ static bool qede_rx_xdp(struct qede_dev *edev,default :xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_hook_exception (edev->ndev, last_hook, act); +trace_xdp_exception (edev->ndev, last_hook, act);case XDP_DROP :qede_recycle_rx_bd_ring (rxq, cqe->bd_num); }
drivers/net/virtio_net.c +4 -4
@@ -427,13 +427,13 @@ static struct sk_buff *receive_small(struct net_device *dev,break ;case XDP_TX :if (unlikely (!virtnet_xdp_xmit (vi, rq, &xdp))) -trace_xdp_hook_exception (vi->dev, last_hook, act); +trace_xdp_exception (vi->dev, last_hook, act);rcu_read_unlock (); goto xdp_xmit;default :xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_hook_exception (vi->dev, last_hook, act); +trace_xdp_exception (vi->dev, last_hook, act);case XDP_DROP : goto err_xdp; }
@@ -619,7 +619,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,break ;case XDP_TX :if (unlikely (!virtnet_xdp_xmit (vi, rq, &xdp))) -trace_xdp_hook_exception (vi->dev, last_hook, act); +trace_xdp_exception (vi->dev, last_hook, act);ewma_pkt_len_add (&rq->mrg_avg_pkt_len, len);if (unlikely (xdp_page != page)) goto err_xdp;
@@ -628,7 +628,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,default :xdp_warn_invalid_action (act);case XDP_ABORTED : -trace_xdp_hook_exception (vi->dev, last_hook, act); +trace_xdp_exception (vi->dev, last_hook, act);case XDP_DROP :if (unlikely (xdp_page != page))__free_pages (xdp_page,0 );
include/linux/filter.h +0 -1
@@ -632,7 +632,6 @@ bool bpf_helper_changes_pkt_data(void *func);struct bpf_prog *bpf_patch_insn_single (struct bpf_prog *prog,u32 off,const struct bpf_insn *patch,u32 len); -void bpf_warn_invalid_xdp_action (u32 act);#ifdef CONFIG_BPF_JIT extern int bpf_jit_enable;
include/linux/netdevice.h +0 -15
@@ -811,18 +811,6 @@ struct tc_to_netdev {* to the netdevice through the xdp op. */ enum xdp_netdev_command { -/* Set or clear a bpf program used in the earliest stages of packet -* rx. The prog will have been loaded as BPF_PROG_TYPE_XDP. The callee -* is responsible for calling bpf_prog_put on any old progs that are -* stored. In case of error, the callee need not release the new prog -* reference, but on success it takes ownership and must bpf_prog_put -* when it is no longer used. -*/ -XDP_SETUP_PROG , -/* Check if a bpf program is set on the device. The callee should -* return true if a program is currently attached and running. -*/ -XDP_QUERY_PROG ,/* Initialize device to use XDP. Called when first XDP program is * registered on a device (including on a NAPI instance). */
@@ -840,11 +828,8 @@ enum xdp_netdev_command {struct netdev_xdp {enum xdp_netdev_command command;union { -/* XDP_SETUP_PROG */ /* XDP_CHECK_BPF_PROG */ struct bpf_prog *prog; -/* XDP_QUERY_PROG */ -bool prog_attached; }; };
include/trace/events/xdp.h +0 -29
@@ -26,35 +26,6 @@ __XDP_ACT_MAP(__XDP_ACT_TP_FN) TRACE_EVENT(xdp_exception, TP_PROTO(const struct net_device *dev, - const struct bpf_prog *xdp, u32 act), - -TP_ARGS (dev, xdp, act), - -TP_STRUCT__entry ( - __string(name, dev->name) - __array(u8, prog_tag, 8) -__field (u32, act) - ), - -TP_fast_assign ( - BUILD_BUG_ON(sizeof(__entry->prog_tag) != sizeof(xdp->tag)); - memcpy(__entry->prog_tag, xdp->tag, sizeof(xdp->tag)); - __assign_str(name, dev->name); - __entry->act = act; - ), - -TP_printk ("prog=%s device=%s action=%s" , -__print_hex_str (__entry->prog_tag,8 ), -__get_str (name), -__print_symbolic (__entry->act, __XDP_ACT_SYM_TAB)) -); - -/* Temporary trace function. This will be renamed to xdp_exception after all -* the calling drivers have been patched. -*/ -TRACE_EVENT(xdp_hook_exception, - - TP_PROTO(const struct net_device *dev, const struct xdp_hook *hook, u32 act), TP_ARGS(dev, hook, act),
kernel/bpf/core.c +0 -1
@@ -1412,7 +1412,6 @@ int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,#include <linux/bpf_trace.h> EXPORT_TRACEPOINT_SYMBOL_GPL (xdp_exception); -EXPORT_TRACEPOINT_SYMBOL_GPL (xdp_hook_exception);EXPORT_TRACEPOINT_SYMBOL_GPL (bpf_prog_get_type);EXPORT_TRACEPOINT_SYMBOL_GPL (bpf_prog_put_rcu);
net/core/filter.c +0 -6
@@ -2991,12 +2991,6 @@ static bool xdp_is_valid_access(int off, int size,return __is_valid_xdp_access (off, size); } -void bpf_warn_invalid_xdp_action (u32 act) -{ -WARN_ONCE (1 ,"Illegal XDP return value %u, expect packet loss\n" , act); -} -EXPORT_SYMBOL_GPL (bpf_warn_invalid_xdp_action); - static u32 bpf_convert_ctx_access(enum bpf_access_type type, const struct bpf_insn *si, struct bpf_insn *insn_buf,
Signature · 1 line
2.9.3
David Miller
maintainerRe: [PATCH RFC v3 8/8] xdp: Cleanup after API changes
From: Tom Herbert <[email protected]>
Date: Tue, 21 Feb 2017 11:34:17 -0800
Quoted 1 line
- Change
trace_xdp_hook_exceptiontotrace_xdp_exception
Just give it this final name in patch #1 where you introduce it.
Re: [PATCH RFC v3 8/8] xdp: Cleanup after API changes
Quoted 6 lines · David Miller
From: Tom Herbert <[email protected]>
Date: Tue, 21 Feb 2017 11:34:17 -0800Quoted 1 line
- Change
trace_xdp_hook_exceptiontotrace_xdp_exceptionJust give it this final name in patch #1 where you introduce it.
That will break compilation of the intervening patches. That is okay?
David Miller
maintainerRe: [PATCH RFC v3 8/8] xdp: Cleanup after API changes
From: Tom Herbert <[email protected]>
Date: Tue, 21 Feb 2017 13:24:43 -0800
Quoted 9 lines · David Miller
Quoted 6 lines
From: Tom Herbert <[email protected]>
Date: Tue, 21 Feb 2017 11:34:17 -0800Quoted 1 line
- Change
trace_xdp_hook_exceptiontotrace_xdp_exceptionJust give it this final name in patch #1 where you introduce it.
That will break compilation of the intervening patches. That is okay?
The trace hook doesn't even exist until patch #1, so yes if you name it properly from the start any references you have to it within followon patches need to be adjusted as well.
Hi,
I still have a few worries about this patch set...
Quoted 4 lines · Tom Herbert
This patch set generalizes XDP by making the hooks in drivers to be generic. This has a number of advantages:
- Allows a means to pipeline XDP programs together
Does it add anything beyond what we already can achieve with tail calls? Is there expectations that users will install independent black box/pre-compiled programs on the same interface?
Quoted 2 lines
- Reduces the amount of code and complexity needed in drivers to manage XDP
Other than for Mellanox drivers the savings are in *teen lines of code?
Quoted 2 lines
- Provides a more structured environment that is extensible to new features while being mostly transparent to the drivers
So far all features we added required explicit driver support. Checksumming support as an example will require driver changes, too. Generalized way to call programs is probably not going to buy us much?
Quoted 1 line
- Allow XDP programs to be set per device or per queue
Some drivers already provide that even though we don't have a user API to set it.
Quoted 2 lines
- Moves management of BPF programs out of driver into a common infrastructure
I appreciate this one, but IMHO this generalized infrastructure is way too complicated for the purpose. Why not simply place an XDP program pointer into netdev and napi and provide driver with a helper to install the program there? Or am I simply not understanding the benefits of the generalized hooks?
I probably have a slightly unique perspective caring about offloads but IMHO the cost of this patchset outweighs the benefits right now. You haven't actually implement the OFFLOAD command at all (grep for XDP_OFFLOAD_BPF) but having to deal with the intermediary layer will certainly complicate things here.
There are also miscellaneous optimizations which are possible when drivers can inspect the program, like only reserving headroom if program may use header adjust... it does seem to me that this set introduces a lot of complexity and only superficial driver simplifications. I would personally rather wait with infrastructure like this until John's TX-to-other netdev is well formulated.
Obviously this set will also be a major pain when backporting things, too.
Re: [PATCH RFC v3 3/8] nfp: Changes to use generic XDP infrastructure
In reply to Tom HerbertQuoted 78 lines · Tom Herbert
Change XDP program management functional interface to correspond to new XDP API.
Signed-off-by Tom Herbert <[email protected]>--- drivers/net/ethernet/netronome/nfp/nfp_net.h | 5 +- .../net/ethernet/netronome/nfp/nfp_net_common.c | 172 ++++++++++----------- .../net/ethernet/netronome/nfp/nfp_net_ethtool.c | 12 +- 3 files changed, 87 insertions(+), 102 deletions(-)drivers/net/ethernet/netronome/nfp/nfp_net.h +2
-3@@ -503,14 +503,13 @@ struct nfp_net { unsigned is_vf:1; unsigned bpf_offload_skip_sw:1; unsigned bpf_offload_xdp:1; + unsigned xdp_enabled:1;u32 ctrl;u32 fl_bufsz;u32 rx_offset; -struct bpf_prog *xdp_prog; -struct nfp_net_tx_ring *tx_rings;struct nfp_net_rx_ring *rx_rings;@@ -788,7 +787,7 @@ void nfp_net_irqs_assign(struct nfp_net *nn, struct msix_entry *irq_entries, unsigned int n);int -nfp_net_ring_reconfig (struct nfp_net *nn,struct bpf_prog **xdp_prog, +nfp_net_ring_reconfig (struct nfp_net *nn,struct nfp_net_ring_set *rx,struct nfp_net_ring_set *tx);#ifdef CONFIG_NFP_DEBUG drivers/net/ethernet/netronome/nfp/nfp_net_common.c +5
-4@@ -65,6 +65,7 @@#include <net/pkt_cls.h> #include <net/vxlan.h> +#include <net/xdp.h> #include "nfp_net_ctrl.h" #include "nfp_net.h" @@ -1169,10 +1170,10 @@ nfp_net_napi_alloc_one(struct nfp_net *nn, int direction, dma_addr_t *dma_addr) {void *frag; -if (!nn->xdp_prog) - frag =napi_alloc_frag (nn->fl_bufsz); -else +if (nn->xdp_enabled) frag =page_address (alloc_page (GFP_ATOMIC | __GFP_COLD)); +else + frag =napi_alloc_frag (nn->fl_bufsz);if (!frag) {nn_warn_ratelimit (nn,"Failed to alloc receive page frag\n" );return NULL ;@@ -1180,7 +1181,7 @@ nfp_net_napi_alloc_one(struct nfp_net *nn, int direction, dma_addr_t *dma_addr) *dma_addr =nfp_net_dma_map_rx (nn, frag, nn->fl_bufsz, direction);if (dma_mapping_error (&nn->pdev->dev, *dma_addr)) { -nfp_net_free_frag (frag, nn->xdp_prog); +nfp_net_free_frag (frag, nn->xdp_enabled);nn_warn_ratelimit (nn,"Failed to map DMA RX buffer\n" );return NULL ; }@@ -1251,17 +1252,15 @@ static void nfp_net_rx_ring_reset(struct nfp_net_rx_ring *rx_ring)* nfp_net_rx_ring_bufs_free() - Free any buffers currently on the RX ring * @nn: NFP Net device * @rx_ring: RX ring to remove buffers from
drivers/net/ethernet/netronome/nfp/nfp_net_common.c static void nfp_net_rx_ring_reset(struct nfp_net_rx_ring *rx_ring) · line 1261
Quoted 10 lines
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +1
-3-* @xdp: Whether XDP is enabled * * Assumes that the device is stopped and buffers are in [0, ring->cnt - 1) * entries. After device is disabled nfp_net_rx_ring_reset() must be called * to restore required ring geometry. */ static void -nfp_net_rx_ring_bufs_free (struct nfp_net *nn,struct nfp_net_rx_ring *rx_ring, -bool xdp) +nfp_net_rx_ring_bufs_free (struct nfp_net *nn,struct nfp_net_rx_ring *rx_ring)
You can't do that. NFP has runtime reconfiguration mechanism which allocates new rings before it stops the device. All those methods need to take XDP program or xdp bool as parameter.
Quoted 17 lines · Jakub Kicinski
Hi,
I still have a few worries about this patch set...
Quoted 4 lines · Tom Herbert
This patch set generalizes XDP by making the hooks in drivers to be generic. This has a number of advantages:
- Allows a means to pipeline XDP programs together
Does it add anything beyond what we already can achieve with tail calls? Is there expectations that users will install independent black box/pre-compiled programs on the same interface?
Quoted 2 lines
- Reduces the amount of code and complexity needed in drivers to manage XDP
Quoted 9 lines
Other than for Mellanox drivers the savings are in *teen lines of code?
Quoted 2 lines
- Provides a more structured environment that is extensible to new features while being mostly transparent to the drivers
So far all features we added required explicit driver support. Checksumming support as an example will require driver changes, too. Generalized way to call programs is probably not going to buy us much?
Hi Jakub,
What is the the concern with checksumming? Isn't that just an issue of defining fields in xdp_data and driver populating with the appropriate information?
Tom
Quoted 29 lines
Quoted 1 line
- Allow XDP programs to be set per device or per queue
Some drivers already provide that even though we don't have a user API to set it.
Quoted 2 lines
- Moves management of BPF programs out of driver into a common infrastructure
I appreciate this one, but IMHO this generalized infrastructure is way too complicated for the purpose. Why not simply place an XDP program pointer into netdev and napi and provide driver with a helper to install the program there? Or am I simply not understanding the benefits of the generalized hooks?
I probably have a slightly unique perspective caring about offloads but IMHO the cost of this patchset outweighs the benefits right now. You haven't actually implement the OFFLOAD command at all (grep for
XDP_OFFLOAD_BPF) but having to deal with the intermediary layer will certainly complicate things here.There are also miscellaneous optimizations which are possible when drivers can inspect the program, like only reserving headroom if program may use header adjust... it does seem to me that this set introduces a lot of complexity and only superficial driver simplifications. I would personally rather wait with infrastructure like this until John's TX-to-other netdev is well formulated.
Obviously this set will also be a major pain when backporting things, too.
Quoted 7 lines · Tom Herbert
Quoted 7 lines
Quoted 2 lines
- Provides a more structured environment that is extensible to new features while being mostly transparent to the drivers
So far all features we added required explicit driver support. Checksumming support as an example will require driver changes, too. Generalized way to call programs is probably not going to buy us much?
Quoted 5 lines
Hi Jakub,
What is the the concern with checksumming? Isn't that just an issue of defining fields in
xdp_dataand driver populating with the appropriate information?
Thanks for replying! I was just using checksumming as an example. I was trying to counter the argument that the hook infrastructure will allow for features to be implemented mostly transparently to the drivers. I may be wrong but it seems that it doesn't buy us anything as far as the features which were so far discussed go.
Quoted 14 lines · Jakub Kicinski
Quoted 7 lines · Tom Herbert
Quoted 7 lines
Quoted 2 lines
- Provides a more structured environment that is extensible to new features while being mostly transparent to the drivers
So far all features we added required explicit driver support. Checksumming support as an example will require driver changes, too. Generalized way to call programs is probably not going to buy us much?
Quoted 5 lines
Hi Jakub,
What is the the concern with checksumming? Isn't that just an issue of defining fields in
xdp_dataand driver populating with the appropriate information?
Quoted 5 lines
Thanks for replying! I was just using checksumming as an example. I was trying to counter the argument that the hook infrastructure will allow for features to be implemented mostly transparently to theom drivers. I may be wrong but it seems that it doesn't buy us anything as far as the features which were so far discussed go.
But I still don't understand the example. In the case of checksumming the driver just needs to populate the values in xdp_data regarding csum. We could basically reuse the same interface as that in skbuff. The stack then can handle the logic of verifying checksums (verifying a csum-complete value for instance). The driver only passes information to the stack concerning a packet, it doesn't need to act on the information. For instance, it's not the driver's prerogative to verify the checksum itself. In general the less drivers have to do and the more we push complexity of common functionality into the stack, the better.
Tom
Quoted 21 lines · Tom Herbert
Quoted 14 lines · Jakub Kicinski
Quoted 7 lines · Tom Herbert
Quoted 7 lines
Quoted 2 lines
- Provides a more structured environment that is extensible to new features while being mostly transparent to the drivers
So far all features we added required explicit driver support. Checksumming support as an example will require driver changes, too. Generalized way to call programs is probably not going to buy us much?
Quoted 5 lines
Hi Jakub,
What is the the concern with checksumming? Isn't that just an issue of defining fields in
xdp_dataand driver populating with the appropriate information?Quoted 5 lines
Thanks for replying! I was just using checksumming as an example. I was trying to counter the argument that the hook infrastructure will allow for features to be implemented mostly transparently to theom drivers. I may be wrong but it seems that it doesn't buy us anything as far as the features which were so far discussed go.
Quoted 10 lines
But I still don't understand the example. In the case of checksumming the driver just needs to populate the values in
xdp_dataregarding csum. We could basically reuse the same interface as that in skbuff. The stack then can handle the logic of verifying checksums (verifying a csum-complete value for instance). The driver only passes information to the stack concerning a packet, it doesn't need to act on the information. For instance, it's not the driver's prerogative to verify the checksum itself. In general the less drivers have to do and the more we push complexity of common functionality into the stack, the better.
Sorry, I thought your patchset abstracts away populating struct xdp. So my initial statement should have read "Checksumming will require driver changes, only". Yes, drivers will just have to populate the appropriate XDP buffer field. What are the XDP features you foresee this hook infrastructure to help drivers with?
Quoted 33 lines · Jakub Kicinski
Quoted 21 lines · Tom Herbert
Quoted 14 lines · Jakub Kicinski
Quoted 7 lines · Tom Herbert
Quoted 7 lines
Quoted 2 lines
- Provides a more structured environment that is extensible to new features while being mostly transparent to the drivers
So far all features we added required explicit driver support. Checksumming support as an example will require driver changes, too. Generalized way to call programs is probably not going to buy us much?
Quoted 5 lines
Hi Jakub,
What is the the concern with checksumming? Isn't that just an issue of defining fields in
xdp_dataand driver populating with the appropriate information?Quoted 5 lines
Thanks for replying! I was just using checksumming as an example. I was trying to counter the argument that the hook infrastructure will allow for features to be implemented mostly transparently to theom drivers. I may be wrong but it seems that it doesn't buy us anything as far as the features which were so far discussed go.
Quoted 10 lines
But I still don't understand the example. In the case of checksumming the driver just needs to populate the values in
xdp_dataregarding csum. We could basically reuse the same interface as that in skbuff. The stack then can handle the logic of verifying checksums (verifying a csum-complete value for instance). The driver only passes information to the stack concerning a packet, it doesn't need to act on the information. For instance, it's not the driver's prerogative to verify the checksum itself. In general the less drivers have to do and the more we push complexity of common functionality into the stack, the better.
Quoted 5 lines
Sorry, I thought your patchset abstracts away populating struct xdp. So my initial statement should have read "Checksumming will require driver changes, only". Yes, drivers will just have to populate the appropriate XDP buffer field. What are the XDP features you foresee this hook infrastructure to help drivers with?
It is part of the direction to take XDP beyond the first use case of BPF and leverage the high performance processing model in a much broader context. For instance, as Saeed alluded to we should be a able to create an skb-less interface into the stack-- this is essentially what we need for TXDP (expedited processing for the transport layer). Also, I think that we should also be able to extrapolate a good RX batch interface from an API like this (please see discussion on that).
Thanks,
Tom
David Miller
maintainerFrom: Tom Herbert <[email protected]>
Date: Tue, 21 Feb 2017 18:54:53 -0800
Quoted 3 lines
It is part of the direction to take XDP beyond the first use case of BPF and leverage the high performance processing model in a much broader context.
And I've stated repeatedly that it's too early to be looking that far into the future.
Look Tom, if all you want to do is create infrastructure so that you can very easily slither XDP for modules in somewhere, please just stop now. Right now I am completely not interested in even entertaining patches which facilitate that.
If instead, you are genuinely interested in making the process of writing XDP support for drivers easier, that extremely useful right now so please just stick to that specific focus.
I really see no other use case for the XDP hook abstraction other than to support XDP module support, which I've said is in no way proven to be necessary.
We don't even know what eBPF XDP itself is fully capable of yet, so please stop reaching like this.
Thank you.
Quoted 19 lines · David Miller
From: Tom Herbert <[email protected]>
Date: Tue, 21 Feb 2017 18:54:53 -0800Quoted 3 lines
It is part of the direction to take XDP beyond the first use case of BPF and leverage the high performance processing model in a much broader context.
And I've stated repeatedly that it's too early to be looking that far into the future.
Look Tom, if all you want to do is create infrastructure so that you can very easily slither XDP for modules in somewhere, please just stop now. Right now I am completely not interested in even entertaining patches which facilitate that.
If instead, you are genuinely interested in making the process of writing XDP support for drivers easier, that extremely useful right now so please just stick to that specific focus.
Quoted 7 lines
I really see no other use case for the XDP hook abstraction other than to support XDP module support, which I've said is in no way proven to be necessary.
We don't even know what eBPF XDP itself is fully capable of yet, so please stop reaching like this.
I took out the parts about allowing non-BPF hooks in the patchset as you requested.I believe code that is cleaner than what is currently there, and the fact that the API is extensible to allow other uses is a hallmark of good design.
Tom
David Miller
maintainerFrom: Tom Herbert <[email protected]>
Date: Tue, 21 Feb 2017 20:02:07 -0800
Quoted 4 lines
I took out the parts about allowing non-BPF hooks in the patchset as you requested.I believe code that is cleaner than what is currently there, and the fact that the API is extensible to allow other uses is a hallmark of good design.
For BPF only cases, there is no need for a chain of callbacks. BPF has tailcalls, which can be used to solve whatever problem chained XDP stuff would be used for.
The only other possible use of chained XDP is non-BPF uses, thus my and others's fundamental objection.
It's not a cleanup or a simplification for driver writers, you're adding a new feature, and one whose need is not at all clear.
I also object to chaining on another level. The whole idea of XDP programs are that they exist in a very _precise_ and specific context and do one thing. If there are chains, there are dependencies, and thus the context is variable. We do not want this, trust me.
Is it such a huge deal to defer this chaining thing to after your other simplifications? All of these things you are trying to add are blocking the less controversial and useful parts of your work.
Thanks.