Fix netdevim to correctly mark NAPI IDs
Subsystems (5)
v3 cover Fix netdevim to correctly mark NAPI IDs
Greetings:
Welcome to v3.
This series fixes netdevsim to correctly set the NAPI ID on the skb. This is helpful for writing tests around features that use SO_INCOMING_NAPI_ID.
In addition to the netdevsim fix in patch 1, patches 2 & 3 do some self test refactoring and add a test for NAPI IDs. The test itself (patch 4) introduces a C helper because apparently python doesn't have socket.SO_INCOMING_NAPI_ID.
Thanks,
Joe
v3:
- Dropped patch 3 from v2 as it is no longer necessary.
- Patch 3 from this series (which was patch 4 in the v2)
- Sorted .gitignore alphabetically
- added cfg.remote_deploy so the test supports real remote machines
- Dropped the NetNSEnter as it is unnecessary
- Fixed a string interpolation issue that Paolo hit with his Python version
v2: https://lore.kernel.org/netdev/[email protected]/
- No longer an RFC
- Minor whitespace change in patch 1 (no functional change).
- Patches 2-4 new in v2
rfcv1: https://lore.kernel.org/netdev/[email protected]/
Joe Damato (3):
netdevsim: Mark NAPI ID on skb in nsim_rcv
selftests: drv-net: Factor out ksft C helpers
selftests: drv-net: Test that NAPI ID is non-zero
drivers/net/netdevsim/netdev.c | 2 + .../testing/selftests/drivers/net/.gitignore | 1 + tools/testing/selftests/drivers/net/Makefile | 6 +- tools/testing/selftests/drivers/net/ksft.h | 56 +++++++++++++ .../testing/selftests/drivers/net/napi_id.py | 24 ++++++ .../selftests/drivers/net/napi_id_helper.c | 83 +++++++++++++++++++ .../selftests/drivers/net/xdp_helper.c | 49 +---------- 7 files changed, 173 insertions(+), 48 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/ksft.h create mode 100755 tools/testing/selftests/drivers/net/napi_id.py create mode 100644 tools/testing/selftests/drivers/net/napi_id_helper.c
base-commit: 22ab6b9467c1822291a1175a0eb825b7ec057ef9
Signature · 1 line
2.43.0
PATCH v3 1/3 netdevsim: Mark NAPI ID on skb in nsim_rcv
Previously, nsim_rcv was not marking the NAPI ID on the skb, leading to applications seeing a napi ID of 0 when using SO_INCOMING_NAPI_ID.
To add to the userland confusion, netlink appears to correctly report the NAPI IDs for netdevsim queues but the resulting file descriptor from a call to accept() was reporting a NAPI ID of 0.
--- drivers/net/netdevsim/netdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/netdevsim/netdev.c +2 -0
@@ -29,6 +29,7 @@#include <net/pkt_cls.h> #include <net/rtnetlink.h> #include <net/udp_tunnel.h> +#include <net/busy_poll.h> #include "netdevsim.h"
@@ -357,6 +358,7 @@ static int nsim_rcv(struct nsim_rq *rq, int budget)break ; skb =skb_dequeue (&rq->skb_queue); +skb_mark_napi_id (skb, &rq->napi);netif_receive_skb (skb); }
Signature · 1 line
2.43.0
PATCH v3 2/3 selftests: drv-net: Factor out ksft C helpers
In reply to Joe DamatoFactor ksft C helpers to a header so they can be used by other C-based tests.
--- tools/testing/selftests/drivers/net/ksft.h | 56 +++++++++++++++++++ .../selftests/drivers/net/xdp_helper.c | 49 +--------------- 2 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/ksft.h
tools/testing/selftests/drivers/net/ksft.h new file +56 -0
@@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#if !defined(__KSFT_H__) +#define __KSFT_H__ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +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); +} + +#endif
tools/testing/selftests/drivers/net/xdp_helper.c +2 -47
58 lines not on this page · raw message
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v3 2/3] selftests: drv-net: Factor out ksft C helpers
tools/testing/selftests/drivers/net/ksft.h line 3
Quoted 2 lines · On Fri, 18 Apr 2025 01:37:04 +0000 Joe Damato wrote:
tools/testing/selftests/drivers/net/ksft.h new file +2
-0+#if !defined(__KSFT_H__) +#define __KSFT_H__
If you have to respin maybe __NET_KSFT_H__ ?
PATCH v3 3/3 selftests: drv-net: Test that NAPI ID is non-zero
In reply to Joe DamatoTest that the SO_INCOMING_NAPI_ID of a network file descriptor is non-zero. This ensures that either the core networking stack or, in some cases like netdevsim, the driver correctly sets the NAPI ID.
--- .../testing/selftests/drivers/net/.gitignore | 1 + tools/testing/selftests/drivers/net/Makefile | 6 +- .../testing/selftests/drivers/net/napi_id.py | 24 ++++++ .../selftests/drivers/net/napi_id_helper.c | 83 +++++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/drivers/net/napi_id.py create mode 100644 tools/testing/selftests/drivers/net/napi_id_helper.c
tools/testing/selftests/drivers/net/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only +napi_id_helper xdp_helper
tools/testing/selftests/drivers/net/Makefile +5 -1
@@ -6,9 +6,13 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \ ../../net/net_helper.sh \ ../../net/lib.sh \ -TEST_GEN_FILES := xdp_helper +TEST_GEN_FILES := \ + napi_id_helper \ + xdp_helper \ +# end of TEST_GEN_FILES TEST_PROGS := \ + napi_id.py \ netcons_basic.sh \ netcons_fragmented_msg.sh \ netcons_overflow.sh \
tools/testing/selftests/drivers/net/napi_id.py new file +24 -0
@@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +from lib.py import ksft_run, ksft_exit +from lib.py import ksft_eq, NetDrvEpEnv +from lib.py import bkg, cmd, rand_port, NetNSEnter + +def test_napi_id(cfg) -> None: + port = rand_port() + bin_remote = cfg.remote.deploy(cfg.test_dir / "napi_id_helper") + listen_cmd = f"{bin_remote} {cfg.addr_v['4']} {port}" + + with bkg(listen_cmd, ksft_wait=3) as server: + cmd(f"echo a | socat - TCP:{cfg.addr_v['4']}:{port}", host=cfg.remote, shell=True) + + ksft_eq(0, server.ret) + +def main() -> None: + with NetDrvEpEnv(__file__) as cfg: + ksft_run([test_napi_id], args=(cfg,)) + ksft_exit() + +if __name__ == "__main__": + main()
tools/testing/selftests/drivers/net/napi_id_helper.c new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v3 3/3] selftests: drv-net: Test that NAPI ID is non-zero
tools/testing/selftests/drivers/net/napi_id.py line 13
Quoted 4 lines · On Fri, 18 Apr 2025 01:37:05 +0000 Joe Damato wrote:
tools/testing/selftests/drivers/net/napi_id.py new file +4
-0+ bin_remote = cfg.remote.deploy(cfg.test_dir / "napi_id_helper") + listen_cmd = f"{bin_remote} {cfg.addr_v['4']} {port}" + + with bkg(listen_cmd, ksft_wait=3) as server:
Sorry, not sure how I misread v2 but you are running the helper locally. So you don't have to deploy it to the remote machine :(
BTW does removing the ksft_wait() from the binary work? Or does it cause trouble? Don't think we need to wait for anything in this case. With the XSK test we had to wait for the test to do the inspection before we unbound. Here once we get the connection we can just exit, no?
Re: [PATCH net-next v3 3/3] selftests: drv-net: Test that NAPI ID is non-zero
Quoted 8 lines · Jakub Kicinski
tools/testing/selftests/drivers/net/napi_id.py line 13
Quoted 4 lines · On Fri, 18 Apr 2025 01:37:05 +0000 Joe Damato wrote:
tools/testing/selftests/drivers/net/napi_id.py new file +4
-0+ bin_remote = cfg.remote.deploy(cfg.test_dir / "napi_id_helper") + listen_cmd = f"{bin_remote} {cfg.addr_v['4']} {port}" + + with bkg(listen_cmd, ksft_wait=3) as server:Sorry, not sure how I misread v2 but you are running the helper locally. So you don't have to deploy it to the remote machine :(
OK I can remove that and fix the macro guard for the v4.
Quoted 4 lines
BTW does removing the
ksft_wait()from the binary work? Or does it cause trouble? Don't think we need to wait for anything in this case. With the XSK test we had to wait for the test to do the inspection before we unbound. Here once we get the connection we can just exit, no?
I agree that we can just exit, but removing the wait breaks ksft utils:
# 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/napi_id.py", line 13, in test_napi_id # Exception| with bkg(listen_cmd, ksft_wait=3) as server: # Exception| File "/home/jdamato/code/net-next/tools/testing/selftests/net/lib/py/utils.py", line 130, in __exit__ # Exception| return self.process(terminate=self.terminate, fail=self.check_fail) # Exception| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Exception| File "/home/jdamato/code/net-next/tools/testing/selftests/net/lib/py/utils.py", line 78, in process # Exception| os.write(self.ksft_term_fd, b"1") # Exception| BrokenPipeError: [Errno 32] Broken pipe
LMK how you'd like me to proceed ?
I'm thinking:
- Leave ksft_wait()
- macro guard
- don't deploy helper to remote machine
Jakub Kicinski
maintainerRe: [PATCH net-next v3 3/3] selftests: drv-net: Test that NAPI ID is non-zero
Quoted 11 lines · On Wed, 23 Apr 2025 17:06:05 -0700 Joe Damato wrote:
# 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/napi_id.py", line 13, in test_napi_id # Exception| with bkg(listen_cmd, ksft_wait=3) as server: # Exception| File "/home/jdamato/code/net-next/tools/testing/selftests/net/lib/py/utils.py", line 130, in __exit__ # Exception| return self.process(terminate=self.terminate, fail=self.check_fail) # Exception| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Exception| File "/home/jdamato/code/net-next/tools/testing/selftests/net/lib/py/utils.py", line 78, in process # Exception| os.write(self.ksft_term_fd, b"1") # Exception| BrokenPipeError: [Errno 32] Broken pipe
Thanks for testing! Makes sense, I don't think it's worth complicating the Python side to handle the "ready but no wait" case if it doesnt work as is.
Quoted 6 lines
LMK how you'd like me to proceed ?
I'm thinking:
- Leaveksft_wait()
- macro guard
- don't deploy helper to remote machine
SG!