bpf: xdp: Report bpf_prog ID in IFLA_XDP
Subsystems (13)
PATCH v3 5/9 bpf: bnxt: Report bpf_prog ID during XDP_QUERY_PROG
In reply to Martin KaFai LauAdd support to bnxt to report bpf_prog ID during XDP_QUERY_PROG.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +1 -0
@@ -218,6 +218,7 @@ int bnxt_xdp(struct net_device *dev, struct netdev_xdp *xdp)break ;case XDP_QUERY_PROG : xdp->prog_attached = !!bp->xdp_prog; + xdp->prog_id = bp->xdp_prog ? bp->xdp_prog->aux->id :0 ; rc =0 ;break ;default :
Signature · 1 line
2.9.3
PATCH v3 6/9 bpf: thunderx: Report bpf_prog ID during XDP_QUERY_PROG
In reply to Martin KaFai LauAdd support to thunderx to report bpf_prog ID during XDP_QUERY_PROG.
--- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +1 -0
@@ -1763,6 +1763,7 @@ static int nicvf_xdp(struct net_device *netdev, struct netdev_xdp *xdp)return nicvf_xdp_setup (nic, xdp->prog);case XDP_QUERY_PROG : xdp->prog_attached = !!nic->xdp_prog; + xdp->prog_id = nic->xdp_prog ? nic->xdp_prog->aux->id :0 ;return 0 ;default :return -EINVAL ;
Signature · 1 line
2.9.3
PATCH v3 7/9 bpf: ixgbe: Report bpf_prog ID during XDP_QUERY_PROG
In reply to Martin KaFai LauAdd support to ixgbe to report bpf_prog ID during XDP_QUERY_PROG.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -0
@@ -9815,6 +9815,8 @@ static int ixgbe_xdp(struct net_device *dev, struct netdev_xdp *xdp)return ixgbe_xdp_setup (dev, xdp->prog);case XDP_QUERY_PROG : xdp->prog_attached = !!(adapter->xdp_prog); + xdp->prog_id = adapter->xdp_prog ? + adapter->xdp_prog->aux->id :0 ;return 0 ;default :return -EINVAL ;
Signature · 1 line
2.9.3
PATCH v3 8/9 bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG
In reply to Martin KaFai LauAdd support to nfp to report bpf_prog ID during XDP_QUERY_PROG.
--- drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +1 -0
@@ -3256,6 +3256,7 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_xdp *xdp)return nfp_net_xdp_setup (nn, xdp);case XDP_QUERY_PROG : xdp->prog_attached = !!nn->dp.xdp_prog; + xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id :0 ;return 0 ;default :return -EINVAL ;
Signature · 1 line
2.9.3
PATCH v3 1/9 net: Add IFLA_XDP_PROG_ID
In reply to Martin KaFai LauExpose prog_id through IFLA_XDP_PROG_ID. This patch makes modification to generic_xdp. The later patches will modify other xdp-supported drivers.
prog_id is added to struct net_dev_xdp.
iproute2 patch will be followed. Here is how the 'ip link' will look like:
Quoted 1 line
ip link show eth0
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdp(prog_id:1) qdisc fq_codel state UP mode DEFAULT group default qlen 1000
--- include/linux/netdevice.h | 7 +++++-- include/uapi/linux/if_link.h | 1 + net/core/dev.c | 19 +++++++++++-------- net/core/rtnetlink.c | 27 +++++++++++++++++++++------ 4 files changed, 38 insertions(+), 16 deletions(-)
include/linux/netdevice.h +5 -2
@@ -824,7 +824,10 @@ struct netdev_xdp {struct netlink_ext_ack *extack; };/* XDP_QUERY_PROG */ -bool prog_attached; +struct { +bool prog_attached; +u32 prog_id; + }; }; };
@@ -3302,7 +3305,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,typedef int (*xdp_op_t )(struct net_device *dev,struct netdev_xdp *xdp);int dev_change_xdp_fd (struct net_device *dev,struct netlink_ext_ack *extack,int fd,u32 flags); -bool __dev_xdp_attached (struct net_device *dev,xdp_op_t xdp_op); +bool __dev_xdp_attached (struct net_device *dev,xdp_op_t xdp_op,u32 *prog_id);int __dev_forward_skb (struct net_device *dev,struct sk_buff *skb);int dev_forward_skb (struct net_device *dev,struct sk_buff *skb);
include/uapi/linux/if_link.h +1 -0
@@ -907,6 +907,7 @@ enum {IFLA_XDP_FD ,IFLA_XDP_ATTACHED ,IFLA_XDP_FLAGS , +IFLA_XDP_PROG_ID , __IFLA_XDP_MAX, };
net/core/dev.c +11 -8
@@ -4342,13 +4342,12 @@ static struct static_key generic_xdp_needed __read_mostly;static int generic_xdp_install (struct net_device *dev,struct netdev_xdp *xdp) { +struct bpf_prog *old =rtnl_dereference (dev->xdp_prog);struct bpf_prog *new = xdp->prog;int ret =0 ;switch (xdp->command) { -case XDP_SETUP_PROG : { -struct bpf_prog *old =rtnl_dereference (dev->xdp_prog); - +case XDP_SETUP_PROG :rcu_assign_pointer (dev->xdp_prog, new);if (old)bpf_prog_put (old);
@@ -4360,10 +4359,10 @@ static int generic_xdp_install(struct net_device *dev, struct netdev_xdp *xdp)dev_disable_lro (dev); }break ; - }case XDP_QUERY_PROG : - xdp->prog_attached = !!rcu_access_pointer (dev->xdp_prog); + xdp->prog_attached = !!old; + xdp->prog_id = old ? old->aux->id :0 ;break ;default :
@@ -6937,7 +6936,8 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down) }EXPORT_SYMBOL (dev_change_proto_down); -bool __dev_xdp_attached (struct net_device *dev,xdp_op_t xdp_op) +bool __dev_xdp_attached (struct net_device *dev,xdp_op_t xdp_op, +u32 *prog_id) {struct netdev_xdp xdp;
@@ -6946,6 +6946,9 @@ bool __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op)/* Query must always succeed. */ WARN_ON (xdp_op (dev, &xdp) <0 ); +if (prog_id) + *prog_id = xdp.prog_id; +return xdp.prog_attached; }
@@ -6991,10 +6994,10 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, xdp_chk = generic_xdp_install;if (fd >=0 ) { -if (xdp_chk &&__dev_xdp_attached (dev, xdp_chk)) +if (xdp_chk &&__dev_xdp_attached (dev, xdp_chk,NULL ))return -EEXIST ;if ((flags &XDP_FLAGS_UPDATE_IF_NOEXIST ) && -__dev_xdp_attached (dev, xdp_op)) +__dev_xdp_attached (dev, xdp_op,NULL ))return -EBUSY ; prog =bpf_prog_get_type (fd,BPF_PROG_TYPE_XDP );
net/core/rtnetlink.c +21 -6
@@ -39,6 +39,7 @@#include <linux/if_vlan.h> #include <linux/pci.h> #include <linux/etherdevice.h> +#include <linux/bpf.h> #include <linux/uaccess.h>
@@ -899,7 +900,8 @@ static size_t rtnl_port_size(const struct net_device *dev,static size_t rtnl_xdp_size (void ) {size_t xdp_size =nla_total_size (0 ) +/* nest IFLA_XDP */ -nla_total_size (1 );/* XDP_ATTACHED */ +nla_total_size (1 ) +/* XDP_ATTACHED */ +nla_total_size (4 );/* XDP_PROG_ID */ return xdp_size; }
@@ -1248,15 +1250,20 @@ static int rtnl_fill_link_ifmap(struct sk_buff *skb, struct net_device *dev)return 0 ; } -static u8 rtnl_xdp_attached_mode (struct net_device *dev) +static u8 rtnl_xdp_attached_mode (struct net_device *dev,u32 *prog_id) {const struct net_device_ops *ops = dev->netdev_ops; +const struct bpf_prog *generic_xdp_prog;ASSERT_RTNL (); -if (rcu_access_pointer (dev->xdp_prog)) + *prog_id =0 ; + generic_xdp_prog =rtnl_dereference (dev->xdp_prog); +if (generic_xdp_prog) { + *prog_id = generic_xdp_prog->aux->id;return XDP_ATTACHED_SKB ; -if (ops->ndo_xdp &&__dev_xdp_attached (dev, ops->ndo_xdp)) + } +if (ops->ndo_xdp &&__dev_xdp_attached (dev, ops->ndo_xdp, prog_id))return XDP_ATTACHED_DRV ;return XDP_ATTACHED_NONE ;
@@ -1265,6 +1272,7 @@ static u8 rtnl_xdp_attached_mode(struct net_device *dev)static int rtnl_xdp_fill (struct sk_buff *skb,struct net_device *dev) {struct nlattr *xdp; +u32 prog_id;int err; xdp =nla_nest_start (skb,IFLA_XDP );
@@ -1272,10 +1280,16 @@ static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)return -EMSGSIZE ; err =nla_put_u8 (skb,IFLA_XDP_ATTACHED , -rtnl_xdp_attached_mode (dev)); +rtnl_xdp_attached_mode (dev, &prog_id));if (err) goto err_cancel; +if (prog_id) { + err =nla_put_u32 (skb,IFLA_XDP_PROG_ID , prog_id); +if (err) + goto err_cancel; + } +nla_nest_end (skb, xdp);return 0 ;
@@ -1553,6 +1567,7 @@ static const struct nla_policy ifla_xdp_policy[IFLA_XDP_MAX + 1] = { [IFLA_XDP_FD] = { .type = NLA_S32 }, [IFLA_XDP_ATTACHED] = { .type = NLA_U8 }, [IFLA_XDP_FLAGS] = { .type = NLA_U32 }, + [IFLA_XDP_PROG_ID] = { .type = NLA_U32 }, };static const struct rtnl_link_ops *linkinfo_to_kind_ops (const struct nlattr *nla)
@@ -2225,7 +2240,7 @@ static int do_setlink(const struct sk_buff *skb,if (err <0 ) goto errout; -if (xdp[IFLA_XDP_ATTACHED ]) { +if (xdp[IFLA_XDP_ATTACHED ] || xdp[IFLA_XDP_PROG_ID ]) { err = -EINVAL ; goto errout; }
Signature · 1 line
2.9.3
PATCH v3 2/9 bpf: mlx4: Report bpf_prog ID during XDP_QUERY_PROG
In reply to Martin KaFai LauAdd support to mlx4 to report bpf_prog ID during XDP_QUERY_PROG.
--- drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +18 -3
@@ -2821,11 +2821,25 @@ static int mlx4_xdp_set(struct net_device *dev, struct bpf_prog *prog)return err; } -static bool mlx4_xdp_attached (struct net_device *dev) +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 !!priv->tx_ring_num[TX_XDP ]; +return prog_id; }static int mlx4_xdp (struct net_device *dev,struct netdev_xdp *xdp)
@@ -2834,7 +2848,8 @@ static int mlx4_xdp(struct net_device *dev, struct netdev_xdp *xdp)case XDP_SETUP_PROG :return mlx4_xdp_set (dev, xdp->prog);case XDP_QUERY_PROG : - xdp->prog_attached =mlx4_xdp_attached (dev); + xdp->prog_id =mlx4_xdp_query (dev); + xdp->prog_attached = !!xdp->prog_id;return 0 ;default :return -EINVAL ;
Signature · 1 line
2.9.3
PATCH v3 3/9 bpf: mlx5e: Report bpf_prog ID during XDP_QUERY_PROG
In reply to Martin KaFai LauAdd support to mlx5e to report bpf_prog ID during XDP_QUERY_PROG.
--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +12 -3
@@ -3599,11 +3599,19 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog)return err; } -static bool mlx5e_xdp_attached (struct net_device *dev) +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 ; -return !!priv->channels.params.xdp_prog; +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_xdp *xdp)
@@ -3612,7 +3620,8 @@ static int mlx5e_xdp(struct net_device *dev, struct netdev_xdp *xdp)case XDP_SETUP_PROG :return mlx5e_xdp_set (dev, xdp->prog);case XDP_QUERY_PROG : - xdp->prog_attached =mlx5e_xdp_attached (dev); + xdp->prog_id =mlx5e_xdp_query (dev); + xdp->prog_attached = !!xdp->prog_id;return 0 ;default :return -EINVAL ;
Signature · 1 line
2.9.3
PATCH v3 9/9 bpf: qede: Report bpf_prog ID during XDP_QUERY_PROG
In reply to Martin KaFai LauAdd support to qede to report bpf_prog ID during XDP_QUERY_PROG.
--- drivers/net/ethernet/qlogic/qede/qede_filter.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/qlogic/qede/qede_filter.c +1 -0
@@ -1037,6 +1037,7 @@ int qede_xdp(struct net_device *dev, struct netdev_xdp *xdp)return qede_xdp_set (edev, xdp->prog);case XDP_QUERY_PROG : xdp->prog_attached = !!edev->xdp_prog; + xdp->prog_id = edev->xdp_prog ? edev->xdp_prog->aux->id :0 ;return 0 ;default :return -EINVAL ;
Signature · 1 line
2.9.3
v3 cover bpf: xdp: Report bpf_prog ID in IFLA_XDP
This is the first usage of the new bpf_prog ID. It is for reporting the ID of a xdp_prog through netlink.
It rides on the existing IFLA_XDP. This patch adds IFLA_XDP_PROG_ID for the bpf_prog ID reporting.
It starts with changing the generic_xdp first. After that, the hardware driver is changed one by one. Jakub Kicinski mentioned that he will soon introduce XDP_ATTACHED_HW (on top of the existing XDP_ATTACHED_DRV and XDP_ATTACHED_SKB)
and he is going to reuse the prog_attached for this purpose. Hence, this patch set keeps the prog_attached even though !!prog_id also implies there is xdp_prog attached.
I have tested with generic_xdp, mlx4 and mlx5.
v3:
1. Replace 'if' by '?' when checking the xdp_prog pointer as suggested by Jakub Kicinski (thanks!)
v2:
1. Remove READ_ONCE since it is alredy under rtnl lock
2. Keep prog_attached in 'struct netdev_xdp' as requested by Jakub Kicinski. The existing prog_attached and the new prog_id are put under a struct for XDP_QUERY_PROG.
Martin KaFai Lau (9):
net: Add IFLA_XDP_PROG_ID
bpf: mlx4: Report bpf_prog ID during XDP_QUERY_PROG
bpf: mlx5e: Report bpf_prog ID during XDP_QUERY_PROG
bpf: virtio_net: Report bpf_prog ID during XDP_QUERY_PROG
bpf: bnxt: Report bpf_prog ID during XDP_QUERY_PROG
bpf: thunderx: Report bpf_prog ID during XDP_QUERY_PROG
bpf: ixgbe: Report bpf_prog ID during XDP_QUERY_PROG
bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG
bpf: qede: Report bpf_prog ID during XDP_QUERY_PROG
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 1 + drivers/net/ethernet/cavium/thunder/nicvf_main.c | 1 + drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 2 ++ drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 21 ++++++++++++++--- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 15 +++++++++--- .../net/ethernet/netronome/nfp/nfp_net_common.c | 1 + drivers/net/ethernet/qlogic/qede/qede_filter.c | 1 + drivers/net/virtio_net.c | 13 +++++++---- include/linux/netdevice.h | 7 ++++-- include/uapi/linux/if_link.h | 1 + net/core/dev.c | 19 ++++++++------- net/core/rtnetlink.c | 27 +++++++++++++++++----- 12 files changed, 82 insertions(+), 27 deletions(-)
Signature · 1 line
2.9.3
PATCH v3 4/9 bpf: virtio_net: Report bpf_prog ID during XDP_QUERY_PROG
Add support to virtio_net to report bpf_prog ID during XDP_QUERY_PROG.
--- drivers/net/virtio_net.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/virtio_net.c +8 -5
@@ -1955,16 +1955,18 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,return err; } -static bool virtnet_xdp_query (struct net_device *dev) +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++) { -if (vi->rq[i].xdp_prog) -return true; + xdp_prog =rtnl_dereference (vi->rq[i].xdp_prog); +if (xdp_prog) +return xdp_prog->aux->id; } -return false; +return 0 ; }static int virtnet_xdp (struct net_device *dev,struct netdev_xdp *xdp)
@@ -1973,7 +1975,8 @@ static int virtnet_xdp(struct net_device *dev, struct netdev_xdp *xdp)case XDP_SETUP_PROG :return virtnet_xdp_set (dev, xdp->prog, xdp->extack);case XDP_QUERY_PROG : - xdp->prog_attached =virtnet_xdp_query (dev); + xdp->prog_id =virtnet_xdp_query (dev); + xdp->prog_attached = !!xdp->prog_id;return 0 ;default :return -EINVAL ;
Signature · 1 line
2.9.3
Re: [PATCH v3 net-next 8/9] bpf: nfp: Report bpf_prog ID during XDP_QUERY_PROG
In reply to Martin KaFai LauQuoted 6 lines · Martin KaFai Lau
Add support to nfp to report
bpf_progID duringXDP_QUERY_PROG.Signed-off-by Martin KaFai Lau <[email protected]>Cc Jakub Kicinski <[email protected]>Acked-by Daniel Borkmann <[email protected]>
Thanks!
David Miller
maintainerFrom: Martin KaFai Lau <[email protected]>
Date: Thu, 15 Jun 2017 17:29:08 -0700
Quoted 14 lines
This is the first usage of the new
bpf_progID. It is for reporting the ID of axdp_progthrough netlink.It rides on the existing
IFLA_XDP. This patch addsIFLA_XDP_PROG_IDfor thebpf_progID reporting.It starts with changing the
generic_xdpfirst. After that, the hardware driver is changed one by one. Jakub Kicinski mentioned that he will soon introduceXDP_ATTACHED_HW(on top of the existingXDP_ATTACHED_DRVandXDP_ATTACHED_SKB)
and he is going to reuse theprog_attachedfor this purpose. Hence, this patch set keeps theprog_attachedeven though !!prog_id also implies there isxdp_progattached.
Quoted 1 line
I have tested with
generic_xdp, mlx4 and mlx5.
...
Series applied, thanks Martin.