xdp: introduce xdp-feature support
Subsystems (40)
Lorenzo Bianconi
maintainercover xdp: introduce xdp-feature support
Introduce the capability to export the XDP features supported by the NIC. Introduce a XDP compliance test tool (xdp_features) to check the features exported by the NIC match the real features supported by the driver. Allow XDP_REDIRECT of non-linear XDP frames into a devmap. Export XDP features for each XDP capable driver.
Extend libbpf netlink implementation in order to support netlink_generic protocol.
Introduce a simple generic netlink family for netdev data.
Changes since RFCv2:
- do not assume fixed layout for genl kernel messages
- fix warnings in netdev_nl_dev_fill
- fix capabilities for nfp driver
- add supported_sg parameter to xdp_features_set_redirect_target and drop __xdp_features_set_redirect_target routine
Changes since RFCv1:
- Introduce netdev-genl implementation and get rid of rtnl one.
- Introduce netlink_generic support in libbpf netlink implementation
- Rename XDP_FEATURE_* in NETDEV_XDP_ACT_*
- Rename XDP_FEATURE_REDIRECT_TARGET in NETDEV_XDP_ACT_NDO_XMIT
- Rename XDP_FEATURE_FRAG_RX in NETDEV_XDP_ACT_RX_SG
- Rename XDP_FEATURE_FRAG_TARFET in NETDEV_XDP_ACT_NDO_XMIT
- Get rid of XDP_LOCK feature.
- Move xdp_feature field in a netdevice struct hole in the 4th cacheline.
Jakub Kicinski (1):
netdev-genl: create a simple family for netdev stuff
Lorenzo Bianconi (4):
libbpf: add the capability to specify netlink proto in
libbpf_netlink_send_recv
libbpf: add API to get XDP/XSK supported features
bpf: devmap: check XDP features in bpf_map_update_elem and
__xdp_enqueue
selftests/bpf: introduce XDP compliance test tool
Marek Majtyka (2):
drivers: net: turn on XDP features
xsk: add usage of XDP features flags
Documentation/netlink/specs/netdev.yaml | 72 ++ drivers/net/ethernet/amazon/ena/ena_netdev.c | 5 + .../net/ethernet/aquantia/atlantic/aq_nic.c | 4 + drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 + drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 2 + .../net/ethernet/cavium/thunder/nicvf_main.c | 2 + .../net/ethernet/freescale/dpaa/dpaa_eth.c | 2 + .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 1 + .../net/ethernet/freescale/enetc/enetc_pf.c | 2 + .../ethernet/fungible/funeth/funeth_main.c | 6 + drivers/net/ethernet/intel/i40e/i40e_main.c | 10 +- drivers/net/ethernet/intel/ice/ice_main.c | 5 + drivers/net/ethernet/intel/igb/igb_main.c | 10 +- drivers/net/ethernet/intel/igc/igc_main.c | 2 + drivers/net/ethernet/intel/igc/igc_xdp.c | 5 + drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 + .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 1 + drivers/net/ethernet/marvell/mvneta.c | 2 + .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 3 + .../ethernet/marvell/octeontx2/nic/otx2_pf.c | 8 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 + .../net/ethernet/mellanox/mlx4/en_netdev.c | 2 + .../net/ethernet/mellanox/mlx5/core/en_main.c | 10 + drivers/net/ethernet/microsoft/mana/mana_en.c | 1 + .../ethernet/netronome/nfp/nfp_net_common.c | 5 + drivers/net/ethernet/qlogic/qede/qede_main.c | 2 + drivers/net/ethernet/sfc/efx.c | 3 + drivers/net/ethernet/sfc/siena/efx.c | 3 + drivers/net/ethernet/socionext/netsec.c | 2 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 1 + drivers/net/ethernet/ti/cpsw.c | 2 + drivers/net/ethernet/ti/cpsw_new.c | 3 + drivers/net/hyperv/netvsc_drv.c | 2 + drivers/net/netdevsim/netdev.c | 1 + drivers/net/tun.c | 4 + drivers/net/veth.c | 3 + drivers/net/virtio_net.c | 5 + drivers/net/xen-netfront.c | 1 + include/linux/netdevice.h | 2 + include/net/xdp.h | 34 + include/uapi/linux/netdev.h | 66 ++ kernel/bpf/devmap.c | 25 +- net/core/Makefile | 3 +- net/core/filter.c | 13 +- net/core/netdev-genl-gen.c | 48 ++ net/core/netdev-genl-gen.h | 23 + net/core/netdev-genl.c | 178 +++++ net/xdp/xsk_buff_pool.c | 3 +- tools/include/uapi/linux/netdev.h | 66 ++ tools/lib/bpf/libbpf.h | 3 +- tools/lib/bpf/netlink.c | 121 ++- tools/lib/bpf/nlattr.h | 12 + tools/testing/selftests/bpf/Makefile | 5 +- .../selftests/bpf/progs/test_xdp_features.c | 237 ++++++ .../selftests/bpf/test_xdp_features.sh | 99 +++ tools/testing/selftests/bpf/xdp_features.c | 743 ++++++++++++++++++ 56 files changed, 1852 insertions(+), 33 deletions(-) create mode 100644 Documentation/netlink/specs/netdev.yaml create mode 100644 include/uapi/linux/netdev.h create mode 100644 net/core/netdev-genl-gen.c create mode 100644 net/core/netdev-genl-gen.h create mode 100644 net/core/netdev-genl.c create mode 100644 tools/include/uapi/linux/netdev.h create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_features.c create mode 100755 tools/testing/selftests/bpf/test_xdp_features.sh create mode 100644 tools/testing/selftests/bpf/xdp_features.c
Signature · 1 line
2.39.0
Lorenzo Bianconi
maintainerPATCH 1/7 netdev-genl: create a simple family for netdev stuff
From: Jakub Kicinski <[email protected]>
Add a Netlink spec-compatible family for netdevs.
This is a very simple implementation without much
thought going into it.
It allows us to reap all the benefits of Netlink specs, one can use the generic client to issue the commands:
$ ./gen.py --spec netdev.yaml --do dev_get --json='{"ifindex": 2}'
{'ifindex': 2, 'xdp-features': 31} $ ./gen.py --spec netdev.yaml --dump dev_get
[{'ifindex': 1, 'xdp-features': 0}, {'ifindex': 2, 'xdp-features': 31}]the generic python library does not have flags-by-name support, yet, but we also don't have to carry strings in the messages, as user space can get the names from the spec.
--- Documentation/netlink/specs/netdev.yaml | 72 ++++++++++ include/linux/netdevice.h | 2 + include/net/xdp.h | 3 + include/uapi/linux/netdev.h | 66 +++++++++ net/core/Makefile | 3 +- net/core/netdev-genl-gen.c | 48 +++++++ net/core/netdev-genl-gen.h | 23 +++ net/core/netdev-genl.c | 178 ++++++++++++++++++++++++ tools/include/uapi/linux/netdev.h | 66 +++++++++ 9 files changed, 460 insertions(+), 1 deletion(-) create mode 100644 Documentation/netlink/specs/netdev.yaml create mode 100644 include/uapi/linux/netdev.h create mode 100644 net/core/netdev-genl-gen.c create mode 100644 net/core/netdev-genl-gen.h create mode 100644 net/core/netdev-genl.c create mode 100644 tools/include/uapi/linux/netdev.h
Documentation/netlink/specs/netdev.yaml new file +72 -0
@@ -0,0 +1,72 @@ +name: netdev + +doc: + netdev configuration over generic netlink. + +definitions: + - + type: enum + name: xdp-feat + entries: [ aborted, drop, pass, redirect, + ndo-xmit, xsk-zerocopy, + hw-offload, rx-sg, ndo-xmit-sg + ] + +attribute-sets: + - + name: dev + attributes: + - + name: ifindex + doc: netdev ifindex + type: u32 + value: 1 + checks: + min: 1 + - + name: pad + type: pad + - + name: xdp-features + doc: Bitmask of enabled xdp-features. + type: u64 + enum: xdp-feat + enum-as-flags: true + +operations: + list: + - + name: dev-get + doc: Get / dump information about a netdev. + value: 1 + attribute-set: dev + do: + request: + attributes: + - ifindex + reply: &dev-all + attributes: + - ifindex + - xdp-features + dump: + reply: *dev-all + - + name: dev-add-ntf + doc: Notification about device appearing. + notify: dev-get + mcgrp: mgmt + - + name: dev-del-ntf + doc: Notification about device disappearing. + notify: dev-get + mcgrp: mgmt + - + name: dev-change-ntf + doc: Notification about device configuration being changed. + notify: dev-get + mcgrp: mgmt + +mcast-groups: + list: + - + name: mgmt
include/linux/netdevice.h +2 -0
@@ -47,6 +47,7 @@#include <uapi/linux/netdevice.h> #include <uapi/linux/if_bonding.h> #include <uapi/linux/pkt_cls.h> +#include <uapi/linux/netdev.h> #include <linux/hashtable.h> #include <linux/rbtree.h> #include <net/net_trackers.h>
@@ -2048,6 +2049,7 @@ struct net_device {/* Read-mostly cache-line for fast-path access */ unsigned int flags; +xdp_features_t xdp_features;unsigned long long priv_flags;const struct net_device_ops *netdev_ops;int ifindex;
include/net/xdp.h +3 -0
@@ -7,6 +7,7 @@#define __LINUX_NET_XDP_H__#include <linux/skbuff.h> /* skb_shared_info */ +#include <uapi/linux/netdev.h> /** * DOC: XDP RX-queue information
@@ -43,6 +44,8 @@ enum xdp_mem_type { MEM_TYPE_MAX, }; +typedef u32 xdp_features_t ; +/* XDP flags for ndo_xdp_xmit */ #define XDP_XMIT_FLUSH (1U << 0)/* doorbell signal consumer */ #define XDP_XMIT_FLAGS_MASK XDP_XMIT_FLUSH
include/uapi/linux/netdev.h new file +66 -0
66 lines not on this page · raw message
net/core/Makefile +2 -1
@@ -12,7 +12,8 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o obj-y += dev.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 \ - fib_notifier.o xdp.o flow_offload.o gro.o + fib_notifier.o xdp.o flow_offload.o gro.o \ + netdev-genl.o netdev-genl-gen.o obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
net/core/netdev-genl-gen.c new file +48 -0
48 lines not on this page · raw message
net/core/netdev-genl-gen.h new file +23 -0
@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/netdev.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_NETDEV_GEN_H +#define _LINUX_NETDEV_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <linux/netdev.h> + +int netdev_nl_dev_get_doit (struct sk_buff *skb,struct genl_info *info); +int netdev_nl_dev_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); + +enum { +NETDEV_NLGRP_MGMT , +}; + +extern struct genl_family netdev_nl_family; + +#endif /* _LINUX_NETDEV_GEN_H */
net/core/netdev-genl.c new file +178 -0
178 lines not on this page · raw message
tools/include/uapi/linux/netdev.h new file +66 -0
66 lines not on this page · raw message
Signature · 6 lines
2.39.0 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Re: [PATCH bpf-next 1/7] netdev-genl: create a simple family for netdev stuff
include/uapi/linux/netdev.h line 39
Quoted 5 lines · Lorenzo Bianconi
include/uapi/linux/netdev.h new file +5
-0+ +#define NETDEV_XDP_ACT_BASIC (NETDEV_XDP_ACT_DROP | \ + NETDEV_XDP_ACT_PASS | \ + NETDEV_XDP_ACT_TX | \ + NETDEV_XDP_ACT_ABORTED)
Why split it into 4?
Is there a driver that does a subset?
Lorenzo Bianconi
maintainerRe: [PATCH bpf-next 1/7] netdev-genl: create a simple family for netdev stuff
Quoted 9 lines · Alexei Starovoitov
include/uapi/linux/netdev.h line 39
Quoted 5 lines · Lorenzo Bianconi
include/uapi/linux/netdev.h new file +5
-0+ +#define NETDEV_XDP_ACT_BASIC (NETDEV_XDP_ACT_DROP | \ + NETDEV_XDP_ACT_PASS | \ + NETDEV_XDP_ACT_TX | \ + NETDEV_XDP_ACT_ABORTED)Why split it into 4?
Is there a driver that does a subset?
nope, at least all drivers support NETDEV_XDP_ACT_BASIC. I guess we can squash them and just add NETDEV_XDP_ACT_BASIC.
Regards,
Lorenzo
Jakub Kicinski
maintainerRe: [PATCH bpf-next 1/7] netdev-genl: create a simple family for netdev stuff
In reply to Lorenzo BianconiQuoted 6 lines · On Fri, 20 Jan 2023 18:16:50 +0100 Lorenzo Bianconi wrote:
From: Jakub Kicinski <[email protected]>
Add a Netlink spec-compatible family for netdevs. This is a very simple implementation without much thought going into it.
Quoted 8 lines
It allows us to reap all the benefits of Netlink specs, one can use the generic client to issue the commands:
$ ./gen.py --spec netdev.yaml --do dev_get --json='{"ifindex": 2}' {'ifindex': 2, 'xdp-features': 31}$ ./gen.py --spec netdev.yaml --dump dev_get [{'ifindex': 1, 'xdp-features': 0}, {'ifindex': 2, 'xdp-features': 31}]
In the meantime I added support for rendering enums in Python. So you can show names in the example. eg:
$ ./cli.py --spec netdev.yaml --dump dev_get
[{'ifindex': 1, 'xdp-features': set()},
{'ifindex': 2,
'xdp-features': {'ndo-xmit', 'pass', 'redirect', 'aborted', 'drop'}},
{'ifindex': 3, 'xdp-features': {'rx-sg'}}]Quoted 12 lines
the generic python library does not have flags-by-name support, yet, but we also don't have to carry strings in the messages, as user space can get the names from the spec.
Co-developed-by Lorenzo Bianconi <[email protected]>Signed-off-by Lorenzo Bianconi <[email protected]>Co-developed-by Kumar Kartikeya Dwivedi <[email protected]>Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>Co-developed-by Marek Majtyka <[email protected]>Signed-off-by Marek Majtyka <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>
Quoted 2 lines
--- Documentation/netlink/specs/netdev.yaml | 72 ++++++++++
FWIW I'm not 100% sure if we should scope the family to all of netdev or just xdp. Same for the name of the op, should we call the op dev_get or dev_xdp_get..
include/uapi/linux/netdev.h line 2
Quoted 8 lines
include/uapi/linux/netdev.h new file +2
-0@@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Do not edit directly, auto-generated from: */
Like this line says, you can't hand edit this file.
Next time someone adds an attribute all your changes will be wiped.
Quoted 10 lines
include/uapi/linux/netdev.h new file +10
-0+/* Documentation/netlink/specs/netdev.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_NETDEV_H +#define _UAPI_LINUX_NETDEV_H + +#define NETDEV_FAMILY_NAME "netdev" +#define NETDEV_FAMILY_VERSION 1 + +enum netdev_xdp_act {
include/uapi/linux/netdev.h line 22
Quoted 10 lines
include/uapi/linux/netdev.h new file +10
-0+NETDEV_XDP_ACT_ABORTED_BIT , +NETDEV_XDP_ACT_DROP_BIT , +NETDEV_XDP_ACT_PASS_BIT , +NETDEV_XDP_ACT_TX_BIT , +NETDEV_XDP_ACT_REDIRECT_BIT , +NETDEV_XDP_ACT_NDO_XMIT_BIT , +NETDEV_XDP_ACT_XSK_ZEROCOPY_BIT , +NETDEV_XDP_ACT_HW_OFFLOAD_BIT , +NETDEV_XDP_ACT_RX_SG_BIT , +NETDEV_XDP_ACT_NDO_XMIT_SG_BIT
You need to add -bit to all the enum names in the yaml if you want to have _BIT in the name here.
Quoted 11 lines
include/uapi/linux/netdev.h new file +11
-0+}; + +#define NETDEV_XDP_ACT_ABORTED BIT(NETDEV_XDP_ACT_ABORTED_BIT) +#define NETDEV_XDP_ACT_DROP BIT(NETDEV_XDP_ACT_DROP_BIT) +#define NETDEV_XDP_ACT_PASS BIT(NETDEV_XDP_ACT_PASS_BIT) +#define NETDEV_XDP_ACT_TX BIT(NETDEV_XDP_ACT_TX_BIT) +#define NETDEV_XDP_ACT_REDIRECT BIT(NETDEV_XDP_ACT_REDIRECT_BIT) +#define NETDEV_XDP_ACT_NDO_XMIT BIT(NETDEV_XDP_ACT_NDO_XMIT_BIT) +#define NETDEV_XDP_ACT_XSK_ZEROCOPY BIT(NETDEV_XDP_ACT_XSK_ZEROCOPY_BIT) +#define NETDEV_XDP_ACT_HW_OFFLOAD BIT(NETDEV_XDP_ACT_HW_OFFLOAD_BIT) +#define NETDEV_XDP_ACT_RX_SG BIT(NETDEV_XDP_ACT_RX_SG_BIT)
include/uapi/linux/netdev.h line 43
Quoted 10 lines
include/uapi/linux/netdev.h new file +10
-0+#define NETDEV_XDP_ACT_NDO_XMIT_SG BIT(NETDEV_XDP_ACT_NDO_XMIT_SG_BIT) + +#define NETDEV_XDP_ACT_BASIC (NETDEV_XDP_ACT_DROP | \ + NETDEV_XDP_ACT_PASS | \ + NETDEV_XDP_ACT_TX | \ + NETDEV_XDP_ACT_ABORTED) +#define NETDEV_XDP_ACT_FULL (NETDEV_XDP_ACT_BASIC | \ + NETDEV_XDP_ACT_REDIRECT) +#define NETDEV_XDP_ACT_ZC (NETDEV_XDP_ACT_FULL | \ + NETDEV_XDP_ACT_XSK_ZEROCOPY)
These defines don't belong in uAPI. Especially the use of BIT().
Quoted 6 lines
include/uapi/linux/netdev.h new file +6
-0+if (err <0 ) +break ; +cont: + idx++; + } + }
include/uapi/linux/netdev.h line 59
Quoted 10 lines
include/uapi/linux/netdev.h new file +10
-0+ +rtnl_unlock (); + +if (err != -EMSGSIZE ) +return err; + + cb->args[1 ] = idx; + cb->args[0 ] = h; + cb->seq = net->dev_base_seq; +nl_dump_check_consistent (cb,nlmsg_hdr (skb));
I think that this line can be dropped.
Quoted 2 lines
include/uapi/linux/netdev.h new file +2
-0+return skb->len; +}
Lorenzo Bianconi
maintainerRe: [PATCH bpf-next 1/7] netdev-genl: create a simple family for netdev stuff
Quoted 40 lines · On Fri, 20 Jan 2023 18:16:50 +0100 Lorenzo Bianconi wrote:
Quoted 6 lines
From: Jakub Kicinski <[email protected]>
Add a Netlink spec-compatible family for netdevs. This is a very simple implementation without much thought going into it.
Quoted 8 lines
It allows us to reap all the benefits of Netlink specs, one can use the generic client to issue the commands:
$ ./gen.py --spec netdev.yaml --do dev_get --json='{"ifindex": 2}' {'ifindex': 2, 'xdp-features': 31}$ ./gen.py --spec netdev.yaml --dump dev_get [{'ifindex': 1, 'xdp-features': 0}, {'ifindex': 2, 'xdp-features': 31}]In the meantime I added support for rendering enums in Python. So you can show names in the example. eg:
$ ./cli.py --spec netdev.yaml --dump dev_get [{'ifindex': 1, 'xdp-features': set()}, {'ifindex': 2, 'xdp-features': {'ndo-xmit', 'pass', 'redirect', 'aborted', 'drop'}}, {'ifindex': 3, 'xdp-features': {'rx-sg'}}]Quoted 12 lines
the generic python library does not have flags-by-name support, yet, but we also don't have to carry strings in the messages, as user space can get the names from the spec.
Co-developed-by Lorenzo Bianconi <[email protected]>Signed-off-by Lorenzo Bianconi <[email protected]>Co-developed-by Kumar Kartikeya Dwivedi <[email protected]>Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>Co-developed-by Marek Majtyka <[email protected]>Signed-off-by Marek Majtyka <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>Quoted 2 lines
--- Documentation/netlink/specs/netdev.yaml | 72 ++++++++++
Quoted 3 lines
FWIW I'm not 100% sure if we should scope the family to all of netdev or just xdp. Same for the name of the op, should we call the op
dev_getordev_xdp_get..
is it likely we are going to add non-xdp info here in the near future? If not I would say we can target just xdp for the moment.
Quoted 12 lines
include/uapi/linux/netdev.h line 2
Quoted 9 lines
include/uapi/linux/netdev.h new file +2
-0@@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Do not edit directly, auto-generated from: */ Like this line says, you can't hand edit this file.
Next time someone adds an attribute all your changes will be wiped.
ack, right.
Quoted 16 lines
Quoted 16 lines
include/uapi/linux/netdev.h new file +15
-0+/* Documentation/netlink/specs/netdev.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_NETDEV_H +#define _UAPI_LINUX_NETDEV_H + +#define NETDEV_FAMILY_NAME "netdev" +#define NETDEV_FAMILY_VERSION 1 + +enum netdev_xdp_act { +NETDEV_XDP_ACT_ABORTED_BIT , +NETDEV_XDP_ACT_DROP_BIT , +NETDEV_XDP_ACT_PASS_BIT , +NETDEV_XDP_ACT_TX_BIT , + NETDEV_XDP_ACT_REDIRECT_BIT,
Quoted 8 lines
include/uapi/linux/netdev.h line 22
Quoted 5 lines
include/uapi/linux/netdev.h new file +5
-0+NETDEV_XDP_ACT_NDO_XMIT_BIT , +NETDEV_XDP_ACT_XSK_ZEROCOPY_BIT , +NETDEV_XDP_ACT_HW_OFFLOAD_BIT , +NETDEV_XDP_ACT_RX_SG_BIT , +NETDEV_XDP_ACT_NDO_XMIT_SG_BIT You need to add -bit to all the enum names in the yaml if you want to have
_BITin the name here.
ack, I do not think it is needed (according to the comment below).
Quoted 16 lines
Quoted 16 lines
include/uapi/linux/netdev.h new file +15
-0+}; + +#define NETDEV_XDP_ACT_ABORTED BIT(NETDEV_XDP_ACT_ABORTED_BIT) +#define NETDEV_XDP_ACT_DROP BIT(NETDEV_XDP_ACT_DROP_BIT) +#define NETDEV_XDP_ACT_PASS BIT(NETDEV_XDP_ACT_PASS_BIT) +#define NETDEV_XDP_ACT_TX BIT(NETDEV_XDP_ACT_TX_BIT) +#define NETDEV_XDP_ACT_REDIRECT BIT(NETDEV_XDP_ACT_REDIRECT_BIT) +#define NETDEV_XDP_ACT_NDO_XMIT BIT(NETDEV_XDP_ACT_NDO_XMIT_BIT) +#define NETDEV_XDP_ACT_XSK_ZEROCOPY BIT(NETDEV_XDP_ACT_XSK_ZEROCOPY_BIT) +#define NETDEV_XDP_ACT_HW_OFFLOAD BIT(NETDEV_XDP_ACT_HW_OFFLOAD_BIT) +#define NETDEV_XDP_ACT_RX_SG BIT(NETDEV_XDP_ACT_RX_SG_BIT) +#define NETDEV_XDP_ACT_NDO_XMIT_SG BIT(NETDEV_XDP_ACT_NDO_XMIT_SG_BIT) + +#define NETDEV_XDP_ACT_BASIC (NETDEV_XDP_ACT_DROP | \ + NETDEV_XDP_ACT_PASS | \
Quoted 8 lines
include/uapi/linux/netdev.h line 43
Quoted 6 lines
include/uapi/linux/netdev.h new file +6
-0+ NETDEV_XDP_ACT_TX | \ + NETDEV_XDP_ACT_ABORTED) +#define NETDEV_XDP_ACT_FULL (NETDEV_XDP_ACT_BASIC | \ + NETDEV_XDP_ACT_REDIRECT) +#define NETDEV_XDP_ACT_ZC (NETDEV_XDP_ACT_FULL | \ + NETDEV_XDP_ACT_XSK_ZEROCOPY)These defines don't belong in uAPI. Especially the use of
BIT().
since netdev xdp_features is a bitmask, can we use 'flags' as type for definitions in netdev.yaml so we can get rid of this BIT() definitions for both user and kernel space?
Quoted 11 lines
Quoted 11 lines
include/uapi/linux/netdev.h new file +10
-0+if (err <0 ) +break ; +cont: + idx++; + } + } + +rtnl_unlock (); + +if (err != -EMSGSIZE )
Quoted 8 lines
include/uapi/linux/netdev.h line 59
Quoted 6 lines
include/uapi/linux/netdev.h new file +6
-0+return err; + + cb->args[1 ] = idx; + cb->args[0 ] = h; + cb->seq = net->dev_base_seq; +nl_dump_check_consistent (cb,nlmsg_hdr (skb));I think that this line can be dropped.
ack, I will fix it.
Regards,
Lorenzo
Quoted 3 lines
Quoted 3 lines
include/uapi/linux/netdev.h new file +2
-0+return skb->len; +}
Jakub Kicinski
maintainerRe: [PATCH bpf-next 1/7] netdev-genl: create a simple family for netdev stuff
Quoted 6 lines · On Mon, 23 Jan 2023 00:00:15 +0100 Lorenzo Bianconi wrote:
Quoted 3 lines
FWIW I'm not 100% sure if we should scope the family to all of netdev or just xdp. Same for the name of the op, should we call the op
dev_getordev_xdp_get..is it likely we are going to add non-xdp info here in the near future? If not I would say we can target just xdp for the moment.
What brought it to mind for me was offloads like the NVMe/DDP for instance. Whether that stuff should live in ethtool or a netdev family is a bit unclear.
Quoted 5 lines
Quoted 1 line
These defines don't belong in uAPI. Especially the use of
BIT().since netdev
xdp_featuresis a bitmask, can we use 'flags' as type for definitions innetdev.yamlso we can get rid of thisBIT()definitions for both user and kernel space?
If you have no use for the bit numbers - definitely.
_______________________________________________
Intel-wired-lan mailing list [email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Lorenzo Bianconi
maintainerRe: [PATCH bpf-next 1/7] netdev-genl: create a simple family for netdev stuff
Quoted 11 lines · On Mon, 23 Jan 2023 00:00:15 +0100 Lorenzo Bianconi wrote:
Quoted 6 lines
Quoted 3 lines
FWIW I'm not 100% sure if we should scope the family to all of netdev or just xdp. Same for the name of the op, should we call the op
dev_getordev_xdp_get..is it likely we are going to add non-xdp info here in the near future? If not I would say we can target just xdp for the moment.
What brought it to mind for me was offloads like the NVMe/DDP for instance. Whether that stuff should live in ethtool or a netdev family is a bit unclear.
ack, let's keep netdev in this case.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
These defines don't belong in uAPI. Especially the use of
BIT().since netdev
xdp_featuresis a bitmask, can we use 'flags' as type for definitions innetdev.yamlso we can get rid of thisBIT()definitions for both user and kernel space?If you have no use for the bit numbers - definitely.
ack
Regards,
Lorenzo
kernel test robot
build botRe: [PATCH bpf-next 1/7] netdev-genl: create a simple family for netdev stuff
In reply to Lorenzo BianconiI love your patch! Perhaps something to improve:
Hi Lorenzo,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Bianconi/netdev-genl-create-a-simple-family-for-netdev-stuff/20230121-011957 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/272fa19f57de2d14e9666b4cd9b1ae8a61a94807.1674234430.git.lorenzo%40kernel.org patch subject: [PATCH bpf-next 1/7] netdev-genl: create a simple family for netdev stuff config: x86_64-rhel-8.3-syz (https://download.01.org/0day-ci/archive/20230121/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/bab8ed890888146e07283e2ae27174b3562b6931 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Lorenzo-Bianconi/netdev-genl-create-a-simple-family-for-netdev-stuff/20230121-011957 git checkout bab8ed890888146e07283e2ae27174b3562b6931 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=x86_64 olddefconfig make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash net/core/
If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
net/core/netdev-genl.c: In function 'netdev_nl_dev_fill':
>> net/core/netdev-genl.c:16:13: warning: unused variable 'err' [-Wunused-variable]
16 | int err;
| ^~~vim +/err +16 net/core/netdev-genl.c
10
11 static int
12 netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp,
13 u32 portid, u32 seq, int flags, u32 cmd)
14 {
15 void *hdr;
> 16 int err;
17
18 hdr = genlmsg_put(rsp, portid, seq, &netdev_nl_family, flags, cmd);
19 if (!hdr)
20 return -EMSGSIZE;
21
22 if (nla_put_u32(rsp, NETDEV_A_DEV_IFINDEX, netdev->ifindex) ||
23 nla_put_u64_64bit(rsp, NETDEV_A_DEV_XDP_FEATURES,
24 netdev->xdp_features, NETDEV_A_DEV_PAD)) {
25 genlmsg_cancel(rsp, hdr);
26 return -EINVAL;
27 }
28
29 genlmsg_end(rsp, hdr);
30
31 return 0;
32 }
33 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Lorenzo Bianconi
maintainerPATCH 2/7 drivers: net: turn on XDP features
In reply to Lorenzo BianconiFrom: Marek Majtyka <[email protected]>
A summary of the flags being set for various drivers is given below. Note that XDP_F_REDIRECT_TARGET and XDP_F_FRAG_TARGET are features that can be turned off and on at runtime. This means that these flags may be set and unset under RTNL lock protection by the driver. Hence, READ_ONCE must be used by code loading the flag value.
Also, these flags are not used for synchronization against the availability of XDP resources on a device. It is merely a hint, and hence the read may race with the actual teardown of XDP resources on the device. This may change in the future, e.g. operations taking a reference on the XDP resources of the driver, and in turn inhibiting turning off this flag. However, for now, it can only be used as a hint to check whether device supports becoming a redirection target.
Turn 'hw-offload' feature flag on for:
- netronome (nfp)
- netdevsim.
Turn 'native' and 'zerocopy' features flags on for:
- intel (i40e, ice, ixgbe, igc)
- mellanox (mlx5).
- stmmac
Turn 'native' features flags on for:
- amazon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2, enetc)
- funeth
- intel (igb)
- marvell (mvneta, mvpp2, octeontx2)
- mellanox (mlx4)
- qlogic (qede)
- sfc
- socionext (netsec)
- ti (cpsw)
- tap
- veth
- xen
- virtio_net.
Turn 'basic' (tx, pass, aborted and drop) features flags on for:
- netronome (nfp)
- cavium (thunder)
- hyperv.
Turn 'tx_lock' feature flag on for:
- aquantia
- freescale (dpaa2)
- intel (igb)
- marvell (mvneta, mvpp2)
- microsoft (mana)
- mediatek
- qlogic (qede)
- socionext (netsec)
- ti (cpsw)
- tap
- veth
- xen
Turn 'redirect_target' feature flag on for:
- amanzon (ena)
- broadcom (bnxt)
- freescale (dpaa, dpaa2)
- intel (i40e, ice, igb, ixgbe)
- ti (cpsw)
- marvell (mvneta, mvpp2)
- sfc
- socionext (netsec)
- qlogic (qede)
- mellanox (mlx5)
- tap
- veth
- virtio_net
- xen
--- drivers/net/ethernet/amazon/ena/ena_netdev.c | 5 +++ .../net/ethernet/aquantia/atlantic/aq_nic.c | 4 +++ drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++ drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 2 ++ .../net/ethernet/cavium/thunder/nicvf_main.c | 2 ++ .../net/ethernet/freescale/dpaa/dpaa_eth.c | 2 ++ .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 1 + .../net/ethernet/freescale/enetc/enetc_pf.c | 2 ++ .../ethernet/fungible/funeth/funeth_main.c | 6 ++++ drivers/net/ethernet/intel/i40e/i40e_main.c | 10 ++++-- drivers/net/ethernet/intel/ice/ice_main.c | 5 +++ drivers/net/ethernet/intel/igb/igb_main.c | 10 +++++- drivers/net/ethernet/intel/igc/igc_main.c | 2 ++ drivers/net/ethernet/intel/igc/igc_xdp.c | 5 +++ drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 +++ .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 1 + drivers/net/ethernet/marvell/mvneta.c | 2 ++ .../net/ethernet/marvell/mvpp2/mvpp2_main.c | 3 ++ .../ethernet/marvell/octeontx2/nic/otx2_pf.c | 8 +++-- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 5 +++ .../net/ethernet/mellanox/mlx4/en_netdev.c | 2 ++ .../net/ethernet/mellanox/mlx5/core/en_main.c | 10 ++++++ drivers/net/ethernet/microsoft/mana/mana_en.c | 1 + .../ethernet/netronome/nfp/nfp_net_common.c | 5 +++ drivers/net/ethernet/qlogic/qede/qede_main.c | 2 ++ drivers/net/ethernet/sfc/efx.c | 3 ++ drivers/net/ethernet/sfc/siena/efx.c | 3 ++ drivers/net/ethernet/socionext/netsec.c | 2 ++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 1 + drivers/net/ethernet/ti/cpsw.c | 2 ++ drivers/net/ethernet/ti/cpsw_new.c | 3 ++ drivers/net/hyperv/netvsc_drv.c | 2 ++ drivers/net/netdevsim/netdev.c | 1 + drivers/net/tun.c | 4 +++ drivers/net/veth.c | 3 ++ drivers/net/virtio_net.c | 5 +++ drivers/net/xen-netfront.c | 1 + include/net/xdp.h | 31 +++++++++++++++++++ 38 files changed, 158 insertions(+), 5 deletions(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +5 -0
@@ -597,7 +597,10 @@ static int ena_xdp_set(struct net_device *netdev, struct netdev_bpf *bpf)if (rc)return rc; } +xdp_features_set_redirect_target (&netdev->xdp_features, + false); }else if (old_bpf_prog) { +xdp_features_clear_redirect_target (&netdev->xdp_features); rc =ena_destroy_and_free_all_xdp_queues (adapter);if (rc)return rc;
@@ -4103,6 +4106,8 @@ static void ena_set_conf_feat_params(struct ena_adapter *adapter,/* Set offload features */ ena_set_dev_offloads (feat, netdev); + netdev->xdp_features =NETDEV_XDP_ACT_FULL ; + adapter->max_mtu = feat->dev_attr.max_mtu; netdev->max_mtu = adapter->max_mtu; netdev->min_mtu =ENA_MIN_MTU ;
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +4 -0
@@ -384,6 +384,10 @@ void aq_nic_ndev_init(struct aq_nic_s *self) self->ndev->mtu = aq_nic_cfg->mtu -ETH_HLEN ; self->ndev->max_mtu = aq_hw_caps->mtu -ETH_FCS_LEN -ETH_HLEN ; + self->ndev->xdp_features =NETDEV_XDP_ACT_FULL | +NETDEV_XDP_ACT_NDO_XMIT | +NETDEV_XDP_ACT_RX_SG | +NETDEV_XDP_ACT_NDO_XMIT_SG ; } void aq_nic_set_tx_ring(struct aq_nic_s *self, unsigned int idx,
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -0
@@ -13686,6 +13686,8 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)netif_set_tso_max_size (dev,GSO_MAX_SIZE ); + dev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_RX_SG ; +#ifdef CONFIG_BNXT_SRIOV init_waitqueue_head (&bp->sriov_cfg_wait);#endif
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +2 -0
@@ -422,9 +422,11 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)if (prog) {bnxt_set_rx_skb_mode (bp, true); +xdp_features_set_redirect_target (&dev->xdp_features, true); }else {int rx, tx; +xdp_features_clear_redirect_target (&dev->xdp_features);bnxt_set_rx_skb_mode (bp, false);bnxt_get_max_rings (bp, &rx, &tx, true);if (rx >1 ) {
drivers/net/ethernet/cavium/thunder/nicvf_main.c +2 -0
@@ -2218,6 +2218,8 @@ static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->netdev_ops = &nicvf_netdev_ops; netdev->watchdog_timeo =NICVF_TX_TIMEOUT ; + netdev->xdp_features =NETDEV_XDP_ACT_BASIC ; +/* MTU range: 64 - 9200 */ netdev->min_mtu =NIC_HW_MIN_FRS ; netdev->max_mtu =NIC_HW_MAX_FRS ;
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +2 -0
@@ -244,6 +244,8 @@ static int dpaa_netdev_init(struct net_device *net_dev, net_dev->features |= net_dev->hw_features; net_dev->vlan_features = net_dev->features; + net_dev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; +if (is_valid_ether_addr (mac_addr)) {memcpy (net_dev->perm_addr, mac_addr, net_dev->addr_len);eth_hw_addr_set (net_dev, mac_addr);
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +1 -0
@@ -4593,6 +4593,7 @@ static int dpaa2_eth_netdev_init(struct net_device *net_dev)NETIF_F_LLTX |NETIF_F_HW_TC |NETIF_F_TSO ; net_dev->gso_max_segs =DPAA2_ETH_ENQUEUE_MAX_FDS ; net_dev->hw_features = net_dev->features; + net_dev->xdp_features =NETDEV_XDP_ACT_ZC |NETDEV_XDP_ACT_NDO_XMIT ;if (priv->dpni_attrs.vlan_filter_entries) net_dev->hw_features |=NETIF_F_HW_VLAN_CTAG_FILTER ;
drivers/net/ethernet/freescale/enetc/enetc_pf.c +2 -0
@@ -825,6 +825,8 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev, ndev->hw_features |=NETIF_F_RXHASH ; ndev->priv_flags |=IFF_UNICAST_FLT ; + ndev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT | +NETDEV_XDP_ACT_RX_SG |NETDEV_XDP_ACT_NDO_XMIT_SG ;if (si->hw_features &ENETC_SI_F_PSFP && !enetc_psfp_enable (priv)) { priv->active_offloads |=ENETC_F_QCI ;
drivers/net/ethernet/fungible/funeth/funeth_main.c +6 -0
@@ -1160,6 +1160,11 @@ static int fun_xdp_setup(struct net_device *dev, struct netdev_bpf *xdp)WRITE_ONCE (rxqs[i]->xdp_prog, prog); } +if (prog) +xdp_features_set_redirect_target (&dev->xdp_features, true); +else +xdp_features_clear_redirect_target (&dev->xdp_features); + dev->max_mtu = prog ?XDP_MAX_MTU :FUN_MAX_MTU ; old_prog =xchg (&fp->xdp_prog, prog);if (old_prog)
@@ -1765,6 +1770,7 @@ static int fun_create_netdev(struct fun_ethdev *ed, unsigned int portid) netdev->vlan_features = netdev->features &VLAN_FEAT ; netdev->mpls_features = netdev->vlan_features; netdev->hw_enc_features = netdev->hw_features; + netdev->xdp_features =NETDEV_XDP_ACT_FULL ; netdev->min_mtu =ETH_MIN_MTU ; netdev->max_mtu =FUN_MAX_MTU ;
drivers/net/ethernet/intel/i40e/i40e_main.c +8 -2
@@ -13339,9 +13339,11 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog, old_prog =xchg (&vsi->xdp_prog, prog);if (need_reset) { -if (!prog) +if (!prog) { +xdp_features_clear_redirect_target (&vsi->netdev->xdp_features);/* Wait until ndo_xsk_wakeup completes. */ synchronize_rcu (); + }i40e_reset_and_rebuild (pf, true, true); }
@@ -13362,11 +13364,14 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog,/* Kick start the NAPI context if there is an AF_XDP socket open * on that queue id. This so that receiving will start. */ -if (need_reset && prog) +if (need_reset && prog) {for (i =0 ; i < vsi->num_queue_pairs; i++)if (vsi->xdp_rings[i]->xsk_pool) (void )i40e_xsk_wakeup (vsi->netdev, i,XDP_WAKEUP_RX ); +xdp_features_set_redirect_target (&vsi->netdev->xdp_features, + true); + }return 0 ; }
@@ -13783,6 +13788,7 @@ static int i40e_config_netdev(struct i40e_vsi *vsi) netdev->hw_enc_features |=NETIF_F_TSO_MANGLEID ; netdev->features &= ~NETIF_F_HW_TC ; + netdev->xdp_features =NETDEV_XDP_ACT_ZC ;if (vsi->type ==I40E_VSI_MAIN ) {SET_NETDEV_DEV (netdev, &pf->pdev->dev);
drivers/net/ethernet/intel/ice/ice_main.c +5 -0
@@ -22,6 +22,7 @@#include "ice_eswitch.h" #include "ice_tc_lib.h" #include "ice_vsi_vlan_ops.h" +#include <net/xdp_sock_drv.h> #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"static const char ice_driver_string[] =DRV_SUMMARY ;
@@ -2899,11 +2900,14 @@ ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,if (xdp_ring_err)NL_SET_ERR_MSG_MOD (extack,"Setting up XDP Tx resources failed" ); } +xdp_features_set_redirect_target (&vsi->netdev->xdp_features, + false);/* reallocate Rx queues that are used for zero-copy */ xdp_ring_err =ice_realloc_zc_buf (vsi, true);if (xdp_ring_err)NL_SET_ERR_MSG_MOD (extack,"Setting up XDP Rx resources failed" ); }else if (ice_is_xdp_ena_vsi (vsi) && !prog) { +xdp_features_clear_redirect_target (&vsi->netdev->xdp_features); xdp_ring_err =ice_destroy_xdp_rings (vsi);if (xdp_ring_err)NL_SET_ERR_MSG_MOD (extack,"Freeing XDP Tx resources failed" );
@@ -3446,6 +3450,7 @@ static int ice_cfg_netdev(struct ice_vsi *vsi) np->vsi = vsi;ice_set_netdev_features (netdev); + netdev->xdp_features =NETDEV_XDP_ACT_ZC ;ice_set_ops (netdev);
drivers/net/ethernet/intel/igb/igb_main.c +9 -1
@@ -2871,8 +2871,15 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)bpf_prog_put (old_prog);/* bpf is just replaced, RXQ and MTU are already setup */ -if (!need_reset) +if (!need_reset) {return 0 ; + }else { +if (prog) +xdp_features_set_redirect_target (&dev->xdp_features, + true); +else +xdp_features_clear_redirect_target (&dev->xdp_features); + }if (running)igb_open (dev);
@@ -3317,6 +3324,7 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->priv_flags |=IFF_SUPP_NOFCS ; netdev->priv_flags |=IFF_UNICAST_FLT ; + netdev->xdp_features =NETDEV_XDP_ACT_FULL ;/* MTU range: 68 - 9216 */ netdev->min_mtu =ETH_MIN_MTU ;
drivers/net/ethernet/intel/igc/igc_main.c +2 -0
@@ -6533,6 +6533,8 @@ static int igc_probe(struct pci_dev *pdev, netdev->mpls_features |=NETIF_F_HW_CSUM ; netdev->hw_enc_features |= netdev->vlan_features; + netdev->xdp_features =NETDEV_XDP_ACT_ZC ; +/* MTU range: 68 - 9216 */ netdev->min_mtu =ETH_MIN_MTU ; netdev->max_mtu =MAX_STD_JUMBO_FRAME_SIZE ;
drivers/net/ethernet/intel/igc/igc_xdp.c +5 -0
@@ -29,6 +29,11 @@ int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,if (old_prog)bpf_prog_put (old_prog); +if (prog) +xdp_features_set_redirect_target (&dev->xdp_features, true); +else +xdp_features_clear_redirect_target (&dev->xdp_features); +if (if_running)igc_open (dev);
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +5 -0
@@ -10301,6 +10301,8 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)rcu_assign_pointer (adapter->xdp_prog, old_prog);return -EINVAL ; } +if (!prog) +xdp_features_clear_redirect_target (&dev->xdp_features); }else {for (i =0 ; i < adapter->num_rx_queues; i++) (void)xchg(&adapter->rx_ring[i]->xdp_prog,
@@ -10320,6 +10322,7 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)if (adapter->xdp_ring[i]->xsk_pool) (void )ixgbe_xsk_wakeup (adapter->netdev, i,XDP_WAKEUP_RX ); +xdp_features_set_redirect_target (&dev->xdp_features, true); }return 0 ;
@@ -11017,6 +11020,8 @@ static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->priv_flags |=IFF_UNICAST_FLT ; netdev->priv_flags |=IFF_SUPP_NOFCS ; + netdev->xdp_features =NETDEV_XDP_ACT_ZC ; +/* MTU range: 68 - 9710 */ netdev->min_mtu =ETH_MIN_MTU ; netdev->max_mtu =IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN +ETH_FCS_LEN );
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +1 -0
@@ -4634,6 +4634,7 @@ static int ixgbevf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)NETIF_F_HW_VLAN_CTAG_TX ; netdev->priv_flags |=IFF_UNICAST_FLT ; + netdev->xdp_features =NETDEV_XDP_ACT_BASIC ;/* MTU range: 68 - 1504 or 9710 */ netdev->min_mtu =ETH_MIN_MTU ;
drivers/net/ethernet/marvell/mvneta.c +2 -0
@@ -5612,6 +5612,8 @@ static int mvneta_probe(struct platform_device *pdev)NETIF_F_TSO |NETIF_F_RXCSUM ; dev->hw_features |= dev->features; dev->vlan_features |= dev->features; + dev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT | +NETDEV_XDP_ACT_RX_SG |NETDEV_XDP_ACT_NDO_XMIT_SG ; dev->priv_flags |=IFF_LIVE_ADDR_CHANGE ;netif_set_tso_max_segs (dev,MVNETA_MAX_TSO_SEGS );
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +3 -0
@@ -6866,6 +6866,9 @@ static int mvpp2_port_probe(struct platform_device *pdev, dev->vlan_features |= features;netif_set_tso_max_segs (dev,MVPP2_MAX_TSO_SEGS ); + + dev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; + dev->priv_flags |=IFF_UNICAST_FLT ;/* MTU range: 68 - 9704 */
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +6 -2
@@ -2512,10 +2512,13 @@ static int otx2_xdp_setup(struct otx2_nic *pf, struct bpf_prog *prog)/* Network stack and XDP shared same rx queues. * Use separate tx queues for XDP and network stack. */ -if (pf->xdp_prog) +if (pf->xdp_prog) { pf->hw.xdp_queues = pf->hw.rx_queues; -else +xdp_features_set_redirect_target (&dev->xdp_features, false); + }else { pf->hw.xdp_queues =0 ; +xdp_features_clear_redirect_target (&dev->xdp_features); + } pf->hw.tot_tx_queues += pf->hw.xdp_queues;
@@ -2878,6 +2881,7 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) netdev->watchdog_timeo =OTX2_TX_TIMEOUT ; netdev->netdev_ops = &otx2_netdev_ops; + netdev->xdp_features =NETDEV_XDP_ACT_FULL ; netdev->min_mtu =OTX2_MIN_MTU ; netdev->max_mtu =otx2_get_max_mtu (pf);
drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -0
@@ -4186,6 +4186,11 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)register_netdevice_notifier (&mac->device_notifier); } +if (mtk_page_pool_enabled (eth)) + eth->netdev[id]->xdp_features =NETDEV_XDP_ACT_FULL | +NETDEV_XDP_ACT_NDO_XMIT | +NETDEV_XDP_ACT_NDO_XMIT_SG ; +return 0 ; free_netdev:
drivers/net/ethernet/mellanox/mlx4/en_netdev.c +2 -0
@@ -3410,6 +3410,8 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, priv->rss_hash_fn =ETH_RSS_HASH_TOP ; } + dev->xdp_features =NETDEV_XDP_ACT_FULL ; +/* MTU range: 68 - hw-specific max */ dev->min_mtu =ETH_MIN_MTU ; dev->max_mtu = priv->max_mtu;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +10 -0
@@ -4776,6 +4776,14 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog)if (old_prog)bpf_prog_put (old_prog); +if (reset) { +if (prog) +xdp_features_set_redirect_target (&netdev->xdp_features, + true); +else +xdp_features_clear_redirect_target (&netdev->xdp_features); + } +if (!test_bit (MLX5E_STATE_OPENED , &priv->state) || reset) goto unlock;
@@ -5170,6 +5178,8 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev) netdev->features |=NETIF_F_HIGHDMA ; netdev->features |=NETIF_F_HW_VLAN_STAG_FILTER ; + netdev->xdp_features =NETDEV_XDP_ACT_ZC |NETDEV_XDP_ACT_RX_SG ; + netdev->priv_flags |=IFF_UNICAST_FLT ;netif_set_tso_max_size (netdev,GSO_MAX_SIZE );
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -0
@@ -2160,6 +2160,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx, ndev->hw_features |=NETIF_F_RXHASH ; ndev->features = ndev->hw_features; ndev->vlan_features =0 ; + ndev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; err =register_netdev (ndev);if (err) {
drivers/net/ethernet/netronome/nfp/nfp_net_common.c +5 -0
@@ -2529,10 +2529,15 @@ static void nfp_net_netdev_init(struct nfp_net *nn) netdev->features &= ~NETIF_F_HW_VLAN_STAG_RX ; nn->dp.ctrl &= ~NFP_NET_CFG_CTRL_RXQINQ ; + netdev->xdp_features =NETDEV_XDP_ACT_BASIC ; +if (nn->app && nn->app->type->id ==NFP_APP_BPF_NIC ) + netdev->xdp_features |=NETDEV_XDP_ACT_HW_OFFLOAD ; +/* Finalise the netdev setup */ switch (nn->dp.ops->version) {case NFP_NFD_VER_NFD3 : netdev->netdev_ops = &nfp_nfd3_netdev_ops; + netdev->xdp_features |=NETDEV_XDP_ACT_XSK_ZEROCOPY ;break ;case NFP_NFD_VER_NFDK : netdev->netdev_ops = &nfp_nfdk_netdev_ops;
drivers/net/ethernet/qlogic/qede/qede_main.c +2 -0
@@ -892,6 +892,8 @@ static void qede_init_ndev(struct qede_dev *edev) ndev->hw_features = hw_features; + ndev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; +/* MTU range: 46 - 9600 */ ndev->min_mtu =ETH_ZLEN -ETH_HLEN ; ndev->max_mtu =QEDE_MAX_JUMBO_PACKET_SIZE ;
drivers/net/ethernet/sfc/efx.c +3 -0
@@ -1078,6 +1078,9 @@ static int efx_pci_probe(struct pci_dev *pci_dev,pci_info (pci_dev,"Solarflare NIC detected\n" ); + efx->net_dev->xdp_features =NETDEV_XDP_ACT_FULL | +NETDEV_XDP_ACT_NDO_XMIT ; +if (!efx->type->is_vf)efx_probe_vpd_strings (efx);
drivers/net/ethernet/sfc/siena/efx.c +3 -0
@@ -1048,6 +1048,9 @@ static int efx_pci_probe(struct pci_dev *pci_dev,pci_info (pci_dev,"Solarflare NIC detected\n" ); + efx->net_dev->xdp_features =NETDEV_XDP_ACT_FULL | +NETDEV_XDP_ACT_NDO_XMIT ; +if (!efx->type->is_vf)efx_probe_vpd_strings (efx);
drivers/net/ethernet/socionext/netsec.c +2 -0
@@ -2104,6 +2104,8 @@ static int netsec_probe(struct platform_device *pdev)NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM ; ndev->hw_features = ndev->features; + ndev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; + priv->rx_cksum_offload_flag = true; ret =netsec_register_mdio (priv, phy_addr);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -7145,6 +7145,7 @@ int stmmac_dvr_probe(struct device *device, ndev->hw_features =NETIF_F_SG |NETIF_F_IP_CSUM |NETIF_F_IPV6_CSUM |NETIF_F_RXCSUM ; + ndev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; ret =stmmac_tc_init (priv, priv);if (!ret) {
drivers/net/ethernet/ti/cpsw.c +2 -0
@@ -1458,6 +1458,7 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv) priv_sl2->emac_port =1 ; cpsw->slaves[1 ].ndev = ndev; ndev->features |=NETIF_F_HW_VLAN_CTAG_FILTER |NETIF_F_HW_VLAN_CTAG_RX ; + ndev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; ndev->netdev_ops = &cpsw_netdev_ops; ndev->ethtool_ops = &cpsw_ethtool_ops;
@@ -1635,6 +1636,7 @@ static int cpsw_probe(struct platform_device *pdev) cpsw->slaves[0 ].ndev = ndev; ndev->features |=NETIF_F_HW_VLAN_CTAG_FILTER |NETIF_F_HW_VLAN_CTAG_RX ; + ndev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; ndev->netdev_ops = &cpsw_netdev_ops; ndev->ethtool_ops = &cpsw_ethtool_ops;
drivers/net/ethernet/ti/cpsw_new.c +3 -0
@@ -1405,6 +1405,9 @@ static int cpsw_create_ports(struct cpsw_common *cpsw) ndev->features |=NETIF_F_HW_VLAN_CTAG_FILTER |NETIF_F_HW_VLAN_CTAG_RX |NETIF_F_NETNS_LOCAL |NETIF_F_HW_TC ; + ndev->xdp_features =NETDEV_XDP_ACT_FULL | +NETDEV_XDP_ACT_NDO_XMIT ; + ndev->netdev_ops = &cpsw_netdev_ops; ndev->ethtool_ops = &cpsw_ethtool_ops;SET_NETDEV_DEV (ndev, dev);
drivers/net/hyperv/netvsc_drv.c +2 -0
@@ -2559,6 +2559,8 @@ static int netvsc_probe(struct hv_device *dev,netdev_lockdep_set_classes (net); + net->xdp_features =NETDEV_XDP_ACT_FULL ; +/* MTU range: 68 - 1500 or 65521 */ net->min_mtu =NETVSC_MTU_MIN ;if (nvdev->nvsp_version >=NVSP_PROTOCOL_VERSION_2 )
drivers/net/netdevsim/netdev.c +1 -0
@@ -286,6 +286,7 @@ static void nsim_setup(struct net_device *dev)NETIF_F_TSO ; dev->hw_features |=NETIF_F_HW_TC ; dev->max_mtu =ETH_MAX_MTU ; + dev->xdp_features =NETDEV_XDP_ACT_HW_OFFLOAD ; }static int nsim_init_netdevsim (struct netdevsim *ns)
drivers/net/tun.c +4 -0
@@ -1401,6 +1401,10 @@ static void tun_net_initialize(struct net_device *dev)eth_hw_addr_random (dev); +/* Currently tun does not support XDP, only tap does. */ + dev->xdp_features =NETDEV_XDP_ACT_FULL | +NETDEV_XDP_ACT_NDO_XMIT ; +break ; }
drivers/net/veth.c +3 -0
@@ -1649,6 +1649,9 @@ static void veth_setup(struct net_device *dev) dev->hw_enc_features =VETH_FEATURES ; dev->mpls_features =NETIF_F_HW_CSUM |NETIF_F_GSO_SOFTWARE ;netif_set_tso_max_size (dev,GSO_MAX_SIZE ); + + dev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT | +NETDEV_XDP_ACT_RX_SG |NETDEV_XDP_ACT_NDO_XMIT_SG ; }/*
drivers/net/virtio_net.c +5 -0
@@ -3155,7 +3155,11 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,if (i ==0 && !old_prog)virtnet_clear_guest_offloads (vi); } +if (!old_prog) +xdp_features_set_redirect_target (&dev->xdp_features, + false); }else { +xdp_features_clear_redirect_target (&dev->xdp_features); vi->xdp_enabled = false; }
@@ -3785,6 +3789,7 @@ static int virtnet_probe(struct virtio_device *vdev) dev->hw_features |=NETIF_F_GRO_HW ; dev->vlan_features = dev->features; + dev->xdp_features =NETDEV_XDP_ACT_FULL ;/* MTU range: 68 - 65535 */ dev->min_mtu =MIN_MTU ;
drivers/net/xen-netfront.c +1 -0
@@ -1741,6 +1741,7 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)* negotiate with the backend regarding supported features. */ netdev->features |= netdev->hw_features; + netdev->xdp_features =NETDEV_XDP_ACT_FULL |NETDEV_XDP_ACT_NDO_XMIT ; netdev->ethtool_ops = &xennet_ethtool_ops; netdev->min_mtu =ETH_MIN_MTU ;
include/net/xdp.h +31 -0
@@ -410,6 +410,37 @@ struct netdev_bpf;void xdp_attachment_setup (struct xdp_attachment_info *info,struct netdev_bpf *bpf); +#if defined(CONFIG_NET ) && defined(CONFIG_BPF_SYSCALL ) + +static inline void +xdp_features_set_redirect_target (xdp_features_t *xdp_features,bool support_sg) +{ + *xdp_features |=NETDEV_XDP_ACT_NDO_XMIT ; +if (support_sg) + *xdp_features |=NETDEV_XDP_ACT_NDO_XMIT_SG ; +} + +static inline void +xdp_features_clear_redirect_target (xdp_features_t *xdp_features) +{ + *xdp_features &= ~(NETDEV_XDP_ACT_NDO_XMIT | +NETDEV_XDP_ACT_NDO_XMIT_SG ); +} + +#else + +static inline void +xdp_features_set_redirect_target (xdp_features_t *xdp_features,bool support_sg) +{ +} + +static inline void +xdp_features_clear_redirect_target (xdp_features_t *xdp_features) +{ +} + +#endif +#define DEV_MAP_BULK_SIZE XDP_BULK_QUEUE_SIZE#endif /* __LINUX_NET_XDP_H__ */
Signature · 6 lines
2.39.0 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Jakub Kicinski
maintainerRe: [PATCH bpf-next 2/7] drivers: net: turn on XDP features
Quoted 5 lines · On Fri, 20 Jan 2023 18:16:51 +0100 Lorenzo Bianconi wrote:
include/net/xdp.h +5
-0+static inline void +xdp_features_set_redirect_target (xdp_features_t *xdp_features,bool support_sg) +{ + *xdp_features |=NETDEV_XDP_ACT_NDO_XMIT ; +if (support_sg)
include/net/xdp.h struct netdev_bpf; · line 429
Quoted 10 lines
include/net/xdp.h +10
-0+ *xdp_features |=NETDEV_XDP_ACT_NDO_XMIT_SG ; +} + +static inline void +xdp_features_clear_redirect_target (xdp_features_t *xdp_features) +{ + *xdp_features &= ~(NETDEV_XDP_ACT_NDO_XMIT | +NETDEV_XDP_ACT_NDO_XMIT_SG ); +} +
Shouldn't these generate netlink notifications?
Lorenzo Bianconi
maintainerRe: [PATCH bpf-next 2/7] drivers: net: turn on XDP features
Quoted 10 lines · On Fri, 20 Jan 2023 18:16:51 +0100 Lorenzo Bianconi wrote:
Quoted 9 lines
include/net/xdp.h +9
-0+static inline void +xdp_features_set_redirect_target (xdp_features_t *xdp_features,bool support_sg) +{ + *xdp_features |=NETDEV_XDP_ACT_NDO_XMIT ; +if (support_sg) + *xdp_features |=NETDEV_XDP_ACT_NDO_XMIT_SG ; +} + +static inline void
Quoted 8 lines
include/net/xdp.h struct netdev_bpf; · line 429
Quoted 6 lines
include/net/xdp.h +6
-0+xdp_features_clear_redirect_target(xdp_features_t *xdp_features) +{ + *xdp_features &= ~(NETDEV_XDP_ACT_NDO_XMIT | +NETDEV_XDP_ACT_NDO_XMIT_SG ); +} +Shouldn't these generate netlink notifications?
ack, I would say we need to add NETDEV_XDP_FEAT_CHANGE case in netdev_genl_netdevice_event routine and maybe add a new NETDEV_XDP_FEAT_CHANGE flag in netdev_cmd. What do you think?
Regards,
Lorenzo
Jakub Kicinski
maintainerRe: [PATCH bpf-next 2/7] drivers: net: turn on XDP features
Quoted 5 lines · On Sun, 22 Jan 2023 12:49:20 +0100 Lorenzo Bianconi wrote:
Quoted 1 line
Shouldn't these generate netlink notifications?
ack, I would say we need to add
NETDEV_XDP_FEAT_CHANGEcase innetdev_genl_netdevice_eventroutine and maybe add a newNETDEV_XDP_FEAT_CHANGEflag innetdev_cmd. What do you think?
No strong preference between a full event or just a direct call until we have another in-kernel user interested in the notification. The changes are wrapped nicely in helpers, so we can change it later easily.
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Lorenzo Bianconi
maintainerPATCH 3/7 xsk: add usage of XDP features flags
In reply to Lorenzo BianconiFrom: Marek Majtyka <[email protected]>
Change necessary condition check for XSK from ndo functions to xdp features flags.
--- net/xdp/xsk_buff_pool.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/xdp/xsk_buff_pool.c +1 -2
@@ -178,8 +178,7 @@ int xp_assign_dev(struct xsk_buff_pool *pool,/* For copy-mode, we are done. */ return 0 ; -if (!netdev->netdev_ops->ndo_bpf || - !netdev->netdev_ops->ndo_xsk_wakeup) { +if ((netdev->xdp_features &NETDEV_XDP_ACT_ZC ) !=NETDEV_XDP_ACT_ZC ) { err = -EOPNOTSUPP ; goto err_unreg_pool; }
Signature · 1 line
2.39.0
Lorenzo Bianconi
maintainerPATCH 4/7 libbpf: add the capability to specify netlink proto in libbpf_netlink_send_recv
In reply to Lorenzo BianconiThis is a preliminary patch in order to introduce netlink_generic protocol support to libbpf.
--- tools/lib/bpf/netlink.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
tools/lib/bpf/netlink.c +12 -10
@@ -41,7 +41,7 @@ struct xdp_id_md {struct xdp_link_info info; }; -static int libbpf_netlink_open (__u32 *nl_pid) +static int libbpf_netlink_open (__u32 *nl_pid,int proto) {struct sockaddr_nl sa;socklen_t addrlen;
@@ -51,7 +51,7 @@ static int libbpf_netlink_open(__u32 *nl_pid)memset (&sa,0 ,sizeof (sa)); sa.nl_family =AF_NETLINK ; - sock =socket (AF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC ,NETLINK_ROUTE ); + sock =socket (AF_NETLINK ,SOCK_RAW |SOCK_CLOEXEC , proto);if (sock <0 )return -errno;
@@ -212,14 +212,14 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq, }static int libbpf_netlink_send_recv (struct libbpf_nla_req *req, -__dump_nlmsg_t parse_msg, +int proto,__dump_nlmsg_t parse_msg,libbpf_dump_nlmsg_t parse_attr,void *cookie) {__u32 nl_pid =0 ;int sock, ret; - sock =libbpf_netlink_open (&nl_pid); + sock =libbpf_netlink_open (&nl_pid, proto);if (sock <0 )return sock;
@@ -271,7 +271,7 @@ static int __bpf_set_link_xdp_fd_replace(int ifindex, int fd, int old_fd, }nlattr_end_nested (&req, nla); -return libbpf_netlink_send_recv (&req,NULL ,NULL ,NULL ); +return libbpf_netlink_send_recv (&req,NETLINK_ROUTE ,NULL ,NULL ,NULL ); }int bpf_xdp_attach (int ifindex,int prog_fd,__u32 flags,const struct bpf_xdp_attach_opts *opts)
@@ -382,7 +382,7 @@ int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts) xdp_id.ifindex = ifindex; xdp_id.flags = xdp_flags; - err =libbpf_netlink_send_recv (&req, __dump_link_nlmsg, + err =libbpf_netlink_send_recv (&req,NETLINK_ROUTE , __dump_link_nlmsg, get_xdp_info, &xdp_id);if (err)return libbpf_err (err);
@@ -493,7 +493,7 @@ static int tc_qdisc_modify(struct bpf_tc_hook *hook, int cmd, int flags)if (ret <0 )return ret; -return libbpf_netlink_send_recv (&req,NULL ,NULL ,NULL ); +return libbpf_netlink_send_recv (&req,NETLINK_ROUTE ,NULL ,NULL ,NULL ); }static int tc_qdisc_create_excl (struct bpf_tc_hook *hook)
@@ -673,7 +673,8 @@ int bpf_tc_attach(const struct bpf_tc_hook *hook, struct bpf_tc_opts *opts) info.opts = opts; - ret =libbpf_netlink_send_recv (&req, get_tc_info,NULL , &info); + ret =libbpf_netlink_send_recv (&req,NETLINK_ROUTE , get_tc_info,NULL , + &info);if (ret <0 )return libbpf_err (ret);if (!info.processed)
@@ -739,7 +740,7 @@ static int __bpf_tc_detach(const struct bpf_tc_hook *hook,return ret; } -return libbpf_netlink_send_recv (&req,NULL ,NULL ,NULL ); +return libbpf_netlink_send_recv (&req,NETLINK_ROUTE ,NULL ,NULL ,NULL ); } int bpf_tc_detach(const struct bpf_tc_hook *hook,
@@ -804,7 +805,8 @@ int bpf_tc_query(const struct bpf_tc_hook *hook, struct bpf_tc_opts *opts) info.opts = opts; - ret =libbpf_netlink_send_recv (&req, get_tc_info,NULL , &info); + ret =libbpf_netlink_send_recv (&req,NETLINK_ROUTE , get_tc_info,NULL , + &info);if (ret <0 )return libbpf_err (ret);if (!info.processed)
Signature · 1 line
2.39.0
Lorenzo Bianconi
maintainerPATCH 5/7 libbpf: add API to get XDP/XSK supported features
In reply to Lorenzo BianconiExtend bpf_xdp_query routine in order to get XDP/XSK supported features of netdev over route netlink interface.
Extend libbpf netlink implementation in order to support netlink_generic protocol.
--- tools/lib/bpf/libbpf.h | 3 +- tools/lib/bpf/netlink.c | 99 +++++++++++++++++++++++++++++++++++++++++ tools/lib/bpf/nlattr.h | 12 +++++ 3 files changed, 113 insertions(+), 1 deletion(-)
tools/lib/bpf/libbpf.h +2 -1
@@ -982,9 +982,10 @@ struct bpf_xdp_query_opts {__u32 hw_prog_id;/* output */ __u32 skb_prog_id;/* output */ __u8 attach_mode;/* output */ +__u64 fflags;/* output */ size_t :0; }; -#define bpf_xdp_query_opts__last_field attach_mode +#define bpf_xdp_query_opts__last_field fflags LIBBPF_API int bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags,const struct bpf_xdp_attach_opts *opts);
tools/lib/bpf/netlink.c +99 -0
129 lines not on this page · raw message
tools/lib/bpf/nlattr.h +12 -0
@@ -14,6 +14,7 @@#include <errno.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> +#include <linux/genetlink.h> /* avoid multiple definition of netlink features */ #define __LINUX_NETLINK_H
@@ -58,6 +59,7 @@ struct libbpf_nla_req {union {struct ifinfomsg ifinfo;struct tcmsg tc; +struct genlmsghdr gnl; };char buf[128 ]; };
@@ -89,11 +91,21 @@ static inline uint8_t libbpf_nla_getattr_u8(const struct nlattr *nla)return *(uint8_t *)libbpf_nla_data (nla); } +static inline uint16_t libbpf_nla_getattr_u16 (const struct nlattr *nla) +{ +return *(uint16_t *)libbpf_nla_data (nla); +} +static inline uint32_t libbpf_nla_getattr_u32 (const struct nlattr *nla) {return *(uint32_t *)libbpf_nla_data (nla); } +static inline uint64_t libbpf_nla_getattr_u64 (const struct nlattr *nla) +{ +return *(uint64_t *)libbpf_nla_data (nla); +} +static inline const char *libbpf_nla_getattr_str (const struct nlattr *nla) {return (const char *)libbpf_nla_data (nla);
Signature · 6 lines
2.39.0 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Jakub Kicinski
maintainerRe: [PATCH bpf-next 5/7] libbpf: add API to get XDP/XSK supported features
tools/lib/bpf/netlink.c static int libbpf_netlink_send_recv(struct libbpf_nla_req *req, · line 273
Quoted 9 lines · On Fri, 20 Jan 2023 18:16:54 +0100 Lorenzo Bianconi wrote:
tools/lib/bpf/netlink.c +9
-0+static int libbpf_netlink_resolve_genl_family_id (const char *name, +__u16 len,__u16 *id) +{ +struct libbpf_nla_req req = { + .nh.nlmsg_len =NLMSG_LENGTH (GENL_HDRLEN ), + .nh.nlmsg_type =GENL_ID_CTRL , + .nh.nlmsg_flags =NLM_F_REQUEST , + .gnl.cmd =CTRL_CMD_GETFAMILY , + .gnl.version =1 ,
nlctrl is version 2, shouldn't matter in practice
Lorenzo Bianconi
maintainerRe: [PATCH bpf-next 5/7] libbpf: add API to get XDP/XSK supported features
Quoted 12 lines · On Fri, 20 Jan 2023 18:16:54 +0100 Lorenzo Bianconi wrote:
tools/lib/bpf/netlink.c static int libbpf_netlink_send_recv(struct libbpf_nla_req *req, · line 273
Quoted 9 lines
tools/lib/bpf/netlink.c +9
-0+static int libbpf_netlink_resolve_genl_family_id (const char *name, +__u16 len,__u16 *id) +{ +struct libbpf_nla_req req = { + .nh.nlmsg_len =NLMSG_LENGTH (GENL_HDRLEN ), + .nh.nlmsg_type =GENL_ID_CTRL , + .nh.nlmsg_flags =NLM_F_REQUEST , + .gnl.cmd =CTRL_CMD_GETFAMILY , + .gnl.version =1 ,nlctrl is version 2, shouldn't matter in practice
ack, I will fix it.
Regards,
Lorenzo
Lorenzo Bianconi
maintainerPATCH 6/7 bpf: devmap: check XDP features in bpf_map_update_elem and __xdp_enqueue
In reply to Lorenzo BianconiWhen we update devmap element, the net_device whose ifindex is specified in map value must support ndo_xdp_xmit callback, which is indicated by the presence of XDP_F_REDIRECT_TARGET feature. Let's check for this feature and return an error if device cannot be used as a redirect target.
Moreover check the device support xdp non-linear frame in __xdp_enqueue and is_valid_dst routines. This patch allows to perfrom XDP_REDIRECT on non-linear xdp buffers.
--- kernel/bpf/devmap.c | 25 +++++++++++++++++++++---- net/core/filter.c | 13 +++++-------- 2 files changed, 26 insertions(+), 12 deletions(-)
kernel/bpf/devmap.c +21 -4
@@ -474,7 +474,11 @@ static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, {int err; -if (!dev->netdev_ops->ndo_xdp_xmit) +if (!(dev->xdp_features &NETDEV_XDP_ACT_NDO_XMIT )) +return -EOPNOTSUPP ; + +if (unlikely (!(dev->xdp_features &NETDEV_XDP_ACT_NDO_XMIT_SG ) && +xdp_frame_has_frags (xdpf)))return -EOPNOTSUPP ; err =xdp_ok_fwd_dev (dev,xdp_get_frame_len (xdpf));
@@ -532,8 +536,14 @@ int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_frame *xdpf,static bool is_valid_dst (struct bpf_dtab_netdev *obj,struct xdp_frame *xdpf) { -if (!obj || - !obj->dev->netdev_ops->ndo_xdp_xmit) +if (!obj) +return false; + +if (!(obj->dev->xdp_features &NETDEV_XDP_ACT_NDO_XMIT )) +return false; + +if (unlikely (!(obj->dev->xdp_features &NETDEV_XDP_ACT_NDO_XMIT_SG ) && +xdp_frame_has_frags (xdpf)))return false;if (xdp_ok_fwd_dev (obj->dev,xdp_get_frame_len (xdpf)))
@@ -843,6 +853,7 @@ static struct bpf_dtab_netdev *__dev_map_alloc_node(struct net *net, {struct bpf_prog *prog =NULL ;struct bpf_dtab_netdev *dev; +int ret = -EINVAL ; dev = bpf_map_kmalloc_node(&dtab->map, sizeof(*dev), GFP_NOWAIT | __GFP_NOWARN,
@@ -854,6 +865,12 @@ static struct bpf_dtab_netdev *__dev_map_alloc_node(struct net *net,if (!dev->dev) goto err_out; +/* Check if net_device can be used as a redirect target */ +if (!(READ_ONCE (dev->dev->xdp_features) &NETDEV_XDP_ACT_NDO_XMIT )) { + ret = -EOPNOTSUPP ; + goto err_put_dev; + } +if (val->bpf_prog.fd >0 ) { prog =bpf_prog_get_type_dev (val->bpf_prog.fd,BPF_PROG_TYPE_XDP , false);
@@ -882,7 +899,7 @@ static struct bpf_dtab_netdev *__dev_map_alloc_node(struct net *net,dev_put (dev->dev); err_out:kfree (dev); -return ERR_PTR (-EINVAL ); +return ERR_PTR (ret); } static int __dev_map_update_elem(struct net *net, struct bpf_map *map,
net/core/filter.c +5 -8
@@ -4314,16 +4314,13 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,struct bpf_redirect_info *ri =this_cpu_ptr (&bpf_redirect_info);enum bpf_map_type map_type = ri->map_type; -/* XDP_REDIRECT is not fully supported yet for xdp frags since -* not all XDP capable drivers can map non-linear xdp_frame in -* ndo_xdp_xmit. -*/ -if (unlikely (xdp_buff_has_frags (xdp) && - map_type !=BPF_MAP_TYPE_CPUMAP )) -return -EOPNOTSUPP ; +if (map_type ==BPF_MAP_TYPE_XSKMAP ) { +/* XDP_REDIRECT is not supported AF_XDP yet. */ +if (unlikely (xdp_buff_has_frags (xdp))) +return -EOPNOTSUPP ; -if (map_type ==BPF_MAP_TYPE_XSKMAP )return __xdp_do_redirect_xsk (ri, dev, xdp, xdp_prog); + }return __xdp_do_redirect_frame (ri, dev,xdp_convert_buff_to_frame (xdp), xdp_prog);
Signature · 6 lines
2.39.0 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Martin KaFai Lau
reviewerRe: [PATCH bpf-next 6/7] bpf: devmap: check XDP features in bpf_map_update_elem and __xdp_enqueue
Quoted 10 lines · Lorenzo Bianconi
--- kernel/bpf/devmap.c | 25 +++++++++++++++++++++---- net/core/filter.c | 13 +++++-------- 2 files changed, 26 insertions(+), 12 deletions(-)kernel/bpf/devmap.c +0
-0
kernel/bpf/devmap.c static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, · line 477
Quoted 5 lines
kernel/bpf/devmap.c +1
-1@@ -474,7 +474,11 @@ static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, {int err; -if (!dev->netdev_ops->ndo_xdp_xmit) +if (!(dev->xdp_features &NETDEV_XDP_ACT_NDO_XMIT ))
The current "dev->netdev_ops->ndo_xdp_xmit" check is self explaining. Any plan to put some document for the NETDEV_XDP_ACT_* values?
Lorenzo Bianconi
maintainerRe: [PATCH bpf-next 6/7] bpf: devmap: check XDP features in bpf_map_update_elem and __xdp_enqueue
Quoted 6 lines · Lorenzo Bianconi
Quoted 5 lines
--- kernel/bpf/devmap.c | 25 +++++++++++++++++++++---- net/core/filter.c | 13 +++++-------- 2 files changed, 26 insertions(+), 12 deletions(-)
Quoted 13 lines
kernel/bpf/devmap.c static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, · line 476
Quoted 9 lines
kernel/bpf/devmap.c +1
-1@@ -474,7 +474,11 @@ static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, {int err; -if (!dev->netdev_ops->ndo_xdp_xmit) +if (!(dev->xdp_features &NETDEV_XDP_ACT_NDO_XMIT ))The current "
dev->netdev_ops->ndo_xdp_xmit" check is self explaining. Any plan to put some document for the NETDEV_XDP_ACT_* values?
I am not a yaml description expert but I guess we can xdp features description in Documentation/netlink/specs/netdev.yaml.
@Jakub: what do you think?
Regards,
Lorenzo
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Jakub Kicinski
maintainerRe: [PATCH bpf-next 6/7] bpf: devmap: check XDP features in bpf_map_update_elem and __xdp_enqueue
Quoted 14 lines · On Sun, 22 Jan 2023 13:13:41 +0100 Lorenzo Bianconi wrote:
Quoted 4 lines
Quoted 4 lines
kernel/bpf/devmap.c +0
-0Quoted 9 lines
kernel/bpf/devmap.c static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, · line 476
Quoted 5 lines
kernel/bpf/devmap.c +1
-1@@ -474,7 +474,11 @@ static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, {int err; -if (!dev->netdev_ops->ndo_xdp_xmit) +if (!(dev->xdp_features &NETDEV_XDP_ACT_NDO_XMIT ))The current "
dev->netdev_ops->ndo_xdp_xmit" check is self explaining. Any plan to put some document for the NETDEV_XDP_ACT_* values?
Quoted 4 lines
I am not a yaml description expert but I guess we can xdp features description in
Documentation/netlink/specs/netdev.yaml.@Jakub: what do you think?
I've added the ability to document enums recently, so you may need to rebase. But it should work and render the documentation as kdoc in the uAPI header (hopefully in a not-too-ugly way).
Example of YAML:
https://github.com/kuba-moo/ynl/blob/dpll/Documentation/netlink/specs/dpll.yaml#L27-L46
I've also talked to the iproute2-py maintainer about generating documentation directly from YAML to Sphinx/htmldocs, hopefully that will happen, too. It would be good to have a few families to work with before we start that work, tho.
Lorenzo Bianconi
maintainerRe: [PATCH bpf-next 6/7] bpf: devmap: check XDP features in bpf_map_update_elem and __xdp_enqueue
Quoted 18 lines · Jakub Kicinski
Quoted 17 lines · On Sun, 22 Jan 2023 13:13:41 +0100 Lorenzo Bianconi wrote:
Quoted 4 lines
Quoted 4 lines
kernel/bpf/devmap.c +0
-0Quoted 9 lines
kernel/bpf/devmap.c static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, · line 476
Quoted 5 lines
kernel/bpf/devmap.c +1
-1@@ -474,7 +474,11 @@ static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf, {int err; -if (!dev->netdev_ops->ndo_xdp_xmit) +if (!(dev->xdp_features &NETDEV_XDP_ACT_NDO_XMIT ))The current "
dev->netdev_ops->ndo_xdp_xmit" check is self explaining. Any plan to put some document for the NETDEV_XDP_ACT_* values?I am not a yaml description expert but I guess we can xdp features description in
Documentation/netlink/specs/netdev.yaml.
Quoted 8 lines
Quoted 1 line
@Jakub: what do you think?
I've added the ability to document enums recently, so you may need to rebase. But it should work and render the documentation as kdoc in the uAPI header (hopefully in a not-too-ugly way).
Example of YAML:
https://github.com/kuba-moo/ynl/blob/dpll/Documentation/netlink/specs/dpll.yaml#L27-L46
ack, it works properly I guess, I got the following kdoc in the uAPI:
/**
* enum netdev_xdp_act
* @NETDEV_XDP_ACT_BASIC: XDP feautues set supported by all drivers
* (XDP_ABORTED, XDP_DROP, XDP_PASS, XDP_TX)
* @NETDEV_XDP_ACT_REDIRECT: The netdev supports XDP_REDIRECT
* @NETDEV_XDP_ACT_NDO_XMIT: This feature informs if netdev implements
* ndo_xdp_xmit callback.
* @NETDEV_XDP_ACT_XSK_ZEROCOPY: This feature informs if netdev supports AF_XDP
* in zero copy mode.
* @NETDEV_XDP_ACT_HW_OFFLOAD: This feature informs if netdev supports XDP hw
* oflloading.
* @NETDEV_XDP_ACT_RX_SG: This feature informs if netdev implements non-linear
* XDP buffer support in the driver napi callback.
* @NETDEV_XDP_ACT_NDO_XMIT_SG: This feature informs if netdev implements
* non-linear XDP buffer support in ndo_xdp_xmit callback.
*/
enum netdev_xdp_act {
NETDEV_XDP_ACT_BASIC,
NETDEV_XDP_ACT_REDIRECT,
NETDEV_XDP_ACT_NDO_XMIT,
NETDEV_XDP_ACT_XSK_ZEROCOPY,
NETDEV_XDP_ACT_HW_OFFLOAD,
NETDEV_XDP_ACT_RX_SG,
NETDEV_XDP_ACT_NDO_XMIT_SG,
};
Regards,
Lorenzo
Quoted 5 lines
I've also talked to the iproute2-py maintainer about generating documentation directly from YAML to Sphinx/htmldocs, hopefully that will happen, too. It would be good to have a few families to work with before we start that work, tho.
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Lorenzo Bianconi
maintainerPATCH 7/7 selftests/bpf: introduce XDP compliance test tool
In reply to Lorenzo BianconiIntroduce xdp_features tool in order to test XDP features supported by the NIC and match them against advertised ones.
In order to test supported/advertised XDP features, xdp_features must run on the Device Under Test (DUT) and on a Tester device. xdp_features opens a control TCP channel between DUT and Tester devices to send control commands from Tester to the DUT and a UDP data channel where the Tester sends UDP 'echo' packets and the DUT is expected to reply back with the same packet. DUT installs multiple XDP programs on the NIC to test XDP capabilities and reports back to the Tester some XDP stats. Currently xdp_features supports the following XDP features:
- XDP_DROP
- XDP_PASS
- XDP_TX
- XDP_REDIRECT
- XDP_REDIRECT_TARGET
--- tools/testing/selftests/bpf/Makefile | 5 +- .../selftests/bpf/progs/test_xdp_features.c | 237 ++++++ .../selftests/bpf/test_xdp_features.sh | 99 +++ tools/testing/selftests/bpf/xdp_features.c | 743 ++++++++++++++++++ 4 files changed, 1082 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_features.c create mode 100755 tools/testing/selftests/bpf/test_xdp_features.sh create mode 100644 tools/testing/selftests/bpf/xdp_features.c
tools/testing/selftests/bpf/Makefile +3 -2
@@ -73,7 +73,8 @@ TEST_PROGS := test_kmod.sh \ test_bpftool.sh \ test_bpftool_metadata.sh \ test_doc_build.sh \ - test_xsk.sh + test_xsk.sh \ + test_xdp_features.sh TEST_PROGS_EXTENDED := with_addr.sh \ with_tunnels.sh ima_setup.sh verify_sig_setup.sh \
@@ -83,7 +84,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \ TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \ flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \ - xskxceiver xdp_redirect_multi xdp_synproxy veristat + xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_features TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read $(OUTPUT)/sign-file TEST_GEN_FILES += liburandom_read.so
tools/testing/selftests/bpf/progs/test_xdp_features.c new file +237 -0
237 lines not on this page · raw message
tools/testing/selftests/bpf/test_xdp_features.sh new file +99 -0
99 lines not on this page · raw message
tools/testing/selftests/bpf/xdp_features.c new file +743 -0
743 lines not on this page · raw message
Signature · 6 lines
2.39.0 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Martin KaFai Lau
reviewerRe: [PATCH bpf-next 7/7] selftests/bpf: introduce XDP compliance test tool
Quoted 8 lines · Lorenzo Bianconi
tools/testing/selftests/bpf/progs/test_xdp_features.c new file +8
-0+static __always_inline int xdp_process_echo_packet(struct xdp_md *xdp, bool dut) +{ +void *data_end = (void *)(long )xdp->data_end; +__be32 saddr = dut ? tester_ip : dut_ip; +__be32 daddr = dut ? dut_ip : tester_ip; +void *data = (void *)(long )xdp->data; +struct ethhdr *eh = data; +struct tlv_hdr *tlv;
tools/testing/selftests/bpf/progs/test_xdp_features.c line 90
Quoted 10 lines
tools/testing/selftests/bpf/progs/test_xdp_features.c new file +10
-0+struct udphdr *uh; +struct iphdr *ih; +__be16 port; +__u8 *cmd; + +if (eh +1 > (struct ethhdr *)data_end) +return -EINVAL ; + +if (eh->h_proto !=bpf_htons (ETH_P_IP )) +return -EINVAL ;
Both v6 and v4 support are needed as a tool.
[ ... ]
Quoted 93 lines
tools/testing/selftests/bpf/test_xdp_features.sh new file +87
-0@@ -0,0 +1,99 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# Create 2 namespaces with two veth peers, and +# check reported and detected XDP capabilities +# +# NS0(v00) NS1(v11) +# | | +# | | +# (v01, id:111) ------ (v10,id:222) + +readonly NS0="ns1-$(mktemp -u XXXXXX)" +readonly NS1="ns2-$(mktemp -u XXXXXX)" +ret=1 + +setup() { + { + ip netns add ${NS0} + ip netns add ${NS1} + + ip link add v01 index 111 type veth peer name v00 netns ${NS0} + ip link add v10 index 222 type veth peer name v11 netns ${NS1} + + ip link set v01 up + ip addr add 10.10.0.1/24 dev v01 + ip link set v01 address 00:11:22:33:44:55 + ip -n ${NS0} link set dev v00 up + ip -n ${NS0} addr add 10.10.0.11/24 dev v00 + ip -n ${NS0} route add default via 10.10.0.1 + ip -n ${NS0} link set v00 address 00:12:22:33:44:55 + + ip link set v10 up + ip addr add 10.10.1.1/24 dev v10 + ip link set v10 address 00:13:22:33:44:55 + ip -n ${NS1} link set dev v11 up + ip -n ${NS1} addr add 10.10.1.11/24 dev v11 + ip -n ${NS1} route add default via 10.10.1.1 + ip -n ${NS1} link set v11 address 00:14:22:33:44:55 + + sysctl -w net.ipv4.ip_forward=1 + # Enable XDP mode + ethtool -K v01 gro on + ethtool -K v01 tx-checksumming off + ip netns exec ${NS0} ethtool -K v00 gro on + ip netns exec ${NS0} ethtool -K v00 tx-checksumming off + ethtool -K v10 gro on + ethtool -K v10 tx-checksumming off + ip netns exec ${NS1} ethtool -K v11 gro on + ip netns exec ${NS1} ethtool -K v11 tx-checksumming off + } > /dev/null 2>&1 +} + +cleanup() { + ip link del v01 2> /dev/null + ip link del v10 2> /dev/null + ip netns del ${NS0} 2> /dev/null + ip netns del ${NS1} 2> /dev/null + [ "$(pidof xdp_features)" = "" ] || kill $(pidof xdp_features) 2> /dev/null +} + +test_xdp_features() { + setup + + ## XDP_PASS + ip netns exec ${NS1} ./xdp_features -f XDP_PASS -D 10.10.1.11 -T 10.10.0.11 v11 & + ip netns exec ${NS0} ./xdp_features -t -f XDP_PASS -D 10.10.1.11 -C 10.10.1.11 -T 10.10.0.11 v00 + + [ $? -ne 0 ] && exit + + # XDP_DROP + ip netns exec ${NS1} ./xdp_features -f XDP_DROP -D 10.10.1.11 -T 10.10.0.11 v11 & + ip netns exec ${NS0} ./xdp_features -t -f XDP_DROP -D 10.10.1.11 -C 10.10.1.11 -T 10.10.0.11 v00 + + [ $? -ne 0 ] && exit + + ## XDP_TX + ./xdp_features -f XDP_TX -D 10.10.0.1 -T 10.10.0.11 v01 & + ip netns exec ${NS0} ./xdp_features -t -f XDP_TX -D 10.10.0.1 -C 10.10.0.1 -T 10.10.0.11 v00 + + ## XDP_REDIRECT + ip netns exec ${NS1} ./xdp_features -f XDP_REDIRECT -D 10.10.1.11 -T 10.10.0.11 v11 & + ip netns exec ${NS0} ./xdp_features -t -f XDP_REDIRECT -D 10.10.1.11 -C 10.10.1.11 -T 10.10.0.11 v00 + + [ $? -ne 0 ] && exit + + ## XDP_NDO_XMIT + ./xdp_features -f XDP_NDO_XMIT -D 10.10.0.1 -T 10.10.0.11 v01 &
tools/testing/selftests/bpf/test_xdp_features.sh line 97
Quoted 10 lines
tools/testing/selftests/bpf/test_xdp_features.sh new file +10
-0+ ip netns exec ${NS0} ./xdp_features -t -f XDP_NDO_XMIT -D 10.10.0.1 -C 10.10.0.1 -T 10.10.0.11 v00 + + ret=$? + cleanup +} + +set -e +trap cleanup 2 3 6 9 + +test_xdp_features
This won't be run by bpf CI.
A selftest in test_progs is needed to test the libbpf changes in patch 6.
Lorenzo Bianconi
maintainerRe: [PATCH bpf-next 7/7] selftests/bpf: introduce XDP compliance test tool
Quoted 13 lines · Lorenzo Bianconi
Quoted 12 lines
tools/testing/selftests/bpf/progs/test_xdp_features.c new file +12
-0+static __always_inline int xdp_process_echo_packet(struct xdp_md *xdp, bool dut) +{ +void *data_end = (void *)(long )xdp->data_end; +__be32 saddr = dut ? tester_ip : dut_ip; +__be32 daddr = dut ? dut_ip : tester_ip; +void *data = (void *)(long )xdp->data; +struct ethhdr *eh = data; +struct tlv_hdr *tlv; +struct udphdr *uh; +struct iphdr *ih; +__be16 port; +__u8 *cmd;
Quoted 8 lines
tools/testing/selftests/bpf/progs/test_xdp_features.c line 90
Quoted 6 lines
tools/testing/selftests/bpf/progs/test_xdp_features.c new file +6
-0+ +if (eh +1 > (struct ethhdr *)data_end) +return -EINVAL ; + +if (eh->h_proto !=bpf_htons (ETH_P_IP )) +return -EINVAL ;Both v6 and v4 support are needed as a tool.
ack, I will fix it.
Quoted 109 lines
[ ... ]
Quoted 93 lines
tools/testing/selftests/bpf/test_xdp_features.sh new file +87
-0@@ -0,0 +1,99 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# Create 2 namespaces with two veth peers, and +# check reported and detected XDP capabilities +# +# NS0(v00) NS1(v11) +# | | +# | | +# (v01, id:111) ------ (v10,id:222) + +readonly NS0="ns1-$(mktemp -u XXXXXX)" +readonly NS1="ns2-$(mktemp -u XXXXXX)" +ret=1 + +setup() { + { + ip netns add ${NS0} + ip netns add ${NS1} + + ip link add v01 index 111 type veth peer name v00 netns ${NS0} + ip link add v10 index 222 type veth peer name v11 netns ${NS1} + + ip link set v01 up + ip addr add 10.10.0.1/24 dev v01 + ip link set v01 address 00:11:22:33:44:55 + ip -n ${NS0} link set dev v00 up + ip -n ${NS0} addr add 10.10.0.11/24 dev v00 + ip -n ${NS0} route add default via 10.10.0.1 + ip -n ${NS0} link set v00 address 00:12:22:33:44:55 + + ip link set v10 up + ip addr add 10.10.1.1/24 dev v10 + ip link set v10 address 00:13:22:33:44:55 + ip -n ${NS1} link set dev v11 up + ip -n ${NS1} addr add 10.10.1.11/24 dev v11 + ip -n ${NS1} route add default via 10.10.1.1 + ip -n ${NS1} link set v11 address 00:14:22:33:44:55 + + sysctl -w net.ipv4.ip_forward=1 + # Enable XDP mode + ethtool -K v01 gro on + ethtool -K v01 tx-checksumming off + ip netns exec ${NS0} ethtool -K v00 gro on + ip netns exec ${NS0} ethtool -K v00 tx-checksumming off + ethtool -K v10 gro on + ethtool -K v10 tx-checksumming off + ip netns exec ${NS1} ethtool -K v11 gro on + ip netns exec ${NS1} ethtool -K v11 tx-checksumming off + } > /dev/null 2>&1 +} + +cleanup() { + ip link del v01 2> /dev/null + ip link del v10 2> /dev/null + ip netns del ${NS0} 2> /dev/null + ip netns del ${NS1} 2> /dev/null + [ "$(pidof xdp_features)" = "" ] || kill $(pidof xdp_features) 2> /dev/null +} + +test_xdp_features() { + setup + + ## XDP_PASS + ip netns exec ${NS1} ./xdp_features -f XDP_PASS -D 10.10.1.11 -T 10.10.0.11 v11 & + ip netns exec ${NS0} ./xdp_features -t -f XDP_PASS -D 10.10.1.11 -C 10.10.1.11 -T 10.10.0.11 v00 + + [ $? -ne 0 ] && exit + + # XDP_DROP + ip netns exec ${NS1} ./xdp_features -f XDP_DROP -D 10.10.1.11 -T 10.10.0.11 v11 & + ip netns exec ${NS0} ./xdp_features -t -f XDP_DROP -D 10.10.1.11 -C 10.10.1.11 -T 10.10.0.11 v00 + + [ $? -ne 0 ] && exit + + ## XDP_TX + ./xdp_features -f XDP_TX -D 10.10.0.1 -T 10.10.0.11 v01 & + ip netns exec ${NS0} ./xdp_features -t -f XDP_TX -D 10.10.0.1 -C 10.10.0.1 -T 10.10.0.11 v00 + + ## XDP_REDIRECT + ip netns exec ${NS1} ./xdp_features -f XDP_REDIRECT -D 10.10.1.11 -T 10.10.0.11 v11 & + ip netns exec ${NS0} ./xdp_features -t -f XDP_REDIRECT -D 10.10.1.11 -C 10.10.1.11 -T 10.10.0.11 v00 + + [ $? -ne 0 ] && exit + + ## XDP_NDO_XMIT + ./xdp_features -f XDP_NDO_XMIT -D 10.10.0.1 -T 10.10.0.11 v01 &tools/testing/selftests/bpf/test_xdp_features.sh line 97
Quoted 10 lines
tools/testing/selftests/bpf/test_xdp_features.sh new file +10
-0+ ip netns exec ${NS0} ./xdp_features -t -f XDP_NDO_XMIT -D 10.10.0.1 -C 10.10.0.1 -T 10.10.0.11 v00 + + ret=$? + cleanup +} + +set -e +trap cleanup 2 3 6 9 + +test_xdp_featuresThis won't be run by bpf CI.
Quoted 1 line
A selftest in
test_progsis needed to test the libbpf changes in patch 6.
ack, I will add it.
Regards,
Lorenzo