OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>, devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v4 3/3] selftests/bpf: run the xsk veth tests in a network namespace of their own
Date: Tue, 27 Oct 2026 19:15:21 +0100	[thread overview]
Message-ID: <20261027-b4-prep-khorenko-vstor-150731-xsk-veth-netns-v4-3-c74cad570c70@virtuozzo.com> (raw)
In-Reply-To: <20261027-b4-prep-khorenko-vstor-150731-xsk-veth-netns-v4-0-c74cad570c70@virtuozzo.com>

From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>

test_xsk.sh makes its veth pair in the namespace it runs in, and the
host treats it as any new interface: address configuration, neighbour
discovery and the like happen on that pair. The AF_XDP sockets under
test receive the host's packets among their own. The tests count and
inspect what they receive, so they fail on a configured host and pass
on a bare one.

Re-run the veth part in an unnamed network namespace with a sysfs of its
own, which the busy poll setup writes to. The namespace goes away with
its last process however the run ends, and takes the pair with it.

With -d the pair has to outlive the run, so the namespace gets a name,
and the script prints how to enter and delete it.

If no network namespace can be created, the tests are skipped, as
without veth or ip. A failure after that, mounting sysfs in the
namespace included, fails the run.

https://virtuozzo.atlassian.net/browse/VSTOR-150731

Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 tools/testing/selftests/bpf/test_xsk.sh | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
index 65aafe0003db0..1554d1ec02b12 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -68,7 +68,8 @@
 # Run with verbose output:
 #   sudo ./test_xsk.sh -v
 #
-# Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:
+# Set up veth interfaces in a network namespace and leave them up so
+# xskxceiver can be launched in a debugger there:
 #   sudo ./test_xsk.sh -d
 #
 # Run test suite for physical device in loopback mode
@@ -162,8 +163,33 @@ if [ ! -z $ETH ]; then
 	VETH1=${ETH}
 else
 	validate_root_exec
-	validate_veth_support ${VETH0}
 	validate_ip_utility
+	# The host configures and talks on any new interface in its namespace
+	if [ -z "$XSK_NETNS" ]; then
+		if ! unshare --net true; then
+			echo "skip all tests: cannot create a network namespace" >&2
+			test_exit $ksft_skip
+		fi
+		if [[ $debug -ne 1 ]]; then
+			# Unnamed, it goes with its last process; its own sysfs shows its interfaces
+			XSK_NETNS=1 exec unshare --net --mount sh -c \
+				'mount -t sysfs sysfs /sys && exec bash "$0" "$@"' \
+				"$0" "$@"
+		fi
+		# The pair of a run by hand outlives it, in a namespace with a name
+		XSK_NETNS=xsk${VETH0_POSTFIX}
+		ip netns add ${XSK_NETNS} || exit 1
+		trap "ip netns del ${XSK_NETNS}" EXIT
+		# This run's veth names were never created; the pair is in the namespace
+		trap "exit 1" INT
+		XSK_NETNS=${XSK_NETNS} ip netns exec ${XSK_NETNS} bash "$0" "$@" || exit
+		trap - EXIT
+		echo "The pair is up in network namespace ${XSK_NETNS}," \
+			"use ip netns exec ${XSK_NETNS};" \
+			"ip netns del ${XSK_NETNS} removes it"
+		exit 0
+	fi
+	validate_veth_support ${VETH0}
 	setup_vethPairs
 
 	retval=$?

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-10-27 18:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 18:15 [Devel] [PATCH hci-8.1 v4 0/3] " Konstantin Khorenko
2026-10-27 18:15 ` [Devel] [PATCH hci-8.1 v4 1/3] selftests/bpf: xsk: exit with the status test_exit() is given Konstantin Khorenko
2026-10-27 18:15 ` [Devel] [PATCH hci-8.1 v4 2/3] selftests/bpf: xsk: take the fragment limit from the kernel's BTF Konstantin Khorenko
2026-10-27 18:15 ` Konstantin Khorenko [this message]
2026-10-27 18:50 ` [Devel] [PATCH hci-8.1 v4 0/3] selftests/bpf: run the xsk veth tests in a network namespace of their own Eva Kurchatova (Virtuozzo)
2026-10-29 13:59 ` Konstantin Khorenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261027-b4-prep-khorenko-vstor-150731-xsk-veth-netns-v4-3-c74cad570c70@virtuozzo.com \
    --to=khorenko@virtuozzo.com \
    --cc=devel@openvz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox