OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 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] selftests/bpf: run the xsk veth tests in a network namespace of their own
Date: Tue, 20 Oct 2026 07:12:17 +0300	[thread overview]
Message-ID: <20261020041218.1659392-1-eva.kurchatova@virtuozzo.com> (raw)

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. An interface
given with -i is used where it is.

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  | 25 ++++++++++++++++++++++--
 tools/testing/selftests/bpf/xskxceiver.c | 13 ++++++++++--
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
index 65aafe0003db..7859c1d31195 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -83,6 +83,9 @@
 # Run a specific test from the test suite
 #   sudo ./test_xsk.sh -t TEST_NAME
 #
+# Run with a max_skb_frags limit other than the host's
+#   sudo ./test_xsk.sh -f FRAGS
+#
 # Display the available command line options
 #   ./test_xsk.sh -h
 
@@ -90,7 +93,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 +102,7 @@ do
 		m) MODE=${OPTARG};;
 		l) list=1;;
 		t) TEST=${OPTARG};;
+		f) FRAGS=${OPTARG};;
 		h) help=1;;
 	esac
 done
@@ -162,8 +166,21 @@ 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}
+		ip netns add ${XSK_NETNS} || test_exit $ksft_fail
+		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)
+		XSK_NETNS=${XSK_NETNS} ip netns exec ${XSK_NETNS} bash "$0" "$@" -f ${FRAGS}
+		retval=$?
+		# The pair stays up for a run by hand
+		[[ $debug -eq 1 ]] && trap - EXIT && echo "ip netns exec ${XSK_NETNS}"
+		exit $retval
+	fi
+	validate_veth_support ${VETH0}
 	setup_vethPairs
 
 	retval=$?
@@ -187,6 +204,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..c26cc31d21fe 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          Use this max_skb_frags instead of the sysctl\n"
 		"  -h, --help           Display this help and exit\n";
 
 	ksft_print_msg(str, basename(argv[0]));
@@ -389,7 +392,7 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
 	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 +440,12 @@ static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj
 			if (errno)
 				print_usage(argv);
 			break;
+		case 'f':
+			errno = 0;
+			opt_max_skb_frags = strtoul(optarg, NULL, 0);
+			if (errno || !opt_max_skb_frags)
+				print_usage(argv);
+			break;
 		case 'h':
 		default:
 			print_usage(argv);
@@ -2271,7 +2280,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-20  4:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20  4:12 Eva Kurchatova [this message]
2026-10-20  4:18 ` no-reply

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=20261020041218.1659392-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox