selftests: Add AF_XDP functionality test
Subsystems (7)
cover selftests: Add AF_XDP functionality test
We have observed that hardware NIC drivers may have faulty AF_XDP implementations, and there seem to be a lack of a test of various modes in which AF_XDP could run. This series adds a test to verify that NIC drivers implements many AF_XDP features by performing a send / receive of a single UDP packet.
I put the C code of the test under selftests/bpf because I'm not really sure how I'd build the BPF-related code without the selftests/bpf build infrastructure.
Tested on Google Cloud, with GVE:
$ sudo NETIF=ens4 REMOTE_TYPE=ssh \
REMOTE_ARGS="[email protected]" \
LOCAL_V4="10.138.15.234" \
REMOTE_V4="10.138.15.235" \
LOCAL_NEXTHOP_MAC="42:01:0a:8a:00:01" \
REMOTE_NEXTHOP_MAC="42:01:0a:8a:00:01" \
python3 xsk_hw.py KTAP version 1
1..22
ok 1 xsk_hw.ipv4_basic
ok 2 xsk_hw.ipv4_tx_skb_copy
ok 3 xsk_hw.ipv4_tx_skb_copy_force_attach
ok 4 xsk_hw.ipv4_rx_skb_copy
ok 5 xsk_hw.ipv4_tx_drv_copy
ok 6 xsk_hw.ipv4_tx_drv_copy_force_attach
ok 7 xsk_hw.ipv4_rx_drv_copy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw: recv_pfpacket: Timeout\n'
not ok 8 xsk_hw.ipv4_tx_drv_zerocopy
ok 9 xsk_hw.ipv4_tx_drv_zerocopy_force_attach
ok 10 xsk_hw.ipv4_rx_drv_zerocopy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw: connect sync client: max_retries\n' [...]
# Exception| STDERR: b'/linux/tools/testing/selftests/bpf/xsk_hw: open_xsk: Device or resource busy\n' not ok 11 xsk_hw.ipv4_rx_drv_zerocopy_fill_after_bind
ok 12 xsk_hw.ipv6_basic # SKIP Test requires IPv6 connectivity
[...]
ok 22 xsk_hw.ipv6_rx_drv_zerocopy_fill_after_bind # SKIP Test requires IPv6 connectivity # Totals: pass:9 fail:2 xfail:0 xpass:0 skip:11 error:0
YiFei Zhu (3):
selftests/bpf: Move rxq_num helper from xdp_hw_metadata to
network_helpers
selftests/bpf: Add xsk_hw AF_XDP functionality test
selftests: drv-net: Add xsk_hw AF_XDP functionality test
tools/testing/selftests/bpf/.gitignore | 1 + tools/testing/selftests/bpf/Makefile | 7 +- tools/testing/selftests/bpf/network_helpers.c | 27 + tools/testing/selftests/bpf/network_helpers.h | 16 + tools/testing/selftests/bpf/progs/xsk_hw.c | 72 ++ tools/testing/selftests/bpf/xdp_hw_metadata.c | 27 +- tools/testing/selftests/bpf/xsk_hw.c | 844 ++++++++++++++++++ .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/xsk_hw.py | 133 +++ 9 files changed, 1102 insertions(+), 26 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/xsk_hw.c create mode 100644 tools/testing/selftests/bpf/xsk_hw.c create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_hw.py
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
RFC PATCH 1/3 selftests/bpf: Move rxq_num helper from xdp_hw_metadata to network_helpers
This helper may be useful for other AF_XDP tests, such as xsk_hw. Moving it out so we don't need to copy-paste that function.
I also changed the function from directly calling error(1, errno, ...) to returning an error because I don't think it makes sense for a library function to outright kill the process if the function fails.
--- tools/testing/selftests/bpf/network_helpers.c | 27 +++++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 2 ++ tools/testing/selftests/bpf/xdp_hw_metadata.c | 27 ++----------------- 3 files changed, 31 insertions(+), 25 deletions(-)
tools/testing/selftests/bpf/network_helpers.c +27 -0
@@ -569,6 +569,33 @@ int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)return 0 ; } +int rxq_num (const char *ifname) +{ +struct ethtool_channels ch = { + .cmd =ETHTOOL_GCHANNELS , + }; +struct ifreq ifr = { + .ifr_data = (void *)&ch, + }; +strncpy (ifr.ifr_name, ifname,IF_NAMESIZE -1 ); +int fd, ret, err; + + fd =socket (AF_UNIX ,SOCK_DGRAM ,0 ); +if (fd <0 ) +return -errno; + + ret =ioctl (fd,SIOCETHTOOL , &ifr); +if (ret <0 ) { + err = errno; +close (fd); +return -err; + } + +close (fd); + +return ch.rx_count + ch.combined_count; +} +struct send_recv_arg {int fd;uint32_t bytes;
tools/testing/selftests/bpf/network_helpers.h +2 -0
@@ -72,6 +72,8 @@ int get_socket_local_port(int sock_fd);int get_hw_ring_size (char *ifname,struct ethtool_ringparam *ring_param);int set_hw_ring_size (char *ifname,struct ethtool_ringparam *ring_param); +int rxq_num (const char *ifname); +struct nstoken ;/** * open_netns() - Switch to specified network namespace by name.
tools/testing/selftests/bpf/xdp_hw_metadata.c +2 -25
@@ -495,31 +495,6 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_treturn 0 ; } -static int rxq_num (const char *ifname) -{ -struct ethtool_channels ch = { - .cmd =ETHTOOL_GCHANNELS , - }; - -struct ifreq ifr = { - .ifr_data = (void *)&ch, - }; -strncpy (ifr.ifr_name, ifname,IF_NAMESIZE -1 ); -int fd, ret; - - fd =socket (AF_UNIX ,SOCK_DGRAM ,0 ); -if (fd <0 ) -error (1 , errno,"socket" ); - - ret =ioctl (fd,SIOCETHTOOL , &ifr); -if (ret <0 ) -error (1 , errno,"ioctl(SIOCETHTOOL)" ); - -close (fd); - -return ch.rx_count + ch.combined_count; -} -static void hwtstamp_ioctl (int op,const char *ifname,struct hwtstamp_config *cfg) {struct ifreq ifr = {
@@ -668,6 +643,8 @@ int main(int argc, char *argv[])read_args (argc, argv); rxq =rxq_num (ifname); +if (rxq <0 ) +error (1 , -rxq,"rxq_num" );printf ("rxq: %d\n" , rxq);
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
RFC PATCH 2/3 selftests/bpf: Add xsk_hw AF_XDP functionality test
In reply to YiFei ZhuA UDP packet is sent from one peer to the other once, and verify if it is received before a timeout. Busypoll mode is not tested since it's more difficult to write a pass/fail test to verify that busypoll mode is working as intended, and adding this test can be future work.
To test TX/RX independently, the non-XDP side uses AF_PACKET to send/recv in order to minimize possible differences in the packet headers (as opposed to having AF_INET(6), which makes the kernel's stack construct the packet). However, an AF_INET(6) SOCK_DGRAM socket is still created and bound to the port in order to mute ICMP port unreachable messages without having to use iptables.
Considering that the set up of AF_XDP may have variable delays on different machines, to synchronize the execution, a simple TCP connection is established between client and server as a synchronization point.
I'm also adding checksum_nofold helper to network_helpers since I'm sure if it would be a good idea to rely on hardware offload and XDP metadata for a basic functionality test. If needed we can extend this test to test checksum offload too.
--- tools/testing/selftests/bpf/.gitignore | 1 + tools/testing/selftests/bpf/Makefile | 7 +- tools/testing/selftests/bpf/network_helpers.h | 14 + tools/testing/selftests/bpf/progs/xsk_hw.c | 72 ++ tools/testing/selftests/bpf/xsk_hw.c | 844 ++++++++++++++++++ 5 files changed, 937 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/progs/xsk_hw.c create mode 100644 tools/testing/selftests/bpf/xsk_hw.c
tools/testing/selftests/bpf/.gitignore +1 -0
@@ -47,6 +47,7 @@ test_cpp *.ko *.tmp xskxceiver +xsk_hw xdp_redirect_multi xdp_synproxy xdp_hw_metadata
tools/testing/selftests/bpf/Makefile +6 -1
@@ -144,7 +144,7 @@ TEST_GEN_PROGS_EXTENDED = 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 xdp_hw_metadata \ - xdp_features bpf_test_no_cfi.ko + xdp_features bpf_test_no_cfi.ko xsk_hw TEST_GEN_FILES += liburandom_read.so urandom_read sign-file uprobe_multi
@@ -476,6 +476,7 @@ test_usdt.skel.h-deps := test_usdt.bpf.o test_usdt_multispec.bpf.o xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o xdp_features.skel.h-deps := xdp_features.bpf.o +xsk_hw.skel.h-deps := xsk_hw.bpf.o LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps)))
@@ -710,6 +711,10 @@ $(OUTPUT)/xdp_features: xdp_features.c $(OUTPUT)/network_helpers.o $(OUTPUT)/xdp $(call msg,BINARY,,$@) $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ +$(OUTPUT)/xsk_hw: xsk_hw.c $(OUTPUT)/network_helpers.o $(OUTPUT)/xsk.o $(OUTPUT)/xsk_hw.skel.h | $(OUTPUT) + $(call msg,BINARY,,$@) + $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ + # Make sure we are able to include and link libbpf against c++. $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ) $(call msg,CXX,,$@)
tools/testing/selftests/bpf/network_helpers.h +14 -0
@@ -85,6 +85,20 @@ struct nstoken *open_netns(const char *name);void close_netns (struct nstoken *token);int send_recv_data (int lfd,int fd,uint32_t total_bytes); +static inline __wsum checksum_nofold (const void *data,size_t len,__wsum sum) +{ +const uint16_t *words = (const uint16_t *)data; +int i; + +for (i =0 ; i < len /2 ; i++) + sum += words[i]; + +if (len &1 ) + sum += ((const unsigned char *)data)[len -1 ]; + +return sum; +} +static __u16 csum_fold (__u32 csum) { csum = (csum &0xffff ) + (csum >>16 );
tools/testing/selftests/bpf/progs/xsk_hw.c new file +72 -0
72 lines not on this page · raw message
tools/testing/selftests/bpf/xsk_hw.c new file +844 -0
844 lines not on this page · raw message
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
RFC PATCH 3/3 selftests: drv-net: Add xsk_hw AF_XDP functionality test
In reply to YiFei ZhuRun tools/testing/selftest/bpf/xsk_hw.c as part of drv-net.
A matrix of TX/RX, copy/zerocopy, and driver mode / skb mode, are tested. Additionally, it tests some edge cases such as:
- Zerocopy TX with and without attaching an XDP prog.
- Zerocopy RX where binding happens before fillq gets filled.
TX and RX are tested separately, and the remote side always runs the basic AF_PACKET handler rather than AF_XDP, in order to isolate potential causes of test failures.
Currently the next-hop MAC address of each side must be manually specified via LOCAL_NEXTHOP_MAC & REMOTE_NEXTHOP_MAC. It's probably doable to detect these addresses automatically, but it's future work, and probably library code since it is also applicable to csum.py.
--- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/xsk_hw.py | 133 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_hw.py
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
@@ -11,6 +11,7 @@ TEST_PROGS = \ hw_stats_l3_gre.sh \ loopback.sh \ pp_alloc_fail.py \ + xsk_hw.py \ # TEST_FILES := \
tools/testing/selftests/drivers/net/hw/xsk_hw.py new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
Re: [RFC PATCH net-next 3/3] selftests: drv-net: Add xsk_hw AF_XDP functionality test
Quoted 11 lines · YiFei Zhu
Run
tools/testing/selftest/bpf/xsk_hw.cas part of drv-net.A matrix of TX/RX, copy/zerocopy, and driver mode / skb mode, are tested. Additionally, it tests some edge cases such as:
- Zerocopy TX with and without attaching an XDP prog.
- Zerocopy RX where binding happens before fillq gets filled.TX and RX are tested separately, and the remote side always runs the basic
AF_PACKEThandler rather thanAF_XDP, in order to isolate potential causes of test failures.
Quoted 6 lines
Currently the next-hop MAC address of each side must be manually specified via
LOCAL_NEXTHOP_MAC&REMOTE_NEXTHOP_MAC. It's probably doable to detect these addresses automatically, but it's future work, and probably library code since it is also applicable tocsum.py.Signed-off-by YiFei Zhu <[email protected]>
Re: [RFC PATCH net-next 1/3] selftests/bpf: Move rxq_num helper from xdp_hw_metadata to network_helpers
In reply to YiFei ZhuQuoted 22 lines · YiFei Zhu
This helper may be useful for other
AF_XDPtests, such asxsk_hw. Moving it out so we don't need to copy-paste that function.I also changed the function from directly calling
error(1, errno, ...)to returning an error because I don't think it makes sense for a library function to outright kill the process if the function fails.Signed-off-by YiFei Zhu <[email protected]>--- tools/testing/selftests/bpf/network_helpers.c | 27 +++++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 2 ++ tools/testing/selftests/bpf/xdp_hw_metadata.c | 27 ++----------------- 3 files changed, 31 insertions(+), 25 deletions(-)tools/testing/selftests/bpf/network_helpers.c +0
-0@@ -569,6 +569,33 @@ int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)return 0 ; }
tools/testing/selftests/bpf/network_helpers.c int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param) · line 581
Quoted 10 lines
tools/testing/selftests/bpf/network_helpers.c +10
-0+int rxq_num (const char *ifname) +{ +struct ethtool_channels ch = { + .cmd =ETHTOOL_GCHANNELS , + }; +struct ifreq ifr = { + .ifr_data = (void *)&ch, + }; +strncpy (ifr.ifr_name, ifname,IF_NAMESIZE -1 ); +int fd, ret, err;
Since sending this as RFC, when sending for inclusion let's move the strncpy, to not mix declarations and code.
Quoted 10 lines · YiFei Zhu
We have observed that hardware NIC drivers may have faulty
AF_XDPimplementations, and there seem to be a lack of a test of various modes in whichAF_XDPcould run. This series adds a test to verify that NIC drivers implements manyAF_XDPfeatures by performing a send / receive of a single UDP packet.I put the C code of the test under selftests/bpf because I'm not really sure how I'd build the BPF-related code without the selftests/bpf build infrastructure.
Happy to see that you are contributing a number of new tests. Would it be possible for you to integrate this into the xskxceiver framework? You can find that in selftests/bpf too. By default, it will run its tests using veth, but if you provide an interface name after the -i option, it will run the tests over a real interface. I put the NIC in loopback mode to use this feature, but feel free to add a new mode if necessary. A lot of the setup and data plane code that you add already exists in xskxceiver, so I would prefer if you could reuse it. Your tests are new though and they would be valuable to have.
You could make the default packet that is sent in xskxceiver be the UDP packet that you want and then add all the other logic that you have to a number of new tests that you introduce.
Quoted 58 lines
Tested on Google Cloud, with GVE:
$ sudo NETIF=ens4 REMOTE_TYPE=ssh \ REMOTE_ARGS="[email protected]" \ LOCAL_V4="10.138.15.234" \ REMOTE_V4="10.138.15.235" \ LOCAL_NEXTHOP_MAC="42:01:0a:8a:00:01" \ REMOTE_NEXTHOP_MAC="42:01:0a:8a:00:01" \ python3 xsk_hw.pyKTAP version 1
1..22
ok 1 xsk_hw.ipv4_basic
ok 2 xsk_hw.ipv4_tx_skb_copy
ok 3 xsk_hw.ipv4_tx_skb_copy_force_attach
ok 4 xsk_hw.ipv4_rx_skb_copy
ok 5 xsk_hw.ipv4_tx_drv_copy
ok 6 xsk_hw.ipv4_tx_drv_copy_force_attach
ok 7 xsk_hw.ipv4_rx_drv_copy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw:recv_pfpacket: Timeout\n'
not ok 8 xsk_hw.ipv4_tx_drv_zerocopy
ok 9 xsk_hw.ipv4_tx_drv_zerocopy_force_attach
ok 10 xsk_hw.ipv4_rx_drv_zerocopy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw: connect sync client: max_retries\n' [...]
# Exception| STDERR: b'/linux/tools/testing/selftests/bpf/xsk_hw:open_xsk: Device or resource busy\n' not ok 11 xsk_hw.ipv4_rx_drv_zerocopy_fill_after_bind
ok 12 xsk_hw.ipv6_basic # SKIP Test requires IPv6 connectivity
[...]
ok 22 xsk_hw.ipv6_rx_drv_zerocopy_fill_after_bind # SKIP Test requires IPv6 connectivity # Totals: pass:9 fail:2 xfail:0 xpass:0 skip:11 error:0YiFei Zhu (3):
selftests/bpf: Moverxq_numhelper fromxdp_hw_metadatato
network_helpers
selftests/bpf: Addxsk_hwAF_XDPfunctionality test
selftests: drv-net: Addxsk_hwAF_XDPfunctionality testtools/testing/selftests/bpf/.gitignore | 1 + tools/testing/selftests/bpf/Makefile | 7 +- tools/testing/selftests/bpf/network_helpers.c | 27 + tools/testing/selftests/bpf/network_helpers.h | 16 + tools/testing/selftests/bpf/progs/xsk_hw.c | 72 ++ tools/testing/selftests/bpf/xdp_hw_metadata.c | 27 +- tools/testing/selftests/bpf/xsk_hw.c | 844 ++++++++++++++++++ .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/xsk_hw.py | 133 +++ 9 files changed, 1102 insertions(+), 26 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/xsk_hw.c create mode 100644 tools/testing/selftests/bpf/xsk_hw.c create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_hw.py--
2.45.2.505.gda0bf45e8d-goog
Maciej Fijalkowski
maintainerQuoted 12 lines · Magnus Karlsson
Quoted 10 lines · YiFei Zhu
We have observed that hardware NIC drivers may have faulty
AF_XDPimplementations, and there seem to be a lack of a test of various modes in whichAF_XDPcould run. This series adds a test to verify that NIC drivers implements manyAF_XDPfeatures by performing a send / receive of a single UDP packet.I put the C code of the test under selftests/bpf because I'm not really sure how I'd build the BPF-related code without the selftests/bpf build infrastructure.
Quoted 9 lines
Happy to see that you are contributing a number of new tests. Would it be possible for you to integrate this into the xskxceiver framework? You can find that in selftests/bpf too. By default, it will run its tests using veth, but if you provide an interface name after the -i option, it will run the tests over a real interface. I put the NIC in loopback mode to use this feature, but feel free to add a new mode if necessary. A lot of the setup and data plane code that you add already exists in xskxceiver, so I would prefer if you could reuse it. Your tests are new though and they would be valuable to have.
+1
I just don't believe that you guys were not aware that xskxceiver exist. Please provide us a proper explanation/justification why this was not fulfilling your needs and you decided to go with another test suite.
Quoted 64 lines
You could make the default packet that is sent in xskxceiver be the UDP packet that you want and then add all the other logic that you have to a number of new tests that you introduce.
Quoted 58 lines
Tested on Google Cloud, with GVE:
$ sudo NETIF=ens4 REMOTE_TYPE=ssh \ REMOTE_ARGS="[email protected]" \ LOCAL_V4="10.138.15.234" \ REMOTE_V4="10.138.15.235" \ LOCAL_NEXTHOP_MAC="42:01:0a:8a:00:01" \ REMOTE_NEXTHOP_MAC="42:01:0a:8a:00:01" \ python3 xsk_hw.pyKTAP version 1
1..22
ok 1 xsk_hw.ipv4_basic
ok 2 xsk_hw.ipv4_tx_skb_copy
ok 3 xsk_hw.ipv4_tx_skb_copy_force_attach
ok 4 xsk_hw.ipv4_rx_skb_copy
ok 5 xsk_hw.ipv4_tx_drv_copy
ok 6 xsk_hw.ipv4_tx_drv_copy_force_attach
ok 7 xsk_hw.ipv4_rx_drv_copy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw:recv_pfpacket: Timeout\n'
not ok 8 xsk_hw.ipv4_tx_drv_zerocopy
ok 9 xsk_hw.ipv4_tx_drv_zerocopy_force_attach
ok 10 xsk_hw.ipv4_rx_drv_zerocopy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw: connect sync client: max_retries\n' [...]
# Exception| STDERR: b'/linux/tools/testing/selftests/bpf/xsk_hw:open_xsk: Device or resource busy\n' not ok 11 xsk_hw.ipv4_rx_drv_zerocopy_fill_after_bind
ok 12 xsk_hw.ipv6_basic # SKIP Test requires IPv6 connectivity
[...]
ok 22 xsk_hw.ipv6_rx_drv_zerocopy_fill_after_bind # SKIP Test requires IPv6 connectivity # Totals: pass:9 fail:2 xfail:0 xpass:0 skip:11 error:0YiFei Zhu (3):
selftests/bpf: Moverxq_numhelper fromxdp_hw_metadatato
network_helpers
selftests/bpf: Addxsk_hwAF_XDPfunctionality test
selftests: drv-net: Addxsk_hwAF_XDPfunctionality testtools/testing/selftests/bpf/.gitignore | 1 + tools/testing/selftests/bpf/Makefile | 7 +- tools/testing/selftests/bpf/network_helpers.c | 27 + tools/testing/selftests/bpf/network_helpers.h | 16 + tools/testing/selftests/bpf/progs/xsk_hw.c | 72 ++ tools/testing/selftests/bpf/xdp_hw_metadata.c | 27 +- tools/testing/selftests/bpf/xsk_hw.c | 844 ++++++++++++++++++ .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/xsk_hw.py | 133 +++ 9 files changed, 1102 insertions(+), 26 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/xsk_hw.c create mode 100644 tools/testing/selftests/bpf/xsk_hw.c create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_hw.py--
2.45.2.505.gda0bf45e8d-goog
Quoted 8 lines · Magnus Karlsson
Quoted 7 lines · YiFei Zhu
We have observed that hardware NIC drivers may have faulty
AF_XDPimplementations, and there seem to be a lack of a test of various modes in whichAF_XDPcould run. This series adds a test to verify that NIC drivers implements manyAF_XDPfeatures by performing a send / receive of a single UDP packet.
Quoted 6 lines
Quoted 3 lines
I put the C code of the test under selftests/bpf because I'm not really sure how I'd build the BPF-related code without the selftests/bpf build infrastructure.
Happy to see that you are contributing a number of new tests. Would it be possible for you to integrate this into the xskxceiver framework?
Makes sense, we'll need to take a look.
This is an internal test that we have been using for a long time in our test framework.
My mistake for not keeping up at all with the changes to xskxceiver.c in the meantime.
We want to test each case independently. Including a few non obvious cases that we discovered from real use, notably
- Using XSK only for Tx, without installing an Rx program
- Using XSK with an empty fill queue, filling it after bind
Quoted 5 lines
You can find that in selftests/bpf too. By default, it will run its tests using veth, but if you provide an interface name after the -i option, it will run the tests over a real interface. I put the NIC in loopback mode to use this feature, but feel free to add a new mode if necessary.
We do really want two machine tests, not loopback mode. Also to integrate into the drv-net infrastructure.
Another non-obvious feature is to test one side AF_XDP and use PF_PACKET on the other side, to be able to isolate and exercise only the Tx or Rx path in a test.
Quoted 7 lines
A lot of the setup and data plane code that you add already exists in xskxceiver, so I would prefer if you could reuse it. Your tests are new though and they would be valuable to have.
You could make the default packet that is sent in xskxceiver be the UDP packet that you want and then add all the other logic that you have to a number of new tests that you introduce.
Quoted 24 lines · Maciej Fijalkowski
Quoted 12 lines · Magnus Karlsson
Quoted 10 lines · YiFei Zhu
We have observed that hardware NIC drivers may have faulty
AF_XDPimplementations, and there seem to be a lack of a test of various modes in whichAF_XDPcould run. This series adds a test to verify that NIC drivers implements manyAF_XDPfeatures by performing a send / receive of a single UDP packet.I put the C code of the test under selftests/bpf because I'm not really sure how I'd build the BPF-related code without the selftests/bpf build infrastructure.
Quoted 9 lines
Happy to see that you are contributing a number of new tests. Would it be possible for you to integrate this into the xskxceiver framework? You can find that in selftests/bpf too. By default, it will run its tests using veth, but if you provide an interface name after the -i option, it will run the tests over a real interface. I put the NIC in loopback mode to use this feature, but feel free to add a new mode if necessary. A lot of the setup and data plane code that you add already exists in xskxceiver, so I would prefer if you could reuse it. Your tests are new though and they would be valuable to have.
Quoted 5 lines
+1
I just don't believe that you guys were not aware that xskxceiver exist. Please provide us a proper explanation/justification why this was not fulfilling your needs and you decided to go with another test suite.
To answer this question, I can't speak for others, but I personally was not fully aware.
Over a year ago when we were testing AF_XDP latency on internal NIC drivers, we extended our internal latency test tool to support AF_XDP. And that was when we observed the NICs we were testing had faulty implementations - panics, packet corruptions, random drops; and we decided to simplify the latency suite to add a simple pass/fail test to our testing infrastructure, and we named it xsk_hw. The test was specifically designed to test hardware NICs (rather than veth), and there was a bunch of code around the test, to reserve & setup machines, and to obtain information such as the IP addresses and the host and next hop MACs addresses. At the time, the code was deemed too dependent on our internal multi-machine-testing infrastructure to upstream, but it has been running as part of our test suite since.
This brings us to recently. I was informed that upstream now have drv-net, and now that upstream also has multi-machine testing, it's time to upstream it. Hence this patch series, which I made after adapting the code to use drv-net and network_helpers.
As for xskxceiver, for me personally, I discarded the idea after reading the initial block comment of xskxceiver saying it spawns two threads in a veth pair to test AF_XDP, which in my mind was like "okay this doesn't test hardware NICs, and to extend that test to hardware is probably a major rewrite that is probably not worth", so I did not look too deeply into its code. I personally was unaware that it can test a real interface, and that's partially my fault.
I'll take a look at xskxceiver and see how feasible it is to integrate this into xskxceiver.
Quoted 64 lines
Quoted 64 lines
You could make the default packet that is sent in xskxceiver be the UDP packet that you want and then add all the other logic that you have to a number of new tests that you introduce.
Quoted 58 lines
Tested on Google Cloud, with GVE:
$ sudo NETIF=ens4 REMOTE_TYPE=ssh \ REMOTE_ARGS="[email protected]" \ LOCAL_V4="10.138.15.234" \ REMOTE_V4="10.138.15.235" \ LOCAL_NEXTHOP_MAC="42:01:0a:8a:00:01" \ REMOTE_NEXTHOP_MAC="42:01:0a:8a:00:01" \ python3 xsk_hw.pyKTAP version 1
1..22
ok 1 xsk_hw.ipv4_basic
ok 2 xsk_hw.ipv4_tx_skb_copy
ok 3 xsk_hw.ipv4_tx_skb_copy_force_attach
ok 4 xsk_hw.ipv4_rx_skb_copy
ok 5 xsk_hw.ipv4_tx_drv_copy
ok 6 xsk_hw.ipv4_tx_drv_copy_force_attach
ok 7 xsk_hw.ipv4_rx_drv_copy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw:recv_pfpacket: Timeout\n'
not ok 8 xsk_hw.ipv4_tx_drv_zerocopy
ok 9 xsk_hw.ipv4_tx_drv_zerocopy_force_attach
ok 10 xsk_hw.ipv4_rx_drv_zerocopy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw: connect sync client: max_retries\n' [...]
# Exception| STDERR: b'/linux/tools/testing/selftests/bpf/xsk_hw:open_xsk: Device or resource busy\n' not ok 11 xsk_hw.ipv4_rx_drv_zerocopy_fill_after_bind
ok 12 xsk_hw.ipv6_basic # SKIP Test requires IPv6 connectivity
[...]
ok 22 xsk_hw.ipv6_rx_drv_zerocopy_fill_after_bind # SKIP Test requires IPv6 connectivity # Totals: pass:9 fail:2 xfail:0 xpass:0 skip:11 error:0YiFei Zhu (3):
selftests/bpf: Moverxq_numhelper fromxdp_hw_metadatato
network_helpers
selftests/bpf: Addxsk_hwAF_XDPfunctionality test
selftests: drv-net: Addxsk_hwAF_XDPfunctionality testtools/testing/selftests/bpf/.gitignore | 1 + tools/testing/selftests/bpf/Makefile | 7 +- tools/testing/selftests/bpf/network_helpers.c | 27 + tools/testing/selftests/bpf/network_helpers.h | 16 + tools/testing/selftests/bpf/progs/xsk_hw.c | 72 ++ tools/testing/selftests/bpf/xdp_hw_metadata.c | 27 +- tools/testing/selftests/bpf/xsk_hw.c | 844 ++++++++++++++++++ .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/xsk_hw.py | 133 +++ 9 files changed, 1102 insertions(+), 26 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/xsk_hw.c create mode 100644 tools/testing/selftests/bpf/xsk_hw.c create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_hw.py--
2.45.2.505.gda0bf45e8d-goog
Quoted 49 lines · YiFei Zhu
Quoted 24 lines · Maciej Fijalkowski
Quoted 12 lines · Magnus Karlsson
Quoted 10 lines · YiFei Zhu
We have observed that hardware NIC drivers may have faulty
AF_XDPimplementations, and there seem to be a lack of a test of various modes in whichAF_XDPcould run. This series adds a test to verify that NIC drivers implements manyAF_XDPfeatures by performing a send / receive of a single UDP packet.I put the C code of the test under selftests/bpf because I'm not really sure how I'd build the BPF-related code without the selftests/bpf build infrastructure.
Quoted 9 lines
Happy to see that you are contributing a number of new tests. Would it be possible for you to integrate this into the xskxceiver framework? You can find that in selftests/bpf too. By default, it will run its tests using veth, but if you provide an interface name after the -i option, it will run the tests over a real interface. I put the NIC in loopback mode to use this feature, but feel free to add a new mode if necessary. A lot of the setup and data plane code that you add already exists in xskxceiver, so I would prefer if you could reuse it. Your tests are new though and they would be valuable to have.
Quoted 5 lines
+1
I just don't believe that you guys were not aware that xskxceiver exist. Please provide us a proper explanation/justification why this was not fulfilling your needs and you decided to go with another test suite.
To answer this question, I can't speak for others, but I personally was not fully aware.
Over a year ago when we were testing
AF_XDPlatency on internal NIC drivers, we extended our internal latency test tool to supportAF_XDP. And that was when we observed the NICs we were testing had faulty implementations - panics, packet corruptions, random drops; and we decided to simplify the latency suite to add a simple pass/fail test to our testing infrastructure, and we named itxsk_hw. The test was specifically designed to test hardware NICs (rather than veth), and there was a bunch of code around the test, to reserve & setup machines, and to obtain information such as the IP addresses and the host and next hop MACs addresses. At the time, the code was deemed too dependent on our internal multi-machine-testing infrastructure to upstream, but it has been running as part of our test suite since.
Quoted 4 lines
This brings us to recently. I was informed that upstream now have drv-net, and now that upstream also has multi-machine testing, it's time to upstream it. Hence this patch series, which I made after adapting the code to use drv-net and
network_helpers.
I was not aware of drv-net. I think it would be a really good idea to just hook up xskxceiver to this even without adding any new tests. If this is something that is run automatically for drivers, perfect, we should make use of it. Any idea what it would take to make xskxceiver use drv-net?
Quoted 7 lines
As for xskxceiver, for me personally, I discarded the idea after reading the initial block comment of xskxceiver saying it spawns two threads in a veth pair to test
AF_XDP, which in my mind was like "okay this doesn't test hardware NICs, and to extend that test to hardware is probably a major rewrite that is probably not worth", so I did not look too deeply into its code. I personally was unaware that it can test a real interface, and that's partially my fault.
Or mine for not updating the initial block comment. In any case, no worries!
Quoted 2 lines
I'll take a look at xskxceiver and see how feasible it is to integrate this into xskxceiver.
Thanks! Please keep the drv-net integration in mind. Hopefully it is not that much work to tweak xskxceiver to fit into that.
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
You could make the default packet that is sent in xskxceiver be the UDP packet that you want and then add all the other logic that you have to a number of new tests that you introduce.
Quoted 58 lines
Tested on Google Cloud, with GVE:
$ sudo NETIF=ens4 REMOTE_TYPE=ssh \ REMOTE_ARGS="[email protected]" \ LOCAL_V4="10.138.15.234" \ REMOTE_V4="10.138.15.235" \ LOCAL_NEXTHOP_MAC="42:01:0a:8a:00:01" \ REMOTE_NEXTHOP_MAC="42:01:0a:8a:00:01" \ python3 xsk_hw.pyKTAP version 1
1..22
ok 1 xsk_hw.ipv4_basic
ok 2 xsk_hw.ipv4_tx_skb_copy
ok 3 xsk_hw.ipv4_tx_skb_copy_force_attach
ok 4 xsk_hw.ipv4_rx_skb_copy
ok 5 xsk_hw.ipv4_tx_drv_copy
ok 6 xsk_hw.ipv4_tx_drv_copy_force_attach
ok 7 xsk_hw.ipv4_rx_drv_copy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw:recv_pfpacket: Timeout\n'
not ok 8 xsk_hw.ipv4_tx_drv_zerocopy
ok 9 xsk_hw.ipv4_tx_drv_zerocopy_force_attach
ok 10 xsk_hw.ipv4_rx_drv_zerocopy
[...]
# Exception| STDERR: b'/tmp/zzfhcqkg/pbgodkgjxsk_hw: connect sync client: max_retries\n' [...]
# Exception| STDERR: b'/linux/tools/testing/selftests/bpf/xsk_hw:open_xsk: Device or resource busy\n' not ok 11 xsk_hw.ipv4_rx_drv_zerocopy_fill_after_bind
ok 12 xsk_hw.ipv6_basic # SKIP Test requires IPv6 connectivity
[...]
ok 22 xsk_hw.ipv6_rx_drv_zerocopy_fill_after_bind # SKIP Test requires IPv6 connectivity # Totals: pass:9 fail:2 xfail:0 xpass:0 skip:11 error:0YiFei Zhu (3):
selftests/bpf: Moverxq_numhelper fromxdp_hw_metadatato
network_helpers
selftests/bpf: Addxsk_hwAF_XDPfunctionality test
selftests: drv-net: Addxsk_hwAF_XDPfunctionality testtools/testing/selftests/bpf/.gitignore | 1 + tools/testing/selftests/bpf/Makefile | 7 +- tools/testing/selftests/bpf/network_helpers.c | 27 + tools/testing/selftests/bpf/network_helpers.h | 16 + tools/testing/selftests/bpf/progs/xsk_hw.c | 72 ++ tools/testing/selftests/bpf/xdp_hw_metadata.c | 27 +- tools/testing/selftests/bpf/xsk_hw.c | 844 ++++++++++++++++++ .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/xsk_hw.py | 133 +++ 9 files changed, 1102 insertions(+), 26 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/xsk_hw.c create mode 100644 tools/testing/selftests/bpf/xsk_hw.c create mode 100755 tools/testing/selftests/drivers/net/hw/xsk_hw.py--
2.45.2.505.gda0bf45e8d-goog