BPF XDP link
Subsystems (29)
v2 cover BPF XDP link
Following cgroup and netns examples, implement bpf_link support for XDP.
The semantics is described in patch #2. Program and link attachments are mutually exclusive, in the sense that neither link can replace attached program nor program can replace attached link. Link can't replace attached link as well, as is the case for any other bpf_link implementation.
Patch #1 refactors existing BPF program-based attachment API and centralizes high-level query/attach decisions in generic kernel code, while drivers are kept simple and are instructed with low-level decisions about attaching and detaching specific bpf_prog. This also makes QUERY command unnecessary, and patch #8 removes support for it from all kernel drivers. If that's a bad idea, we can drop that patch altogether.
With refactoring in patch #1, adding bpf_xdp_link is completely transparent to drivers, they are still functioning at the level of "effective" bpf_prog, that should be called in XDP data path.
Corresponding libbpf support for BPF XDP link is added in patch #5.
v1->v2:
- fix prog refcounting bug (David);
- split dev_change_xdp_fd() changes into 2 patches (David);
- add extack messages to all user-induced errors (David).
Andrii Nakryiko (8):
bpf, xdp: maintain info on attached XDP BPF programs in net_device bpf, xdp: extract commong XDP program attachment logic bpf, xdp: add bpf_link-based XDP attachment API
bpf, xdp: implement LINK_UPDATE for BPF XDP link
bpf: implement BPF XDP link-specific introspection APIs
libbpf: add support for BPF XDP link
selftests/bpf: add BPF XDP link selftests
bpf, xdp: remove XDP_QUERY_PROG and XDP_QUERY_PROG_HW XDP commands
drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 - 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/ice/ice_main.c | 3 - drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 4 - .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 6 - drivers/net/ethernet/marvell/mvneta.c | 5 - .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 3 - .../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/ethernet/sfc/efx.c | 5 - drivers/net/ethernet/socionext/netsec.c | 3 - drivers/net/ethernet/ti/cpsw_priv.c | 3 - drivers/net/hyperv/netvsc_bpf.c | 21 +- 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 - drivers/net/xen-netfront.c | 21 - include/linux/netdevice.h | 29 +- include/net/xdp.h | 2 - include/uapi/linux/bpf.h | 10 +- kernel/bpf/syscall.c | 5 + net/core/dev.c | 523 +++++++++++++----- net/core/rtnetlink.c | 5 +- net/core/xdp.c | 9 - tools/include/uapi/linux/bpf.h | 10 +- tools/lib/bpf/libbpf.c | 9 +- tools/lib/bpf/libbpf.h | 2 + tools/lib/bpf/libbpf.map | 1 + .../selftests/bpf/prog_tests/section_names.c | 2 +- .../selftests/bpf/prog_tests/xdp_link.c | 137 +++++ .../selftests/bpf/progs/test_xdp_link.c | 12 + 38 files changed, 601 insertions(+), 350 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_link.c create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_link.c
Signature · 1 line
2.24.1
PATCH v2 2/8 bpf, xdp: extract commong XDP program attachment logic
Further refactor XDP attachment code. dev_change_xdp_fd() is split into two
parts: getting bpf_progs from FDs and attachment logic, working with bpf_progs. This makes attachment logic a bit more straightforward and prepares code for bpf_xdp_link inclusion, which will share the common logic.
--- net/core/dev.c | 158 ++++++++++++++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 69 deletions(-)
net/core/dev.c +89 -69
@@ -8812,104 +8812,124 @@ static void dev_xdp_uninstall(struct net_device *dev) } } -/** -* dev_change_xdp_fd - set or clear a bpf program for a device rx path -* @dev: device -* @extack: netlink extended ack -* @fd: new program fd or negative value to clear -* @expected_fd: old program fd that userspace expects to replace or clear -* @flags: xdp-related flags -* -* Set or clear a bpf program for a device -*/ -int dev_change_xdp_fd (struct net_device *dev,struct netlink_ext_ack *extack, -int fd,int expected_fd,u32 flags) +static int dev_xdp_attach (struct net_device *dev,struct netlink_ext_ack *extack, +struct bpf_prog *new_prog,struct bpf_prog *old_prog, +u32 flags) { -const struct net_device_ops *ops = dev->netdev_ops; -enum bpf_xdp_mode mode =dev_xdp_mode (flags); -bool offload = mode ==XDP_MODE_HW ; -u32 prog_id, expected_id =0 ; -struct bpf_prog *prog; +struct bpf_prog *cur_prog; +enum bpf_xdp_mode mode;bpf_op_t bpf_op;int err;ASSERT_RTNL (); - bpf_op =dev_xdp_bpf_op (dev, mode); -if (!bpf_op) { -NL_SET_ERR_MSG (extack,"underlying driver does not support XDP in native mode" ); -return -EOPNOTSUPP ; +/* just one XDP mode bit should be set, zero defaults to SKB mode */ +if (hweight32 (flags &XDP_FLAGS_MODES ) >1 ) { +NL_SET_ERR_MSG (extack,"Only one XDP mode flag can be set" ); +return -EINVAL ; + } +/* old_prog != NULL implies XDP_FLAGS_REPLACE is set */ +if (old_prog && !(flags &XDP_FLAGS_REPLACE )) { +NL_SET_ERR_MSG (extack,"XDP_FLAGS_REPLACE is not specified" ); +return -EINVAL ; } - prog_id =dev_xdp_prog_id (dev, mode); -if (flags &XDP_FLAGS_REPLACE ) { -if (expected_fd >=0 ) { - prog =bpf_prog_get_type_dev (expected_fd, -BPF_PROG_TYPE_XDP , - bpf_op == ops->ndo_bpf); -if (IS_ERR (prog)) -return PTR_ERR (prog); - expected_id = prog->aux->id; -bpf_prog_put (prog); - } - -if (prog_id != expected_id) { -NL_SET_ERR_MSG (extack,"Active program does not match expected" ); -return -EEXIST ; - } + mode =dev_xdp_mode (flags); + cur_prog =dev_xdp_prog (dev, mode); +if ((flags &XDP_FLAGS_REPLACE ) && cur_prog != old_prog) { +NL_SET_ERR_MSG (extack,"Active program does not match expected" ); +return -EEXIST ; } -if (fd >=0 ) { +if ((flags &XDP_FLAGS_UPDATE_IF_NOEXIST ) && cur_prog) { +NL_SET_ERR_MSG (extack,"XDP program already attached" ); +return -EBUSY ; + } + +if (new_prog) { +bool offload = mode ==XDP_MODE_HW ;enum bpf_xdp_mode other_mode = mode ==XDP_MODE_SKB ?XDP_MODE_DRV :XDP_MODE_SKB ; -if (!offload &&dev_xdp_prog_id (dev, other_mode)) { +if (!offload &&dev_xdp_prog (dev, other_mode)) {NL_SET_ERR_MSG (extack,"Native and generic XDP can't be active at the same time" );return -EEXIST ; } - -if ((flags &XDP_FLAGS_UPDATE_IF_NOEXIST ) && prog_id) { -NL_SET_ERR_MSG (extack,"XDP program already attached" ); -return -EBUSY ; - } - - prog =bpf_prog_get_type_dev (fd,BPF_PROG_TYPE_XDP , - bpf_op == ops->ndo_bpf); -if (IS_ERR (prog)) -return PTR_ERR (prog); - -if (!offload &&bpf_prog_is_dev_bound (prog->aux)) { +if (!offload &&bpf_prog_is_dev_bound (new_prog->aux)) {NL_SET_ERR_MSG (extack,"Using device-bound program without HW_MODE flag is not supported" ); -bpf_prog_put (prog);return -EINVAL ; } - -if (prog->expected_attach_type ==BPF_XDP_DEVMAP ) { +if (new_prog->expected_attach_type ==BPF_XDP_DEVMAP ) {NL_SET_ERR_MSG (extack,"BPF_XDP_DEVMAP programs can not be attached to a device" ); -bpf_prog_put (prog);return -EINVAL ; } + } -/* prog->aux->id may be 0 for orphaned device-bound progs */ -if (prog->aux->id && prog->aux->id == prog_id) { -bpf_prog_put (prog); -return 0 ; +/* don't call drivers if the effective program didn't change */ +if (new_prog != cur_prog) { + bpf_op =dev_xdp_bpf_op (dev, mode); +if (!bpf_op) { +NL_SET_ERR_MSG (extack,"Underlying driver does not support XDP in native mode" ); +return -EOPNOTSUPP ; } - }else { -if (!prog_id) -return 0 ; - prog =NULL ; - } - err =dev_xdp_install (dev, mode, bpf_op, extack, flags, prog); -if (err <0 && prog) { -bpf_prog_put (prog); -return err; + err =dev_xdp_install (dev, mode, bpf_op, extack, flags, new_prog); +if (err) +return err; } -dev_xdp_set_prog (dev, mode, prog); + +dev_xdp_set_prog (dev, mode, new_prog); +if (cur_prog) +bpf_prog_put (cur_prog);return 0 ; } +/** +* dev_change_xdp_fd - set or clear a bpf program for a device rx path +* @dev: device +* @extack: netlink extended ack +* @fd: new program fd or negative value to clear +* @expected_fd: old program fd that userspace expects to replace or clear +* @flags: xdp-related flags +* +* Set or clear a bpf program for a device +*/ +int dev_change_xdp_fd (struct net_device *dev,struct netlink_ext_ack *extack, +int fd,int expected_fd,u32 flags) +{ +enum bpf_xdp_mode mode =dev_xdp_mode (flags); +struct bpf_prog *new_prog =NULL , *old_prog =NULL ; +int err; + +ASSERT_RTNL (); + +if (fd >=0 ) { + new_prog =bpf_prog_get_type_dev (fd,BPF_PROG_TYPE_XDP , + mode !=XDP_MODE_SKB ); +if (IS_ERR (new_prog)) +return PTR_ERR (new_prog); + } + +if (expected_fd >=0 ) { + old_prog =bpf_prog_get_type_dev (expected_fd,BPF_PROG_TYPE_XDP , + mode !=XDP_MODE_SKB ); +if (IS_ERR (old_prog)) { + err =PTR_ERR (old_prog); + old_prog =NULL ; + goto err_out; + } + } + + err =dev_xdp_attach (dev, extack, new_prog, old_prog, flags); + +err_out: +if (err && new_prog) +bpf_prog_put (new_prog); +if (old_prog) +bpf_prog_put (old_prog); +return err; +} +/** * dev_new_index - allocate an ifindex * @net: the applicable net namespace
Signature · 1 line
2.24.1
PATCH v2 1/8 bpf, xdp: maintain info on attached XDP BPF programs in net_device
In reply to Andrii NakryikoInstead of delegating to drivers, maintain information about which BPF programs are attached in which XDP modes (generic/skb, driver, or hardware) locally in net_device. This effectively obsoletes XDP_QUERY_PROG command.
Such re-organization simplifies existing code already. But it also allows to further add bpf_link-based XDP attachments without drivers having to know about any of this at all, which seems like a good setup. XDP_SETUP_PROG/XDP_SETUP_PROG_HW are just low-level commands to driver to install/uninstall active BPF program. All the higher-level concerns about prog/link interaction will be contained within generic driver-agnostic logic.
All the XDP_QUERY_PROG calls to driver in dev_xdp_uninstall() were removed. It's not clear for me why dev_xdp_uninstall() were passing previous prog_flags when resetting installed programs. That seems unnecessary, plus most drivers don't populate prog_flags anyways. Having XDP_SETUP_PROG vs XDP_SETUP_PROG_HW should be enough of an indicator of what is required of driver to correctly reset active BPF program. dev_xdp_uninstall() is also generalized as an iteration over all three supported mode.
--- include/linux/netdevice.h | 17 +++- net/core/dev.c | 158 +++++++++++++++++++++----------------- net/core/rtnetlink.c | 5 +- 3 files changed, 105 insertions(+), 75 deletions(-)
include/linux/netdevice.h +15 -2
@@ -887,6 +887,17 @@ struct netlink_ext_ack;struct xdp_umem ;struct xdp_dev_bulk_queue ; +enum bpf_xdp_mode { +XDP_MODE_SKB =0 , +XDP_MODE_DRV =1 , +XDP_MODE_HW =2 , + __MAX_XDP_MODE +}; + +struct bpf_xdp_entity { +struct bpf_prog *prog; +}; +struct netdev_bpf {enum bpf_netdev_command command;union {
@@ -2134,6 +2145,9 @@ struct net_device {/* MACsec management functions */ const struct macsec_ops *macsec_ops;#endif + +/* protected by rtnl_lock */ +struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE]; };#define to_net_dev (d) container_of(d, struct net_device, dev)
@@ -3809,8 +3823,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,typedef int (*bpf_op_t )(struct net_device *dev,struct netdev_bpf *bpf);int dev_change_xdp_fd (struct net_device *dev,struct netlink_ext_ack *extack,int fd,int expected_fd,u32 flags); -u32 __dev_xdp_query (struct net_device *dev,bpf_op_t xdp_op, -enum bpf_netdev_command cmd); +u32 dev_xdp_prog_id (struct net_device *dev,enum bpf_xdp_mode mode);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 +88 -70
227 lines not on this page · raw message
net/core/rtnetlink.c +2 -3
@@ -1416,13 +1416,12 @@ static u32 rtnl_xdp_prog_skb(struct net_device *dev)static u32 rtnl_xdp_prog_drv (struct net_device *dev) { -return __dev_xdp_query (dev, dev->netdev_ops->ndo_bpf,XDP_QUERY_PROG ); +return dev_xdp_prog_id (dev,XDP_MODE_DRV ); }static u32 rtnl_xdp_prog_hw (struct net_device *dev) { -return __dev_xdp_query (dev, dev->netdev_ops->ndo_bpf, -XDP_QUERY_PROG_HW ); +return dev_xdp_prog_id (dev,XDP_MODE_HW ); } static int rtnl_xdp_report_one(struct sk_buff *skb, struct net_device *dev,
Signature · 1 line
2.24.1
PATCH v2 3/8 bpf, xdp: add bpf_link-based XDP attachment API
In reply to Andrii NakryikoAdd bpf_link-based API (bpf_xdp_link) to attach BPF XDP program through BPF_LINK_CREATE command.
bpf_xdp_link is mutually exclusive with direct BPF program attachment, previous BPF program should be detached prior to attempting to create a new bpf_xdp_link attachment (for a given XDP mode). Once BPF link is attached, it can't be replaced by other BPF program attachment or link attachment. It will be detached only when the last BPF link FD is closed.
bpf_xdp_link will be auto-detached when net_device is shutdown, similarly to how other BPF links behave (cgroup, flow_dissector). At that point bpf_link will become defunct, but won't be destroyed until last FD is closed.
--- include/linux/netdevice.h | 4 + include/uapi/linux/bpf.h | 7 +- kernel/bpf/syscall.c | 5 ++ net/core/dev.c | 169 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 178 insertions(+), 7 deletions(-)
include/linux/netdevice.h +4 -0
@@ -886,6 +886,7 @@ struct bpf_prog_offload_ops;struct netlink_ext_ack ;struct xdp_umem ;struct xdp_dev_bulk_queue ; +struct bpf_xdp_link ;enum bpf_xdp_mode {XDP_MODE_SKB =0 ,
@@ -896,6 +897,7 @@ enum bpf_xdp_mode {struct bpf_xdp_entity {struct bpf_prog *prog; +struct bpf_xdp_link *link; };struct netdev_bpf {
@@ -3823,7 +3825,9 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,typedef int (*bpf_op_t )(struct net_device *dev,struct netdev_bpf *bpf);int dev_change_xdp_fd (struct net_device *dev,struct netlink_ext_ack *extack,int fd,int expected_fd,u32 flags); +int bpf_xdp_link_attach (const union bpf_attr *attr,struct bpf_prog *prog);u32 dev_xdp_prog_id (struct net_device *dev,enum bpf_xdp_mode mode); +int xdp_umem_query (struct net_device *dev,u16 queue_id);int __dev_forward_skb (struct net_device *dev,struct sk_buff *skb);
include/uapi/linux/bpf.h +6 -1
@@ -227,6 +227,7 @@ enum bpf_attach_type {BPF_CGROUP_INET6_GETSOCKNAME ,BPF_XDP_DEVMAP ,BPF_CGROUP_INET_SOCK_RELEASE , +BPF_XDP , __MAX_BPF_ATTACH_TYPE };
@@ -239,6 +240,7 @@ enum bpf_link_type {BPF_LINK_TYPE_CGROUP =3 ,BPF_LINK_TYPE_ITER =4 ,BPF_LINK_TYPE_NETNS =5 , +BPF_LINK_TYPE_XDP =6 , MAX_BPF_LINK_TYPE, };
@@ -604,7 +606,10 @@ union bpf_attr {struct {/* struct used by BPF_LINK_CREATE command */ __u32 prog_fd;/* eBPF program to attach */ -__u32 target_fd;/* object to attach to */ +union { +__u32 target_fd;/* object to attach to */ +__u32 target_ifindex;/* target ifindex */ + };__u32 attach_type;/* attach type */ __u32 flags;/* extra flags */ } link_create;
kernel/bpf/syscall.c +5 -0
@@ -2817,6 +2817,8 @@ attach_type_to_prog_type(enum bpf_attach_type attach_type)return BPF_PROG_TYPE_CGROUP_SOCKOPT ;case BPF_TRACE_ITER :return BPF_PROG_TYPE_TRACING ; +case BPF_XDP : +return BPF_PROG_TYPE_XDP ;default :return BPF_PROG_TYPE_UNSPEC ; }
@@ -3890,6 +3892,9 @@ static int link_create(union bpf_attr *attr)case BPF_PROG_TYPE_FLOW_DISSECTOR : ret =netns_bpf_link_create (attr, prog);break ; +case BPF_PROG_TYPE_XDP : + ret =bpf_xdp_link_attach (attr, prog); +break ;default : ret = -EINVAL ; }
net/core/dev.c +163 -6
246 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v2 4/8 bpf, xdp: implement LINK_UPDATE for BPF XDP link
In reply to Andrii NakryikoAdd support for LINK_UPDATE command for BPF XDP link to enable reliable replacement of underlying BPF program.
--- net/core/dev.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
net/core/dev.c +43 -0
@@ -8989,9 +8989,52 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link)kfree (xdp_link); } +static int bpf_xdp_link_update (struct bpf_link *link,struct bpf_prog *new_prog, +struct bpf_prog *old_prog) +{ + struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link); +enum bpf_xdp_mode mode; +bpf_op_t bpf_op; +int err =0 ; + +rtnl_lock (); + +/* link might have been auto-released already, so fail */ +if (!xdp_link->dev) { + err = -ENOLINK ; + goto out_unlock; + } + +if (old_prog && link->prog != old_prog) { + err = -EPERM ; + goto out_unlock; + } + old_prog = link->prog; +if (old_prog == new_prog) { +/* no-op, don't disturb drivers */ +bpf_prog_put (new_prog); + goto out_unlock; + } + + mode =dev_xdp_mode (xdp_link->flags); + bpf_op =dev_xdp_bpf_op (xdp_link->dev, mode); + err =dev_xdp_install (xdp_link->dev, mode, bpf_op,NULL , + xdp_link->flags, new_prog); +if (err) + goto out_unlock; + + old_prog =xchg (&link->prog, new_prog); +bpf_prog_put (old_prog); + +out_unlock: +rtnl_unlock (); +return err; +} +static const struct bpf_link_ops bpf_xdp_link_lops = { .release = bpf_xdp_link_release, .dealloc = bpf_xdp_link_dealloc, + .update_prog = bpf_xdp_link_update, };int bpf_xdp_link_attach (const union bpf_attr *attr,struct bpf_prog *prog)
Signature · 1 line
2.24.1
PATCH v2 5/8 bpf: implement BPF XDP link-specific introspection APIs
In reply to Andrii NakryikoImplement XDP link-specific show_fdinfo and link_info to emit ifindex.
--- include/uapi/linux/bpf.h | 3 +++ net/core/dev.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
include/uapi/linux/bpf.h +3 -0
@@ -3985,6 +3985,9 @@ struct bpf_link_info {__u32 netns_ino;__u32 attach_type; } netns; +struct { +__u32 ifindex; + } xdp; }; } __attribute__((aligned(8)));
net/core/dev.c +31 -0
@@ -8989,6 +8989,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link)kfree (xdp_link); } +static void bpf_xdp_link_show_fdinfo (const struct bpf_link *link, +struct seq_file *seq) +{ + struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link); +u32 ifindex =0 ; + +rtnl_lock (); +if (xdp_link->dev) + ifindex = xdp_link->dev->ifindex; +rtnl_unlock (); + +seq_printf (seq,"ifindex:\t%u\n" , ifindex); +} + +static int bpf_xdp_link_fill_link_info (const struct bpf_link *link, +struct bpf_link_info *info) +{ + struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link); +u32 ifindex =0 ; + +rtnl_lock (); +if (xdp_link->dev) + ifindex = xdp_link->dev->ifindex; +rtnl_unlock (); + + info->xdp.ifindex = ifindex; +return 0 ; +} +static int bpf_xdp_link_update (struct bpf_link *link,struct bpf_prog *new_prog,struct bpf_prog *old_prog) {
@@ -9034,6 +9063,8 @@ static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog,static const struct bpf_link_ops bpf_xdp_link_lops = { .release = bpf_xdp_link_release, .dealloc = bpf_xdp_link_dealloc, + .show_fdinfo = bpf_xdp_link_show_fdinfo, + .fill_link_info = bpf_xdp_link_fill_link_info, .update_prog = bpf_xdp_link_update, };
Signature · 1 line
2.24.1
PATCH v2 6/8 libbpf: add support for BPF XDP link
In reply to Andrii NakryikoSync UAPI header and add support for using bpf_link-based XDP attachment. Make xdp/ prog type set expected attach type. Kernel didn't enforce attach_type for XDP programs before, so there is no backwards compatiblity issues there.
Also fix section_names selftest to recognize that xdp prog types now have expected attach type.
--- tools/include/uapi/linux/bpf.h | 10 +++++++++- tools/lib/bpf/libbpf.c | 9 ++++++++- tools/lib/bpf/libbpf.h | 2 ++ tools/lib/bpf/libbpf.map | 1 + tools/testing/selftests/bpf/prog_tests/section_names.c | 2 +- 5 files changed, 21 insertions(+), 3 deletions(-)
tools/include/uapi/linux/bpf.h +9 -1
@@ -227,6 +227,7 @@ enum bpf_attach_type {BPF_CGROUP_INET6_GETSOCKNAME ,BPF_XDP_DEVMAP ,BPF_CGROUP_INET_SOCK_RELEASE , +BPF_XDP , __MAX_BPF_ATTACH_TYPE };
@@ -239,6 +240,7 @@ enum bpf_link_type {BPF_LINK_TYPE_CGROUP =3 ,BPF_LINK_TYPE_ITER =4 ,BPF_LINK_TYPE_NETNS =5 , +BPF_LINK_TYPE_XDP =6 , MAX_BPF_LINK_TYPE, };
@@ -604,7 +606,10 @@ union bpf_attr {struct {/* struct used by BPF_LINK_CREATE command */ __u32 prog_fd;/* eBPF program to attach */ -__u32 target_fd;/* object to attach to */ +union { +__u32 target_fd;/* object to attach to */ +__u32 target_ifindex;/* target ifindex */ + };__u32 attach_type;/* attach type */ __u32 flags;/* extra flags */ } link_create;
@@ -3980,6 +3985,9 @@ struct bpf_link_info {__u32 netns_ino;__u32 attach_type; } netns; +struct { +__u32 ifindex; + } xdp; }; } __attribute__((aligned(8)));
tools/lib/bpf/libbpf.c +8 -1
@@ -6906,7 +6906,8 @@ static const struct bpf_sec_def section_defs[] = { .attach_fn = attach_iter),BPF_EAPROG_SEC ("xdp_devmap" ,BPF_PROG_TYPE_XDP ,BPF_XDP_DEVMAP ), -BPF_PROG_SEC ("xdp" ,BPF_PROG_TYPE_XDP ), +BPF_EAPROG_SEC ("xdp" ,BPF_PROG_TYPE_XDP , +BPF_XDP ),BPF_PROG_SEC ("perf_event" ,BPF_PROG_TYPE_PERF_EVENT ),BPF_PROG_SEC ("lwt_in" ,BPF_PROG_TYPE_LWT_IN ), BPF_PROG_SEC("lwt_out", BPF_PROG_TYPE_LWT_OUT),
@@ -8267,6 +8268,12 @@ bpf_program__attach_netns(struct bpf_program *prog, int netns_fd)return bpf_program__attach_fd (prog, netns_fd,"netns" ); } +struct bpf_link *bpf_program__attach_xdp (struct bpf_program *prog,int ifindex) +{ +/* target_fd/target_ifindex use the same field in LINK_CREATE */ +return bpf_program__attach_fd (prog, ifindex,"xdp" ); +} +struct bpf_link *bpf_program__attach_iter (struct bpf_program *prog,const struct bpf_iter_attach_opts *opts)
tools/lib/bpf/libbpf.h +2 -0
@@ -257,6 +257,8 @@ LIBBPF_API struct bpf_link * bpf_program__attach_cgroup(struct bpf_program *prog, int cgroup_fd); LIBBPF_API struct bpf_link *bpf_program__attach_netns (struct bpf_program *prog,int netns_fd); +LIBBPF_API struct bpf_link * +bpf_program__attach_xdp (struct bpf_program *prog,int ifindex);struct bpf_map ;
tools/lib/bpf/libbpf.map +1 -0
@@ -286,6 +286,7 @@ LIBBPF_0.1.0 { bpf_map__set_value_size; bpf_map__type; bpf_map__value_size; + bpf_program__attach_xdp; bpf_program__autoload; bpf_program__set_autoload; btf__set_fd;
tools/testing/selftests/bpf/prog_tests/section_names.c +1 -1
@@ -35,7 +35,7 @@ static struct sec_name_test tests[] = { {-EINVAL, 0}, }, {"raw_tp/", {0, BPF_PROG_TYPE_RAW_TRACEPOINT, 0}, {-EINVAL, 0} }, - {"xdp", {0, BPF_PROG_TYPE_XDP, 0}, {-EINVAL, 0} }, + {"xdp", {0, BPF_PROG_TYPE_XDP, BPF_XDP}, {0, BPF_XDP} }, {"perf_event", {0, BPF_PROG_TYPE_PERF_EVENT, 0}, {-EINVAL, 0} }, {"lwt_in", {0, BPF_PROG_TYPE_LWT_IN, 0}, {-EINVAL, 0} }, {"lwt_out", {0, BPF_PROG_TYPE_LWT_OUT, 0}, {-EINVAL, 0} },
Signature · 1 line
2.24.1
PATCH v2 8/8 bpf, xdp: remove XDP_QUERY_PROG and XDP_QUERY_PROG_HW XDP commands
In reply to Andrii NakryikoNow that BPF program/link management is centralized in generic net_device code, kernel code never queries program id from drivers, so XDP_QUERY_PROG/XDP_QUERY_PROG_HW commands are unnecessary.
This patch removes all the implementations of those commands in kernel, along the xdp_attachment_query().
This patch was compile-tested on allyesconfig.
--- drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 ----- 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/ice/ice_main.c | 3 --- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 4 ---- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 6 ----- drivers/net/ethernet/marvell/mvneta.c | 5 ---- .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 3 --- .../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/ethernet/sfc/efx.c | 5 ---- drivers/net/ethernet/socionext/netsec.c | 3 --- drivers/net/ethernet/ti/cpsw_priv.c | 3 --- drivers/net/hyperv/netvsc_bpf.c | 21 +--------------- 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 ------------- drivers/net/xen-netfront.c | 21 ---------------- include/linux/netdevice.h | 8 ------- include/net/xdp.h | 2 -- net/core/dev.c | 4 ---- net/core/xdp.c | 9 ------- 28 files changed, 2 insertions(+), 216 deletions(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +0 -6
@@ -576,15 +576,9 @@ static int ena_xdp_set(struct net_device *netdev, struct netdev_bpf *bpf)*/ static int ena_xdp (struct net_device *netdev,struct netdev_bpf *bpf) { -struct ena_adapter *adapter =netdev_priv (netdev); -switch (bpf->command) {case XDP_SETUP_PROG :return ena_xdp_set (netdev, bpf); -case XDP_QUERY_PROG : - bpf->prog_id = adapter->xdp_bpf_prog ? - adapter->xdp_bpf_prog->aux->id :0 ; -break ;default :return -EINVAL ; }
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +0 -4
@@ -330,10 +330,6 @@ int bnxt_xdp(struct net_device *dev, struct netdev_bpf *xdp)case XDP_SETUP_PROG : rc =bnxt_xdp_set (bp, xdp->prog);break ; -case XDP_QUERY_PROG : - xdp->prog_id = bp->xdp_prog ? bp->xdp_prog->aux->id :0 ; - rc =0 ; -break ;default : rc = -EINVAL ;break ;
drivers/net/ethernet/cavium/thunder/nicvf_main.c +0 -3
@@ -1906,9 +1906,6 @@ static int nicvf_xdp(struct net_device *netdev, struct netdev_bpf *xdp)switch (xdp->command) {case XDP_SETUP_PROG :return nicvf_xdp_setup (nic, xdp->prog); -case XDP_QUERY_PROG : - xdp->prog_id = nic->xdp_prog ? nic->xdp_prog->aux->id :0 ; -return 0 ;default :return -EINVAL ; }
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +0 -3
@@ -2081,9 +2081,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
@@ -12923,9 +12923,6 @@ static int i40e_xdp(struct net_device *dev,switch (xdp->command) {case XDP_SETUP_PROG :return i40e_xdp_setup (vsi, xdp->prog); -case XDP_QUERY_PROG : - xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id :0 ; -return 0 ;case XDP_SETUP_XSK_UMEM :return i40e_xsk_umem_setup (vsi, xdp->xsk.umem, xdp->xsk.queue_id);
drivers/net/ethernet/intel/ice/ice_main.c +0 -3
@@ -1974,9 +1974,6 @@ static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)switch (xdp->command) {case XDP_SETUP_PROG :return ice_xdp_setup_prog (vsi, xdp->prog, xdp->extack); -case XDP_QUERY_PROG : - xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id :0 ; -return 0 ;case XDP_SETUP_XSK_UMEM :return ice_xsk_umem_setup (vsi, xdp->xsk.umem, xdp->xsk.queue_id);
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +0 -4
@@ -10314,10 +10314,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 -6
@@ -4502,15 +4502,9 @@ static int ixgbevf_xdp_setup(struct net_device *dev, struct bpf_prog *prog)static int ixgbevf_xdp (struct net_device *dev,struct netdev_bpf *xdp) { -struct ixgbevf_adapter *adapter =netdev_priv (dev); -switch (xdp->command) {case XDP_SETUP_PROG :return ixgbevf_xdp_setup (dev, xdp->prog); -case XDP_QUERY_PROG : - xdp->prog_id = adapter->xdp_prog ? - adapter->xdp_prog->aux->id :0 ; -return 0 ;default :return -EINVAL ; }
drivers/net/ethernet/marvell/mvneta.c +0 -5
@@ -4417,14 +4417,9 @@ static int mvneta_xdp_setup(struct net_device *dev, struct bpf_prog *prog,static int mvneta_xdp (struct net_device *dev,struct netdev_bpf *xdp) { -struct mvneta_port *pp =netdev_priv (dev); -switch (xdp->command) {case XDP_SETUP_PROG :return mvneta_xdp_setup (dev, xdp->prog, xdp->extack); -case XDP_QUERY_PROG : - xdp->prog_id = pp->xdp_prog ? pp->xdp_prog->aux->id :0 ; -return 0 ;default :return -EINVAL ; }
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +0 -3
@@ -4656,9 +4656,6 @@ static int mvpp2_xdp(struct net_device *dev, struct netdev_bpf *xdp)switch (xdp->command) {case XDP_SETUP_PROG :return mvpp2_xdp_setup (port, xdp); -case XDP_QUERY_PROG : - xdp->prog_id = port->xdp_prog ? port->xdp_prog->aux->id :0 ; -return 0 ;default :return -EINVAL ; }
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +0 -24
@@ -2859,35 +2859,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
@@ -4520,29 +4520,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 ;case XDP_SETUP_XSK_UMEM :return mlx5e_xsk_setup_umem (dev, xdp->xsk.umem, xdp->xsk.queue_id);
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +0 -4
@@ -3704,10 +3704,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
@@ -1093,9 +1093,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/ethernet/sfc/efx.c +0 -5
@@ -721,15 +721,10 @@ static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)static int efx_xdp (struct net_device *dev,struct netdev_bpf *xdp) {struct efx_nic *efx =netdev_priv (dev); -struct bpf_prog *xdp_prog;switch (xdp->command) {case XDP_SETUP_PROG :return efx_xdp_setup_prog (efx, xdp->prog); -case XDP_QUERY_PROG : - xdp_prog =rtnl_dereference (efx->xdp_prog); - xdp->prog_id = xdp_prog ? xdp_prog->aux->id :0 ; -return 0 ;default :return -EINVAL ; }
drivers/net/ethernet/socionext/netsec.c +0 -3
@@ -1811,9 +1811,6 @@ static int netsec_xdp(struct net_device *ndev, struct netdev_bpf *xdp)switch (xdp->command) {case XDP_SETUP_PROG :return netsec_xdp_setup (priv, xdp->prog, xdp->extack); -case XDP_QUERY_PROG : - xdp->prog_id = priv->xdp_prog ? priv->xdp_prog->aux->id :0 ; -return 0 ;default :return -EINVAL ; }
drivers/net/ethernet/ti/cpsw_priv.c +0 -3
@@ -1286,9 +1286,6 @@ int cpsw_ndo_bpf(struct net_device *ndev, struct netdev_bpf *bpf)case XDP_SETUP_PROG :return cpsw_xdp_prog_setup (priv, bpf); -case XDP_QUERY_PROG : -return xdp_attachment_query (&priv->xdpi, bpf); -default :return -EINVAL ; }
drivers/net/hyperv/netvsc_bpf.c +1 -20
@@ -163,16 +163,6 @@ int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog)return ret; } -static u32 netvsc_xdp_query (struct netvsc_device *nvdev) -{ -struct bpf_prog *prog =netvsc_xdp_get (nvdev); - -if (prog) -return prog->aux->id; - -return 0 ; -} -int netvsc_bpf (struct net_device *dev,struct netdev_bpf *bpf) {struct net_device_context *ndevctx =netdev_priv (dev);
@@ -182,12 +172,7 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)int ret;if (!nvdev || nvdev->destroy) { -if (bpf->command ==XDP_QUERY_PROG ) { - bpf->prog_id =0 ; -return 0 ;/* Query must always succeed */ - }else { -return -ENODEV ; - } +return -ENODEV ; }switch (bpf->command) {
@@ -208,10 +193,6 @@ int netvsc_bpf(struct net_device *dev, struct netdev_bpf *bpf)return ret; -case XDP_QUERY_PROG : - bpf->prog_id =netvsc_xdp_query (nvdev); -return 0 ; -default :return -EINVAL ; }
drivers/net/netdevsim/bpf.c +0 -4
@@ -551,10 +551,6 @@ int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)ASSERT_RTNL ();switch (bpf->command) { -case XDP_QUERY_PROG : -return xdp_attachment_query (&ns->xdp, bpf); -case XDP_QUERY_PROG_HW : -return xdp_attachment_query (&ns->xdp_hw, bpf);case XDP_SETUP_PROG : err =nsim_setup_prog_checks (ns, bpf);if (err)
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
@@ -1183,26 +1183,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
@@ -1198,26 +1198,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
@@ -2490,28 +2490,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 ; }
drivers/net/xen-netfront.c +0 -21
@@ -1478,32 +1478,11 @@ static int xennet_xdp_set(struct net_device *dev, struct bpf_prog *prog,return 0 ; } -static u32 xennet_xdp_query (struct net_device *dev) -{ -unsigned int num_queues = dev->real_num_tx_queues; -struct netfront_info *np =netdev_priv (dev); -const struct bpf_prog *xdp_prog; -struct netfront_queue *queue; -unsigned int i; - -for (i =0 ; i < num_queues; ++i) { - queue = &np->queues[i]; - xdp_prog =rtnl_dereference (queue->xdp_prog); -if (xdp_prog) -return xdp_prog->aux->id; - } - -return 0 ; -} -static int xennet_xdp (struct net_device *dev,struct netdev_bpf *xdp) {switch (xdp->command) {case XDP_SETUP_PROG :return xennet_xdp_set (dev, xdp->prog, xdp->extack); -case XDP_QUERY_PROG : - xdp->prog_id =xennet_xdp_query (dev); -return 0 ;default :return -EINVAL ; }
include/linux/netdevice.h +0 -8
@@ -874,8 +874,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,
@@ -909,12 +907,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
@@ -209,8 +209,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 -4
@@ -5466,10 +5466,6 @@ static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp) }break ; -case XDP_QUERY_PROG : - xdp->prog_id = old ? old->aux->id :0 ; -break ; -default : ret = -EINVAL ;break ;
net/core/xdp.c +0 -9
@@ -400,15 +400,6 @@ void __xdp_release_frame(void *data, struct xdp_mem_info *mem) }EXPORT_SYMBOL_GPL (__xdp_release_frame); -int xdp_attachment_query (struct xdp_attachment_info *info, -struct netdev_bpf *bpf) -{ - bpf->prog_id = info->prog ? info->prog->aux->id :0 ; - bpf->prog_flags = info->prog ? info->flags :0 ; -return 0 ; -} -EXPORT_SYMBOL_GPL (xdp_attachment_query); -bool xdp_attachment_flags_ok (struct xdp_attachment_info *info,struct netdev_bpf *bpf) {
Signature · 1 line
2.24.1
PATCH v2 7/8 selftests/bpf: add BPF XDP link selftests
In reply to Andrii NakryikoAdd selftest validating all the attachment logic around BPF XDP link. Test also link updates and get_obj_info() APIs.
--- .../selftests/bpf/prog_tests/xdp_link.c | 137 ++++++++++++++++++ .../selftests/bpf/progs/test_xdp_link.c | 12 ++ 2 files changed, 149 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_link.c create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_link.c
tools/testing/selftests/bpf/prog_tests/xdp_link.c new file +137 -0
@@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2020 Facebook */ +#include <uapi/linux/if_link.h> +#include <test_progs.h> +#include "test_xdp_link.skel.h" + +#define IFINDEX_LO 1 + +void test_xdp_link (void ) +{ +__u32 duration =0 , id1, id2, id0 =0 , prog_fd1, prog_fd2, err; + DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, .old_fd = -1); +struct test_xdp_link *skel1 =NULL , *skel2 =NULL ; +struct bpf_link_info link_info; +struct bpf_prog_info prog_info; +struct bpf_link *link; +__u32 link_info_len =sizeof (link_info); +__u32 prog_info_len =sizeof (prog_info); + + skel1 =test_xdp_link__open_and_load (); +if (CHECK (!skel1,"skel_load" ,"skeleton open and load failed\n" )) + goto cleanup; + prog_fd1 =bpf_program__fd (skel1->progs.xdp_handler); + + skel2 =test_xdp_link__open_and_load (); +if (CHECK (!skel2,"skel_load" ,"skeleton open and load failed\n" )) + goto cleanup; + prog_fd2 =bpf_program__fd (skel2->progs.xdp_handler); + +memset (&prog_info,0 ,sizeof (prog_info)); + err =bpf_obj_get_info_by_fd (prog_fd1, &prog_info, &prog_info_len); +if (CHECK (err,"fd_info1" ,"failed %d\n" , -errno)) + goto cleanup; + id1 = prog_info.id; + +memset (&prog_info,0 ,sizeof (prog_info)); + err =bpf_obj_get_info_by_fd (prog_fd2, &prog_info, &prog_info_len); +if (CHECK (err,"fd_info2" ,"failed %d\n" , -errno)) + goto cleanup; + id2 = prog_info.id; + +/* set initial prog attachment */ + err =bpf_set_link_xdp_fd_opts (IFINDEX_LO , prog_fd1,XDP_FLAGS_REPLACE , &opts); +if (CHECK (err,"fd_attach" ,"initial prog attach failed: %d\n" , err)) + goto cleanup; + +/* validate prog ID */ + err =bpf_get_link_xdp_id (IFINDEX_LO , &id0,0 ); +CHECK (err || id0 != id1,"id1_check" , +"loaded prog id %u != id1 %u, err %d" , id0, id1, err); + +/* BPF link is not allowed to replace prog attachment */ + link =bpf_program__attach_xdp (skel1->progs.xdp_handler,IFINDEX_LO ); +if (CHECK (!IS_ERR (link),"link_attach_fail" ,"unexpected success\n" )) { +bpf_link__destroy (link); +/* best-effort detach prog */ + opts.old_fd = prog_fd1; +bpf_set_link_xdp_fd_opts (IFINDEX_LO ,-1 ,XDP_FLAGS_REPLACE , &opts); + goto cleanup; + } + +/* detach BPF program */ + opts.old_fd = prog_fd1; + err =bpf_set_link_xdp_fd_opts (IFINDEX_LO ,-1 ,XDP_FLAGS_REPLACE , &opts); +if (CHECK (err,"prog_detach" ,"failed %d\n" , err)) + goto cleanup; + +/* now BPF link should attach successfully */ + link =bpf_program__attach_xdp (skel1->progs.xdp_handler,IFINDEX_LO ); +if (CHECK (IS_ERR (link),"link_attach" ,"failed: %ld\n" ,PTR_ERR (link))) + goto cleanup; + skel1->links.xdp_handler = link; + +/* validate prog ID */ + err =bpf_get_link_xdp_id (IFINDEX_LO , &id0,0 ); +if (CHECK (err || id0 != id1,"id1_check" , +"loaded prog id %u != id1 %u, err %d" , id0, id1, err)) + goto cleanup; + +/* BPF prog attach is not allowed to replace BPF link */ + opts.old_fd = prog_fd1; + err =bpf_set_link_xdp_fd_opts (IFINDEX_LO , prog_fd2,XDP_FLAGS_REPLACE , &opts); +if (CHECK (!err,"prog_attach_fail" ,"unexpected success\n" )) + goto cleanup; + +/* Can't force-update when BPF link is active */ + err =bpf_set_link_xdp_fd (IFINDEX_LO , prog_fd2,0 ); +if (CHECK (!err,"prog_update_fail" ,"unexpected success\n" )) + goto cleanup; + +/* Can't force-detach when BPF link is active */ + err =bpf_set_link_xdp_fd (IFINDEX_LO ,-1 ,0 ); +if (CHECK (!err,"prog_detach_fail" ,"unexpected success\n" )) + goto cleanup; + +/* BPF link is not allowed to replace another BPF link */ + link =bpf_program__attach_xdp (skel2->progs.xdp_handler,IFINDEX_LO ); +if (CHECK (!IS_ERR (link),"link_attach_fail" ,"unexpected success\n" )) { +bpf_link__destroy (link); + goto cleanup; + } + +bpf_link__destroy (skel1->links.xdp_handler); + skel1->links.xdp_handler =NULL ; + +/* new link attach should succeed */ + link =bpf_program__attach_xdp (skel2->progs.xdp_handler,IFINDEX_LO ); +if (CHECK (IS_ERR (link),"link_attach" ,"failed: %ld\n" ,PTR_ERR (link))) + goto cleanup; + skel2->links.xdp_handler = link; + + err =bpf_get_link_xdp_id (IFINDEX_LO , &id0,0 ); +if (CHECK (err || id0 != id2,"id2_check" , +"loaded prog id %u != id2 %u, err %d" , id0, id1, err)) + goto cleanup; + +/* updating program under active BPF link works as expected */ + err =bpf_link__update_program (link, skel1->progs.xdp_handler); +if (CHECK (err,"link_upd" ,"failed: %d\n" , err)) + goto cleanup; + +memset (&link_info,0 ,sizeof (link_info)); + err =bpf_obj_get_info_by_fd (bpf_link__fd (link), &link_info, &link_info_len); +if (CHECK (err,"link_info" ,"failed: %d\n" , err)) + goto cleanup; + +CHECK (link_info.type !=BPF_LINK_TYPE_XDP ,"link_type" , +"got %u != exp %u\n" , link_info.type,BPF_LINK_TYPE_XDP ); +CHECK (link_info.prog_id != id1,"link_prog_id" , +"got %u != exp %u\n" , link_info.prog_id, id1); +CHECK (link_info.xdp.ifindex !=IFINDEX_LO ,"link_ifindex" , +"got %u != exp %u\n" , link_info.xdp.ifindex,IFINDEX_LO ); + +cleanup: +test_xdp_link__destroy (skel1); +test_xdp_link__destroy (skel2); +}
tools/testing/selftests/bpf/progs/test_xdp_link.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2020 Facebook */ +#include <linux/bpf.h> +#include <bpf/bpf_helpers.h> + +char LICENSE[] SEC("license") = "GPL"; + +SEC("xdp/handler") +int xdp_handler (struct xdp_md *xdp) +{ +return 0 ; +}
Signature · 1 line
2.24.1
kernel test robot
build botRe: [PATCH v2 bpf-next 4/8] bpf, xdp: implement LINK_UPDATE for BPF XDP link
In reply to Andrii NakryikoI love your patch! Perhaps something to improve:
Hi Andrii,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Andrii-Nakryiko/BPF-XDP-link/20200714-120909 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: parisc-defconfig (attached as .config) compiler: hppa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=parisc
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
net/core/dev.c:8717:18: error: field 'link' has incomplete type
8717 | struct bpf_link link;
| ^~~~
In file included from include/linux/instrumented.h:10,
from include/linux/uaccess.h:5,
from net/core/dev.c:71:
net/core/dev.c: In function 'bpf_xdp_link_release':
include/linux/kernel.h:1003:32: error: dereferencing pointer to incomplete type 'struct bpf_link'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~
include/linux/compiler.h:372:9: note: in definition of macro '__compiletime_assert'
372 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler.h:392:2: note: in expansion of macro '_compiletime_assert'
392 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/kernel.h:1003:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~~~~~~~~~~~
include/linux/kernel.h:1003:20: note: in expansion of macro '__same_type'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~~~~~~
net/core/dev.c:8972:34: note: in expansion of macro 'container_of'
8972 | struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
| ^~~~~~~~~~~~
In file included from arch/parisc/include/asm/atomic.h:10,
from include/linux/atomic.h:7,
from arch/parisc/include/asm/bitops.h:13,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from arch/parisc/include/asm/bug.h:5,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/current.h:5,
from ./arch/parisc/include/generated/asm/current.h:1,
from include/linux/sched.h:12,
from include/linux/uaccess.h:6,
from net/core/dev.c:71:
net/core/dev.c: In function 'bpf_xdp_link_update':
>> arch/parisc/include/asm/cmpxchg.h:50:27: warning: initialization of 'int' from 'struct bpf_prog *' makes integer from pointer without a cast [-Wint-conversion]
50 | __typeof__(*(ptr)) _x_ = (x); \
| ^
net/core/dev.c:9026:13: note: in expansion of macro 'xchg'
9026 | old_prog = xchg(&link->prog, new_prog);
| ^~~~
net/core/dev.c:9026:11: warning: assignment to 'struct bpf_prog *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
9026 | old_prog = xchg(&link->prog, new_prog);
| ^
net/core/dev.c: At top level:
net/core/dev.c:9034:21: error: variable 'bpf_xdp_link_lops' has initializer but incomplete type
9034 | static const struct bpf_link_ops bpf_xdp_link_lops = {
| ^~~~~~~~~~~~
net/core/dev.c:9035:3: error: 'const struct bpf_link_ops' has no member named 'release'
9035 | .release = bpf_xdp_link_release,
| ^~~~~~~
net/core/dev.c:9035:13: warning: excess elements in struct initializer
9035 | .release = bpf_xdp_link_release,
| ^~~~~~~~~~~~~~~~~~~~
net/core/dev.c:9035:13: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c:9036:3: error: 'const struct bpf_link_ops' has no member named 'dealloc'
9036 | .dealloc = bpf_xdp_link_dealloc,
| ^~~~~~~
net/core/dev.c:9036:13: warning: excess elements in struct initializer
9036 | .dealloc = bpf_xdp_link_dealloc,
| ^~~~~~~~~~~~~~~~~~~~
net/core/dev.c:9036:13: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c:9037:3: error: 'const struct bpf_link_ops' has no member named 'update_prog'
9037 | .update_prog = bpf_xdp_link_update,
| ^~~~~~~~~~~
net/core/dev.c:9037:17: warning: excess elements in struct initializer
9037 | .update_prog = bpf_xdp_link_update,
| ^~~~~~~~~~~~~~~~~~~
net/core/dev.c:9037:17: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c: In function 'bpf_xdp_link_attach':
net/core/dev.c:9043:25: error: storage size of 'link_primer' isn't known
9043 | struct bpf_link_primer link_primer;
| ^~~~~~~~~~~
net/core/dev.c:9058:2: error: implicit declaration of function 'bpf_link_init'; did you mean 'bio_list_init'? [-Werror=implicit-function-declaration]
9058 | bpf_link_init(&link->link, BPF_LINK_TYPE_XDP, &bpf_xdp_link_lops, prog);
| ^~~~~~~~~~~~~
| bio_list_init
net/core/dev.c:9062:8: error: implicit declaration of function 'bpf_link_prime' [-Werror=implicit-function-declaration]
9062 | err = bpf_link_prime(&link->link, &link_primer);
| ^~~~~~~~~~~~~~
net/core/dev.c:9073:3: error: implicit declaration of function 'bpf_link_cleanup' [-Werror=implicit-function-declaration]
9073 | bpf_link_cleanup(&link_primer);
| ^~~~~~~~~~~~~~~~
net/core/dev.c:9077:7: error: implicit declaration of function 'bpf_link_settle' [-Werror=implicit-function-declaration]
9077 | fd = bpf_link_settle(&link_primer);
| ^~~~~~~~~~~~~~~
net/core/dev.c:9043:25: warning: unused variable 'link_primer' [-Wunused-variable]
9043 | struct bpf_link_primer link_primer;
| ^~~~~~~~~~~
net/core/dev.c: At top level:
net/core/dev.c:9034:34: error: storage size of 'bpf_xdp_link_lops' isn't known
9034 | static const struct bpf_link_ops bpf_xdp_link_lops = {
| ^~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +50 arch/parisc/include/asm/cmpxchg.h
9e5228ce0b9619 Paul Gortmaker 2012-04-01 37
9e5228ce0b9619 Paul Gortmaker 2012-04-01 38 /*
9e5228ce0b9619 Paul Gortmaker 2012-04-01 39 ** REVISIT - Abandoned use of LDCW in xchg() for now:
9e5228ce0b9619 Paul Gortmaker 2012-04-01 40 ** o need to test sizeof(*ptr) to avoid clearing adjacent bytes
9e5228ce0b9619 Paul Gortmaker 2012-04-01 41 ** o and while we are at it, could CONFIG_64BIT code use LDCD too?
9e5228ce0b9619 Paul Gortmaker 2012-04-01 42 **
9e5228ce0b9619 Paul Gortmaker 2012-04-01 43 ** if (__builtin_constant_p(x) && (x == NULL))
9e5228ce0b9619 Paul Gortmaker 2012-04-01 44 ** if (((unsigned long)p & 0xf) == 0)
9e5228ce0b9619 Paul Gortmaker 2012-04-01 45 ** return __ldcw(p);
9e5228ce0b9619 Paul Gortmaker 2012-04-01 46 */
9e5228ce0b9619 Paul Gortmaker 2012-04-01 47 #define xchg(ptr, x) \
75cf9797006a3a Helge Deller 2019-12-20 48 ({ \
75cf9797006a3a Helge Deller 2019-12-20 49 __typeof__(*(ptr)) __ret; \
75cf9797006a3a Helge Deller 2019-12-20 @50 __typeof__(*(ptr)) _x_ = (x); \
75cf9797006a3a Helge Deller 2019-12-20 51 __ret = (__typeof__(*(ptr))) \
75cf9797006a3a Helge Deller 2019-12-20 52 __xchg((unsigned long)_x_, (ptr), sizeof(*(ptr))); \
75cf9797006a3a Helge Deller 2019-12-20 53 __ret; \
75cf9797006a3a Helge Deller 2019-12-20 54 })9e5228ce0b9619 Paul Gortmaker 2012-04-01 55
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v2 bpf-next 4/8] bpf, xdp: implement LINK_UPDATE for BPF XDP link
In reply to Andrii NakryikoI love your patch! Perhaps something to improve:
Hi Andrii,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Andrii-Nakryiko/BPF-XDP-link/20200714-120909 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: alpha-defconfig (attached as .config) compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
net/core/dev.c:8717:18: error: field 'link' has incomplete type
8717 | struct bpf_link link;
| ^~~~
In file included from include/linux/instrumented.h:10,
from include/linux/uaccess.h:5,
from net/core/dev.c:71:
net/core/dev.c: In function 'bpf_xdp_link_release':
include/linux/kernel.h:1003:32: error: dereferencing pointer to incomplete type 'struct bpf_link'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~
include/linux/compiler.h:372:9: note: in definition of macro '__compiletime_assert'
372 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler.h:392:2: note: in expansion of macro '_compiletime_assert'
392 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/kernel.h:1003:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~~~~~~~~~~~
include/linux/kernel.h:1003:20: note: in expansion of macro '__same_type'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~~~~~~
net/core/dev.c:8972:34: note: in expansion of macro 'container_of'
8972 | struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
| ^~~~~~~~~~~~
In file included from arch/alpha/include/asm/atomic.h:7,
from include/linux/atomic.h:7,
from include/linux/rcupdate.h:25,
from include/linux/rculist.h:11,
from include/linux/pid.h:5,
from include/linux/sched.h:14,
from include/linux/uaccess.h:6,
from net/core/dev.c:71:
net/core/dev.c: In function 'bpf_xdp_link_update':
>> arch/alpha/include/asm/cmpxchg.h:48:27: warning: initialization of 'int' from 'struct bpf_prog *' makes integer from pointer without a cast [-Wint-conversion]
48 | __typeof__(*(ptr)) _x_ = (x); \
| ^
net/core/dev.c:9026:13: note: in expansion of macro 'xchg'
9026 | old_prog = xchg(&link->prog, new_prog);
| ^~~~
net/core/dev.c:9026:11: warning: assignment to 'struct bpf_prog *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
9026 | old_prog = xchg(&link->prog, new_prog);
| ^
net/core/dev.c: At top level:
net/core/dev.c:9034:21: error: variable 'bpf_xdp_link_lops' has initializer but incomplete type
9034 | static const struct bpf_link_ops bpf_xdp_link_lops = {
| ^~~~~~~~~~~~
net/core/dev.c:9035:3: error: 'const struct bpf_link_ops' has no member named 'release'
9035 | .release = bpf_xdp_link_release,
| ^~~~~~~
net/core/dev.c:9035:13: warning: excess elements in struct initializer
9035 | .release = bpf_xdp_link_release,
| ^~~~~~~~~~~~~~~~~~~~
net/core/dev.c:9035:13: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c:9036:3: error: 'const struct bpf_link_ops' has no member named 'dealloc'
9036 | .dealloc = bpf_xdp_link_dealloc,
| ^~~~~~~
net/core/dev.c:9036:13: warning: excess elements in struct initializer
9036 | .dealloc = bpf_xdp_link_dealloc,
| ^~~~~~~~~~~~~~~~~~~~
net/core/dev.c:9036:13: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c:9037:3: error: 'const struct bpf_link_ops' has no member named 'update_prog'
9037 | .update_prog = bpf_xdp_link_update,
| ^~~~~~~~~~~
net/core/dev.c:9037:17: warning: excess elements in struct initializer
9037 | .update_prog = bpf_xdp_link_update,
| ^~~~~~~~~~~~~~~~~~~
net/core/dev.c:9037:17: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c: In function 'bpf_xdp_link_attach':
net/core/dev.c:9043:25: error: storage size of 'link_primer' isn't known
9043 | struct bpf_link_primer link_primer;
| ^~~~~~~~~~~
net/core/dev.c:9058:2: error: implicit declaration of function 'bpf_link_init'; did you mean 'bio_list_init'? [-Werror=implicit-function-declaration]
9058 | bpf_link_init(&link->link, BPF_LINK_TYPE_XDP, &bpf_xdp_link_lops, prog);
| ^~~~~~~~~~~~~
| bio_list_init
net/core/dev.c:9062:8: error: implicit declaration of function 'bpf_link_prime' [-Werror=implicit-function-declaration]
9062 | err = bpf_link_prime(&link->link, &link_primer);
| ^~~~~~~~~~~~~~
net/core/dev.c:9073:3: error: implicit declaration of function 'bpf_link_cleanup' [-Werror=implicit-function-declaration]
9073 | bpf_link_cleanup(&link_primer);
| ^~~~~~~~~~~~~~~~
net/core/dev.c:9077:7: error: implicit declaration of function 'bpf_link_settle' [-Werror=implicit-function-declaration]
9077 | fd = bpf_link_settle(&link_primer);
| ^~~~~~~~~~~~~~~
net/core/dev.c:9043:25: warning: unused variable 'link_primer' [-Wunused-variable]
9043 | struct bpf_link_primer link_primer;
| ^~~~~~~~~~~
net/core/dev.c: At top level:
net/core/dev.c:9034:34: error: storage size of 'bpf_xdp_link_lops' isn't known
9034 | static const struct bpf_link_ops bpf_xdp_link_lops = {
| ^~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +48 arch/alpha/include/asm/cmpxchg.h
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 40
fbfcd019917098 Andrea Parri 2018-02-27 41 /*
fbfcd019917098 Andrea Parri 2018-02-27 42 * The leading and the trailing memory barriers guarantee that these
fbfcd019917098 Andrea Parri 2018-02-27 43 * operations are fully ordered.
fbfcd019917098 Andrea Parri 2018-02-27 44 */
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 45 #define xchg(ptr, x) \
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 46 ({ \
fbfcd019917098 Andrea Parri 2018-02-27 47 __typeof__(*(ptr)) __ret; \
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 @48 __typeof__(*(ptr)) _x_ = (x); \
fbfcd019917098 Andrea Parri 2018-02-27 49 smp_mb(); \
fbfcd019917098 Andrea Parri 2018-02-27 50 __ret = (__typeof__(*(ptr))) \
fbfcd019917098 Andrea Parri 2018-02-27 51 __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
fbfcd019917098 Andrea Parri 2018-02-27 52 smp_mb(); \
fbfcd019917098 Andrea Parri 2018-02-27 53 __ret; \
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 54 })5ba840f9da1ff9 Paul Gortmaker 2012-04-02 55
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v2 bpf-next 3/8] bpf, xdp: add bpf_link-based XDP attachment API
In reply to Andrii NakryikoI love your patch! Yet something to improve:
Hi Andrii,
I love your patch! Yet something to improve:
[auto build test ERROR on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Andrii-Nakryiko/BPF-XDP-link/20200714-120909 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: x86_64-defconfig (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 02946de3802d3bc65bc9f2eb9b8d4969b5a7add8)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> net/core/dev.c:8717:18: error: field has incomplete type 'struct bpf_link'
struct bpf_link link;
^
include/net/netns/bpf.h:15:9: note: forward declaration of 'struct bpf_link'
struct bpf_link *links[MAX_NETNS_BPF_ATTACH_TYPE];
^
>> net/core/dev.c:8992:34: error: variable has incomplete type 'const struct bpf_link_ops'
static const struct bpf_link_ops bpf_xdp_link_lops = {
^
net/core/dev.c:8992:21: note: forward declaration of 'struct bpf_link_ops'
static const struct bpf_link_ops bpf_xdp_link_lops = {
^
>> net/core/dev.c:9000:25: error: variable has incomplete type 'struct bpf_link_primer'
struct bpf_link_primer link_primer;
^
net/core/dev.c:9000:9: note: forward declaration of 'struct bpf_link_primer'
struct bpf_link_primer link_primer;
^
>> net/core/dev.c:9015:2: error: implicit declaration of function 'bpf_link_init' [-Werror,-Wimplicit-function-declaration]
bpf_link_init(&link->link, BPF_LINK_TYPE_XDP, &bpf_xdp_link_lops, prog);
^
net/core/dev.c:9015:2: note: did you mean 'bio_list_init'?
include/linux/bio.h:575:20: note: 'bio_list_init' declared here
static inline void bio_list_init(struct bio_list *bl)
^
>> net/core/dev.c:9019:8: error: implicit declaration of function 'bpf_link_prime' [-Werror,-Wimplicit-function-declaration]
err = bpf_link_prime(&link->link, &link_primer);
^
net/core/dev.c:9019:8: note: did you mean 'bpf_link_init'?
net/core/dev.c:9015:2: note: 'bpf_link_init' declared here
bpf_link_init(&link->link, BPF_LINK_TYPE_XDP, &bpf_xdp_link_lops, prog);
^
>> net/core/dev.c:9030:3: error: implicit declaration of function 'bpf_link_cleanup' [-Werror,-Wimplicit-function-declaration]
bpf_link_cleanup(&link_primer);
^
net/core/dev.c:9030:3: note: did you mean 'tcf_idr_cleanup'?
include/net/act_api.h:171:6: note: 'tcf_idr_cleanup' declared here
void tcf_idr_cleanup(struct tc_action_net *tn, u32 index);
^
>> net/core/dev.c:9034:7: error: implicit declaration of function 'bpf_link_settle' [-Werror,-Wimplicit-function-declaration]
fd = bpf_link_settle(&link_primer);
^7 errors generated.
vim +8717 net/core/dev.c
8715
8716 struct bpf_xdp_link {
> 8717 struct bpf_link link;
8718 struct net_device *dev; /* protected by rtnl_lock, no refcnt held */
8719 int flags;
8720 };
8721
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v2 bpf-next 3/8] bpf, xdp: add bpf_link-based XDP attachment API
Quoted 19 lines · kernel test robot
Hi Andrii,
I love your patch! Yet something to improve:
[auto build test ERROR on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Andrii-Nakryiko/BPF-XDP-link/20200714-120909 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: x86_64-defconfig (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 02946de3802d3bc65bc9f2eb9b8d4969b5a7add8)reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# installx86_64cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
Quoted 8 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
net/core/dev.c:8717:18: error: field has incomplete type 'structbpf_link'struct bpf_link link; ^
This is all due to bpf_link-related API is conditionally defined only #ifdef CONFIG_BPF_SYSCALL. I'm doing the same as is done for bpf_prog:
moving it outside of CONFIG_BPF_SYSCALL-only region and adding stubs for generic API (init/settle/cleanup, inc/put, etc). Will add this as a separate pre-patch in the v3.
Quoted 3 lines
include/net/netns/bpf.h:15:9: note: forward declaration of 'struct bpf_link'
struct bpf_link *links[MAX_NETNS_BPF_ATTACH_TYPE];
^[...]