Skip to contentSkip to conversation

selftests: drv-net: improve the queue test for XSK

PATCH In review Jakub Kicinski 5 participants 22 messages Feb 19, 2025 – Feb 21, 2025

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

v2 cover selftests: drv-net: improve the queue test for XSK

We see some flakes in the the XSK test:

   Exception| Traceback (most recent call last):
   Exception|   File "/home/virtme/testing-18/tools/testing/selftests/net/lib/py/ksft.py", line 218, in ksft_run
   Exception|     case(*args)
   Exception|   File "/home/virtme/testing-18/tools/testing/selftests/drivers/net/./queues.py", line 53, in check_xdp
   Exception|     ksft_eq(q['xsk'], {})
   Exception| KeyError: 'xsk'

I think it's because the method or running the helper in the background is racy. Add more solid infra for waiting for a background helper to be initialized.

v2:
- add patch 1, 3 and 4
- redo patch 5
v1: https://lore.kernel.org/[email protected]

Jakub Kicinski (7):
selftests: drv-net: add a warning for bkg + shell + terminate
selftests: drv-net: use cfg.rpath() in netlink xsk attr test
selftests: drv-net: add missing new line in xdp_helper
selftests: drv-net: probe for AF_XDP sockets more explicitly
selftests: drv-net: add a way to wait for a local process
selftests: drv-net: improve the use of ksft helpers in XSK queue test
selftests: drv-net: rename queues check_xdp to check_xsk

 .../selftests/drivers/net/xdp_helper.c        | 63 ++++++++++++++--
 tools/testing/selftests/drivers/net/queues.py | 61 ++++++++--------
 tools/testing/selftests/net/lib/py/ksft.py    |  5 ++
 tools/testing/selftests/net/lib/py/utils.py   | 72 +++++++++++++++++--
 4 files changed, 161 insertions(+), 40 deletions(-)
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH v2 1/7 selftests: drv-net: add a warning for bkg + shell + terminate

Joe Damato reports that some shells will fork before running the command when python does "sh -c $cmd", while bash does an exec of $cmd directly. This will have implications for our ability to terminate the child process on bash vs other shells. Warn about using

bkg(... shell=True, termininate=True)

most background commands can hopefully exit cleanly (exit_wait).

---
v2: new

---
 tools/testing/selftests/net/lib/py/utils.py | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/net/lib/py/utils.py +4 -0
index 9e3bcddcf3e8..33b153767d89 100644
@@ -61,6 +61,10 @@ import time
         self.terminate = not exit_wait
         self.check_fail = fail
 
+        if shell and self.terminate:
+            print("# Warning: combining shell and terminate is risky!")
+            print("#          SIGTERM may not reach the child on zsh/ksh!")
+
     def __enter__(self):
         return self
 
Signature · 1 line
2.48.1
Acked-by on v2 1/7
#2 lore raw

Re: [PATCH net-next v2 1/7] selftests: drv-net: add a warning for bkg + shell + terminate

Quoted 6 lines · Jakub Kicinski

Joe Damato reports that some shells will fork before running the command when python does "sh -c $cmd", while bash does an exec of $cmd directly. This will have implications for our ability to terminate the child process on bash vs other shells. Warn about using

Quoted 6 lines

bkg(... shell=True, termininate=True)

most background commands can hopefully exit cleanly (exit_wait).

#3 lore raw

Re: [PATCH net-next v2 1/7] selftests: drv-net: add a warning for bkg + shell + terminate

In reply to Jakub Kicinski
Quoted 3 lines · Jakub Kicinski

Joe Damato reports that some shells will fork before running the command when python does "sh -c $cmd", while bash does an exec of $cmd directly.

I'm not sure what's going on, but as I mentioned in the other thread and below, I am using bash as well.

Quoted 21 lines

This will have implications for our
ability to terminate the child process on bash vs other shells. Warn about using

bkg(... shell=True, termininate=True)

most background commands can hopefully exit cleanly (exit_wait).

---
v2: new

---
 tools/testing/selftests/net/lib/py/utils.py | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/net/lib/py/utils.py +0 -0
index 9e3bcddcf3e8..33b153767d89 100644

tools/testing/selftests/net/lib/py/utils.py import time · line 66

Quoted 6 lines
tools/testing/selftests/net/lib/py/utils.py +3 -0
@@ -61,6 +61,10 @@ import time
         self.terminate = not exit_wait
         self.check_fail = fail
 
+        if shell and self.terminate:
+            print("# Warning: combining shell and terminate is risky!")
+            print("#          SIGTERM may not reach the child on zsh/ksh!")

I'm not opposed to putting a warning here, but just as a disclaimer and for anyone else following along -- I am using bash:

$ echo $SHELL
/bin/bash
$ bash --version
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
Acked-by on v2 1/7
#4 lore raw

Re: [PATCH net-next v2 1/7] selftests: drv-net: add a warning for bkg + shell + terminate

In reply to Jakub Kicinski
Quoted 23 lines · Jakub Kicinski

Joe Damato reports that some shells will fork before running the command when python does "sh -c $cmd", while bash does an exec of $cmd directly. This will have implications for our ability to terminate the child process on bash vs other shells. Warn about using

bkg(... shell=True, termininate=True)

most background commands can hopefully exit cleanly (exit_wait).

---
v2: new

---
 tools/testing/selftests/net/lib/py/utils.py | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/net/lib/py/utils.py +0 -0
index 9e3bcddcf3e8..33b153767d89 100644

tools/testing/selftests/net/lib/py/utils.py import time · line 67

Quoted 7 lines
tools/testing/selftests/net/lib/py/utils.py +4 -0
@@ -61,6 +61,10 @@ import time
         self.terminate = not exit_wait
         self.check_fail = fail
 
+        if shell and self.terminate:
+            print("# Warning: combining shell and terminate is risky!")
+            print("#          SIGTERM may not reach the child on zsh/ksh!")
+

This warning did not print on my system, FWIW. Up to you if you want to respin and drop it or just leave it be.

I am fine with this warning being added, although I disagree with the commit message as mentioned in my previous email.

Since the code seems fine though:

author maintainer
#5 lore raw

Re: [PATCH net-next v2 1/7] selftests: drv-net: add a warning for bkg + shell + terminate

Quoted 7 lines · On Thu, 20 Feb 2025 14:31:35 -0500 Joe Damato wrote:

tools/testing/selftests/net/lib/py/utils.py import time · line 67

Quoted 4 lines
tools/testing/selftests/net/lib/py/utils.py +4 -0
+        if shell and self.terminate:
+            print("# Warning: combining shell and terminate is risky!")
+            print("#          SIGTERM may not reach the child on zsh/ksh!")
+  

This warning did not print on my system, FWIW. Up to you if you want to respin and drop it or just leave it be.

You mean when running this patchset? It shouldn't, the current test uses ksft_wait rather than terminate. The warning is for test developers trying to use the risky config in new tests.

Quoted 2 lines

I am fine with this warning being added, although I disagree with the commit message as mentioned in my previous email.

I'll edit the commit message when applying. Unless you want to dig deeper and find out why your bash/env is different than mine :(

GNU bash, version 5.2.32(1)-release (x86_64-redhat-linux-gnu)

We know that "some shells" fork, that's the important point.

#6 lore raw

Re: [PATCH net-next v2 1/7] selftests: drv-net: add a warning for bkg + shell + terminate

Quoted 13 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 20 Feb 2025 14:31:35 -0500 Joe Damato wrote:

tools/testing/selftests/net/lib/py/utils.py import time · line 67

Quoted 4 lines
tools/testing/selftests/net/lib/py/utils.py +4 -0
+        if shell and self.terminate:
+            print("# Warning: combining shell and terminate is risky!")
+            print("#          SIGTERM may not reach the child on zsh/ksh!")
+  

This warning did not print on my system, FWIW. Up to you if you want to respin and drop it or just leave it be.

You mean when running this patchset? It shouldn't, the current test uses ksft_wait rather than terminate. The warning is for test developers trying to use the risky config in new tests.

Quoted 5 lines
Quoted 2 lines

I am fine with this warning being added, although I disagree with the commit message as mentioned in my previous email.

I'll edit the commit message when applying. Unless you want to dig deeper and find out why your bash/env is different than mine :(

No, no - no need for that much extra work. Just wanted to mention for anyone following along or who stumbles on this in the future that my shell is bash, is all :)

Thanks again for the work on this.

author maintainer
#7 lore raw

PATCH v2 2/7 selftests: drv-net: use cfg.rpath() in netlink xsk attr test

In reply to Jakub Kicinski

The cfg.rpath() helper was been recently added to make formatting paths for helper binaries easier.

---
 tools/testing/selftests/drivers/net/queues.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/drivers/net/queues.py +1 -2
index 5fdfebc6415f..b6896a57a5fd 100755
@@ -25,8 +25,7 @@ import subprocess
     return None
 
 def check_xdp(cfg, nl, xdp_queue_id=0) -> None:
-    test_dir = os.path.dirname(os.path.realpath(__file__))
-    xdp = subprocess.Popen([f"{test_dir}/xdp_helper", f"{cfg.ifindex}", f"{xdp_queue_id}"],
+    xdp = subprocess.Popen([cfg.rpath("xdp_helper"), f"{cfg.ifindex}", f"{xdp_queue_id}"],
                            stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1,
                            text=True)
     defer(xdp.kill)
Signature · 1 line
2.48.1
author maintainer
#8 lore raw

PATCH v2 3/7 selftests: drv-net: add missing new line in xdp_helper

In reply to Jakub Kicinski

Kurt and Joe report missing new line at the end of Usage.

---
v2: new

---
 tools/testing/selftests/drivers/net/xdp_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/drivers/net/xdp_helper.c +1 -1
index cf06a88b830b..80f86c2fe1a5 100644
@@ -35,7 +35,7 @@ int main(int argc, char **argv)
 	char byte;
 
 	if (argc != 3) {
-		fprintf(stderr, "Usage: %s ifindex queue_id", argv[0]);
+		fprintf(stderr, "Usage: %s ifindex queue_id\n", argv[0]);
 		return 1;
 	}
 
Signature · 1 line
2.48.1
Reviewed-by on v2 3/7
#10 lore raw

Re: [PATCH net-next v2 3/7] selftests: drv-net: add missing new line in xdp_helper

In reply to Jakub Kicinski
Quoted 14 lines · Jakub Kicinski

Kurt and Joe report missing new line at the end of Usage.

---
v2: new

---
 tools/testing/selftests/drivers/net/xdp_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/drivers/net/xdp_helper.c +0 -0
index cf06a88b830b..80f86c2fe1a5 100644

tools/testing/selftests/drivers/net/xdp_helper.c int main(int argc, char **argv) · line 40

Quoted 7 lines
tools/testing/selftests/drivers/net/xdp_helper.c +1 -1
@@ -35,7 +35,7 @@ int main(int argc, char **argv)
 	char byte;
 
 	if (argc != 3) {
-		fprintf(stderr, "Usage: %s ifindex queue_id", argv[0]);
+		fprintf(stderr, "Usage: %s ifindex queue_id\n", argv[0]);
 		return 1;
 	}
author maintainer
#11 lore raw

PATCH v2 4/7 selftests: drv-net: probe for AF_XDP sockets more explicitly

In reply to Jakub Kicinski

Separate the support check from socket binding for easier refactoring.
Use: ./helper - - just to probe if we can open the socket.

---
v2: new

---
 tools/testing/selftests/drivers/net/xdp_helper.c |  7 +++++++
 tools/testing/selftests/drivers/net/queues.py    | 12 +++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)
tools/testing/selftests/drivers/net/xdp_helper.c +7 -0
index 80f86c2fe1a5..2bad3b4d616c 100644
@@ -50,6 +50,13 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
+	/* "Probing mode", just checking if AF_XDP sockets are supported */
+	if (!strcmp(argv[1], "-") && !strcmp(argv[2], "-")) {
+		printf("AF_XDP support detected\n");
+		close(sock_fd);
+		return 0;
+	}
+
 	ifindex = atoi(argv[1]);
 	queue = atoi(argv[2]);
 
tools/testing/selftests/drivers/net/queues.py +7 -5
index b6896a57a5fd..0c959b2eb618 100755
@@ -25,6 +25,13 @@ import subprocess
     return None
 
 def check_xdp(cfg, nl, xdp_queue_id=0) -> None:
+    # Probe for support
+    xdp = cmd(cfg.rpath("xdp_helper") + ' - -', fail=False)
+    if xdp.ret == 255:
+        raise KsftSkipEx('AF_XDP unsupported')
+    elif xdp.ret > 0:
+        raise KsftFailEx('unable to create AF_XDP socket')
+
     xdp = subprocess.Popen([cfg.rpath("xdp_helper"), f"{cfg.ifindex}", f"{xdp_queue_id}"],
                            stdin=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1,
                            text=True)
@@ -33,11 +40,6 @@ import subprocess
     stdout, stderr = xdp.communicate(timeout=10)
     rx = tx = False
 
-    if xdp.returncode == 255:
-        raise KsftSkipEx('AF_XDP unsupported')
-    elif xdp.returncode > 0:
-        raise KsftFailEx('unable to create AF_XDP socket')
-
     queues = nl.queue_get({'ifindex': cfg.ifindex}, dump=True)
     if not queues:
         raise KsftSkipEx("Netlink reports no queues")
Signature · 1 line
2.48.1
Reviewed-by on v2 4/7
#13 lore raw

Re: [PATCH net-next v2 4/7] selftests: drv-net: probe for AF_XDP sockets more explicitly

In reply to Jakub Kicinski
Quoted 11 lines · Jakub Kicinski

Separate the support check from socket binding for easier refactoring.
Use: ./helper - - just to probe if we can open the socket.

---
v2: new

---
 tools/testing/selftests/drivers/net/xdp_helper.c |  7 +++++++
 tools/testing/selftests/drivers/net/queues.py    | 12 +++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

I've tested this on a kernel with XDP enabled and also a kernel with XDP disabled and the change appears to work as intended.

Here's what it looks like on a kernel with XDP disabled:

KTAP version 1
1..4
ok 1 queues.get_queues
2ok 2 queues.addremove_queues
ok 3 queues.check_down

# Exception| Traceback (most recent call last):
# Exception|   File "/home/jdamato/code/net-next/tools/testing/selftests/net/lib/py/ksft.py", line 223, in ksft_run
# Exception|     case(*args)
# Exception|   File "/home/jdamato/code/net-next/./tools/testing/selftests/drivers/net/queues.py", line 33, in check_xsk
# Exception|     raise KsftFailEx('unable to create AF_XDP socket')
# Exception| net.lib.py.ksft.KsftFailEx: unable to create AF_XDP socket

not ok 4 queues.check_xsk
# Totals: pass:3 fail:1 xfail:0 xpass:0 skip:0 error:0

author maintainer
#14 lore raw

PATCH v2 5/7 selftests: drv-net: add a way to wait for a local process

In reply to Jakub Kicinski

We use wait_port_listen() extensively to wait for a process we spawned to be ready. Not all processes will open listening sockets. Add a method of explicitly waiting for a child to be ready. Pass a FD to the spawned process and wait for it to write a message to us. FD number is passed via KSFT_READY_FD env variable.

Similarly use KSFT_WAIT_FD to let the child process for a sign that we are done and child should exit. Sending a signal to a child with shell=True can get tricky.

Make use of this method in the queues test to make it less flaky.

---
v2:
- use fd for exit, too
- warn if env variables are bad
v1: https://lore.kernel.org/[email protected]

---
 .../selftests/drivers/net/xdp_helper.c        | 54 +++++++++++++--
 tools/testing/selftests/drivers/net/queues.py | 43 ++++++------
 tools/testing/selftests/net/lib/py/utils.py   | 68 +++++++++++++++++--
 3 files changed, 133 insertions(+), 32 deletions(-)
tools/testing/selftests/drivers/net/xdp_helper.c +50 -4
index 2bad3b4d616c..aeed25914104 100644
@@ -14,6 +14,54 @@
 #define UMEM_SZ (1U << 16)
 #define NUM_DESC (UMEM_SZ / 2048)
 
+/* Move this to a common header when reused! */
+static void ksft_ready(void)
+{
+	const char msg[7] = "ready\n";
+	char *env_str;
+	int fd;
+
+	env_str = getenv("KSFT_READY_FD");
+	if (env_str) {
+		fd = atoi(env_str);
+		if (!fd) {
+			fprintf(stderr, "invalid KSFT_READY_FD = '%s'\n",
+				env_str);
+			return;
+		}
+	} else {
+		fd = STDOUT_FILENO;
+	}
+
+	write(fd, msg, sizeof(msg));
+	if (fd != STDOUT_FILENO)
+		close(fd);
+}
+
+static void ksft_wait(void)
+{
+	char *env_str;
+	char byte;
+	int fd;
+
+	env_str = getenv("KSFT_WAIT_FD");
+	if (env_str) {
+		fd = atoi(env_str);
+		if (!fd) {
+			fprintf(stderr, "invalid KSFT_WAIT_FD = '%s'\n",
+				env_str);
+			return;
+		}
+	} else {
+		/* Not running in KSFT env, wait for input from STDIN instead */
+		fd = STDIN_FILENO;
+	}
+
+	read(fd, &byte, sizeof(byte));
+	if (fd != STDIN_FILENO)
+		close(fd);
+}
+
 /* this is a simple helper program that creates an XDP socket and does the
  * minimum necessary to get bind() to succeed.
  *
@@ -32,7 +80,6 @@ int main(int argc, char **argv)
 	int ifindex;
 	int sock_fd;
 	int queue;
-	char byte;
 
 	if (argc != 3) {
 		fprintf(stderr, "Usage: %s ifindex queue_id\n", argv[0]);
@@ -92,13 +139,12 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	/* give the parent program some data when the socket is ready*/
-	fprintf(stdout, "%d\n", sock_fd);
+	ksft_ready();
+	ksft_wait();
 
 	/* parent program will write a byte to stdin when its ready for this
 	 * helper to exit
 	 */
-	read(STDIN_FILENO, &byte, 1);
 
 	close(sock_fd);
 	return 0;
tools/testing/selftests/drivers/net/queues.py +20 -23

65 lines not on this page · raw message

tools/testing/selftests/net/lib/py/utils.py +63 -5

109 lines not on this page · raw message

Signature · 1 line
2.48.1
Acked-by on v2 5/7
#15 lore raw

Re: [PATCH net-next v2 5/7] selftests: drv-net: add a way to wait for a local process

Quoted 7 lines · Jakub Kicinski

We use wait_port_listen() extensively to wait for a process we spawned to be ready. Not all processes will open listening sockets. Add a method of explicitly waiting for a child to be ready. Pass a FD to the spawned process and wait for it to write a message to us. FD number is passed via KSFT_READY_FD env variable.

Quoted 7 lines

Similarly use KSFT_WAIT_FD to let the child process for a sign that we are done and child should exit. Sending a signal to a child with shell=True can get tricky.

Make use of this method in the queues test to make it less flaky.

Acked-by on v2 5/7
#16 lore raw

Re: [PATCH net-next v2 5/7] selftests: drv-net: add a way to wait for a local process

In reply to Jakub Kicinski
Quoted 19 lines · Jakub Kicinski

We use wait_port_listen() extensively to wait for a process we spawned to be ready. Not all processes will open listening sockets. Add a method of explicitly waiting for a child to be ready. Pass a FD to the spawned process and wait for it to write a message to us. FD number is passed via KSFT_READY_FD env variable.

Similarly use KSFT_WAIT_FD to let the child process for a sign that we are done and child should exit. Sending a signal to a child with shell=True can get tricky.

Make use of this method in the queues test to make it less flaky.

---
v2:
- use fd for exit, too
- warn if env variables are bad
v1: https://lore.kernel.org/[email protected]

Quoted 5 lines
---
 .../selftests/drivers/net/xdp_helper.c        | 54 +++++++++++++--
 tools/testing/selftests/drivers/net/queues.py | 43 ++++++------
 tools/testing/selftests/net/lib/py/utils.py   | 68 +++++++++++++++++--
 3 files changed, 133 insertions(+), 32 deletions(-)

This appears to have fixed the test on my system and the hang is gone. Thanks.

author maintainer
#17 lore raw

PATCH v2 6/7 selftests: drv-net: improve the use of ksft helpers in XSK queue test

In reply to Jakub Kicinski

Avoid exceptions when xsk attr is not present, and add a proper ksft helper for "not in" condition.

---
 tools/testing/selftests/drivers/net/queues.py | 9 +++++----
 tools/testing/selftests/net/lib/py/ksft.py    | 5 +++++
 2 files changed, 10 insertions(+), 4 deletions(-)
tools/testing/selftests/drivers/net/queues.py +5 -4
index 7af2adb61c25..a49f1a146e28 100755
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 from lib.py import ksft_disruptive, ksft_exit, ksft_run
-from lib.py import ksft_eq, ksft_raises, KsftSkipEx, KsftFailEx
+from lib.py import ksft_eq, ksft_not_in, ksft_raises, KsftSkipEx, KsftFailEx
 from lib.py import EthtoolFamily, NetdevFamily, NlError
 from lib.py import NetDrvEnv
 from lib.py import bkg, cmd, defer, ip
@@ -47,10 +47,11 @@ import struct
                 if q['type'] == 'tx':
                     tx = True
 
-                ksft_eq(q['xsk'], {})
+                ksft_eq(q.get('xsk', None), {},
+                        comment="xsk attr on queue we configured")
             else:
-                if 'xsk' in q:
-                    _fail("Check failed: xsk attribute set.")
+                ksft_not_in('xsk', q,
+                            comment="xsk attr on queue we didn't configure")
 
         ksft_eq(rx, True)
         ksft_eq(tx, True)
tools/testing/selftests/net/lib/py/ksft.py +5 -0
index 3efe005436cd..fd23349fa8ca 100644
@@ -71,6 +71,11 @@ KSFT_DISRUPTIVE = True
         _fail("Check failed", a, "not in", b, comment)
 
 
+def ksft_not_in(a, b, comment=""):
+    if a in b:
+        _fail("Check failed", a, "in", b, comment)
+
+
 def ksft_is(a, b, comment=""):
     if a is not b:
         _fail("Check failed", a, "is not", b, comment)
Signature · 1 line
2.48.1
Tested-by on v2 6/7
#18 lore raw

Re: [PATCH net-next v2 6/7] selftests: drv-net: improve the use of ksft helpers in XSK queue test

Quoted 25 lines · Jakub Kicinski

Avoid exceptions when xsk attr is not present, and add a proper ksft helper for "not in" condition.

---
 tools/testing/selftests/drivers/net/queues.py | 9 +++++----
 tools/testing/selftests/net/lib/py/ksft.py    | 5 +++++
 2 files changed, 10 insertions(+), 4 deletions(-)
tools/testing/selftests/drivers/net/queues.py +1 -1
index 7af2adb61c25..a49f1a146e28 100755
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 from lib.py import ksft_disruptive, ksft_exit, ksft_run
-from lib.py import ksft_eq, ksft_raises, KsftSkipEx, KsftFailEx
+from lib.py import ksft_eq, ksft_not_in, ksft_raises, KsftSkipEx, KsftFailEx
 from lib.py import EthtoolFamily, NetdevFamily, NlError
 from lib.py import NetDrvEnv
 from lib.py import bkg, cmd, defer, ip

tools/testing/selftests/drivers/net/queues.py import struct · line 51

Quoted 6 lines
tools/testing/selftests/drivers/net/queues.py +2 -1
@@ -47,10 +47,11 @@ import struct
                 if q['type'] == 'tx':
                     tx = True
 
-                ksft_eq(q['xsk'], {})
+                ksft_eq(q.get('xsk', None), {},
+                        comment="xsk attr on queue we configured")

Thanks. That's much better than getting exceptions in the case where no xsk attribute is available:

author maintainer
#19 lore raw

PATCH v2 7/7 selftests: drv-net: rename queues check_xdp to check_xsk

In reply to Jakub Kicinski

The test is for AF_XDP, we refer to AF_XDP as XSK.

---
 tools/testing/selftests/drivers/net/queues.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/queues.py +4 -2
index a49f1a146e28..9040baf7b726 100755
@@ -23,7 +23,8 @@ import struct
         return len([q for q in queues if q['type'] == qtype])
     return None
 
-def check_xdp(cfg, nl, xdp_queue_id=0) -> None:
+
+def check_xsk(cfg, nl, xdp_queue_id=0) -> None:
     # Probe for support
     xdp = cmd(cfg.rpath("xdp_helper") + ' - -', fail=False)
     if xdp.ret == 255:
@@ -116,7 +117,8 @@ import struct
 
 def main() -> None:
     with NetDrvEnv(__file__, queue_count=100) as cfg:
-        ksft_run([get_queues, addremove_queues, check_down, check_xdp], args=(cfg, NetdevFamily()))
+        ksft_run([get_queues, addremove_queues, check_down, check_xsk],
+                 args=(cfg, NetdevFamily()))
     ksft_exit()
 
 
Signature · 1 line
2.48.1
Tested-by on the v2 series
#20 lore raw
In reply to Jakub Kicinski
Quoted 9 lines · Jakub Kicinski

We see some flakes in the the XSK test:

   Exception| Traceback (most recent call last):
   Exception|   File "/home/virtme/testing-18/tools/testing/selftests/net/lib/py/ksft.py", line 218, in ksft_run
   Exception|     case(*args)
   Exception|   File "/home/virtme/testing-18/tools/testing/selftests/drivers/net/./queues.py", line 53, in check_xdp
   Exception|     ksft_eq(q['xsk'], {})
   Exception| KeyError: 'xsk'
Quoted 8 lines

I think it's because the method or running the helper in the background is racy. Add more solid infra for waiting for a background helper to be initialized.

v2:
- add patch 1, 3 and 4
- redo patch 5
v1: https://lore.kernel.org/[email protected]

Thanks for doing this work.

I tested this on my system in four cases:
- XDP disabled:
- NETIF=mlx5
- NETIF unset
- XDP enabled
- NETIF=mlx5
- NETIF unset

The warning in patch 1 does not print on my system, but the code changes introduced in patch 5/7 fix the hang.

I've already given my Reviewed-by / Acked-by on all patches, so not sure if it matters but since I did test this as described above:

#21 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Wed, 19 Feb 2025 15:49:49 -0800 you wrote:

We see some flakes in the the XSK test:

   Exception| Traceback (most recent call last):
   Exception|   File "/home/virtme/testing-18/tools/testing/selftests/net/lib/py/ksft.py", line 218, in ksft_run
   Exception|     case(*args)
   Exception|   File "/home/virtme/testing-18/tools/testing/selftests/drivers/net/./queues.py", line 53, in check_xdp
   Exception|     ksft_eq(q['xsk'], {})
   Exception| KeyError: 'xsk'

[...]

Here is the summary with links:
- [net-next,v2,1/7] selftests: drv-net: add a warning for bkg + shell + terminate

    https://git.kernel.org/netdev/net-next/c/846742f7e32f
  - [net-next,v2,2/7] selftests: drv-net: use cfg.rpath() in netlink xsk attr test
    https://git.kernel.org/netdev/net-next/c/dabd31baa3b5
  - [net-next,v2,3/7] selftests: drv-net: add missing new line in xdp_helper
    https://git.kernel.org/netdev/net-next/c/bab59dcf71fb
  - [net-next,v2,4/7] selftests: drv-net: probe for AF_XDP sockets more explicitly
    (no matching commit)
  - [net-next,v2,5/7] selftests: drv-net: add a way to wait for a local process
    (no matching commit)
  - [net-next,v2,6/7] selftests: drv-net: improve the use of ksft helpers in XSK queue test
    https://git.kernel.org/netdev/net-next/c/4fde8398462f
  - [net-next,v2,7/7] selftests: drv-net: rename queues check_xdp to check_xsk
    https://git.kernel.org/netdev/net-next/c/932a9249f71f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html