bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/5] selftests/bpf: xsk selftests
@ 2020-11-25 18:37 Weqaar Janjua
  2020-11-25 18:37 ` [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework Weqaar Janjua
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-25 18:37 UTC (permalink / raw)
  To: bpf, netdev, daniel, ast, magnus.karlsson, bjorn.topel, yhs
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon

This patch set adds AF_XDP selftests based on veth to selftests/bpf.

# Topology:
# ---------
#                 -----------
#               _ | Process | _
#              /  -----------  \
#             /        |        \
#            /         |         \
#      -----------     |     -----------
#      | Thread1 |     |     | Thread2 |
#      -----------     |     -----------
#           |          |          |
#      -----------     |     -----------
#      |  xskX   |     |     |  xskY   |
#      -----------     |     -----------
#           |          |          |
#      -----------     |     ----------
#      |  vethX  | --------- |  vethY |
#      -----------   peer    ----------
#           |          |          |
#      namespaceX      |     namespaceY

These selftests test AF_XDP SKB and Native/DRV modes using veth Virtual
Ethernet interfaces.

The test program contains two threads, each thread is single socket with
a unique UMEM. It validates in-order packet delivery and packet content
by sending packets to each other.

Prerequisites setup by script test_xsk.sh:

   Set up veth interfaces as per the topology shown ^^:
   * setup two veth interfaces and one namespace
   ** veth<xxxx> in root namespace
   ** veth<yyyy> in af_xdp<xxxx> namespace
   ** namespace af_xdp<xxxx>
   * create a spec file veth.spec that includes this run-time configuration
   *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
       conflict with any existing interface

The following tests are provided:

1. AF_XDP SKB mode
   Generic mode XDP is driver independent, used when the driver does
   not have support for XDP. Works on any netdevice using sockets and
   generic XDP path. XDP hook from netif_receive_skb().
   a. nopoll - soft-irq processing
   b. poll - using poll() syscall
   c. Socket Teardown
      Create a Tx and a Rx socket, Tx from one socket, Rx on another.
      Destroy both sockets, then repeat multiple times. Only nopoll mode
	  is used
   d. Bi-directional Sockets
      Configure sockets as bi-directional tx/rx sockets, sets up fill
	  and completion rings on each socket, tx/rx in both directions.
	  Only nopoll mode is used

2. AF_XDP DRV/Native mode
   Works on any netdevice with XDP_REDIRECT support, driver dependent.
   Processes packets before SKB allocation. Provides better performance
   than SKB. Driver hook available just after DMA of buffer descriptor.
   a. nopoll
   b. poll
   c. Socket Teardown
   d. Bi-directional Sockets
   * Only copy mode is supported because veth does not currently support
     zero-copy mode

Total tests: 8

Flow:
* Single process spawns two threads: Tx and Rx
* Each of these two threads attach to a veth interface within their
  assigned namespaces
* Each thread creates one AF_XDP socket connected to a unique umem
  for each veth interface
* Tx thread transmits 10k packets from veth<xxxx> to veth<yyyy>
* Rx thread verifies if all 10k packets were received and delivered
  in-order, and have the right content

v2 changes:
* Move selftests/xsk to selftests/bpf
* Remove Makefiles under selftests/xsk, and utilize selftests/bpf/Makefile

v3 changes:
* merge all test scripts test_xsk_*.sh into test_xsk.sh

This patch set requires applying patch from bpf stable tree:
commit 36ccdf85829a by Björn Töpel <bjorn.topel@intel.com>
[PATCH bpf v2] net, xsk: Avoid taking multiple skbuff references

Structure of the patch set:

Patch 1: This patch adds XSK Selftests framework under selftests/bpf
Patch 2: Adds tests: SKB poll and nopoll mode, and mac-ip-udp debug
Patch 3: Adds tests: DRV poll and nopoll mode
Patch 4: Adds tests: SKB and DRV Socket Teardown
Patch 5: Adds tests: SKB and DRV Bi-directional Sockets

Thanks: Weqaar

Weqaar Janjua (5):
  selftests/bpf: xsk selftests framework
  selftests/bpf: xsk selftests - SKB POLL, NOPOLL
  selftests/bpf: xsk selftests - DRV POLL, NOPOLL
  selftests/bpf: xsk selftests - Socket Teardown - SKB, DRV
  selftests/bpf: xsk selftests - Bi-directional Sockets - SKB, DRV

 tools/testing/selftests/bpf/Makefile       |    7 +-
 tools/testing/selftests/bpf/test_xsk.sh    |  238 +++++
 tools/testing/selftests/bpf/xdpxceiver.c   | 1056 ++++++++++++++++++++
 tools/testing/selftests/bpf/xdpxceiver.h   |  158 +++
 tools/testing/selftests/bpf/xsk_env.sh     |   28 +
 tools/testing/selftests/bpf/xsk_prereqs.sh |  119 +++
 6 files changed, 1604 insertions(+), 2 deletions(-)
 create mode 100755 tools/testing/selftests/bpf/test_xsk.sh
 create mode 100644 tools/testing/selftests/bpf/xdpxceiver.c
 create mode 100644 tools/testing/selftests/bpf/xdpxceiver.h
 create mode 100755 tools/testing/selftests/bpf/xsk_env.sh
 create mode 100755 tools/testing/selftests/bpf/xsk_prereqs.sh

-- 
2.20.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework
  2020-11-25 18:37 [PATCH bpf-next v3 0/5] selftests/bpf: xsk selftests Weqaar Janjua
@ 2020-11-25 18:37 ` Weqaar Janjua
  2020-11-26  6:44   ` Yonghong Song
  2020-11-25 18:37 ` [PATCH bpf-next v3 2/5] selftests/bpf: xsk selftests - SKB POLL, NOPOLL Weqaar Janjua
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-25 18:37 UTC (permalink / raw)
  To: bpf, netdev, daniel, ast, yhs, magnus.karlsson, bjorn.topel
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon

This patch adds AF_XDP selftests framework under selftests/bpf.

Topology:
---------
     -----------           -----------
     |  xskX   | --------- |  xskY   |
     -----------     |     -----------
          |          |          |
     -----------     |     ----------
     |  vethX  | --------- |  vethY |
     -----------   peer    ----------
          |          |          |
     namespaceX      |     namespaceY

Prerequisites setup by script test_xsk.sh:

   Set up veth interfaces as per the topology shown ^^:
   * setup two veth interfaces and one namespace
   ** veth<xxxx> in root namespace
   ** veth<yyyy> in af_xdp<xxxx> namespace
   ** namespace af_xdp<xxxx>
   * create a spec file veth.spec that includes this run-time configuration
   *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
       conflict with any existing interface
   * tests the veth and xsk layers of the topology

Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com>
---
 tools/testing/selftests/bpf/Makefile       |   5 +-
 tools/testing/selftests/bpf/test_xsk.sh    | 146 +++++++++++++++++++++
 tools/testing/selftests/bpf/xsk_env.sh     |  11 ++
 tools/testing/selftests/bpf/xsk_prereqs.sh | 119 +++++++++++++++++
 4 files changed, 280 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/bpf/test_xsk.sh
 create mode 100755 tools/testing/selftests/bpf/xsk_env.sh
 create mode 100755 tools/testing/selftests/bpf/xsk_prereqs.sh

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 3d5940cd110d..596ee5c27906 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -46,7 +46,9 @@ endif
 
 TEST_GEN_FILES =
 TEST_FILES = test_lwt_ip_encap.o \
-	test_tc_edt.o
+	test_tc_edt.o \
+	xsk_prereqs.sh \
+	xsk_env.sh
 
 # Order correspond to 'make run_tests' order
 TEST_PROGS := test_kmod.sh \
@@ -70,6 +72,7 @@ TEST_PROGS := test_kmod.sh \
 	test_bpftool_build.sh \
 	test_bpftool.sh \
 	test_bpftool_metadata.sh \
+	test_xsk.sh
 
 TEST_PROGS_EXTENDED := with_addr.sh \
 	with_tunnels.sh \
diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
new file mode 100755
index 000000000000..1836f2d2f617
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -0,0 +1,146 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
+
+# AF_XDP selftests based on veth
+#
+# End-to-end AF_XDP over Veth test
+#
+# Topology:
+# ---------
+#      -----------           -----------
+#      |  xskX   | --------- |  xskY   |
+#      -----------     |     -----------
+#           |          |          |
+#      -----------     |     ----------
+#      |  vethX  | --------- |  vethY |
+#      -----------   peer    ----------
+#           |          |          |
+#      namespaceX      |     namespaceY
+#
+# AF_XDP is an address family optimized for high performance packet processing,
+# it is XDP’s user-space interface.
+#
+# An AF_XDP socket is linked to a single UMEM which is a region of virtual
+# contiguous memory, divided into equal-sized frames.
+#
+# Refer to AF_XDP Kernel Documentation for detailed information:
+# https://www.kernel.org/doc/html/latest/networking/af_xdp.html
+#
+# Prerequisites setup by script:
+#
+#   Set up veth interfaces as per the topology shown ^^:
+#   * setup two veth interfaces and one namespace
+#   ** veth<xxxx> in root namespace
+#   ** veth<yyyy> in af_xdp<xxxx> namespace
+#   ** namespace af_xdp<xxxx>
+#   * create a spec file veth.spec that includes this run-time configuration
+#   *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
+#       conflict with any existing interface
+#   * tests the veth and xsk layers of the topology
+#
+# Kernel configuration:
+# ---------------------
+# See "config" file for recommended kernel config options.
+#
+# Turn on XDP sockets and veth support when compiling i.e.
+# 	Networking support -->
+# 		Networking options -->
+# 			[ * ] XDP sockets
+#
+# Executing Tests:
+# ----------------
+# Must run with CAP_NET_ADMIN capability.
+#
+# Run (summary only):
+#  sudo make summary=1 run_tests
+#
+# Run (full color-coded output):
+#   sudo make colorconsole=1 run_tests
+#
+# Run (full output without color-coding):
+#   sudo make run_tests
+#
+# Clean:
+#  sudo make clean
+
+. xsk_prereqs.sh
+
+TEST_NAME="PREREQUISITES"
+
+URANDOM=/dev/urandom
+[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; }
+
+VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
+VETH0=ve${VETH0_POSTFIX}
+VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
+VETH1=ve${VETH1_POSTFIX}
+NS1=af_xdp${VETH1_POSTFIX}
+IPADDR_VETH0=192.168.222.1/30
+IPADDR_VETH1=192.168.222.2/30
+MTU=1500
+
+setup_vethPairs() {
+	echo "setting up ${VETH0}: root: ${IPADDR_VETH0}"
+	ip netns add ${NS1}
+	ip link add ${VETH0} type veth peer name ${VETH1}
+	ip addr add dev ${VETH0} ${IPADDR_VETH0}
+	echo "setting up ${VETH1}: ${NS1}: ${IPADDR_VETH1}"
+	ip link set ${VETH1} netns ${NS1}
+	ip netns exec ${NS1} ip addr add dev ${VETH1} ${IPADDR_VETH1}
+	ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
+	ip netns exec ${NS1} ip link set ${VETH1} up
+	ip link set ${VETH0} mtu ${MTU}
+	ip link set ${VETH0} up
+}
+
+validate_root_exec
+validate_veth_support ${VETH0}
+validate_configs
+setup_vethPairs
+
+retval=$?
+if [ $retval -ne 0 ]; then
+	test_status $retval "${TEST_NAME}"
+	cleanup_exit ${VETH0} ${VETH1} ${NS1}
+	exit $retval
+fi
+
+echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE}
+
+echo "Spec file created: ${SPECFILE}"
+
+test_status $retval "${TEST_NAME}"
+
+## START TESTS
+
+statusList=()
+
+### TEST 1
+TEST_NAME="XSK FRAMEWORK"
+
+echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Generic mode"
+vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
+
+retval=$?
+if [ $retval -eq 0 ]; then
+	echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Native mode"
+	vethXDPnative ${VETH0} ${VETH1} ${NS1}
+fi
+
+retval=$?
+test_status $retval "${TEST_NAME}"
+statusList+=($retval)
+
+## END TESTS
+
+cleanup_exit ${VETH0} ${VETH1} ${NS1}
+
+for _status in "${statusList[@]}"
+do
+	if [ $_status -ne 0 ]; then
+		test_exit $ksft_fail 0
+	fi
+done
+
+test_exit $ksft_pass 0
diff --git a/tools/testing/selftests/bpf/xsk_env.sh b/tools/testing/selftests/bpf/xsk_env.sh
new file mode 100755
index 000000000000..2c41b4284cae
--- /dev/null
+++ b/tools/testing/selftests/bpf/xsk_env.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2020 Intel Corporation.
+
+. xsk_prereqs.sh
+
+validate_veth_spec_file
+
+VETH0=$(cat ${SPECFILE} | cut -d':' -f 1)
+VETH1=$(cat ${SPECFILE} | cut -d':' -f 2 | cut -d',' -f 1)
+NS1=$(cat ${SPECFILE} | cut -d':' -f 2 | cut -d',' -f 2)
diff --git a/tools/testing/selftests/bpf/xsk_prereqs.sh b/tools/testing/selftests/bpf/xsk_prereqs.sh
new file mode 100755
index 000000000000..694c5f5ab5e3
--- /dev/null
+++ b/tools/testing/selftests/bpf/xsk_prereqs.sh
@@ -0,0 +1,119 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright(c) 2020 Intel Corporation.
+
+ksft_pass=0
+ksft_fail=1
+ksft_xfail=2
+ksft_xpass=3
+ksft_skip=4
+
+GREEN='\033[0;92m'
+YELLOW='\033[0;93m'
+RED='\033[0;31m'
+NC='\033[0m'
+STACK_LIM=131072
+SPECFILE=veth.spec
+
+validate_root_exec()
+{
+	msg="skip all tests:"
+	if [ $UID != 0 ]; then
+		echo $msg must be run as root >&2
+		test_exit $ksft_fail 2
+	else
+		return $ksft_pass
+	fi
+}
+
+validate_veth_support()
+{
+	msg="skip all tests:"
+	if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then
+		echo $msg veth kernel support not available >&2
+		test_exit $ksft_skip 1
+	else
+		ip link del $1
+		return $ksft_pass
+	fi
+}
+
+validate_veth_spec_file()
+{
+	if [ ! -f ${SPECFILE} ]; then
+		test_exit $ksft_skip 1
+	fi
+}
+
+test_status()
+{
+	statusval=$1
+	if [ -n "${colorconsole+set}" ]; then
+		if [ $statusval -eq 2 ]; then
+			echo -e "${YELLOW}$2${NC}: [ ${RED}FAIL${NC} ]"
+		elif [ $statusval -eq 1 ]; then
+			echo -e "${YELLOW}$2${NC}: [ ${RED}SKIPPED${NC} ]"
+		elif [ $statusval -eq 0 ]; then
+			echo -e "${YELLOW}$2${NC}: [ ${GREEN}PASS${NC} ]"
+		fi
+	else
+		if [ $statusval -eq 2 ]; then
+			echo -e "$2: [ FAIL ]"
+		elif [ $statusval -eq 1 ]; then
+			echo -e "$2: [ SKIPPED ]"
+		elif [ $statusval -eq 0 ]; then
+			echo -e "$2: [ PASS ]"
+		fi
+	fi
+}
+
+test_exit()
+{
+	retval=$1
+	if [ $2 -ne 0 ]; then
+		test_status $2 $(basename $0)
+	fi
+	exit $retval
+}
+
+clear_configs()
+{
+	if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then
+		[ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] &&
+			{ echo "removing link $2"; ip netns exec $3 ip link del $2; }
+		echo "removing ns $3"
+		ip netns del $3
+	fi
+	#Once we delete a veth pair node, the entire veth pair is removed,
+	#this is just to be cautious just incase the NS does not exist then
+	#veth node inside NS won't get removed so we explicitly remove it
+	[ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
+		{ echo "removing link $1"; ip link del $1; }
+	if [ -f ${SPECFILE} ]; then
+		echo "removing spec file:" ${SPECFILE}
+		rm -f ${SPECFILE}
+	fi
+}
+
+cleanup_exit()
+{
+	echo "cleaning up..."
+	clear_configs $1 $2 $3
+}
+
+validate_configs()
+{
+	[ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip 1; }
+}
+
+vethXDPgeneric()
+{
+	ip link set dev $1 xdpdrv off
+	ip netns exec $3 ip link set dev $2 xdpdrv off
+}
+
+vethXDPnative()
+{
+	ip link set dev $1 xdpgeneric off
+	ip netns exec $3 ip link set dev $2 xdpgeneric off
+}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH bpf-next v3 2/5] selftests/bpf: xsk selftests - SKB POLL, NOPOLL
  2020-11-25 18:37 [PATCH bpf-next v3 0/5] selftests/bpf: xsk selftests Weqaar Janjua
  2020-11-25 18:37 ` [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework Weqaar Janjua
@ 2020-11-25 18:37 ` Weqaar Janjua
  2020-11-27  4:31   ` Yonghong Song
  2020-11-25 18:37 ` [PATCH bpf-next v3 3/5] selftests/bpf: xsk selftests - DRV " Weqaar Janjua
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-25 18:37 UTC (permalink / raw)
  To: bpf, netdev, daniel, ast, yhs, magnus.karlsson, bjorn.topel
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon

Adds following tests:

1. AF_XDP SKB mode
   Generic mode XDP is driver independent, used when the driver does
   not have support for XDP. Works on any netdevice using sockets and
   generic XDP path. XDP hook from netif_receive_skb().
   a. nopoll - soft-irq processing
   b. poll - using poll() syscall

Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com>
---
 tools/testing/selftests/bpf/Makefile     |   2 +-
 tools/testing/selftests/bpf/test_xsk.sh  |  36 +-
 tools/testing/selftests/bpf/xdpxceiver.c | 961 +++++++++++++++++++++++
 tools/testing/selftests/bpf/xdpxceiver.h | 151 ++++
 tools/testing/selftests/bpf/xsk_env.sh   |  17 +
 5 files changed, 1158 insertions(+), 9 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/xdpxceiver.c
 create mode 100644 tools/testing/selftests/bpf/xdpxceiver.h

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 596ee5c27906..a2be2725be11 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -83,7 +83,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
 # Compile but not part of 'make run_tests'
 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
+	test_lirc_mode2_user xdping test_cpp runqslower bench xdpxceiver
 
 TEST_CUSTOM_PROGS = urandom_read
 
diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
index 1836f2d2f617..9c3812bd353f 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -8,8 +8,17 @@
 #
 # Topology:
 # ---------
-#      -----------           -----------
-#      |  xskX   | --------- |  xskY   |
+#                 -----------
+#               _ | Process | _
+#              /  -----------  \
+#             /        |        \
+#            /         |         \
+#      -----------     |     -----------
+#      | Thread1 |     |     | Thread2 |
+#      -----------     |     -----------
+#           |          |          |
+#      -----------     |     -----------
+#      |  xskX   |     |     |  xskY   |
 #      -----------     |     -----------
 #           |          |          |
 #      -----------     |     ----------
@@ -39,6 +48,8 @@
 #       conflict with any existing interface
 #   * tests the veth and xsk layers of the topology
 #
+# See the source xdpxceiver.c for information on each test
+#
 # Kernel configuration:
 # ---------------------
 # See "config" file for recommended kernel config options.
@@ -114,19 +125,28 @@ test_status $retval "${TEST_NAME}"
 
 ## START TESTS
 
+. xsk_env.sh
 statusList=()
 
 ### TEST 1
-TEST_NAME="XSK FRAMEWORK"
+TEST_NAME="SKB NOPOLL"
 
-echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Generic mode"
 vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
 
+params=("-S")
+execxdpxceiver params
+
 retval=$?
-if [ $retval -eq 0 ]; then
-	echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Native mode"
-	vethXDPnative ${VETH0} ${VETH1} ${NS1}
-fi
+test_status $retval "${TEST_NAME}"
+statusList+=($retval)
+
+### TEST 2
+TEST_NAME="SKB POLL"
+
+vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
+
+params=("-S" "-p")
+execxdpxceiver params
 
 retval=$?
 test_status $retval "${TEST_NAME}"
diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
new file mode 100644
index 000000000000..e6c448668cd9
--- /dev/null
+++ b/tools/testing/selftests/bpf/xdpxceiver.c
@@ -0,0 +1,961 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2020 Intel Corporation. */
+
+/*
+ * Some functions in this program are taken from
+ * Linux kernel samples/bpf/xdpsock* and modified
+ * for use.
+ *
+ * See test_xsk.sh for detailed information on test topology
+ * and prerequisite network setup.
+ *
+ * This test program contains two threads, each thread is single socket with
+ * a unique UMEM. It validates in-order packet delivery and packet content
+ * by sending packets to each other.
+ *
+ * Tests Information:
+ * ------------------
+ * These selftests test AF_XDP SKB and Native/DRV modes using veth
+ * Virtual Ethernet interfaces.
+ *
+ * The following tests are run:
+ *
+ * 1. AF_XDP SKB mode
+ *    Generic mode XDP is driver independent, used when the driver does
+ *    not have support for XDP. Works on any netdevice using sockets and
+ *    generic XDP path. XDP hook from netif_receive_skb().
+ *    a. nopoll - soft-irq processing
+ *    b. poll - using poll() syscall
+ *
+ * Total tests: 2
+ *
+ * Flow:
+ * -----
+ * - Single process spawns two threads: Tx and Rx
+ * - Each of these two threads attach to a veth interface within their assigned
+ *   namespaces
+ * - Each thread Creates one AF_XDP socket connected to a unique umem for each
+ *   veth interface
+ * - Tx thread Transmits 10k packets from veth<xxxx> to veth<yyyy>
+ * - Rx thread verifies if all 10k packets were received and delivered in-order,
+ *   and have the right content
+ *
+ * Enable/disable debug mode:
+ * --------------------------
+ * To enable L2 - L4 headers and payload dump of each packet on STDOUT, add
+ * parameter -D to params array in test_xsk.sh, i.e. params=("-S" "-D")
+ */
+
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <errno.h>
+#include <getopt.h>
+#include <asm/barrier.h>
+typedef __u16 __sum16;
+#include <linux/if_link.h>
+#include <linux/if_ether.h>
+#include <linux/ip.h>
+#include <linux/udp.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <locale.h>
+#include <poll.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <time.h>
+#include <unistd.h>
+#include <stdatomic.h>
+#include <bpf/xsk.h>
+#include "xdpxceiver.h"
+#include "../kselftest.h"
+
+static void __exit_with_error(int error, const char *file, const char *func, int line)
+{
+	ksft_test_result_fail
+	    ("[%s:%s:%i]: ERROR: %d/\"%s\"\n", file, func, line, error, strerror(error));
+	ksft_exit_xfail();
+}
+
+#define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)
+
+#define print_ksft_result(void)\
+	(ksft_test_result_pass("PASS: %s %s\n", uut ? "" : "SKB", opt_poll ? "POLL" : "NOPOLL"))
+
+static void pthread_init_mutex(void)
+{
+	pthread_mutex_init(&sync_mutex, NULL);
+	pthread_mutex_init(&sync_mutex_tx, NULL);
+	pthread_cond_init(&signal_rx_condition, NULL);
+	pthread_cond_init(&signal_tx_condition, NULL);
+}
+
+static void pthread_destroy_mutex(void)
+{
+	pthread_mutex_destroy(&sync_mutex);
+	pthread_mutex_destroy(&sync_mutex_tx);
+	pthread_cond_destroy(&signal_rx_condition);
+	pthread_cond_destroy(&signal_tx_condition);
+}
+
+static void *memset32_htonl(void *dest, u32 val, u32 size)
+{
+	u32 *ptr = (u32 *)dest;
+	int i;
+
+	val = htonl(val);
+
+	for (i = 0; i < (size & (~0x3)); i += 4)
+		ptr[i >> 2] = val;
+
+	for (; i < size; i++)
+		((char *)dest)[i] = ((char *)&val)[i & 3];
+
+	return dest;
+}
+
+/*
+ * This function code has been taken from
+ * Linux kernel lib/checksum.c
+ */
+static inline unsigned short from32to16(unsigned int x)
+{
+	/* add up 16-bit and 16-bit for 16+c bit */
+	x = (x & 0xffff) + (x >> 16);
+	/* add up carry.. */
+	x = (x & 0xffff) + (x >> 16);
+	return x;
+}
+
+/*
+ * Fold a partial checksum
+ * This function code has been taken from
+ * Linux kernel include/asm-generic/checksum.h
+ */
+static inline __u16 csum_fold(__u32 csum)
+{
+	u32 sum = (__force u32)csum;
+
+	sum = (sum & 0xffff) + (sum >> 16);
+	sum = (sum & 0xffff) + (sum >> 16);
+	return (__force __u16)~sum;
+}
+
+/*
+ * This function code has been taken from
+ * Linux kernel lib/checksum.c
+ */
+static inline u32 from64to32(u64 x)
+{
+	/* add up 32-bit and 32-bit for 32+c bit */
+	x = (x & 0xffffffff) + (x >> 32);
+	/* add up carry.. */
+	x = (x & 0xffffffff) + (x >> 32);
+	return (u32)x;
+}
+
+__u32 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, __u8 proto, __u32 sum);
+
+/*
+ * This function code has been taken from
+ * Linux kernel lib/checksum.c
+ */
+__u32 csum_tcpudp_nofold(__be32 saddr, __be32 daddr, __u32 len, __u8 proto, __u32 sum)
+{
+	unsigned long long s = (__force u32)sum;
+
+	s += (__force u32)saddr;
+	s += (__force u32)daddr;
+#ifdef __BIG_ENDIAN__
+	s += proto + len;
+#else
+	s += (proto + len) << 8;
+#endif
+	return (__force __u32)from64to32(s);
+}
+
+/*
+ * This function has been taken from
+ * Linux kernel include/asm-generic/checksum.h
+ */
+static inline __u16
+csum_tcpudp_magic(__be32 saddr, __be32 daddr, __u32 len, __u8 proto, __u32 sum)
+{
+	return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
+}
+
+static inline u16 udp_csum(u32 saddr, u32 daddr, u32 len, u8 proto, u16 *udp_pkt)
+{
+	u32 csum = 0;
+	u32 cnt = 0;
+
+	/* udp hdr and data */
+	for (; cnt < len; cnt += 2)
+		csum += udp_pkt[cnt >> 1];
+
+	return csum_tcpudp_magic(saddr, daddr, len, proto, csum);
+}
+
+static void gen_eth_hdr(void *data, struct ethhdr *eth_hdr)
+{
+	memcpy(eth_hdr->h_dest, ((struct ifobject *)data)->dst_mac, ETH_ALEN);
+	memcpy(eth_hdr->h_source, ((struct ifobject *)data)->src_mac, ETH_ALEN);
+	eth_hdr->h_proto = htons(ETH_P_IP);
+}
+
+static void gen_ip_hdr(void *data, struct iphdr *ip_hdr)
+{
+	ip_hdr->version = IPVERSION;
+	ip_hdr->ihl = 0x5;
+	ip_hdr->tos = 0x0;
+	ip_hdr->tot_len = htons(IP_PKT_SIZE);
+	ip_hdr->id = 0;
+	ip_hdr->frag_off = 0;
+	ip_hdr->ttl = IPDEFTTL;
+	ip_hdr->protocol = IPPROTO_UDP;
+	ip_hdr->saddr = ((struct ifobject *)data)->src_ip;
+	ip_hdr->daddr = ((struct ifobject *)data)->dst_ip;
+	ip_hdr->check = 0;
+}
+
+static void gen_udp_hdr(void *data, void *arg, struct udphdr *udp_hdr)
+{
+	udp_hdr->source = htons(((struct ifobject *)arg)->src_port);
+	udp_hdr->dest = htons(((struct ifobject *)arg)->dst_port);
+	udp_hdr->len = htons(UDP_PKT_SIZE);
+	memset32_htonl(pkt_data + PKT_HDR_SIZE,
+		       htonl(((struct generic_data *)data)->seqnum), UDP_PKT_DATA_SIZE);
+}
+
+static void gen_udp_csum(struct udphdr *udp_hdr, struct iphdr *ip_hdr)
+{
+	udp_hdr->check = 0;
+	udp_hdr->check =
+	    udp_csum(ip_hdr->saddr, ip_hdr->daddr, UDP_PKT_SIZE, IPPROTO_UDP, (u16 *)udp_hdr);
+}
+
+static void gen_eth_frame(struct xsk_umem_info *umem, u64 addr)
+{
+	memcpy(xsk_umem__get_data(umem->buffer, addr), pkt_data, PKT_SIZE);
+}
+
+static void xsk_configure_umem(struct ifobject *data, void *buffer, u64 size)
+{
+	int ret;
+
+	data->umem = calloc(1, sizeof(struct xsk_umem_info));
+	if (!data->umem)
+		exit_with_error(errno);
+
+	ret = xsk_umem__create(&data->umem->umem, buffer, size,
+			       &data->umem->fq, &data->umem->cq, NULL);
+	if (ret)
+		exit_with_error(ret);
+
+	data->umem->buffer = buffer;
+}
+
+static void xsk_populate_fill_ring(struct xsk_umem_info *umem)
+{
+	int ret, i;
+	u32 idx;
+
+	ret = xsk_ring_prod__reserve(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS, &idx);
+	if (ret != XSK_RING_PROD__DEFAULT_NUM_DESCS)
+		exit_with_error(ret);
+	for (i = 0; i < XSK_RING_PROD__DEFAULT_NUM_DESCS; i++)
+		*xsk_ring_prod__fill_addr(&umem->fq, idx++) = i * XSK_UMEM__DEFAULT_FRAME_SIZE;
+	xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS);
+}
+
+static int xsk_configure_socket(struct ifobject *ifobject)
+{
+	struct xsk_socket_config cfg;
+	struct xsk_ring_cons *rxr;
+	struct xsk_ring_prod *txr;
+	int ret;
+
+	ifobject->xsk = calloc(1, sizeof(struct xsk_socket_info));
+	if (!ifobject->xsk)
+		exit_with_error(errno);
+
+	ifobject->xsk->umem = ifobject->umem;
+	cfg.rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;
+	cfg.tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
+	cfg.libbpf_flags = 0;
+	cfg.xdp_flags = opt_xdp_flags;
+	cfg.bind_flags = opt_xdp_bind_flags;
+
+	rxr = (ifobject->fv.vector == rx) ? &ifobject->xsk->rx : NULL;
+	txr = (ifobject->fv.vector == tx) ? &ifobject->xsk->tx : NULL;
+
+	ret = xsk_socket__create(&ifobject->xsk->xsk, ifobject->ifname,
+				 opt_queue, ifobject->umem->umem, rxr, txr, &cfg);
+
+	if (ret)
+		return 1;
+
+	return 0;
+}
+
+static struct option long_options[] = {
+	{"interface", required_argument, 0, 'i'},
+	{"queue", optional_argument, 0, 'q'},
+	{"poll", no_argument, 0, 'p'},
+	{"xdp-skb", no_argument, 0, 'S'},
+	{"copy", no_argument, 0, 'c'},
+	{"debug", optional_argument, 0, 'D'},
+	{"tx-pkt-count", optional_argument, 0, 'C'},
+	{0, 0, 0, 0}
+};
+
+static void usage(const char *prog)
+{
+	const char *str =
+	    "  Usage: %s [OPTIONS]\n"
+	    "  Options:\n"
+	    "  -i, --interface      Use interface\n"
+	    "  -q, --queue=n        Use queue n (default 0)\n"
+	    "  -p, --poll           Use poll syscall\n"
+	    "  -S, --xdp-skb=n      Use XDP SKB mode\n"
+	    "  -c, --copy           Force copy mode\n"
+	    "  -D, --debug          Debug mode - dump packets L2 - L5\n"
+	    "  -C, --tx-pkt-count=n Number of packets to send\n";
+	ksft_print_msg(str, prog);
+}
+
+static bool switch_namespace(int idx)
+{
+	char fqns[26] = "/var/run/netns/";
+	int nsfd;
+
+	strncat(fqns, ifdict[idx]->nsname, sizeof(fqns) - strlen(fqns) - 1);
+	nsfd = open(fqns, O_RDONLY);
+
+	if (nsfd == -1)
+		exit_with_error(errno);
+
+	if (setns(nsfd, 0) == -1)
+		exit_with_error(errno);
+
+	return true;
+}
+
+static void *nsswitchthread(void *args)
+{
+	if (switch_namespace(((struct targs *)args)->idx)) {
+		ifdict[((struct targs *)args)->idx]->ifindex =
+		    if_nametoindex(ifdict[((struct targs *)args)->idx]->ifname);
+		if (!ifdict[((struct targs *)args)->idx]->ifindex) {
+			ksft_test_result_fail
+			    ("ERROR: [%s] interface \"%s\" does not exist\n",
+			     __func__, ifdict[((struct targs *)args)->idx]->ifname);
+			((struct targs *)args)->retptr = false;
+		} else {
+			ksft_print_msg("Interface found: %s\n",
+				       ifdict[((struct targs *)args)->idx]->ifname);
+			((struct targs *)args)->retptr = true;
+		}
+	} else {
+		((struct targs *)args)->retptr = false;
+	}
+	pthread_exit(NULL);
+}
+
+static int validate_interfaces(void)
+{
+	bool ret = true;
+
+	for (int i = 0; i < MAX_INTERFACES; i++) {
+		if (!strcmp(ifdict[i]->ifname, "")) {
+			ret = false;
+			ksft_test_result_fail("ERROR: interfaces: -i <int>,<ns> -i <int>,<ns>.");
+		}
+		if (strcmp(ifdict[i]->nsname, "")) {
+			struct targs *targs;
+
+			targs = (struct targs *)malloc(sizeof(struct targs));
+			if (!targs)
+				exit_with_error(errno);
+
+			targs->idx = i;
+			if (pthread_create(&ns_thread, NULL, nsswitchthread, (void *)targs))
+				exit_with_error(errno);
+
+			pthread_join(ns_thread, NULL);
+
+			if (targs->retptr)
+				ksft_print_msg("NS switched: %s\n", ifdict[i]->nsname);
+
+			free(targs);
+		} else {
+			ifdict[i]->ifindex = if_nametoindex(ifdict[i]->ifname);
+			if (!ifdict[i]->ifindex) {
+				ksft_test_result_fail
+				    ("ERROR: interface \"%s\" does not exist\n", ifdict[i]->ifname);
+				ret = false;
+			} else {
+				ksft_print_msg("Interface found: %s\n", ifdict[i]->ifname);
+			}
+		}
+	}
+	return ret;
+}
+
+static void parse_command_line(int argc, char **argv)
+{
+	int option_index, interface_index = 0, c;
+
+	opterr = 0;
+
+	for (;;) {
+		c = getopt_long(argc, argv, "i:q:pScDC:", long_options, &option_index);
+
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'i':
+			if (interface_index == MAX_INTERFACES)
+				break;
+			char *sptr, *token;
+
+			memcpy(ifdict[interface_index]->ifname,
+			       strtok_r(optarg, ",", &sptr), MAX_INTERFACE_NAME_CHARS);
+			token = strtok_r(NULL, ",", &sptr);
+			if (token)
+				memcpy(ifdict[interface_index]->nsname, token,
+				       MAX_INTERFACES_NAMESPACE_CHARS);
+			interface_index++;
+			break;
+		case 'q':
+			opt_queue = atoi(optarg);
+			break;
+		case 'p':
+			opt_poll = 1;
+			break;
+		case 'S':
+			opt_xdp_flags |= XDP_FLAGS_SKB_MODE;
+			opt_xdp_bind_flags |= XDP_COPY;
+			uut = ORDER_CONTENT_VALIDATE_XDP_SKB;
+			break;
+		case 'c':
+			opt_xdp_bind_flags |= XDP_COPY;
+			break;
+		case 'D':
+			debug_pkt_dump = 1;
+			break;
+		case 'C':
+			opt_pkt_count = atoi(optarg);
+			break;
+		default:
+			usage(basename(argv[0]));
+			ksft_exit_xfail();
+		}
+	}
+
+	if (!validate_interfaces()) {
+		usage(basename(argv[0]));
+		ksft_exit_xfail();
+	}
+}
+
+static void kick_tx(struct xsk_socket_info *xsk)
+{
+	int ret;
+
+	ret = sendto(xsk_socket__fd(xsk->xsk), NULL, 0, MSG_DONTWAIT, NULL, 0);
+	if (ret >= 0 || errno == ENOBUFS || errno == EAGAIN || errno == EBUSY || errno == ENETDOWN)
+		return;
+	exit_with_error(errno);
+}
+
+static inline void complete_tx_only(struct xsk_socket_info *xsk, int batch_size)
+{
+	unsigned int rcvd;
+	u32 idx;
+
+	if (!xsk->outstanding_tx)
+		return;
+
+	if (!NEED_WAKEUP || xsk_ring_prod__needs_wakeup(&xsk->tx))
+		kick_tx(xsk);
+
+	rcvd = xsk_ring_cons__peek(&xsk->umem->cq, batch_size, &idx);
+	if (rcvd) {
+		xsk_ring_cons__release(&xsk->umem->cq, rcvd);
+		xsk->outstanding_tx -= rcvd;
+		xsk->tx_npkts += rcvd;
+	}
+}
+
+static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds)
+{
+	unsigned int rcvd, i;
+	u32 idx_rx = 0, idx_fq = 0;
+	int ret;
+
+	rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx);
+	if (!rcvd) {
+		if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) {
+			ret = poll(fds, 1, POLL_TMOUT);
+			if (ret < 0)
+				exit_with_error(ret);
+		}
+		return;
+	}
+
+	ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq);
+	while (ret != rcvd) {
+		if (ret < 0)
+			exit_with_error(ret);
+		if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) {
+			ret = poll(fds, 1, POLL_TMOUT);
+			if (ret < 0)
+				exit_with_error(ret);
+		}
+		ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq);
+	}
+
+	for (i = 0; i < rcvd; i++) {
+		u64 addr = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx)->addr;
+		(void)xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++)->len;
+		u64 orig = xsk_umem__extract_addr(addr);
+
+		addr = xsk_umem__add_offset_to_addr(addr);
+		pkt_node_rx = malloc(sizeof(struct pkt) + PKT_SIZE);
+		if (!pkt_node_rx)
+			exit_with_error(errno);
+
+		pkt_node_rx->pkt_frame = (char *)malloc(PKT_SIZE);
+		if (!pkt_node_rx->pkt_frame)
+			exit_with_error(errno);
+
+		memcpy(pkt_node_rx->pkt_frame, xsk_umem__get_data(xsk->umem->buffer, addr),
+		       PKT_SIZE);
+
+		TAILQ_INSERT_HEAD(&head, pkt_node_rx, pkt_nodes);
+
+		*xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = orig;
+	}
+
+	xsk_ring_prod__submit(&xsk->umem->fq, rcvd);
+	xsk_ring_cons__release(&xsk->rx, rcvd);
+	xsk->rx_npkts += rcvd;
+}
+
+static void tx_only(struct xsk_socket_info *xsk, u32 *frameptr, int batch_size)
+{
+	u32 idx;
+	unsigned int i;
+
+	while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) < batch_size)
+		complete_tx_only(xsk, batch_size);
+
+	for (i = 0; i < batch_size; i++) {
+		struct xdp_desc *tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx + i);
+
+		tx_desc->addr = (*frameptr + i) << XSK_UMEM__DEFAULT_FRAME_SHIFT;
+		tx_desc->len = PKT_SIZE;
+	}
+
+	xsk_ring_prod__submit(&xsk->tx, batch_size);
+	xsk->outstanding_tx += batch_size;
+	*frameptr += batch_size;
+	*frameptr %= num_frames;
+	complete_tx_only(xsk, batch_size);
+}
+
+static inline int get_batch_size(int pkt_cnt)
+{
+	if (!opt_pkt_count)
+		return BATCH_SIZE;
+
+	if (pkt_cnt + BATCH_SIZE <= opt_pkt_count)
+		return BATCH_SIZE;
+
+	return opt_pkt_count - pkt_cnt;
+}
+
+static void complete_tx_only_all(void *arg)
+{
+	bool pending;
+
+	do {
+		pending = false;
+		if (((struct ifobject *)arg)->xsk->outstanding_tx) {
+			complete_tx_only(((struct ifobject *)
+					  arg)->xsk, BATCH_SIZE);
+			pending = !!((struct ifobject *)arg)->xsk->outstanding_tx;
+		}
+	} while (pending);
+}
+
+static void tx_only_all(void *arg)
+{
+	struct pollfd fds[MAX_SOCKS] = { };
+	u32 frame_nb = 0;
+	int pkt_cnt = 0;
+	int ret;
+
+	fds[0].fd = xsk_socket__fd(((struct ifobject *)arg)->xsk->xsk);
+	fds[0].events = POLLOUT;
+
+	while ((opt_pkt_count && pkt_cnt < opt_pkt_count) || !opt_pkt_count) {
+		int batch_size = get_batch_size(pkt_cnt);
+
+		if (opt_poll) {
+			ret = poll(fds, 1, POLL_TMOUT);
+			if (ret <= 0)
+				continue;
+
+			if (!(fds[0].revents & POLLOUT))
+				continue;
+		}
+
+		tx_only(((struct ifobject *)arg)->xsk, &frame_nb, batch_size);
+		pkt_cnt += batch_size;
+	}
+
+	if (opt_pkt_count)
+		complete_tx_only_all(arg);
+}
+
+static void worker_pkt_dump(void)
+{
+	struct in_addr ipaddr;
+
+	fprintf(stdout, "---------------------------------------\n");
+	for (int iter = 0; iter < num_frames - 1; iter++) {
+		/*extract L2 frame */
+		fprintf(stdout, "DEBUG>> L2: dst mac: ");
+		for (int i = 0; i < ETH_ALEN; i++)
+			fprintf(stdout, "%02X", ((struct ethhdr *)
+						 pkt_buf[iter]->payload)->h_dest[i]);
+
+		fprintf(stdout, "\nDEBUG>> L2: src mac: ");
+		for (int i = 0; i < ETH_ALEN; i++)
+			fprintf(stdout, "%02X", ((struct ethhdr *)
+						 pkt_buf[iter]->payload)->h_source[i]);
+
+		/*extract L3 frame */
+		fprintf(stdout, "\nDEBUG>> L3: ip_hdr->ihl: %02X\n",
+			((struct iphdr *)(pkt_buf[iter]->payload + sizeof(struct ethhdr)))->ihl);
+
+		ipaddr.s_addr =
+		    ((struct iphdr *)(pkt_buf[iter]->payload + sizeof(struct ethhdr)))->saddr;
+		fprintf(stdout, "DEBUG>> L3: ip_hdr->saddr: %s\n", inet_ntoa(ipaddr));
+
+		ipaddr.s_addr =
+		    ((struct iphdr *)(pkt_buf[iter]->payload + sizeof(struct ethhdr)))->daddr;
+		fprintf(stdout, "DEBUG>> L3: ip_hdr->daddr: %s\n", inet_ntoa(ipaddr));
+
+		/*extract L4 frame */
+		fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n",
+			ntohs(((struct udphdr *)(pkt_buf[iter]->payload +
+						 sizeof(struct ethhdr) +
+						 sizeof(struct iphdr)))->source));
+
+		fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n",
+			ntohs(((struct udphdr *)(pkt_buf[iter]->payload +
+						 sizeof(struct ethhdr) +
+						 sizeof(struct iphdr)))->dest));
+		/*extract L5 frame */
+		int payload = *((uint32_t *)(pkt_buf[iter]->payload + PKT_HDR_SIZE));
+
+		if (payload == EOT) {
+			ksft_print_msg("End-of-tranmission frame received\n");
+			fprintf(stdout, "---------------------------------------\n");
+			break;
+		}
+		fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload);
+		fprintf(stdout, "---------------------------------------\n");
+	}
+}
+
+static void worker_pkt_validate(void)
+{
+	u32 payloadseqnum = -2;
+
+	while (1) {
+		pkt_node_rx_q = malloc(sizeof(struct pkt));
+		pkt_node_rx_q = TAILQ_LAST(&head, head_s);
+		if (!pkt_node_rx_q)
+			break;
+
+		payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE));
+		if (debug_pkt_dump && payloadseqnum != EOT) {
+			pkt_obj = (struct pkt_frame *)malloc(sizeof(struct pkt_frame));
+			pkt_obj->payload = (char *)malloc(PKT_SIZE);
+			memcpy(pkt_obj->payload, pkt_node_rx_q->pkt_frame, PKT_SIZE);
+			pkt_buf[payloadseqnum] = pkt_obj;
+		}
+
+		if (payloadseqnum == EOT) {
+			ksft_print_msg("End-of-tranmission frame received: PASS\n");
+			sigvar = 1;
+			break;
+		}
+
+		if (prev_pkt + 1 != payloadseqnum) {
+			ksft_test_result_fail
+			    ("ERROR: [%s] prev_pkt [%d], payloadseqnum [%d]\n",
+			     __func__, prev_pkt, payloadseqnum);
+			ksft_exit_xfail();
+		}
+
+		TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes);
+		free(pkt_node_rx_q->pkt_frame);
+		free(pkt_node_rx_q);
+		pkt_node_rx_q = NULL;
+		prev_pkt = payloadseqnum;
+		pkt_counter++;
+	}
+}
+
+static void thread_common_ops(void *arg, void *bufs, pthread_mutex_t *mutexptr,
+			      atomic_int *spinningptr)
+{
+	int ctr = 0;
+	int ret;
+
+	xsk_configure_umem((struct ifobject *)arg, bufs, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE);
+	ret = xsk_configure_socket((struct ifobject *)arg);
+
+	/* Retry Create Socket if it fails as xsk_socket__create()
+	 * is asynchronous
+	 *
+	 * Essential to lock Mutex here to prevent Tx thread from
+	 * entering before Rx and causing a deadlock
+	 */
+	pthread_mutex_lock(mutexptr);
+	while (ret && ctr < SOCK_RECONF_CTR) {
+		atomic_store(spinningptr, 1);
+		xsk_configure_umem((struct ifobject *)arg,
+				   bufs, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE);
+		ret = xsk_configure_socket((struct ifobject *)arg);
+		usleep(USLEEP_MAX);
+		ctr++;
+	}
+	atomic_store(spinningptr, 0);
+	pthread_mutex_unlock(mutexptr);
+
+	if (ctr >= SOCK_RECONF_CTR)
+		exit_with_error(ret);
+}
+
+static void *worker_testapp_validate(void *arg)
+{
+	struct udphdr *udp_hdr =
+	    (struct udphdr *)(pkt_data + sizeof(struct ethhdr) + sizeof(struct iphdr));
+	struct generic_data *data = (struct generic_data *)malloc(sizeof(struct generic_data));
+	struct iphdr *ip_hdr = (struct iphdr *)(pkt_data + sizeof(struct ethhdr));
+	struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data;
+	void *bufs;
+
+	pthread_attr_setstacksize(&attr, THREAD_STACK);
+
+	bufs = mmap(NULL, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE,
+		    PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	if (bufs == MAP_FAILED)
+		exit_with_error(errno);
+
+	if (strcmp(((struct ifobject *)arg)->nsname, ""))
+		switch_namespace(((struct ifobject *)arg)->ifdict_index);
+
+	if (((struct ifobject *)arg)->fv.vector == tx) {
+		int spinningrxctr = 0;
+
+		thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_tx);
+
+		while (atomic_load(&spinning_rx) && spinningrxctr < SOCK_RECONF_CTR) {
+			spinningrxctr++;
+			usleep(USLEEP_MAX);
+		}
+
+		ksft_print_msg("Interface [%s] vector [Tx]\n", ((struct ifobject *)arg)->ifname);
+		for (int i = 0; i < num_frames; i++) {
+			/*send EOT frame */
+			if (i == (num_frames - 1))
+				data->seqnum = -1;
+			else
+				data->seqnum = i;
+			gen_udp_hdr((void *)data, (void *)arg, udp_hdr);
+			gen_ip_hdr((void *)arg, ip_hdr);
+			gen_udp_csum(udp_hdr, ip_hdr);
+			gen_eth_hdr((void *)arg, eth_hdr);
+			gen_eth_frame(((struct ifobject *)arg)->umem,
+				      i * XSK_UMEM__DEFAULT_FRAME_SIZE);
+		}
+
+		free(data);
+		ksft_print_msg("Sending %d packets on interface %s\n",
+			       (opt_pkt_count - 1), ((struct ifobject *)arg)->ifname);
+		tx_only_all(arg);
+	} else if (((struct ifobject *)arg)->fv.vector == rx) {
+		struct pollfd fds[MAX_SOCKS] = { };
+		int ret;
+
+		thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_rx);
+
+		ksft_print_msg("Interface [%s] vector [Rx]\n", ((struct ifobject *)arg)->ifname);
+		xsk_populate_fill_ring(((struct ifobject *)arg)->umem);
+
+		TAILQ_INIT(&head);
+		if (debug_pkt_dump) {
+			pkt_buf = malloc(sizeof(struct pkt_frame **) * num_frames);
+			if (!pkt_buf)
+				exit_with_error(errno);
+		}
+
+		fds[0].fd = xsk_socket__fd(((struct ifobject *)arg)->xsk->xsk);
+		fds[0].events = POLLIN;
+
+		pthread_mutex_lock(&sync_mutex);
+		pthread_cond_signal(&signal_rx_condition);
+		pthread_mutex_unlock(&sync_mutex);
+
+		while (1) {
+			if (opt_poll) {
+				ret = poll(fds, 1, POLL_TMOUT);
+				if (ret <= 0)
+					continue;
+			}
+			rx_pkt(((struct ifobject *)arg)->xsk, fds);
+			worker_pkt_validate();
+
+			if (sigvar)
+				break;
+		}
+
+		ksft_print_msg("Received %d packets on interface %s\n",
+			       pkt_counter, ((struct ifobject *)arg)->ifname);
+	}
+
+	xsk_socket__delete(((struct ifobject *)arg)->xsk->xsk);
+	(void)xsk_umem__delete(((struct ifobject *)arg)->umem->umem);
+	pthread_exit(NULL);
+}
+
+static void testapp_validate(void)
+{
+	pthread_attr_init(&attr);
+	pthread_attr_setstacksize(&attr, THREAD_STACK);
+
+	pthread_mutex_lock(&sync_mutex);
+
+	/*Spawn RX thread */
+	if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[1]))
+		exit_with_error(errno);
+
+	struct timespec max_wait = { 0, 0 };
+
+	if (clock_gettime(CLOCK_REALTIME, &max_wait))
+		exit_with_error(errno);
+	max_wait.tv_sec += TMOUT_SEC;
+
+	if (pthread_cond_timedwait(&signal_rx_condition, &sync_mutex, &max_wait) == ETIMEDOUT)
+		exit_with_error(errno);
+
+	pthread_mutex_unlock(&sync_mutex);
+
+	/*Spawn TX thread */
+	if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[0]))
+		exit_with_error(errno);
+
+	pthread_join(t1, NULL);
+	pthread_join(t0, NULL);
+
+	if (debug_pkt_dump) {
+		worker_pkt_dump();
+		for (int iter = 0; iter < num_frames - 1; iter++) {
+			free(pkt_buf[iter]->payload);
+			free(pkt_buf[iter]);
+		}
+		free(pkt_buf);
+	}
+
+	print_ksft_result();
+}
+
+static void init_iface_config(void *ifaceconfig)
+{
+	/*Init interface0 */
+	ifdict[0]->fv.vector = tx;
+	memcpy(ifdict[0]->dst_mac, ((struct ifaceconfigobj *)ifaceconfig)->dst_mac, ETH_ALEN);
+	memcpy(ifdict[0]->src_mac, ((struct ifaceconfigobj *)ifaceconfig)->src_mac, ETH_ALEN);
+	ifdict[0]->dst_ip = ((struct ifaceconfigobj *)ifaceconfig)->dst_ip.s_addr;
+	ifdict[0]->src_ip = ((struct ifaceconfigobj *)ifaceconfig)->src_ip.s_addr;
+	ifdict[0]->dst_port = ((struct ifaceconfigobj *)ifaceconfig)->dst_port;
+	ifdict[0]->src_port = ((struct ifaceconfigobj *)ifaceconfig)->src_port;
+
+	/*Init interface1 */
+	ifdict[1]->fv.vector = rx;
+	memcpy(ifdict[1]->dst_mac, ((struct ifaceconfigobj *)ifaceconfig)->src_mac, ETH_ALEN);
+	memcpy(ifdict[1]->src_mac, ((struct ifaceconfigobj *)ifaceconfig)->dst_mac, ETH_ALEN);
+	ifdict[1]->dst_ip = ((struct ifaceconfigobj *)ifaceconfig)->src_ip.s_addr;
+	ifdict[1]->src_ip = ((struct ifaceconfigobj *)ifaceconfig)->dst_ip.s_addr;
+	ifdict[1]->dst_port = ((struct ifaceconfigobj *)ifaceconfig)->src_port;
+	ifdict[1]->src_port = ((struct ifaceconfigobj *)ifaceconfig)->dst_port;
+}
+
+int main(int argc, char **argv)
+{
+	struct rlimit _rlim = { RLIM_INFINITY, RLIM_INFINITY };
+
+	if (setrlimit(RLIMIT_MEMLOCK, &_rlim))
+		exit_with_error(errno);
+
+	const char *MAC1 = "\x00\x0A\x56\x9E\xEE\x62";
+	const char *MAC2 = "\x00\x0A\x56\x9E\xEE\x61";
+	const char *IP1 = "192.168.100.162";
+	const char *IP2 = "192.168.100.161";
+	u16 UDP_DST_PORT = 2020;
+	u16 UDP_SRC_PORT = 2121;
+
+	ifaceconfig = (struct ifaceconfigobj *)malloc(sizeof(struct ifaceconfigobj));
+	memcpy(ifaceconfig->dst_mac, MAC1, ETH_ALEN);
+	memcpy(ifaceconfig->src_mac, MAC2, ETH_ALEN);
+	inet_aton(IP1, &ifaceconfig->dst_ip);
+	inet_aton(IP2, &ifaceconfig->src_ip);
+	ifaceconfig->dst_port = UDP_DST_PORT;
+	ifaceconfig->src_port = UDP_SRC_PORT;
+
+	for (int i = 0; i < MAX_INTERFACES; i++) {
+		ifdict[i] = (struct ifobject *)malloc(sizeof(struct ifobject));
+		if (!ifdict[i])
+			exit_with_error(errno);
+
+		ifdict[i]->ifdict_index = i;
+	}
+
+	setlocale(LC_ALL, "");
+
+	parse_command_line(argc, argv);
+
+	num_frames = ++opt_pkt_count;
+
+	init_iface_config((void *)ifaceconfig);
+
+	pthread_init_mutex();
+
+	ksft_set_plan(1);
+
+	testapp_validate();
+
+	for (int i = 0; i < MAX_INTERFACES; i++)
+		free(ifdict[i]);
+
+	pthread_destroy_mutex();
+
+	ksft_exit_pass();
+
+	return 0;
+}
diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h
new file mode 100644
index 000000000000..32ee33311141
--- /dev/null
+++ b/tools/testing/selftests/bpf/xdpxceiver.h
@@ -0,0 +1,151 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Copyright(c) 2020 Intel Corporation.
+ */
+
+#ifndef XDPXCEIVER_H_
+#define XDPXCEIVER_H_
+
+#ifndef SOL_XDP
+#define SOL_XDP 283
+#endif
+
+#ifndef AF_XDP
+#define AF_XDP 44
+#endif
+
+#ifndef PF_XDP
+#define PF_XDP AF_XDP
+#endif
+
+#define MAX_INTERFACES 2
+#define MAX_INTERFACE_NAME_CHARS 7
+#define MAX_INTERFACES_NAMESPACE_CHARS 10
+#define MAX_SOCKS 1
+#define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \
+			sizeof(struct udphdr))
+#define MIN_PKT_SIZE 64
+#define ETH_FCS_SIZE 4
+#define PKT_SIZE (MIN_PKT_SIZE - ETH_FCS_SIZE)
+#define IP_PKT_SIZE (PKT_SIZE - sizeof(struct ethhdr))
+#define UDP_PKT_SIZE (IP_PKT_SIZE - sizeof(struct iphdr))
+#define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr))
+#define TMOUT_SEC (3)
+#define EOT (-1)
+#define USLEEP_MAX 200000
+#define THREAD_STACK 60000000
+#define SOCK_RECONF_CTR 10
+#define BATCH_SIZE 64
+#define POLL_TMOUT 1000
+#define NEED_WAKEUP true
+
+typedef __u32 u32;
+typedef __u16 u16;
+typedef __u8 u8;
+
+enum TESTS {
+	ORDER_CONTENT_VALIDATE_XDP_SKB = 0,
+};
+
+u8 uut;
+u8 debug_pkt_dump;
+u32 num_frames;
+
+static u32 opt_xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
+static int opt_queue;
+static int opt_pkt_count;
+static int opt_poll;
+static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
+static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE];
+static u32 pkt_counter;
+static u32 prev_pkt = -1;
+static int sigvar;
+
+struct xsk_umem_info {
+	struct xsk_ring_prod fq;
+	struct xsk_ring_cons cq;
+	struct xsk_umem *umem;
+	void *buffer;
+};
+
+struct xsk_socket_info {
+	struct xsk_ring_cons rx;
+	struct xsk_ring_prod tx;
+	struct xsk_umem_info *umem;
+	struct xsk_socket *xsk;
+	unsigned long rx_npkts;
+	unsigned long tx_npkts;
+	unsigned long prev_rx_npkts;
+	unsigned long prev_tx_npkts;
+	u32 outstanding_tx;
+};
+
+struct flow_vector {
+	enum fvector {
+		tx,
+		rx,
+		bidi,
+		undef,
+	} vector;
+};
+
+struct generic_data {
+	u32 seqnum;
+};
+
+struct ifaceconfigobj {
+	u8 dst_mac[ETH_ALEN];
+	u8 src_mac[ETH_ALEN];
+	struct in_addr dst_ip;
+	struct in_addr src_ip;
+	u16 src_port;
+	u16 dst_port;
+} *ifaceconfig;
+
+struct ifobject {
+	int ifindex;
+	int ifdict_index;
+	char ifname[MAX_INTERFACE_NAME_CHARS];
+	char nsname[MAX_INTERFACES_NAMESPACE_CHARS];
+	struct flow_vector fv;
+	struct xsk_socket_info *xsk;
+	struct xsk_umem_info *umem;
+	u8 dst_mac[ETH_ALEN];
+	u8 src_mac[ETH_ALEN];
+	u32 dst_ip;
+	u32 src_ip;
+	u16 src_port;
+	u16 dst_port;
+};
+
+static struct ifobject *ifdict[MAX_INTERFACES];
+
+/*threads*/
+atomic_int spinning_tx;
+atomic_int spinning_rx;
+pthread_mutex_t sync_mutex;
+pthread_mutex_t sync_mutex_tx;
+pthread_cond_t signal_rx_condition;
+pthread_cond_t signal_tx_condition;
+pthread_t t0, t1, ns_thread;
+pthread_attr_t attr;
+
+struct targs {
+	bool retptr;
+	int idx;
+};
+
+TAILQ_HEAD(head_s, pkt) head = TAILQ_HEAD_INITIALIZER(head);
+struct head_s *head_p;
+struct pkt {
+	char *pkt_frame;
+
+	TAILQ_ENTRY(pkt) pkt_nodes;
+} *pkt_node_rx, *pkt_node_rx_q;
+
+struct pkt_frame {
+	char *payload;
+} *pkt_obj;
+
+struct pkt_frame **pkt_buf;
+
+#endif				/* XDPXCEIVER_H */
diff --git a/tools/testing/selftests/bpf/xsk_env.sh b/tools/testing/selftests/bpf/xsk_env.sh
index 2c41b4284cae..1490bae406e8 100755
--- a/tools/testing/selftests/bpf/xsk_env.sh
+++ b/tools/testing/selftests/bpf/xsk_env.sh
@@ -4,8 +4,25 @@
 
 . xsk_prereqs.sh
 
+XSKOBJ=xdpxceiver
+NUMPKTS=10000
+
 validate_veth_spec_file
 
 VETH0=$(cat ${SPECFILE} | cut -d':' -f 1)
 VETH1=$(cat ${SPECFILE} | cut -d':' -f 2 | cut -d',' -f 1)
 NS1=$(cat ${SPECFILE} | cut -d':' -f 2 | cut -d',' -f 2)
+
+execxdpxceiver()
+{
+	local -a 'paramkeys=("${!'"$1"'[@]}")' copy
+	paramkeysstr=${paramkeys[*]}
+
+	for index in $paramkeysstr;
+		do
+			current=$1"[$index]"
+			copy[$index]=${!current}
+		done
+
+	./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${copy[*]} -C ${NUMPKTS}
+}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH bpf-next v3 3/5] selftests/bpf: xsk selftests - DRV POLL, NOPOLL
  2020-11-25 18:37 [PATCH bpf-next v3 0/5] selftests/bpf: xsk selftests Weqaar Janjua
  2020-11-25 18:37 ` [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework Weqaar Janjua
  2020-11-25 18:37 ` [PATCH bpf-next v3 2/5] selftests/bpf: xsk selftests - SKB POLL, NOPOLL Weqaar Janjua
@ 2020-11-25 18:37 ` Weqaar Janjua
  2020-11-25 18:37 ` [PATCH bpf-next v3 4/5] selftests/bpf: xsk selftests - Socket Teardown - SKB, DRV Weqaar Janjua
  2020-11-25 18:37 ` [PATCH bpf-next v3 5/5] selftests/bpf: xsk selftests - Bi-directional Sockets " Weqaar Janjua
  4 siblings, 0 replies; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-25 18:37 UTC (permalink / raw)
  To: bpf, netdev, daniel, ast, yhs, magnus.karlsson, bjorn.topel
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon

Adds following tests:

2. AF_XDP DRV/Native mode
   Works on any netdevice with XDP_REDIRECT support, driver dependent.
   Processes packets before SKB allocation. Provides better performance
   than SKB. Driver hook available just after DMA of buffer descriptor.
   a. nopoll
   b. poll
   * Only copy mode is supported because veth does not currently support
     zero-copy mode

Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com>
---
 tools/testing/selftests/bpf/test_xsk.sh  | 24 ++++++++++++++++++++++++
 tools/testing/selftests/bpf/xdpxceiver.c | 22 +++++++++++++++++++---
 tools/testing/selftests/bpf/xdpxceiver.h |  1 +
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
index 9c3812bd353f..375f9590db90 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -152,6 +152,30 @@ retval=$?
 test_status $retval "${TEST_NAME}"
 statusList+=($retval)
 
+### TEST 3
+TEST_NAME="DRV NOPOLL"
+
+vethXDPnative ${VETH0} ${VETH1} ${NS1}
+
+params=("-N")
+execxdpxceiver params
+
+retval=$?
+test_status $retval "${TEST_NAME}"
+statusList+=($retval)
+
+### TEST 4
+TEST_NAME="DRV POLL"
+
+vethXDPnative ${VETH0} ${VETH1} ${NS1}
+
+params=("-N" "-p")
+execxdpxceiver params
+
+retval=$?
+test_status $retval "${TEST_NAME}"
+statusList+=($retval)
+
 ## END TESTS
 
 cleanup_exit ${VETH0} ${VETH1} ${NS1}
diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
index e6c448668cd9..3027247bbb4e 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.c
+++ b/tools/testing/selftests/bpf/xdpxceiver.c
@@ -27,7 +27,16 @@
  *    a. nopoll - soft-irq processing
  *    b. poll - using poll() syscall
  *
- * Total tests: 2
+ * 2. AF_XDP DRV/Native mode
+ *    Works on any netdevice with XDP_REDIRECT support, driver dependent. Processes
+ *    packets before SKB allocation. Provides better performance than SKB. Driver
+ *    hook available just after DMA of buffer descriptor.
+ *    a. nopoll
+ *    b. poll
+ *    - Only copy mode is supported because veth does not currently support
+ *      zero-copy mode
+ *
+ * Total tests: 4
  *
  * Flow:
  * -----
@@ -87,7 +96,7 @@ static void __exit_with_error(int error, const char *file, const char *func, int
 #define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)
 
 #define print_ksft_result(void)\
-	(ksft_test_result_pass("PASS: %s %s\n", uut ? "" : "SKB", opt_poll ? "POLL" : "NOPOLL"))
+	(ksft_test_result_pass("PASS: %s %s\n", uut ? "DRV" : "SKB", opt_poll ? "POLL" : "NOPOLL"))
 
 static void pthread_init_mutex(void)
 {
@@ -310,6 +319,7 @@ static struct option long_options[] = {
 	{"queue", optional_argument, 0, 'q'},
 	{"poll", no_argument, 0, 'p'},
 	{"xdp-skb", no_argument, 0, 'S'},
+	{"xdp-native", no_argument, 0, 'N'},
 	{"copy", no_argument, 0, 'c'},
 	{"debug", optional_argument, 0, 'D'},
 	{"tx-pkt-count", optional_argument, 0, 'C'},
@@ -325,6 +335,7 @@ static void usage(const char *prog)
 	    "  -q, --queue=n        Use queue n (default 0)\n"
 	    "  -p, --poll           Use poll syscall\n"
 	    "  -S, --xdp-skb=n      Use XDP SKB mode\n"
+	    "  -N, --xdp-native=n   Enforce XDP DRV (native) mode\n"
 	    "  -c, --copy           Force copy mode\n"
 	    "  -D, --debug          Debug mode - dump packets L2 - L5\n"
 	    "  -C, --tx-pkt-count=n Number of packets to send\n";
@@ -416,7 +427,7 @@ static void parse_command_line(int argc, char **argv)
 	opterr = 0;
 
 	for (;;) {
-		c = getopt_long(argc, argv, "i:q:pScDC:", long_options, &option_index);
+		c = getopt_long(argc, argv, "i:q:pSNcDC:", long_options, &option_index);
 
 		if (c == -1)
 			break;
@@ -446,6 +457,11 @@ static void parse_command_line(int argc, char **argv)
 			opt_xdp_bind_flags |= XDP_COPY;
 			uut = ORDER_CONTENT_VALIDATE_XDP_SKB;
 			break;
+		case 'N':
+			opt_xdp_flags |= XDP_FLAGS_DRV_MODE;
+			opt_xdp_bind_flags |= XDP_COPY;
+			uut = ORDER_CONTENT_VALIDATE_XDP_DRV;
+			break;
 		case 'c':
 			opt_xdp_bind_flags |= XDP_COPY;
 			break;
diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h
index 32ee33311141..dba47e818466 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.h
+++ b/tools/testing/selftests/bpf/xdpxceiver.h
@@ -44,6 +44,7 @@ typedef __u8 u8;
 
 enum TESTS {
 	ORDER_CONTENT_VALIDATE_XDP_SKB = 0,
+	ORDER_CONTENT_VALIDATE_XDP_DRV = 1,
 };
 
 u8 uut;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH bpf-next v3 4/5] selftests/bpf: xsk selftests - Socket Teardown - SKB, DRV
  2020-11-25 18:37 [PATCH bpf-next v3 0/5] selftests/bpf: xsk selftests Weqaar Janjua
                   ` (2 preceding siblings ...)
  2020-11-25 18:37 ` [PATCH bpf-next v3 3/5] selftests/bpf: xsk selftests - DRV " Weqaar Janjua
@ 2020-11-25 18:37 ` Weqaar Janjua
  2020-11-25 18:37 ` [PATCH bpf-next v3 5/5] selftests/bpf: xsk selftests - Bi-directional Sockets " Weqaar Janjua
  4 siblings, 0 replies; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-25 18:37 UTC (permalink / raw)
  To: bpf, netdev, daniel, ast, yhs, magnus.karlsson, bjorn.topel
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon

Adds following tests:

1. AF_XDP SKB mode
   c. Socket Teardown
      Create a Tx and a Rx socket, Tx from one socket, Rx on another.
      Destroy both sockets, then repeat multiple times. Only nopoll mode
      is used

2. AF_XDP DRV/Native mode
   c. Socket Teardown
   * Only copy mode is supported because veth does not currently support
     zero-copy mode

Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com>
---
 tools/testing/selftests/bpf/test_xsk.sh  | 24 ++++++++++++++++
 tools/testing/selftests/bpf/xdpxceiver.c | 35 +++++++++++++++++++++---
 tools/testing/selftests/bpf/xdpxceiver.h |  2 ++
 3 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
index 375f9590db90..76de8080092d 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -176,6 +176,30 @@ retval=$?
 test_status $retval "${TEST_NAME}"
 statusList+=($retval)
 
+### TEST 5
+TEST_NAME="SKB SOCKET TEARDOWN"
+
+vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
+
+params=("-S" "-T")
+execxdpxceiver params
+
+retval=$?
+test_status $retval "${TEST_NAME}"
+statusList+=($retval)
+
+### TEST 6
+TEST_NAME="DRV SOCKET TEARDOWN"
+
+vethXDPnative ${VETH0} ${VETH1} ${NS1}
+
+params=("-N" "-T")
+execxdpxceiver params
+
+retval=$?
+test_status $retval "${TEST_NAME}"
+statusList+=($retval)
+
 ## END TESTS
 
 cleanup_exit ${VETH0} ${VETH1} ${NS1}
diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
index 3027247bbb4e..62560e058111 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.c
+++ b/tools/testing/selftests/bpf/xdpxceiver.c
@@ -26,6 +26,9 @@
  *    generic XDP path. XDP hook from netif_receive_skb().
  *    a. nopoll - soft-irq processing
  *    b. poll - using poll() syscall
+ *    c. Socket Teardown
+ *       Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy
+ *       both sockets, then repeat multiple times. Only nopoll mode is used
  *
  * 2. AF_XDP DRV/Native mode
  *    Works on any netdevice with XDP_REDIRECT support, driver dependent. Processes
@@ -33,10 +36,11 @@
  *    hook available just after DMA of buffer descriptor.
  *    a. nopoll
  *    b. poll
+ *    c. Socket Teardown
  *    - Only copy mode is supported because veth does not currently support
  *      zero-copy mode
  *
- * Total tests: 4
+ * Total tests: 6
  *
  * Flow:
  * -----
@@ -96,7 +100,8 @@ static void __exit_with_error(int error, const char *file, const char *func, int
 #define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)
 
 #define print_ksft_result(void)\
-	(ksft_test_result_pass("PASS: %s %s\n", uut ? "DRV" : "SKB", opt_poll ? "POLL" : "NOPOLL"))
+	(ksft_test_result_pass("PASS: %s %s %s\n", uut ? "DRV" : "SKB", opt_poll ? "POLL" :\
+			       "NOPOLL", opt_teardown ? "Socket Teardown" : ""))
 
 static void pthread_init_mutex(void)
 {
@@ -321,6 +326,7 @@ static struct option long_options[] = {
 	{"xdp-skb", no_argument, 0, 'S'},
 	{"xdp-native", no_argument, 0, 'N'},
 	{"copy", no_argument, 0, 'c'},
+	{"tear-down", no_argument, 0, 'T'},
 	{"debug", optional_argument, 0, 'D'},
 	{"tx-pkt-count", optional_argument, 0, 'C'},
 	{0, 0, 0, 0}
@@ -337,6 +343,7 @@ static void usage(const char *prog)
 	    "  -S, --xdp-skb=n      Use XDP SKB mode\n"
 	    "  -N, --xdp-native=n   Enforce XDP DRV (native) mode\n"
 	    "  -c, --copy           Force copy mode\n"
+	    "  -T, --tear-down      Tear down sockets by repeatedly recreating them\n"
 	    "  -D, --debug          Debug mode - dump packets L2 - L5\n"
 	    "  -C, --tx-pkt-count=n Number of packets to send\n";
 	ksft_print_msg(str, prog);
@@ -427,7 +434,7 @@ static void parse_command_line(int argc, char **argv)
 	opterr = 0;
 
 	for (;;) {
-		c = getopt_long(argc, argv, "i:q:pSNcDC:", long_options, &option_index);
+		c = getopt_long(argc, argv, "i:q:pSNcTDC:", long_options, &option_index);
 
 		if (c == -1)
 			break;
@@ -465,6 +472,9 @@ static void parse_command_line(int argc, char **argv)
 		case 'c':
 			opt_xdp_bind_flags |= XDP_COPY;
 			break;
+		case 'T':
+			opt_teardown = 1;
+			break;
 		case 'D':
 			debug_pkt_dump = 1;
 			break;
@@ -853,6 +863,9 @@ static void *worker_testapp_validate(void *arg)
 
 		ksft_print_msg("Received %d packets on interface %s\n",
 			       pkt_counter, ((struct ifobject *)arg)->ifname);
+
+		if (opt_teardown)
+			ksft_print_msg("Destroying socket\n");
 	}
 
 	xsk_socket__delete(((struct ifobject *)arg)->xsk->xsk);
@@ -898,6 +911,20 @@ static void testapp_validate(void)
 		free(pkt_buf);
 	}
 
+	if (!opt_teardown)
+		print_ksft_result();
+}
+
+static void testapp_sockets(void)
+{
+	for (int i = 0; i < MAX_TEARDOWN_ITER; i++) {
+		pkt_counter = 0;
+		prev_pkt = -1;
+		sigvar = 0;
+		ksft_print_msg("Creating socket\n");
+		testapp_validate();
+	}
+
 	print_ksft_result();
 }
 
@@ -964,7 +991,7 @@ int main(int argc, char **argv)
 
 	ksft_set_plan(1);
 
-	testapp_validate();
+	opt_teardown ? testapp_sockets() : testapp_validate();
 
 	for (int i = 0; i < MAX_INTERFACES; i++)
 		free(ifdict[i]);
diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h
index dba47e818466..9d2670f28d86 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.h
+++ b/tools/testing/selftests/bpf/xdpxceiver.h
@@ -21,6 +21,7 @@
 #define MAX_INTERFACE_NAME_CHARS 7
 #define MAX_INTERFACES_NAMESPACE_CHARS 10
 #define MAX_SOCKS 1
+#define MAX_TEARDOWN_ITER 10
 #define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \
 			sizeof(struct udphdr))
 #define MIN_PKT_SIZE 64
@@ -55,6 +56,7 @@ static u32 opt_xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
 static int opt_queue;
 static int opt_pkt_count;
 static int opt_poll;
+static int opt_teardown;
 static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
 static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE];
 static u32 pkt_counter;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH bpf-next v3 5/5] selftests/bpf: xsk selftests - Bi-directional Sockets - SKB, DRV
  2020-11-25 18:37 [PATCH bpf-next v3 0/5] selftests/bpf: xsk selftests Weqaar Janjua
                   ` (3 preceding siblings ...)
  2020-11-25 18:37 ` [PATCH bpf-next v3 4/5] selftests/bpf: xsk selftests - Socket Teardown - SKB, DRV Weqaar Janjua
@ 2020-11-25 18:37 ` Weqaar Janjua
  4 siblings, 0 replies; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-25 18:37 UTC (permalink / raw)
  To: bpf, netdev, daniel, ast, yhs, magnus.karlsson, bjorn.topel
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon

Adds following tests:

1. AF_XDP SKB mode
   d. Bi-directional Sockets
      Configure sockets as bi-directional tx/rx sockets, sets up fill
      and completion rings on each socket, tx/rx in both directions.
      Only nopoll mode is used

2. AF_XDP DRV/Native mode
   d. Bi-directional Sockets
   * Only copy mode is supported because veth does not currently support
     zero-copy mode

Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com>
---
 tools/testing/selftests/bpf/test_xsk.sh  |  24 ++++++
 tools/testing/selftests/bpf/xdpxceiver.c | 100 +++++++++++++++++------
 tools/testing/selftests/bpf/xdpxceiver.h |   4 +
 3 files changed, 104 insertions(+), 24 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
index 76de8080092d..05df57806d95 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -200,6 +200,30 @@ retval=$?
 test_status $retval "${TEST_NAME}"
 statusList+=($retval)
 
+### TEST 7
+TEST_NAME="SKB BIDIRECTIONAL SOCKETS"
+
+vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
+
+params=("-S" "-B")
+execxdpxceiver params
+
+retval=$?
+test_status $retval "${TEST_NAME}"
+statusList+=($retval)
+
+### TEST 8
+TEST_NAME="DRV BIDIRECTIONAL SOCKETS"
+
+vethXDPnative ${VETH0} ${VETH1} ${NS1}
+
+params=("-N" "-B")
+execxdpxceiver params
+
+retval=$?
+test_status $retval "${TEST_NAME}"
+statusList+=($retval)
+
 ## END TESTS
 
 cleanup_exit ${VETH0} ${VETH1} ${NS1}
diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c
index 62560e058111..5a508a94d8f9 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.c
+++ b/tools/testing/selftests/bpf/xdpxceiver.c
@@ -29,6 +29,10 @@
  *    c. Socket Teardown
  *       Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy
  *       both sockets, then repeat multiple times. Only nopoll mode is used
+ *    d. Bi-directional sockets
+ *       Configure sockets as bi-directional tx/rx sockets, sets up fill and
+ *       completion rings on each socket, tx/rx in both directions. Only nopoll
+ *       mode is used
  *
  * 2. AF_XDP DRV/Native mode
  *    Works on any netdevice with XDP_REDIRECT support, driver dependent. Processes
@@ -37,10 +41,11 @@
  *    a. nopoll
  *    b. poll
  *    c. Socket Teardown
+ *    d. Bi-directional sockets
  *    - Only copy mode is supported because veth does not currently support
  *      zero-copy mode
  *
- * Total tests: 6
+ * Total tests: 8
  *
  * Flow:
  * -----
@@ -100,8 +105,9 @@ static void __exit_with_error(int error, const char *file, const char *func, int
 #define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__)
 
 #define print_ksft_result(void)\
-	(ksft_test_result_pass("PASS: %s %s %s\n", uut ? "DRV" : "SKB", opt_poll ? "POLL" :\
-			       "NOPOLL", opt_teardown ? "Socket Teardown" : ""))
+	(ksft_test_result_pass("PASS: %s %s %s%s\n", uut ? "DRV" : "SKB", opt_poll ? "POLL" :\
+			       "NOPOLL", opt_teardown ? "Socket Teardown" : "",\
+			       opt_bidi ? "Bi-directional Sockets" : ""))
 
 static void pthread_init_mutex(void)
 {
@@ -307,8 +313,13 @@ static int xsk_configure_socket(struct ifobject *ifobject)
 	cfg.xdp_flags = opt_xdp_flags;
 	cfg.bind_flags = opt_xdp_bind_flags;
 
-	rxr = (ifobject->fv.vector == rx) ? &ifobject->xsk->rx : NULL;
-	txr = (ifobject->fv.vector == tx) ? &ifobject->xsk->tx : NULL;
+	if (!opt_bidi) {
+		rxr = (ifobject->fv.vector == rx) ? &ifobject->xsk->rx : NULL;
+		txr = (ifobject->fv.vector == tx) ? &ifobject->xsk->tx : NULL;
+	} else {
+		rxr = &ifobject->xsk->rx;
+		txr = &ifobject->xsk->tx;
+	}
 
 	ret = xsk_socket__create(&ifobject->xsk->xsk, ifobject->ifname,
 				 opt_queue, ifobject->umem->umem, rxr, txr, &cfg);
@@ -327,6 +338,7 @@ static struct option long_options[] = {
 	{"xdp-native", no_argument, 0, 'N'},
 	{"copy", no_argument, 0, 'c'},
 	{"tear-down", no_argument, 0, 'T'},
+	{"bidi", optional_argument, 0, 'B'},
 	{"debug", optional_argument, 0, 'D'},
 	{"tx-pkt-count", optional_argument, 0, 'C'},
 	{0, 0, 0, 0}
@@ -344,6 +356,7 @@ static void usage(const char *prog)
 	    "  -N, --xdp-native=n   Enforce XDP DRV (native) mode\n"
 	    "  -c, --copy           Force copy mode\n"
 	    "  -T, --tear-down      Tear down sockets by repeatedly recreating them\n"
+	    "  -B, --bidi           Bi-directional sockets test\n"
 	    "  -D, --debug          Debug mode - dump packets L2 - L5\n"
 	    "  -C, --tx-pkt-count=n Number of packets to send\n";
 	ksft_print_msg(str, prog);
@@ -434,7 +447,7 @@ static void parse_command_line(int argc, char **argv)
 	opterr = 0;
 
 	for (;;) {
-		c = getopt_long(argc, argv, "i:q:pSNcTDC:", long_options, &option_index);
+		c = getopt_long(argc, argv, "i:q:pSNcTBDC:", long_options, &option_index);
 
 		if (c == -1)
 			break;
@@ -475,6 +488,9 @@ static void parse_command_line(int argc, char **argv)
 		case 'T':
 			opt_teardown = 1;
 			break;
+		case 'B':
+			opt_bidi = 1;
+			break;
 		case 'D':
 			debug_pkt_dump = 1;
 			break;
@@ -784,22 +800,25 @@ static void *worker_testapp_validate(void *arg)
 	struct generic_data *data = (struct generic_data *)malloc(sizeof(struct generic_data));
 	struct iphdr *ip_hdr = (struct iphdr *)(pkt_data + sizeof(struct ethhdr));
 	struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data;
-	void *bufs;
+	void *bufs = NULL;
 
 	pthread_attr_setstacksize(&attr, THREAD_STACK);
 
-	bufs = mmap(NULL, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE,
-		    PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-	if (bufs == MAP_FAILED)
-		exit_with_error(errno);
+	if (!bidi_pass) {
+		bufs = mmap(NULL, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE,
+			    PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		if (bufs == MAP_FAILED)
+			exit_with_error(errno);
 
-	if (strcmp(((struct ifobject *)arg)->nsname, ""))
-		switch_namespace(((struct ifobject *)arg)->ifdict_index);
+		if (strcmp(((struct ifobject *)arg)->nsname, ""))
+			switch_namespace(((struct ifobject *)arg)->ifdict_index);
+	}
 
 	if (((struct ifobject *)arg)->fv.vector == tx) {
 		int spinningrxctr = 0;
 
-		thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_tx);
+		if (!bidi_pass)
+			thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_tx);
 
 		while (atomic_load(&spinning_rx) && spinningrxctr < SOCK_RECONF_CTR) {
 			spinningrxctr++;
@@ -829,7 +848,8 @@ static void *worker_testapp_validate(void *arg)
 		struct pollfd fds[MAX_SOCKS] = { };
 		int ret;
 
-		thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_rx);
+		if (!bidi_pass)
+			thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_rx);
 
 		ksft_print_msg("Interface [%s] vector [Rx]\n", ((struct ifobject *)arg)->ifname);
 		xsk_populate_fill_ring(((struct ifobject *)arg)->umem);
@@ -868,8 +888,10 @@ static void *worker_testapp_validate(void *arg)
 			ksft_print_msg("Destroying socket\n");
 	}
 
-	xsk_socket__delete(((struct ifobject *)arg)->xsk->xsk);
-	(void)xsk_umem__delete(((struct ifobject *)arg)->umem->umem);
+	if (!opt_bidi || (opt_bidi && bidi_pass)) {
+		xsk_socket__delete(((struct ifobject *)arg)->xsk->xsk);
+		(void)xsk_umem__delete(((struct ifobject *)arg)->umem->umem);
+	}
 	pthread_exit(NULL);
 }
 
@@ -878,11 +900,26 @@ static void testapp_validate(void)
 	pthread_attr_init(&attr);
 	pthread_attr_setstacksize(&attr, THREAD_STACK);
 
+	if (opt_bidi && bidi_pass) {
+		pthread_init_mutex();
+		if (!switching_notify) {
+			ksft_print_msg("Switching Tx/Rx vectors\n");
+			switching_notify++;
+		}
+	}
+
 	pthread_mutex_lock(&sync_mutex);
 
 	/*Spawn RX thread */
-	if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[1]))
-		exit_with_error(errno);
+	if (!opt_bidi || (opt_bidi && !bidi_pass)) {
+		if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[1]))
+			exit_with_error(errno);
+	} else if (opt_bidi && bidi_pass) {
+		/*switch Tx/Rx vectors */
+		ifdict[0]->fv.vector = rx;
+		if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[0]))
+			exit_with_error(errno);
+	}
 
 	struct timespec max_wait = { 0, 0 };
 
@@ -896,8 +933,15 @@ static void testapp_validate(void)
 	pthread_mutex_unlock(&sync_mutex);
 
 	/*Spawn TX thread */
-	if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[0]))
-		exit_with_error(errno);
+	if (!opt_bidi || (opt_bidi && !bidi_pass)) {
+		if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[0]))
+			exit_with_error(errno);
+	} else if (opt_bidi && bidi_pass) {
+		/*switch Tx/Rx vectors */
+		ifdict[1]->fv.vector = tx;
+		if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[1]))
+			exit_with_error(errno);
+	}
 
 	pthread_join(t1, NULL);
 	pthread_join(t0, NULL);
@@ -911,18 +955,19 @@ static void testapp_validate(void)
 		free(pkt_buf);
 	}
 
-	if (!opt_teardown)
+	if (!opt_teardown && !opt_bidi)
 		print_ksft_result();
 }
 
 static void testapp_sockets(void)
 {
-	for (int i = 0; i < MAX_TEARDOWN_ITER; i++) {
+	for (int i = 0; i < (opt_teardown ? MAX_TEARDOWN_ITER : MAX_BIDI_ITER); i++) {
 		pkt_counter = 0;
 		prev_pkt = -1;
 		sigvar = 0;
 		ksft_print_msg("Creating socket\n");
 		testapp_validate();
+		opt_bidi ? bidi_pass++ : bidi_pass;
 	}
 
 	print_ksft_result();
@@ -991,7 +1036,14 @@ int main(int argc, char **argv)
 
 	ksft_set_plan(1);
 
-	opt_teardown ? testapp_sockets() : testapp_validate();
+	if (!opt_teardown && !opt_bidi) {
+		testapp_validate();
+	} else if (opt_teardown && opt_bidi) {
+		ksft_test_result_fail("ERROR: parameters -T and -B cannot be used together\n");
+		ksft_exit_xfail();
+	} else {
+		testapp_sockets();
+	}
 
 	for (int i = 0; i < MAX_INTERFACES; i++)
 		free(ifdict[i]);
diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h
index 9d2670f28d86..d6630a19140b 100644
--- a/tools/testing/selftests/bpf/xdpxceiver.h
+++ b/tools/testing/selftests/bpf/xdpxceiver.h
@@ -22,6 +22,7 @@
 #define MAX_INTERFACES_NAMESPACE_CHARS 10
 #define MAX_SOCKS 1
 #define MAX_TEARDOWN_ITER 10
+#define MAX_BIDI_ITER 2
 #define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \
 			sizeof(struct udphdr))
 #define MIN_PKT_SIZE 64
@@ -51,12 +52,15 @@ enum TESTS {
 u8 uut;
 u8 debug_pkt_dump;
 u32 num_frames;
+u8 switching_notify;
+u8 bidi_pass;
 
 static u32 opt_xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
 static int opt_queue;
 static int opt_pkt_count;
 static int opt_poll;
 static int opt_teardown;
+static int opt_bidi;
 static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
 static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE];
 static u32 pkt_counter;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework
  2020-11-25 18:37 ` [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework Weqaar Janjua
@ 2020-11-26  6:44   ` Yonghong Song
  2020-11-26  9:01     ` Björn Töpel
  0 siblings, 1 reply; 15+ messages in thread
From: Yonghong Song @ 2020-11-26  6:44 UTC (permalink / raw)
  To: Weqaar Janjua, bpf, netdev, daniel, ast, magnus.karlsson, bjorn.topel
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon



On 11/25/20 10:37 AM, Weqaar Janjua wrote:
> This patch adds AF_XDP selftests framework under selftests/bpf.
> 
> Topology:
> ---------
>       -----------           -----------
>       |  xskX   | --------- |  xskY   |
>       -----------     |     -----------
>            |          |          |
>       -----------     |     ----------
>       |  vethX  | --------- |  vethY |
>       -----------   peer    ----------
>            |          |          |
>       namespaceX      |     namespaceY
> 
> Prerequisites setup by script test_xsk.sh:
> 
>     Set up veth interfaces as per the topology shown ^^:
>     * setup two veth interfaces and one namespace
>     ** veth<xxxx> in root namespace
>     ** veth<yyyy> in af_xdp<xxxx> namespace
>     ** namespace af_xdp<xxxx>
>     * create a spec file veth.spec that includes this run-time configuration
>     *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
>         conflict with any existing interface
>     * tests the veth and xsk layers of the topology
> 
> Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com>
> ---
>   tools/testing/selftests/bpf/Makefile       |   5 +-
>   tools/testing/selftests/bpf/test_xsk.sh    | 146 +++++++++++++++++++++
>   tools/testing/selftests/bpf/xsk_env.sh     |  11 ++
>   tools/testing/selftests/bpf/xsk_prereqs.sh | 119 +++++++++++++++++
>   4 files changed, 280 insertions(+), 1 deletion(-)
>   create mode 100755 tools/testing/selftests/bpf/test_xsk.sh
>   create mode 100755 tools/testing/selftests/bpf/xsk_env.sh
>   create mode 100755 tools/testing/selftests/bpf/xsk_prereqs.sh
> 
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 3d5940cd110d..596ee5c27906 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -46,7 +46,9 @@ endif
>   
>   TEST_GEN_FILES =
>   TEST_FILES = test_lwt_ip_encap.o \
> -	test_tc_edt.o
> +	test_tc_edt.o \
> +	xsk_prereqs.sh \
> +	xsk_env.sh
>   
>   # Order correspond to 'make run_tests' order
>   TEST_PROGS := test_kmod.sh \
> @@ -70,6 +72,7 @@ TEST_PROGS := test_kmod.sh \
>   	test_bpftool_build.sh \
>   	test_bpftool.sh \
>   	test_bpftool_metadata.sh \
> +	test_xsk.sh
>   
>   TEST_PROGS_EXTENDED := with_addr.sh \
>   	with_tunnels.sh \
> diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
> new file mode 100755
> index 000000000000..1836f2d2f617
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/test_xsk.sh
> @@ -0,0 +1,146 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright(c) 2020 Intel Corporation, Weqaar Janjua <weqaar.a.janjua@intel.com>
> +
> +# AF_XDP selftests based on veth
> +#
> +# End-to-end AF_XDP over Veth test
> +#
> +# Topology:
> +# ---------
> +#      -----------           -----------
> +#      |  xskX   | --------- |  xskY   |
> +#      -----------     |     -----------
> +#           |          |          |
> +#      -----------     |     ----------
> +#      |  vethX  | --------- |  vethY |
> +#      -----------   peer    ----------
> +#           |          |          |
> +#      namespaceX      |     namespaceY
> +#
> +# AF_XDP is an address family optimized for high performance packet processing,
> +# it is XDP’s user-space interface.
> +#
> +# An AF_XDP socket is linked to a single UMEM which is a region of virtual
> +# contiguous memory, divided into equal-sized frames.
> +#
> +# Refer to AF_XDP Kernel Documentation for detailed information:
> +# https://www.kernel.org/doc/html/latest/networking/af_xdp.html
> +#
> +# Prerequisites setup by script:
> +#
> +#   Set up veth interfaces as per the topology shown ^^:
> +#   * setup two veth interfaces and one namespace
> +#   ** veth<xxxx> in root namespace
> +#   ** veth<yyyy> in af_xdp<xxxx> namespace
> +#   ** namespace af_xdp<xxxx>
> +#   * create a spec file veth.spec that includes this run-time configuration
> +#   *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid
> +#       conflict with any existing interface
> +#   * tests the veth and xsk layers of the topology
> +#
> +# Kernel configuration:
> +# ---------------------
> +# See "config" file for recommended kernel config options.
> +#
> +# Turn on XDP sockets and veth support when compiling i.e.
> +# 	Networking support -->
> +# 		Networking options -->
> +# 			[ * ] XDP sockets
> +#
> +# Executing Tests:
> +# ----------------
> +# Must run with CAP_NET_ADMIN capability.
> +#
> +# Run (summary only):
> +#  sudo make summary=1 run_tests
> +#
> +# Run (full color-coded output):
> +#   sudo make colorconsole=1 run_tests
> +#
> +# Run (full output without color-coding):
> +#   sudo make run_tests
> +#
> +# Clean:
> +#  sudo make clean

Can I just run test_xsk.sh at tools/testing/selftests/bpf/ directory?
This will be easier than the above for bpf developers. If it does not 
work, I would like to recommend to make it work.

I did that and there are some test failures.

root@arch-fb-vm1:~/net-next/net-next/tools/testing/selftests/bpf 
./test_xsk.sh
[ 3857.572549] ip (2547) used greatest stack depth: 11864 bytes left 

setting up ve1417: root: 192.168.222.1/30 

setting up ve6185: af_xdp6185: 192.168.222.2/30 

[ 3857.673408] IPv6: ADDRCONF(NETDEV_CHANGE): ve6185: link becomes ready 

Spec file created: veth.spec 

PREREQUISITES: [ PASS ] 

# Interface found: ve1417 

# Interface found: ve6185 

# NS switched: af_xdp6185 

1..1 

# Interface [ve6185] vector [Rx] 

# Interface [ve1417] vector [Tx] 

# Sending 10000 packets on interface ve1417 

not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0] 

# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0 

SKB NOPOLL: [ FAIL ] 

# Interface found: ve1417 

# Interface found: ve6185 

# NS switched: af_xdp6185 

1..1 

# Interface [ve6185] vector [Rx] 

# Interface [ve1417] vector [Tx] 

# Sending 10000 packets on interface ve1417 

# End-of-tranmission frame received: PASS 

# Received 10000 packets on interface ve6185
ok 1 PASS: SKB POLL
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
SKB POLL: [ PASS ]
# Interface found: ve1417
# Interface found: ve6185
# NS switched: af_xdp6185
1..1
# Interface [ve6185] vector [Rx]
# Interface [ve1417] vector [Tx]
# Sending 10000 packets on interface ve1417
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [95], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV NOPOLL: [ FAIL ]
# Interface found: ve1417
# Interface found: ve6185
# NS switched: af_xdp6185
1..1
# Interface [ve6185] vector [Rx]
# Interface [ve1417] vector [Tx]
# Sending 10000 packets on interface ve1417
# End-of-tranmission frame received: PASS
# Received 10000 packets on interface ve6185
ok 1 PASS: DRV POLL
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
DRV POLL: [ PASS ]
# Interface found: ve1417
# Interface found: ve6185
# NS switched: af_xdp6185
1..1
# Creating socket
# Interface [ve6185] vector [Rx]
# Interface [ve1417] vector [Tx]
# Sending 10000 packets on interface ve1417
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [29], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
SKB SOCKET TEARDOWN: [ FAIL ]
# Interface found: ve1417
# Interface found: ve6185
# NS switched: af_xdp6185
1..1
# Creating socket
# Interface [ve6185] vector [Rx]
# Interface [ve1417] vector [Tx]
# Sending 10000 packets on interface ve1417
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [23], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV SOCKET TEARDOWN: [ FAIL ]
# Interface found: ve1417
# Interface found: ve6185
# NS switched: af_xdp6185
1..1
# Creating socket
# Interface [ve6185] vector [Rx]
# Interface [ve1417] vector [Tx]
# Sending 10000 packets on interface ve1417
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [88], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
SKB BIDIRECTIONAL SOCKETS: [ FAIL ]
# Interface found: ve1417
# Interface found: ve6185
# NS switched: af_xdp6185
1..1
# Creating socket
# Interface [ve6185] vector [Rx]
# Interface [ve1417] vector [Tx]
# Sending 10000 packets on interface ve1417
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [1], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV BIDIRECTIONAL SOCKETS: [ FAIL ]
cleaning up...
removing link ve6185
removing ns af_xdp6185
removing spec file: veth.spec
root@arch-fb-vm1:~/net-next/net-next/tools/testing/selftests/bpf

I do have the following
    CONFIG_VETH=y
    CONFIG_XDP_SOCKETS=y

What other configures I am missing?

BTW, I cherry-picked the following pick from bpf tree in this experiment.
   commit e7f4a5919bf66e530e08ff352d9b78ed89574e6b (HEAD -> xsk)
   Author: Björn Töpel <bjorn.topel@intel.com>
   Date:   Mon Nov 23 18:56:00 2020 +0100

       net, xsk: Avoid taking multiple skbuff references

> +
> +. xsk_prereqs.sh
> +
> +TEST_NAME="PREREQUISITES"
> +
> +URANDOM=/dev/urandom
> +[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; }
> +
> +VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
> +VETH0=ve${VETH0_POSTFIX}
> +VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4)
> +VETH1=ve${VETH1_POSTFIX}
> +NS1=af_xdp${VETH1_POSTFIX}
> +IPADDR_VETH0=192.168.222.1/30
> +IPADDR_VETH1=192.168.222.2/30
> +MTU=1500
> +
> +setup_vethPairs() {
> +	echo "setting up ${VETH0}: root: ${IPADDR_VETH0}"
> +	ip netns add ${NS1}
> +	ip link add ${VETH0} type veth peer name ${VETH1}
> +	ip addr add dev ${VETH0} ${IPADDR_VETH0}
> +	echo "setting up ${VETH1}: ${NS1}: ${IPADDR_VETH1}"
> +	ip link set ${VETH1} netns ${NS1}
> +	ip netns exec ${NS1} ip addr add dev ${VETH1} ${IPADDR_VETH1}
> +	ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU}
> +	ip netns exec ${NS1} ip link set ${VETH1} up
> +	ip link set ${VETH0} mtu ${MTU}
> +	ip link set ${VETH0} up
> +}
> +
> +validate_root_exec
> +validate_veth_support ${VETH0}
> +validate_configs
> +setup_vethPairs
> +
> +retval=$?
> +if [ $retval -ne 0 ]; then
> +	test_status $retval "${TEST_NAME}"
> +	cleanup_exit ${VETH0} ${VETH1} ${NS1}
> +	exit $retval
> +fi
> +
> +echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE}
> +
> +echo "Spec file created: ${SPECFILE}"
> +
> +test_status $retval "${TEST_NAME}"
> +
> +## START TESTS
> +
> +statusList=()
> +
> +### TEST 1
> +TEST_NAME="XSK FRAMEWORK"
> +
> +echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Generic mode"
> +vethXDPgeneric ${VETH0} ${VETH1} ${NS1}
> +
> +retval=$?
> +if [ $retval -eq 0 ]; then
> +	echo "Switching interfaces [${VETH0}, ${VETH1}] to XDP Native mode"
> +	vethXDPnative ${VETH0} ${VETH1} ${NS1}
> +fi
> +
> +retval=$?
> +test_status $retval "${TEST_NAME}"
> +statusList+=($retval)
> +
> +## END TESTS
> +
> +cleanup_exit ${VETH0} ${VETH1} ${NS1}
> +
> +for _status in "${statusList[@]}"
> +do
> +	if [ $_status -ne 0 ]; then
> +		test_exit $ksft_fail 0
> +	fi
> +done
> +
> +test_exit $ksft_pass 0
> diff --git a/tools/testing/selftests/bpf/xsk_env.sh b/tools/testing/selftests/bpf/xsk_env.sh
> new file mode 100755
> index 000000000000..2c41b4284cae
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/xsk_env.sh
> @@ -0,0 +1,11 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright(c) 2020 Intel Corporation.
> +
> +. xsk_prereqs.sh
> +
> +validate_veth_spec_file
> +
> +VETH0=$(cat ${SPECFILE} | cut -d':' -f 1)
> +VETH1=$(cat ${SPECFILE} | cut -d':' -f 2 | cut -d',' -f 1)
> +NS1=$(cat ${SPECFILE} | cut -d':' -f 2 | cut -d',' -f 2)
> diff --git a/tools/testing/selftests/bpf/xsk_prereqs.sh b/tools/testing/selftests/bpf/xsk_prereqs.sh
> new file mode 100755
> index 000000000000..694c5f5ab5e3
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/xsk_prereqs.sh
> @@ -0,0 +1,119 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright(c) 2020 Intel Corporation.
> +
> +ksft_pass=0
> +ksft_fail=1
> +ksft_xfail=2
> +ksft_xpass=3
> +ksft_skip=4
> +
> +GREEN='\033[0;92m'
> +YELLOW='\033[0;93m'
> +RED='\033[0;31m'
> +NC='\033[0m'
> +STACK_LIM=131072
> +SPECFILE=veth.spec
> +
> +validate_root_exec()
> +{
> +	msg="skip all tests:"
> +	if [ $UID != 0 ]; then
> +		echo $msg must be run as root >&2
> +		test_exit $ksft_fail 2
> +	else
> +		return $ksft_pass
> +	fi
> +}
> +
> +validate_veth_support()
> +{
> +	msg="skip all tests:"
> +	if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then
> +		echo $msg veth kernel support not available >&2
> +		test_exit $ksft_skip 1
> +	else
> +		ip link del $1
> +		return $ksft_pass
> +	fi
> +}
> +
> +validate_veth_spec_file()
> +{
> +	if [ ! -f ${SPECFILE} ]; then
> +		test_exit $ksft_skip 1
> +	fi
> +}
> +
> +test_status()
> +{
> +	statusval=$1
> +	if [ -n "${colorconsole+set}" ]; then
> +		if [ $statusval -eq 2 ]; then
> +			echo -e "${YELLOW}$2${NC}: [ ${RED}FAIL${NC} ]"
> +		elif [ $statusval -eq 1 ]; then
> +			echo -e "${YELLOW}$2${NC}: [ ${RED}SKIPPED${NC} ]"
> +		elif [ $statusval -eq 0 ]; then
> +			echo -e "${YELLOW}$2${NC}: [ ${GREEN}PASS${NC} ]"
> +		fi
> +	else
> +		if [ $statusval -eq 2 ]; then
> +			echo -e "$2: [ FAIL ]"
> +		elif [ $statusval -eq 1 ]; then
> +			echo -e "$2: [ SKIPPED ]"
> +		elif [ $statusval -eq 0 ]; then
> +			echo -e "$2: [ PASS ]"
> +		fi
> +	fi
> +}
> +
> +test_exit()
> +{
> +	retval=$1
> +	if [ $2 -ne 0 ]; then
> +		test_status $2 $(basename $0)
> +	fi
> +	exit $retval
> +}
> +
> +clear_configs()
> +{
> +	if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then
> +		[ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] &&
> +			{ echo "removing link $2"; ip netns exec $3 ip link del $2; }
> +		echo "removing ns $3"
> +		ip netns del $3
> +	fi
> +	#Once we delete a veth pair node, the entire veth pair is removed,
> +	#this is just to be cautious just incase the NS does not exist then
> +	#veth node inside NS won't get removed so we explicitly remove it
> +	[ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
> +		{ echo "removing link $1"; ip link del $1; }
> +	if [ -f ${SPECFILE} ]; then
> +		echo "removing spec file:" ${SPECFILE}
> +		rm -f ${SPECFILE}
> +	fi
> +}
> +
> +cleanup_exit()
> +{
> +	echo "cleaning up..."
> +	clear_configs $1 $2 $3
> +}
> +
> +validate_configs()
> +{
> +	[ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip 1; }
> +}
> +
> +vethXDPgeneric()
> +{
> +	ip link set dev $1 xdpdrv off
> +	ip netns exec $3 ip link set dev $2 xdpdrv off
> +}
> +
> +vethXDPnative()
> +{
> +	ip link set dev $1 xdpgeneric off
> +	ip netns exec $3 ip link set dev $2 xdpgeneric off
> +}
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework
  2020-11-26  6:44   ` Yonghong Song
@ 2020-11-26  9:01     ` Björn Töpel
  2020-11-26 21:22       ` Weqaar Janjua
  0 siblings, 1 reply; 15+ messages in thread
From: Björn Töpel @ 2020-11-26  9:01 UTC (permalink / raw)
  To: Yonghong Song, Weqaar Janjua, bpf, netdev, daniel, ast, magnus.karlsson
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon

On 2020-11-26 07:44, Yonghong Song wrote:
> 
[...]
> 
> What other configures I am missing?
> 
> BTW, I cherry-picked the following pick from bpf tree in this experiment.
>    commit e7f4a5919bf66e530e08ff352d9b78ed89574e6b (HEAD -> xsk)
>    Author: Björn Töpel <bjorn.topel@intel.com>
>    Date:   Mon Nov 23 18:56:00 2020 +0100
> 
>        net, xsk: Avoid taking multiple skbuff references
>

Hmm, I'm getting an oops, unless I cherry-pick:

36ccdf85829a ("net, xsk: Avoid taking multiple skbuff references")

*AND*

537cf4e3cc2f ("xsk: Fix umem cleanup bug at socket destruct")

from bpf/master.


Björn

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework
  2020-11-26  9:01     ` Björn Töpel
@ 2020-11-26 21:22       ` Weqaar Janjua
       [not found]         ` <9c73643f-0fdc-d867-6fe0-b3b8031a6cf2@fb.com>
  0 siblings, 1 reply; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-26 21:22 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Yonghong Song, bpf, netdev, Daniel Borkmann, ast,
	Magnus Karlsson, Weqaar Janjua, shuah, skhan, linux-kselftest,
	Anders Roxell, jonathan.lemon

On Thu, 26 Nov 2020 at 09:01, Björn Töpel <bjorn.topel@intel.com> wrote:
>
> On 2020-11-26 07:44, Yonghong Song wrote:
> >
> [...]
> >
> > What other configures I am missing?
> >
> > BTW, I cherry-picked the following pick from bpf tree in this experiment.
> >    commit e7f4a5919bf66e530e08ff352d9b78ed89574e6b (HEAD -> xsk)
> >    Author: Björn Töpel <bjorn.topel@intel.com>
> >    Date:   Mon Nov 23 18:56:00 2020 +0100
> >
> >        net, xsk: Avoid taking multiple skbuff references
> >
>
> Hmm, I'm getting an oops, unless I cherry-pick:
>
> 36ccdf85829a ("net, xsk: Avoid taking multiple skbuff references")
>
> *AND*
>
> 537cf4e3cc2f ("xsk: Fix umem cleanup bug at socket destruct")
>
> from bpf/master.
>

Same as Bjorn's findings ^^^, additionally applying the second patch
537cf4e3cc2f [PASS] all tests for me

PREREQUISITES: [ PASS ]
SKB NOPOLL: [ PASS ]
SKB POLL: [ PASS ]
DRV NOPOLL: [ PASS ]
DRV POLL: [ PASS ]
SKB SOCKET TEARDOWN: [ PASS ]
DRV SOCKET TEARDOWN: [ PASS ]
SKB BIDIRECTIONAL SOCKETS: [ PASS ]
DRV BIDIRECTIONAL SOCKETS: [ PASS ]

With the first patch alone, as soon as we enter DRV/Native NOPOLL mode
kernel panics, whereas in your case NOPOLL tests were falling with
packets being *lost* as per seqnum mismatch.

Can you please test this out with both patches and let us know?

> Can I just run test_xsk.sh at tools/testing/selftests/bpf/ directory?
> This will be easier than the above for bpf developers. If it does not
> work, I would like to recommend to make it work.
>
yes test_xsk.shis self contained, will update the instructions in there with v4.

Thanks,
/Weqaar
>
> Björn

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 2/5] selftests/bpf: xsk selftests - SKB POLL, NOPOLL
  2020-11-25 18:37 ` [PATCH bpf-next v3 2/5] selftests/bpf: xsk selftests - SKB POLL, NOPOLL Weqaar Janjua
@ 2020-11-27  4:31   ` Yonghong Song
  2020-11-27  9:01     ` Weqaar Janjua
  0 siblings, 1 reply; 15+ messages in thread
From: Yonghong Song @ 2020-11-27  4:31 UTC (permalink / raw)
  To: Weqaar Janjua, bpf, netdev, daniel, ast, magnus.karlsson, bjorn.topel
  Cc: Weqaar Janjua, shuah, skhan, linux-kselftest, anders.roxell,
	jonathan.lemon



On 11/25/20 10:37 AM, Weqaar Janjua wrote:
> Adds following tests:
> 
> 1. AF_XDP SKB mode
>     Generic mode XDP is driver independent, used when the driver does
>     not have support for XDP. Works on any netdevice using sockets and
>     generic XDP path. XDP hook from netif_receive_skb().
>     a. nopoll - soft-irq processing
>     b. poll - using poll() syscall
> 
> Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com>
> ---
>   tools/testing/selftests/bpf/Makefile     |   2 +-
>   tools/testing/selftests/bpf/test_xsk.sh  |  36 +-
>   tools/testing/selftests/bpf/xdpxceiver.c | 961 +++++++++++++++++++++++
>   tools/testing/selftests/bpf/xdpxceiver.h | 151 ++++
>   tools/testing/selftests/bpf/xsk_env.sh   |  17 +
>   5 files changed, 1158 insertions(+), 9 deletions(-)
>   create mode 100644 tools/testing/selftests/bpf/xdpxceiver.c
>   create mode 100644 tools/testing/selftests/bpf/xdpxceiver.h
> 
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 596ee5c27906..a2be2725be11 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -83,7 +83,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
>   # Compile but not part of 'make run_tests'
>   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
> +	test_lirc_mode2_user xdping test_cpp runqslower bench xdpxceiver
>   
>   TEST_CUSTOM_PROGS = urandom_read
>   
[...]
> +
> +static void parse_command_line(int argc, char **argv)
> +{
> +	int option_index, interface_index = 0, c;
> +
> +	opterr = 0;
> +
> +	for (;;) {
> +		c = getopt_long(argc, argv, "i:q:pScDC:", long_options, &option_index);
> +
> +		if (c == -1)
> +			break;
> +
> +		switch (c) {
> +		case 'i':
> +			if (interface_index == MAX_INTERFACES)
> +				break;
> +			char *sptr, *token;
> +
> +			memcpy(ifdict[interface_index]->ifname,
> +			       strtok_r(optarg, ",", &sptr), MAX_INTERFACE_NAME_CHARS);

During compilation, I hit the following compiler warnings,

xdpxceiver.c: In function ‘main’:
xdpxceiver.c:461:4: warning: ‘__s’ may be used uninitialized in this 
function [-Wmaybe-uninitialized]
     memcpy(ifdict[interface_index]->ifname,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            strtok_r(optarg, ",", &sptr), MAX_INTERFACE_NAME_CHARS);
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xdpxceiver.c:443:13: note: ‘__s’ was declared here
  static void parse_command_line(int argc, char **argv)
              ^~~~~~~~~~~~~~~~~~

I am using gcc8. I am not sure whether we should silence such
warning or not (-Wno-maybe-uninitialized). Did you see such a warning
during your compilation?

> +			token = strtok_r(NULL, ",", &sptr);
> +			if (token)
> +				memcpy(ifdict[interface_index]->nsname, token,
> +				       MAX_INTERFACES_NAMESPACE_CHARS);
> +			interface_index++;
> +			break;
> +		case 'q':
> +			opt_queue = atoi(optarg);
> +			break;
> +		case 'p':
> +			opt_poll = 1;
> +			break;
> +		case 'S':
> +			opt_xdp_flags |= XDP_FLAGS_SKB_MODE;
> +			opt_xdp_bind_flags |= XDP_COPY;
> +			uut = ORDER_CONTENT_VALIDATE_XDP_SKB;
> +			break;
> +		case 'c':
> +			opt_xdp_bind_flags |= XDP_COPY;
> +			break;
> +		case 'D':
> +			debug_pkt_dump = 1;
> +			break;
> +		case 'C':
> +			opt_pkt_count = atoi(optarg);
> +			break;
> +		default:
> +			usage(basename(argv[0]));
> +			ksft_exit_xfail();
> +		}
> +	}
> +
> +	if (!validate_interfaces()) {
> +		usage(basename(argv[0]));
> +		ksft_exit_xfail();
> +	}
> +}
> +
[...]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 2/5] selftests/bpf: xsk selftests - SKB POLL, NOPOLL
  2020-11-27  4:31   ` Yonghong Song
@ 2020-11-27  9:01     ` Weqaar Janjua
  0 siblings, 0 replies; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-27  9:01 UTC (permalink / raw)
  To: Yonghong Song
  Cc: bpf, netdev, Daniel Borkmann, ast, Magnus Karlsson,
	Björn Töpel, Weqaar Janjua, shuah, skhan,
	linux-kselftest, Anders Roxell, jonathan.lemon

On Fri, 27 Nov 2020 at 04:31, Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 11/25/20 10:37 AM, Weqaar Janjua wrote:
> > Adds following tests:
> >
> > 1. AF_XDP SKB mode
> >     Generic mode XDP is driver independent, used when the driver does
> >     not have support for XDP. Works on any netdevice using sockets and
> >     generic XDP path. XDP hook from netif_receive_skb().
> >     a. nopoll - soft-irq processing
> >     b. poll - using poll() syscall
> >
> > Signed-off-by: Weqaar Janjua <weqaar.a.janjua@intel.com>
> > ---
> >   tools/testing/selftests/bpf/Makefile     |   2 +-
> >   tools/testing/selftests/bpf/test_xsk.sh  |  36 +-
> >   tools/testing/selftests/bpf/xdpxceiver.c | 961 +++++++++++++++++++++++
> >   tools/testing/selftests/bpf/xdpxceiver.h | 151 ++++
> >   tools/testing/selftests/bpf/xsk_env.sh   |  17 +
> >   5 files changed, 1158 insertions(+), 9 deletions(-)
> >   create mode 100644 tools/testing/selftests/bpf/xdpxceiver.c
> >   create mode 100644 tools/testing/selftests/bpf/xdpxceiver.h
> >
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index 596ee5c27906..a2be2725be11 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -83,7 +83,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
> >   # Compile but not part of 'make run_tests'
> >   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
> > +     test_lirc_mode2_user xdping test_cpp runqslower bench xdpxceiver
> >
> >   TEST_CUSTOM_PROGS = urandom_read
> >
> [...]
> > +
> > +static void parse_command_line(int argc, char **argv)
> > +{
> > +     int option_index, interface_index = 0, c;
> > +
> > +     opterr = 0;
> > +
> > +     for (;;) {
> > +             c = getopt_long(argc, argv, "i:q:pScDC:", long_options, &option_index);
> > +
> > +             if (c == -1)
> > +                     break;
> > +
> > +             switch (c) {
> > +             case 'i':
> > +                     if (interface_index == MAX_INTERFACES)
> > +                             break;
> > +                     char *sptr, *token;
> > +
> > +                     memcpy(ifdict[interface_index]->ifname,
> > +                            strtok_r(optarg, ",", &sptr), MAX_INTERFACE_NAME_CHARS);
>
> During compilation, I hit the following compiler warnings,
>
> xdpxceiver.c: In function ‘main’:
> xdpxceiver.c:461:4: warning: ‘__s’ may be used uninitialized in this
> function [-Wmaybe-uninitialized]
>      memcpy(ifdict[interface_index]->ifname,
>      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>             strtok_r(optarg, ",", &sptr), MAX_INTERFACE_NAME_CHARS);
>             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> xdpxceiver.c:443:13: note: ‘__s’ was declared here
>   static void parse_command_line(int argc, char **argv)
>               ^~~~~~~~~~~~~~~~~~
>
> I am using gcc8. I am not sure whether we should silence such
> warning or not (-Wno-maybe-uninitialized). Did you see such a warning
> during your compilation?
>
Most probably you have hit gcc bug 71701, we do not see this warning
as our gcc builds might be different even though mine is 8, I will try
to get rid of strtok_r to avoid the whole thing.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71701

> > +                     token = strtok_r(NULL, ",", &sptr);
> > +                     if (token)
> > +                             memcpy(ifdict[interface_index]->nsname, token,
> > +                                    MAX_INTERFACES_NAMESPACE_CHARS);
> > +                     interface_index++;
> > +                     break;
> > +             case 'q':
> > +                     opt_queue = atoi(optarg);
> > +                     break;
> > +             case 'p':
> > +                     opt_poll = 1;
> > +                     break;
> > +             case 'S':
> > +                     opt_xdp_flags |= XDP_FLAGS_SKB_MODE;
> > +                     opt_xdp_bind_flags |= XDP_COPY;
> > +                     uut = ORDER_CONTENT_VALIDATE_XDP_SKB;
> > +                     break;
> > +             case 'c':
> > +                     opt_xdp_bind_flags |= XDP_COPY;
> > +                     break;
> > +             case 'D':
> > +                     debug_pkt_dump = 1;
> > +                     break;
> > +             case 'C':
> > +                     opt_pkt_count = atoi(optarg);
> > +                     break;
> > +             default:
> > +                     usage(basename(argv[0]));
> > +                     ksft_exit_xfail();
> > +             }
> > +     }
> > +
> > +     if (!validate_interfaces()) {
> > +             usage(basename(argv[0]));
> > +             ksft_exit_xfail();
> > +     }
> > +}
> > +
> [...]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework
       [not found]         ` <9c73643f-0fdc-d867-6fe0-b3b8031a6cf2@fb.com>
@ 2020-11-27 17:54           ` Weqaar Janjua
  2020-11-28  3:13             ` Yonghong Song
  0 siblings, 1 reply; 15+ messages in thread
From: Weqaar Janjua @ 2020-11-27 17:54 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Björn Töpel, bpf, netdev, Daniel Borkmann, ast,
	Magnus Karlsson, Weqaar Janjua, shuah, skhan, linux-kselftest,
	Anders Roxell, jonathan.lemon

On Fri, 27 Nov 2020 at 04:19, Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 11/26/20 1:22 PM, Weqaar Janjua wrote:
> > On Thu, 26 Nov 2020 at 09:01, Björn Töpel <bjorn.topel@intel.com> wrote:
> >>
> >> On 2020-11-26 07:44, Yonghong Song wrote:
> >>>
> >> [...]
> >>>
> >>> What other configures I am missing?
> >>>
> >>> BTW, I cherry-picked the following pick from bpf tree in this experiment.
> >>>     commit e7f4a5919bf66e530e08ff352d9b78ed89574e6b (HEAD -> xsk)
> >>>     Author: Björn Töpel <bjorn.topel@intel.com>
> >>>     Date:   Mon Nov 23 18:56:00 2020 +0100
> >>>
> >>>         net, xsk: Avoid taking multiple skbuff references
> >>>
> >>
> >> Hmm, I'm getting an oops, unless I cherry-pick:
> >>
> >> 36ccdf85829a ("net, xsk: Avoid taking multiple skbuff references")
> >>
> >> *AND*
> >>
> >> 537cf4e3cc2f ("xsk: Fix umem cleanup bug at socket destruct")
> >>
> >> from bpf/master.
> >>
> >
> > Same as Bjorn's findings ^^^, additionally applying the second patch
> > 537cf4e3cc2f [PASS] all tests for me
> >
> > PREREQUISITES: [ PASS ]
> > SKB NOPOLL: [ PASS ]
> > SKB POLL: [ PASS ]
> > DRV NOPOLL: [ PASS ]
> > DRV POLL: [ PASS ]
> > SKB SOCKET TEARDOWN: [ PASS ]
> > DRV SOCKET TEARDOWN: [ PASS ]
> > SKB BIDIRECTIONAL SOCKETS: [ PASS ]
> > DRV BIDIRECTIONAL SOCKETS: [ PASS ]
> >
> > With the first patch alone, as soon as we enter DRV/Native NOPOLL mode
> > kernel panics, whereas in your case NOPOLL tests were falling with
> > packets being *lost* as per seqnum mismatch.
> >
> > Can you please test this out with both patches and let us know?
>
> I applied both the above patches in bpf-next as well as this patch set,
> I still see failures. I am attaching my config file. Maybe you can take
> a look at what is the issue.
>
Thanks for the config, can you please confirm the compiler version,
and resource limits i.e. stack size, memory, etc.?

Only NOPOLL tests are failing for you as I see it, do the same tests
fail every time?

I will need to spend some time debugging this to have a fix.

Thanks,
/Weqaar

> >
> >> Can I just run test_xsk.sh at tools/testing/selftests/bpf/ directory?
> >> This will be easier than the above for bpf developers. If it does not
> >> work, I would like to recommend to make it work.
> >>
> > yes test_xsk.shis self contained, will update the instructions in there with v4.
>
> That will be great. Thanks!
>
> >
> > Thanks,
> > /Weqaar
> >>
> >> Björn

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework
  2020-11-27 17:54           ` Weqaar Janjua
@ 2020-11-28  3:13             ` Yonghong Song
  2020-12-07 21:55               ` Weqaar Janjua
  0 siblings, 1 reply; 15+ messages in thread
From: Yonghong Song @ 2020-11-28  3:13 UTC (permalink / raw)
  To: Weqaar Janjua
  Cc: Björn Töpel, bpf, netdev, Daniel Borkmann, ast,
	Magnus Karlsson, Weqaar Janjua, shuah, skhan, linux-kselftest,
	Anders Roxell, jonathan.lemon



On 11/27/20 9:54 AM, Weqaar Janjua wrote:
> On Fri, 27 Nov 2020 at 04:19, Yonghong Song <yhs@fb.com> wrote:
>>
>>
>>
>> On 11/26/20 1:22 PM, Weqaar Janjua wrote:
>>> On Thu, 26 Nov 2020 at 09:01, Björn Töpel <bjorn.topel@intel.com> wrote:
>>>>
>>>> On 2020-11-26 07:44, Yonghong Song wrote:
>>>>>
>>>> [...]
>>>>>
>>>>> What other configures I am missing?
>>>>>
>>>>> BTW, I cherry-picked the following pick from bpf tree in this experiment.
>>>>>      commit e7f4a5919bf66e530e08ff352d9b78ed89574e6b (HEAD -> xsk)
>>>>>      Author: Björn Töpel <bjorn.topel@intel.com>
>>>>>      Date:   Mon Nov 23 18:56:00 2020 +0100
>>>>>
>>>>>          net, xsk: Avoid taking multiple skbuff references
>>>>>
>>>>
>>>> Hmm, I'm getting an oops, unless I cherry-pick:
>>>>
>>>> 36ccdf85829a ("net, xsk: Avoid taking multiple skbuff references")
>>>>
>>>> *AND*
>>>>
>>>> 537cf4e3cc2f ("xsk: Fix umem cleanup bug at socket destruct")
>>>>
>>>> from bpf/master.
>>>>
>>>
>>> Same as Bjorn's findings ^^^, additionally applying the second patch
>>> 537cf4e3cc2f [PASS] all tests for me
>>>
>>> PREREQUISITES: [ PASS ]
>>> SKB NOPOLL: [ PASS ]
>>> SKB POLL: [ PASS ]
>>> DRV NOPOLL: [ PASS ]
>>> DRV POLL: [ PASS ]
>>> SKB SOCKET TEARDOWN: [ PASS ]
>>> DRV SOCKET TEARDOWN: [ PASS ]
>>> SKB BIDIRECTIONAL SOCKETS: [ PASS ]
>>> DRV BIDIRECTIONAL SOCKETS: [ PASS ]
>>>
>>> With the first patch alone, as soon as we enter DRV/Native NOPOLL mode
>>> kernel panics, whereas in your case NOPOLL tests were falling with
>>> packets being *lost* as per seqnum mismatch.
>>>
>>> Can you please test this out with both patches and let us know?
>>
>> I applied both the above patches in bpf-next as well as this patch set,
>> I still see failures. I am attaching my config file. Maybe you can take
>> a look at what is the issue.
>>
> Thanks for the config, can you please confirm the compiler version,
> and resource limits i.e. stack size, memory, etc.?

root@arch-fb-vm1:~/net-next/net-next/tools/testing/selftests/bpf ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 15587
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 15587
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

compiler: gcc 8.2

> 
> Only NOPOLL tests are failing for you as I see it, do the same tests
> fail every time?

In my case, with above two bpf patches applied as well, I got:
$ ./test_xsk.sh
setting up ve9127: root: 192.168.222.1/30 

setting up ve4520: af_xdp4520: 192.168.222.2/30 

Spec file created: veth.spec 

PREREQUISITES: [ PASS ] 

# Interface found: ve9127 

# Interface found: ve4520 

# NS switched: af_xdp4520 

1..1 

# Interface [ve4520] vector [Rx] 

# Interface [ve9127] vector [Tx] 

# Sending 10000 packets on interface ve9127 

not ok 1 ERROR: [worker_pkt_validate] prev_pkt [59], payloadseqnum [0] 

# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0 

SKB NOPOLL: [ FAIL ] 

# Interface found: ve9127 

# Interface found: ve4520 

# NS switched: af_xdp4520
# NS switched: af_xdp4520 

1..1
# Interface [ve4520] vector [Rx]
# Interface [ve9127] vector [Tx]
# Sending 10000 packets on interface ve9127
# End-of-tranmission frame received: PASS
# Received 10000 packets on interface ve4520
ok 1 PASS: SKB POLL
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
SKB POLL: [ PASS ]
# Interface found: ve9127
# Interface found: ve4520
# NS switched: af_xdp4520
1..1
# Interface [ve4520] vector [Rx]
# Interface [ve9127] vector [Tx]
# Sending 10000 packets on interface ve9127
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [153], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV NOPOLL: [ FAIL ]
# Interface found: ve9127
# Interface found: ve4520
# NS switched: af_xdp4520
1..1
# Interface [ve4520] vector [Rx]
# Interface [ve9127] vector [Tx]
# Sending 10000 packets on interface ve9127
# End-of-tranmission frame received: PASS
# Received 10000 packets on interface ve4520
ok 1 PASS: DRV POLL
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
DRV POLL: [ PASS ]
# Interface found: ve9127
# Interface found: ve4520
# NS switched: af_xdp4520
1..1
# Creating socket
# Interface [ve4520] vector [Rx]
# Interface [ve9127] vector [Tx]
# Sending 10000 packets on interface ve9127
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [54], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
SKB SOCKET TEARDOWN: [ FAIL ]
# Interface found: ve9127
# Interface found: ve4520
# NS switched: af_xdp4520
1..1
# Creating socket
# Interface [ve4520] vector [Rx]
# Interface [ve9127] vector [Tx]
# Sending 10000 packets on interface ve9127
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV SOCKET TEARDOWN: [ FAIL ]
# Interface found: ve9127
# Interface found: ve4520
# NS switched: af_xdp4520
1..1
# Creating socket
# Interface [ve4520] vector [Rx]
# Interface [ve9127] vector [Tx]
# Sending 10000 packets on interface ve9127
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [64], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
SKB BIDIRECTIONAL SOCKETS: [ FAIL ]
# Interface found: ve9127
# Interface found: ve4520
# NS switched: af_xdp4520
1..1
# Creating socket
# Interface [ve4520] vector [Rx]
# Interface [ve9127] vector [Tx]
# Sending 10000 packets on interface ve9127
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [83], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV BIDIRECTIONAL SOCKETS: [ FAIL ]
cleaning up...
removing link ve4520
removing ns af_xdp4520
removing spec file: veth.spec

Second runs have one previous success becoming failure.

./test_xsk.sh
setting up ve2458: root: 192.168.222.1/30 

setting up ve4468: af_xdp4468: 192.168.222.2/30 

[  286.597111] IPv6: ADDRCONF(NETDEV_CHANGE): ve4468: link becomes ready 

Spec file created: veth.spec 

PREREQUISITES: [ PASS ] 

# Interface found: ve2458 

# Interface found: ve4468 

# NS switched: af_xdp4468 

1..1 

# Interface [ve4468] vector [Rx] 

# Interface [ve2458] vector [Tx] 

# Sending 10000 packets on interface ve2458 

not ok 1 ERROR: [worker_pkt_validate] prev_pkt [67], payloadseqnum [0] 

# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0 

SKB NOPOLL: [ FAIL ] 

# Interface found: ve2458 

# Interface found: ve4468 

# NS switched: af_xdp4468 

1..1 

# Interface [ve4468] vector [Rx] 

# Interface [ve2458] vector [Tx] 

# Sending 10000 packets on interface ve2458 

# End-of-tranmission frame received: PASS
# Received 10000 packets on interface ve4468
ok 1 PASS: SKB POLL
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
SKB POLL: [ PASS ]
# Interface found: ve2458
# Interface found: ve4468
# NS switched: af_xdp4468
1..1
# Interface [ve4468] vector [Rx]
# Interface [ve2458] vector [Tx]
# Sending 10000 packets on interface ve2458
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [191], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV NOPOLL: [ FAIL ]
# Interface found: ve2458
# Interface found: ve4468
# NS switched: af_xdp4468
1..1
# Interface [ve4468] vector [Rx]
# Interface [ve2458] vector [Tx]
# Sending 10000 packets on interface ve2458
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV POLL: [ FAIL ]
# Interface found: ve2458
# Interface found: ve4468
# NS switched: af_xdp4468
1..1
# Creating socket
# Interface [ve4468] vector [Rx]
# Interface [ve2458] vector [Tx]
# Sending 10000 packets on interface ve2458
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
SKB SOCKET TEARDOWN: [ FAIL ]
# Interface found: ve2458
# Interface found: ve4468
# NS switched: af_xdp4468
1..1
# Creating socket
# Interface [ve4468] vector [Rx]
# Interface [ve2458] vector [Tx]
# Sending 10000 packets on interface ve2458
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [171], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV SOCKET TEARDOWN: [ FAIL ]
# Interface found: ve2458
# Interface found: ve4468
# NS switched: af_xdp4468
1..1
# Creating socket
# Interface [ve4468] vector [Rx]
# Interface [ve2458] vector [Tx]
# Sending 10000 packets on interface ve2458
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [124], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
SKB BIDIRECTIONAL SOCKETS: [ FAIL ]
# Interface found: ve2458
# Interface found: ve4468
# NS switched: af_xdp4468
1..1
# Creating socket
# Interface [ve4468] vector [Rx]
# Interface [ve2458] vector [Tx]
# Sending 10000 packets on interface ve2458
not ok 1 ERROR: [worker_pkt_validate] prev_pkt [195], payloadseqnum [0]
# Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
DRV BIDIRECTIONAL SOCKETS: [ FAIL ]
cleaning up...
removing link ve4468
removing ns af_xdp4468
removing spec file: veth.spec

> 
> I will need to spend some time debugging this to have a fix.

Thanks.

> 
> Thanks,
> /Weqaar
> 
>>>
>>>> Can I just run test_xsk.sh at tools/testing/selftests/bpf/ directory?
>>>> This will be easier than the above for bpf developers. If it does not
>>>> work, I would like to recommend to make it work.
>>>>
>>> yes test_xsk.shis self contained, will update the instructions in there with v4.
>>
>> That will be great. Thanks!
>>
>>>
>>> Thanks,
>>> /Weqaar
>>>>
>>>> Björn

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework
  2020-11-28  3:13             ` Yonghong Song
@ 2020-12-07 21:55               ` Weqaar Janjua
  2020-12-08  3:48                 ` Yonghong Song
  0 siblings, 1 reply; 15+ messages in thread
From: Weqaar Janjua @ 2020-12-07 21:55 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Björn Töpel, bpf, netdev, Daniel Borkmann, ast,
	Magnus Karlsson, Weqaar Janjua, shuah, skhan, linux-kselftest,
	Anders Roxell, jonathan.lemon

On Sat, 28 Nov 2020 at 03:13, Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 11/27/20 9:54 AM, Weqaar Janjua wrote:
> > On Fri, 27 Nov 2020 at 04:19, Yonghong Song <yhs@fb.com> wrote:
> >>
> >>
> >>
> >> On 11/26/20 1:22 PM, Weqaar Janjua wrote:
> >>> On Thu, 26 Nov 2020 at 09:01, Björn Töpel <bjorn.topel@intel.com> wrote:
> >>>>
> >>>> On 2020-11-26 07:44, Yonghong Song wrote:
> >>>>>
> >>>> [...]
> >>>>>
> >>>>> What other configures I am missing?
> >>>>>
> >>>>> BTW, I cherry-picked the following pick from bpf tree in this experiment.
> >>>>>      commit e7f4a5919bf66e530e08ff352d9b78ed89574e6b (HEAD -> xsk)
> >>>>>      Author: Björn Töpel <bjorn.topel@intel.com>
> >>>>>      Date:   Mon Nov 23 18:56:00 2020 +0100
> >>>>>
> >>>>>          net, xsk: Avoid taking multiple skbuff references
> >>>>>
> >>>>
> >>>> Hmm, I'm getting an oops, unless I cherry-pick:
> >>>>
> >>>> 36ccdf85829a ("net, xsk: Avoid taking multiple skbuff references")
> >>>>
> >>>> *AND*
> >>>>
> >>>> 537cf4e3cc2f ("xsk: Fix umem cleanup bug at socket destruct")
> >>>>
> >>>> from bpf/master.
> >>>>
> >>>
> >>> Same as Bjorn's findings ^^^, additionally applying the second patch
> >>> 537cf4e3cc2f [PASS] all tests for me
> >>>
> >>> PREREQUISITES: [ PASS ]
> >>> SKB NOPOLL: [ PASS ]
> >>> SKB POLL: [ PASS ]
> >>> DRV NOPOLL: [ PASS ]
> >>> DRV POLL: [ PASS ]
> >>> SKB SOCKET TEARDOWN: [ PASS ]
> >>> DRV SOCKET TEARDOWN: [ PASS ]
> >>> SKB BIDIRECTIONAL SOCKETS: [ PASS ]
> >>> DRV BIDIRECTIONAL SOCKETS: [ PASS ]
> >>>
> >>> With the first patch alone, as soon as we enter DRV/Native NOPOLL mode
> >>> kernel panics, whereas in your case NOPOLL tests were falling with
> >>> packets being *lost* as per seqnum mismatch.
> >>>
> >>> Can you please test this out with both patches and let us know?
> >>
> >> I applied both the above patches in bpf-next as well as this patch set,
> >> I still see failures. I am attaching my config file. Maybe you can take
> >> a look at what is the issue.
> >>
> > Thanks for the config, can you please confirm the compiler version,
> > and resource limits i.e. stack size, memory, etc.?
>
> root@arch-fb-vm1:~/net-next/net-next/tools/testing/selftests/bpf ulimit -a
> core file size          (blocks, -c) unlimited
> data seg size           (kbytes, -d) unlimited
> scheduling priority             (-e) 0
> file size               (blocks, -f) unlimited
> pending signals                 (-i) 15587
> max locked memory       (kbytes, -l) unlimited
> max memory size         (kbytes, -m) unlimited
> open files                      (-n) 1024
> pipe size            (512 bytes, -p) 8
> POSIX message queues     (bytes, -q) 819200
> real-time priority              (-r) 0
> stack size              (kbytes, -s) 8192
> cpu time               (seconds, -t) unlimited
> max user processes              (-u) 15587
> virtual memory          (kbytes, -v) unlimited
> file locks                      (-x) unlimited
>
> compiler: gcc 8.2
>
> >
> > Only NOPOLL tests are failing for you as I see it, do the same tests
> > fail every time?
>
> In my case, with above two bpf patches applied as well, I got:
> $ ./test_xsk.sh
> setting up ve9127: root: 192.168.222.1/30
>
> setting up ve4520: af_xdp4520: 192.168.222.2/30
>
> Spec file created: veth.spec
>
> PREREQUISITES: [ PASS ]
>
> # Interface found: ve9127
>
> # Interface found: ve4520
>
> # NS switched: af_xdp4520
>
> 1..1
>
> # Interface [ve4520] vector [Rx]
>
> # Interface [ve9127] vector [Tx]
>
> # Sending 10000 packets on interface ve9127
>
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [59], payloadseqnum [0]
>
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>
> SKB NOPOLL: [ FAIL ]
>
> # Interface found: ve9127
>
> # Interface found: ve4520
>
> # NS switched: af_xdp4520
> # NS switched: af_xdp4520
>
> 1..1
> # Interface [ve4520] vector [Rx]
> # Interface [ve9127] vector [Tx]
> # Sending 10000 packets on interface ve9127
> # End-of-tranmission frame received: PASS
> # Received 10000 packets on interface ve4520
> ok 1 PASS: SKB POLL
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> SKB POLL: [ PASS ]
> # Interface found: ve9127
> # Interface found: ve4520
> # NS switched: af_xdp4520
> 1..1
> # Interface [ve4520] vector [Rx]
> # Interface [ve9127] vector [Tx]
> # Sending 10000 packets on interface ve9127
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [153], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> DRV NOPOLL: [ FAIL ]
> # Interface found: ve9127
> # Interface found: ve4520
> # NS switched: af_xdp4520
> 1..1
> # Interface [ve4520] vector [Rx]
> # Interface [ve9127] vector [Tx]
> # Sending 10000 packets on interface ve9127
> # End-of-tranmission frame received: PASS
> # Received 10000 packets on interface ve4520
> ok 1 PASS: DRV POLL
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> DRV POLL: [ PASS ]
> # Interface found: ve9127
> # Interface found: ve4520
> # NS switched: af_xdp4520
> 1..1
> # Creating socket
> # Interface [ve4520] vector [Rx]
> # Interface [ve9127] vector [Tx]
> # Sending 10000 packets on interface ve9127
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [54], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> SKB SOCKET TEARDOWN: [ FAIL ]
> # Interface found: ve9127
> # Interface found: ve4520
> # NS switched: af_xdp4520
> 1..1
> # Creating socket
> # Interface [ve4520] vector [Rx]
> # Interface [ve9127] vector [Tx]
> # Sending 10000 packets on interface ve9127
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> DRV SOCKET TEARDOWN: [ FAIL ]
> # Interface found: ve9127
> # Interface found: ve4520
> # NS switched: af_xdp4520
> 1..1
> # Creating socket
> # Interface [ve4520] vector [Rx]
> # Interface [ve9127] vector [Tx]
> # Sending 10000 packets on interface ve9127
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [64], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> SKB BIDIRECTIONAL SOCKETS: [ FAIL ]
> # Interface found: ve9127
> # Interface found: ve4520
> # NS switched: af_xdp4520
> 1..1
> # Creating socket
> # Interface [ve4520] vector [Rx]
> # Interface [ve9127] vector [Tx]
> # Sending 10000 packets on interface ve9127
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [83], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> DRV BIDIRECTIONAL SOCKETS: [ FAIL ]
> cleaning up...
> removing link ve4520
> removing ns af_xdp4520
> removing spec file: veth.spec
>
> Second runs have one previous success becoming failure.
>
> ./test_xsk.sh
> setting up ve2458: root: 192.168.222.1/30
>
> setting up ve4468: af_xdp4468: 192.168.222.2/30
>
> [  286.597111] IPv6: ADDRCONF(NETDEV_CHANGE): ve4468: link becomes ready
>
> Spec file created: veth.spec
>
> PREREQUISITES: [ PASS ]
>
> # Interface found: ve2458
>
> # Interface found: ve4468
>
> # NS switched: af_xdp4468
>
> 1..1
>
> # Interface [ve4468] vector [Rx]
>
> # Interface [ve2458] vector [Tx]
>
> # Sending 10000 packets on interface ve2458
>
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [67], payloadseqnum [0]
>
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>
> SKB NOPOLL: [ FAIL ]
>
> # Interface found: ve2458
>
> # Interface found: ve4468
>
> # NS switched: af_xdp4468
>
> 1..1
>
> # Interface [ve4468] vector [Rx]
>
> # Interface [ve2458] vector [Tx]
>
> # Sending 10000 packets on interface ve2458
>
> # End-of-tranmission frame received: PASS
> # Received 10000 packets on interface ve4468
> ok 1 PASS: SKB POLL
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> SKB POLL: [ PASS ]
> # Interface found: ve2458
> # Interface found: ve4468
> # NS switched: af_xdp4468
> 1..1
> # Interface [ve4468] vector [Rx]
> # Interface [ve2458] vector [Tx]
> # Sending 10000 packets on interface ve2458
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [191], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> DRV NOPOLL: [ FAIL ]
> # Interface found: ve2458
> # Interface found: ve4468
> # NS switched: af_xdp4468
> 1..1
> # Interface [ve4468] vector [Rx]
> # Interface [ve2458] vector [Tx]
> # Sending 10000 packets on interface ve2458
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> DRV POLL: [ FAIL ]
> # Interface found: ve2458
> # Interface found: ve4468
> # NS switched: af_xdp4468
> 1..1
> # Creating socket
> # Interface [ve4468] vector [Rx]
> # Interface [ve2458] vector [Tx]
> # Sending 10000 packets on interface ve2458
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> SKB SOCKET TEARDOWN: [ FAIL ]
> # Interface found: ve2458
> # Interface found: ve4468
> # NS switched: af_xdp4468
> 1..1
> # Creating socket
> # Interface [ve4468] vector [Rx]
> # Interface [ve2458] vector [Tx]
> # Sending 10000 packets on interface ve2458
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [171], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> DRV SOCKET TEARDOWN: [ FAIL ]
> # Interface found: ve2458
> # Interface found: ve4468
> # NS switched: af_xdp4468
> 1..1
> # Creating socket
> # Interface [ve4468] vector [Rx]
> # Interface [ve2458] vector [Tx]
> # Sending 10000 packets on interface ve2458
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [124], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> SKB BIDIRECTIONAL SOCKETS: [ FAIL ]
> # Interface found: ve2458
> # Interface found: ve4468
> # NS switched: af_xdp4468
> 1..1
> # Creating socket
> # Interface [ve4468] vector [Rx]
> # Interface [ve2458] vector [Tx]
> # Sending 10000 packets on interface ve2458
> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [195], payloadseqnum [0]
> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> DRV BIDIRECTIONAL SOCKETS: [ FAIL ]
> cleaning up...
> removing link ve4468
> removing ns af_xdp4468
> removing spec file: veth.spec
>
> >
> > I will need to spend some time debugging this to have a fix.
>
> Thanks.
>
> >
> > Thanks,
> > /Weqaar
> >
> >>>
> >>>> Can I just run test_xsk.sh at tools/testing/selftests/bpf/ directory?
> >>>> This will be easier than the above for bpf developers. If it does not
> >>>> work, I would like to recommend to make it work.
> >>>>
> >>> yes test_xsk.shis self contained, will update the instructions in there with v4.
> >>
> >> That will be great. Thanks!
> >>
v4 is out on the list, incorporating most if not all your suggestions
to the best of my memory.

I was able to reproduce the issue you were seeing (from your logs) ->
veth interfaces were receiving packets from the IPv6 neighboring
system (thanks @Björn Töpel for mentioning this).

The packet validation algo in *xdpxceiver* *assumed* all packets would
be IPv4 and intended for Rx.
Rx validates packets on both ip->tos = 0x9 (id for xsk tests) and
ip->version = 0x4, ignores the rest.

Hoping the tests now work -> PASS in your environment.

Thanks,
/Weqaar

> >>>
> >>> Thanks,
> >>> /Weqaar
> >>>>
> >>>> Björn

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework
  2020-12-07 21:55               ` Weqaar Janjua
@ 2020-12-08  3:48                 ` Yonghong Song
  0 siblings, 0 replies; 15+ messages in thread
From: Yonghong Song @ 2020-12-08  3:48 UTC (permalink / raw)
  To: Weqaar Janjua
  Cc: Björn Töpel, bpf, netdev, Daniel Borkmann, ast,
	Magnus Karlsson, Weqaar Janjua, shuah, skhan, linux-kselftest,
	Anders Roxell, jonathan.lemon



On 12/7/20 1:55 PM, Weqaar Janjua wrote:
> On Sat, 28 Nov 2020 at 03:13, Yonghong Song <yhs@fb.com> wrote:
>>
>>
>>
>> On 11/27/20 9:54 AM, Weqaar Janjua wrote:
>>> On Fri, 27 Nov 2020 at 04:19, Yonghong Song <yhs@fb.com> wrote:
>>>>
>>>>
>>>>
>>>> On 11/26/20 1:22 PM, Weqaar Janjua wrote:
>>>>> On Thu, 26 Nov 2020 at 09:01, Björn Töpel <bjorn.topel@intel.com> wrote:
>>>>>>
>>>>>> On 2020-11-26 07:44, Yonghong Song wrote:
>>>>>>>
>>>>>> [...]
>>>>>>>
>>>>>>> What other configures I am missing?
>>>>>>>
>>>>>>> BTW, I cherry-picked the following pick from bpf tree in this experiment.
>>>>>>>       commit e7f4a5919bf66e530e08ff352d9b78ed89574e6b (HEAD -> xsk)
>>>>>>>       Author: Björn Töpel <bjorn.topel@intel.com>
>>>>>>>       Date:   Mon Nov 23 18:56:00 2020 +0100
>>>>>>>
>>>>>>>           net, xsk: Avoid taking multiple skbuff references
>>>>>>>
>>>>>>
>>>>>> Hmm, I'm getting an oops, unless I cherry-pick:
>>>>>>
>>>>>> 36ccdf85829a ("net, xsk: Avoid taking multiple skbuff references")
>>>>>>
>>>>>> *AND*
>>>>>>
>>>>>> 537cf4e3cc2f ("xsk: Fix umem cleanup bug at socket destruct")
>>>>>>
>>>>>> from bpf/master.
>>>>>>
>>>>>
>>>>> Same as Bjorn's findings ^^^, additionally applying the second patch
>>>>> 537cf4e3cc2f [PASS] all tests for me
>>>>>
>>>>> PREREQUISITES: [ PASS ]
>>>>> SKB NOPOLL: [ PASS ]
>>>>> SKB POLL: [ PASS ]
>>>>> DRV NOPOLL: [ PASS ]
>>>>> DRV POLL: [ PASS ]
>>>>> SKB SOCKET TEARDOWN: [ PASS ]
>>>>> DRV SOCKET TEARDOWN: [ PASS ]
>>>>> SKB BIDIRECTIONAL SOCKETS: [ PASS ]
>>>>> DRV BIDIRECTIONAL SOCKETS: [ PASS ]
>>>>>
>>>>> With the first patch alone, as soon as we enter DRV/Native NOPOLL mode
>>>>> kernel panics, whereas in your case NOPOLL tests were falling with
>>>>> packets being *lost* as per seqnum mismatch.
>>>>>
>>>>> Can you please test this out with both patches and let us know?
>>>>
>>>> I applied both the above patches in bpf-next as well as this patch set,
>>>> I still see failures. I am attaching my config file. Maybe you can take
>>>> a look at what is the issue.
>>>>
>>> Thanks for the config, can you please confirm the compiler version,
>>> and resource limits i.e. stack size, memory, etc.?
>>
>> root@arch-fb-vm1:~/net-next/net-next/tools/testing/selftests/bpf ulimit -a
>> core file size          (blocks, -c) unlimited
>> data seg size           (kbytes, -d) unlimited
>> scheduling priority             (-e) 0
>> file size               (blocks, -f) unlimited
>> pending signals                 (-i) 15587
>> max locked memory       (kbytes, -l) unlimited
>> max memory size         (kbytes, -m) unlimited
>> open files                      (-n) 1024
>> pipe size            (512 bytes, -p) 8
>> POSIX message queues     (bytes, -q) 819200
>> real-time priority              (-r) 0
>> stack size              (kbytes, -s) 8192
>> cpu time               (seconds, -t) unlimited
>> max user processes              (-u) 15587
>> virtual memory          (kbytes, -v) unlimited
>> file locks                      (-x) unlimited
>>
>> compiler: gcc 8.2
>>
>>>
>>> Only NOPOLL tests are failing for you as I see it, do the same tests
>>> fail every time?
>>
>> In my case, with above two bpf patches applied as well, I got:
>> $ ./test_xsk.sh
>> setting up ve9127: root: 192.168.222.1/30
>>
>> setting up ve4520: af_xdp4520: 192.168.222.2/30
>>
>> Spec file created: veth.spec
>>
>> PREREQUISITES: [ PASS ]
>>
>> # Interface found: ve9127
>>
>> # Interface found: ve4520
>>
>> # NS switched: af_xdp4520
>>
>> 1..1
>>
>> # Interface [ve4520] vector [Rx]
>>
>> # Interface [ve9127] vector [Tx]
>>
>> # Sending 10000 packets on interface ve9127
>>
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [59], payloadseqnum [0]
>>
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>>
>> SKB NOPOLL: [ FAIL ]
>>
>> # Interface found: ve9127
>>
>> # Interface found: ve4520
>>
>> # NS switched: af_xdp4520
>> # NS switched: af_xdp4520
>>
>> 1..1
>> # Interface [ve4520] vector [Rx]
>> # Interface [ve9127] vector [Tx]
>> # Sending 10000 packets on interface ve9127
>> # End-of-tranmission frame received: PASS
>> # Received 10000 packets on interface ve4520
>> ok 1 PASS: SKB POLL
>> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
>> SKB POLL: [ PASS ]
>> # Interface found: ve9127
>> # Interface found: ve4520
>> # NS switched: af_xdp4520
>> 1..1
>> # Interface [ve4520] vector [Rx]
>> # Interface [ve9127] vector [Tx]
>> # Sending 10000 packets on interface ve9127
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [153], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> DRV NOPOLL: [ FAIL ]
>> # Interface found: ve9127
>> # Interface found: ve4520
>> # NS switched: af_xdp4520
>> 1..1
>> # Interface [ve4520] vector [Rx]
>> # Interface [ve9127] vector [Tx]
>> # Sending 10000 packets on interface ve9127
>> # End-of-tranmission frame received: PASS
>> # Received 10000 packets on interface ve4520
>> ok 1 PASS: DRV POLL
>> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
>> DRV POLL: [ PASS ]
>> # Interface found: ve9127
>> # Interface found: ve4520
>> # NS switched: af_xdp4520
>> 1..1
>> # Creating socket
>> # Interface [ve4520] vector [Rx]
>> # Interface [ve9127] vector [Tx]
>> # Sending 10000 packets on interface ve9127
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [54], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> SKB SOCKET TEARDOWN: [ FAIL ]
>> # Interface found: ve9127
>> # Interface found: ve4520
>> # NS switched: af_xdp4520
>> 1..1
>> # Creating socket
>> # Interface [ve4520] vector [Rx]
>> # Interface [ve9127] vector [Tx]
>> # Sending 10000 packets on interface ve9127
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> DRV SOCKET TEARDOWN: [ FAIL ]
>> # Interface found: ve9127
>> # Interface found: ve4520
>> # NS switched: af_xdp4520
>> 1..1
>> # Creating socket
>> # Interface [ve4520] vector [Rx]
>> # Interface [ve9127] vector [Tx]
>> # Sending 10000 packets on interface ve9127
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [64], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> SKB BIDIRECTIONAL SOCKETS: [ FAIL ]
>> # Interface found: ve9127
>> # Interface found: ve4520
>> # NS switched: af_xdp4520
>> 1..1
>> # Creating socket
>> # Interface [ve4520] vector [Rx]
>> # Interface [ve9127] vector [Tx]
>> # Sending 10000 packets on interface ve9127
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [83], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> DRV BIDIRECTIONAL SOCKETS: [ FAIL ]
>> cleaning up...
>> removing link ve4520
>> removing ns af_xdp4520
>> removing spec file: veth.spec
>>
>> Second runs have one previous success becoming failure.
>>
>> ./test_xsk.sh
>> setting up ve2458: root: 192.168.222.1/30
>>
>> setting up ve4468: af_xdp4468: 192.168.222.2/30
>>
>> [  286.597111] IPv6: ADDRCONF(NETDEV_CHANGE): ve4468: link becomes ready
>>
>> Spec file created: veth.spec
>>
>> PREREQUISITES: [ PASS ]
>>
>> # Interface found: ve2458
>>
>> # Interface found: ve4468
>>
>> # NS switched: af_xdp4468
>>
>> 1..1
>>
>> # Interface [ve4468] vector [Rx]
>>
>> # Interface [ve2458] vector [Tx]
>>
>> # Sending 10000 packets on interface ve2458
>>
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [67], payloadseqnum [0]
>>
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>>
>> SKB NOPOLL: [ FAIL ]
>>
>> # Interface found: ve2458
>>
>> # Interface found: ve4468
>>
>> # NS switched: af_xdp4468
>>
>> 1..1
>>
>> # Interface [ve4468] vector [Rx]
>>
>> # Interface [ve2458] vector [Tx]
>>
>> # Sending 10000 packets on interface ve2458
>>
>> # End-of-tranmission frame received: PASS
>> # Received 10000 packets on interface ve4468
>> ok 1 PASS: SKB POLL
>> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
>> SKB POLL: [ PASS ]
>> # Interface found: ve2458
>> # Interface found: ve4468
>> # NS switched: af_xdp4468
>> 1..1
>> # Interface [ve4468] vector [Rx]
>> # Interface [ve2458] vector [Tx]
>> # Sending 10000 packets on interface ve2458
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [191], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> DRV NOPOLL: [ FAIL ]
>> # Interface found: ve2458
>> # Interface found: ve4468
>> # NS switched: af_xdp4468
>> 1..1
>> # Interface [ve4468] vector [Rx]
>> # Interface [ve2458] vector [Tx]
>> # Sending 10000 packets on interface ve2458
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> DRV POLL: [ FAIL ]
>> # Interface found: ve2458
>> # Interface found: ve4468
>> # NS switched: af_xdp4468
>> 1..1
>> # Creating socket
>> # Interface [ve4468] vector [Rx]
>> # Interface [ve2458] vector [Tx]
>> # Sending 10000 packets on interface ve2458
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [0], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> SKB SOCKET TEARDOWN: [ FAIL ]
>> # Interface found: ve2458
>> # Interface found: ve4468
>> # NS switched: af_xdp4468
>> 1..1
>> # Creating socket
>> # Interface [ve4468] vector [Rx]
>> # Interface [ve2458] vector [Tx]
>> # Sending 10000 packets on interface ve2458
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [171], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> DRV SOCKET TEARDOWN: [ FAIL ]
>> # Interface found: ve2458
>> # Interface found: ve4468
>> # NS switched: af_xdp4468
>> 1..1
>> # Creating socket
>> # Interface [ve4468] vector [Rx]
>> # Interface [ve2458] vector [Tx]
>> # Sending 10000 packets on interface ve2458
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [124], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> SKB BIDIRECTIONAL SOCKETS: [ FAIL ]
>> # Interface found: ve2458
>> # Interface found: ve4468
>> # NS switched: af_xdp4468
>> 1..1
>> # Creating socket
>> # Interface [ve4468] vector [Rx]
>> # Interface [ve2458] vector [Tx]
>> # Sending 10000 packets on interface ve2458
>> not ok 1 ERROR: [worker_pkt_validate] prev_pkt [195], payloadseqnum [0]
>> # Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
>> DRV BIDIRECTIONAL SOCKETS: [ FAIL ]
>> cleaning up...
>> removing link ve4468
>> removing ns af_xdp4468
>> removing spec file: veth.spec
>>
>>>
>>> I will need to spend some time debugging this to have a fix.
>>
>> Thanks.
>>
>>>
>>> Thanks,
>>> /Weqaar
>>>
>>>>>
>>>>>> Can I just run test_xsk.sh at tools/testing/selftests/bpf/ directory?
>>>>>> This will be easier than the above for bpf developers. If it does not
>>>>>> work, I would like to recommend to make it work.
>>>>>>
>>>>> yes test_xsk.shis self contained, will update the instructions in there with v4.
>>>>
>>>> That will be great. Thanks!
>>>>
> v4 is out on the list, incorporating most if not all your suggestions
> to the best of my memory.
> 
> I was able to reproduce the issue you were seeing (from your logs) ->
> veth interfaces were receiving packets from the IPv6 neighboring
> system (thanks @Björn Töpel for mentioning this).
> 
> The packet validation algo in *xdpxceiver* *assumed* all packets would
> be IPv4 and intended for Rx.
> Rx validates packets on both ip->tos = 0x9 (id for xsk tests) and
> ip->version = 0x4, ignores the rest.
> 
> Hoping the tests now work -> PASS in your environment.

Yes, no all tests passed in my environment. I will reply the v4
with Test-by tag. Now I think xsk people can really look at details.

> 
> Thanks,
> /Weqaar
> 
>>>>>
>>>>> Thanks,
>>>>> /Weqaar
>>>>>>
>>>>>> Björn

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-12-08  3:49 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 18:37 [PATCH bpf-next v3 0/5] selftests/bpf: xsk selftests Weqaar Janjua
2020-11-25 18:37 ` [PATCH bpf-next v3 1/5] selftests/bpf: xsk selftests framework Weqaar Janjua
2020-11-26  6:44   ` Yonghong Song
2020-11-26  9:01     ` Björn Töpel
2020-11-26 21:22       ` Weqaar Janjua
     [not found]         ` <9c73643f-0fdc-d867-6fe0-b3b8031a6cf2@fb.com>
2020-11-27 17:54           ` Weqaar Janjua
2020-11-28  3:13             ` Yonghong Song
2020-12-07 21:55               ` Weqaar Janjua
2020-12-08  3:48                 ` Yonghong Song
2020-11-25 18:37 ` [PATCH bpf-next v3 2/5] selftests/bpf: xsk selftests - SKB POLL, NOPOLL Weqaar Janjua
2020-11-27  4:31   ` Yonghong Song
2020-11-27  9:01     ` Weqaar Janjua
2020-11-25 18:37 ` [PATCH bpf-next v3 3/5] selftests/bpf: xsk selftests - DRV " Weqaar Janjua
2020-11-25 18:37 ` [PATCH bpf-next v3 4/5] selftests/bpf: xsk selftests - Socket Teardown - SKB, DRV Weqaar Janjua
2020-11-25 18:37 ` [PATCH bpf-next v3 5/5] selftests/bpf: xsk selftests - Bi-directional Sockets " Weqaar Janjua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).