All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
To: khorenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v2 1/1] selftests/bpf: run the xsk veth tests in a network namespace of their own
Date: Thu, 22 Oct 2026 05:47:47 +0300	[thread overview]
Message-ID: <20261022024816.2435565-2-eva.kurchatova@virtuozzo.com> (raw)
In-Reply-To: <20261022024816.2435565-1-eva.kurchatova@virtuozzo.com>

test_xsk.sh makes its veth pair in the namespace it runs in. Whatever
the host does with a new interface, address configuration, neighbour
discovery, happens on that pair, and the AF_XDP sockets under test
receive the host's packets among their own. The tests count and
inspect what they receive, so a preconfigured host fails some of them
in every mode, and a bare one passes.

Run the veth part in a network namespace of its own. The max_skb_frags
sysctl has no file outside the initial namespace, so xskxceiver takes
the limit from a new -f option ahead of the file, and the script hands
it the host's value, or the one given to its own -f; the option tells
the tests what the kernel's limit is and changes nothing in the kernel.
An interface given with -i is used where it is. Without network
namespaces the tests are skipped, as they are without veth.

https://virtuozzo.atlassian.net/browse/VSTOR-150731
Feature: fix selftests

Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
 tools/testing/selftests/bpf/test_xsk.sh  | 32 ++++++++++++++++++++++--
 tools/testing/selftests/bpf/xskxceiver.c | 17 +++++++++++--
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
index 65aafe0003db..f6bff443ef1d 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -83,6 +83,10 @@
 # Run a specific test from the test suite
 #   sudo ./test_xsk.sh -t TEST_NAME
 #
+# Tell the tests the kernel's max_skb_frags where its sysctl file cannot
+# be read, in a network namespace other than the initial one say
+#   sudo ./test_xsk.sh -f FRAGS
+#
 # Display the available command line options
 #   ./test_xsk.sh -h
 
@@ -90,7 +94,7 @@
 
 ETH=""
 
-while getopts "vi:dm:lt:h" flag
+while getopts "vi:dm:lt:f:h" flag
 do
 	case "${flag}" in
 		v) verbose=1;;
@@ -99,6 +103,7 @@ do
 		m) MODE=${OPTARG};;
 		l) list=1;;
 		t) TEST=${OPTARG};;
+		f) FRAGS=${OPTARG};;
 		h) help=1;;
 	esac
 done
@@ -162,8 +167,27 @@ 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
+		XSK_NETNS=xsk${VETH0_POSTFIX}
+		if ! ip netns add ${XSK_NETNS}; then
+			echo "skip all tests: cannot create a network namespace" >&2
+			test_exit $ksft_skip
+		fi
+		trap "ip netns del ${XSK_NETNS}" EXIT
+		# The max_skb_frags sysctl has no file outside the initial namespace
+		[ -n "$FRAGS" ] || FRAGS=$(cat /proc/sys/net/core/max_skb_frags 2>/dev/null)
+		XSK_NETNS=${XSK_NETNS} ip netns exec ${XSK_NETNS} \
+			bash "$0" "$@" ${FRAGS:+-f "${FRAGS}"}
+		retval=$?
+		# The pair stays up for a run by hand
+		[[ $debug -eq 1 ]] && trap - EXIT && \
+			echo "The pair is up in network namespace ${XSK_NETNS}," \
+				"use ip netns exec ${XSK_NETNS}"
+		exit $retval
+	fi
+	validate_veth_support ${VETH0}
 	setup_vethPairs
 
 	retval=$?
@@ -187,6 +211,10 @@ if [ -n "$TEST" ]; then
 	ARGS+="-t ${TEST} "
 fi
 
+if [ -n "$FRAGS" ]; then
+	ARGS+="-f ${FRAGS} "
+fi
+
 retval=$?
 test_status $retval "${TEST_NAME}"
 
diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 11f047b8af75..37c0f3b6677a 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -113,6 +113,7 @@ static bool opt_verbose;
 static bool opt_print_tests;
 static enum test_mode opt_mode = TEST_MODE_ALL;
 static u32 opt_run_test = RUN_ALL_TESTS;
+static u32 opt_max_skb_frags;
 
 void test__fail(void) { /* for network_helpers.c */ }
 
@@ -351,6 +352,7 @@ static struct option long_options[] = {
 	{"mode", required_argument, 0, 'm'},
 	{"list", no_argument, 0, 'l'},
 	{"test", required_argument, 0, 't'},
+	{"frags", required_argument, 0, 'f'},
 	{"help", no_argument, 0, 'h'},
 	{0, 0, 0, 0}
 };
@@ -366,6 +368,7 @@ static void print_usage(char **argv)
 		"  -m, --mode           Run only mode skb, drv, or zc\n"
 		"  -l, --list           List all available tests\n"
 		"  -t, --test           Run a specific test. Enter number from -l option.\n"
+		"  -f, --frags          Take this as the kernel's max_skb_frags, not the sysctl's\n"
 		"  -h, --help           Display this help and exit\n";
 
 	ksft_print_msg(str, basename(argv[0]));
@@ -385,11 +388,13 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
 	struct ifobject *ifobj;
 	u32 interface_nb = 0;
 	int option_index, c;
+	unsigned long frags;
+	char *end;
 
 	opterr = 0;
 
 	for (;;) {
-		c = getopt_long(argc, argv, "i:vbm:lt:", long_options, &option_index);
+		c = getopt_long(argc, argv, "i:vbm:lt:f:", long_options, &option_index);
 		if (c == -1)
 			break;
 
@@ -437,6 +442,14 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
 			if (errno)
 				print_usage(argv);
 			break;
+		case 'f':
+			errno = 0;
+			frags = strtoul(optarg, &end, 0);
+			/* The sysctl's own range: 1 to MAX_SKB_FRAGS, which is 45 at most */
+			if (errno || *end || !frags || frags > 45)
+				print_usage(argv);
+			opt_max_skb_frags = frags;
+			break;
 		case 'h':
 		default:
 			print_usage(argv);
@@ -2271,7 +2284,7 @@ static int testapp_too_many_frags(struct test_spec *test)
 	if (test->mode == TEST_MODE_ZC) {
 		max_frags = test->ifobj_tx->xdp_zc_max_segs;
 	} else {
-		max_frags = get_max_skb_frags();
+		max_frags = opt_max_skb_frags ? : get_max_skb_frags();
 		if (!max_frags) {
 			ksft_print_msg("Couldn't retrieve MAX_SKB_FRAGS from system, using default (17) value\n");
 			max_frags = 17;
-- 
2.56.0

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

  reply	other threads:[~2026-10-22  2:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22  2:47 [Devel] [PATCH hci-8.1 v2 0/1] " Eva Kurchatova
2026-10-22  2:47 ` Eva Kurchatova [this message]
2026-10-22  2:53   ` [Devel] [PATCH hci-8.1 v2 1/1] " no-reply
2026-10-22  3:06     ` Eva Kurchatova (Virtuozzo)
2026-10-22 16:14   ` 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=20261022024816.2435565-2-eva.kurchatova@virtuozzo.com \
    --to=eva.kurchatova@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.