Commit 4acf6d4f authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'fix-netdevim-to-correctly-mark-napi-ids'

Joe Damato says:

====================
Fix netdevim to correctly mark NAPI IDs

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 3)
introduces a C helper because apparently python doesn't have
socket.SO_INCOMING_NAPI_ID.

v3: https://lore.kernel.org/20250418013719.12094-1-jdamato@fastly.com
v2: https://lore.kernel.org/20250417013301.39228-1-jdamato@fastly.com
rfcv1: https://lore.kernel.org/20250329000030.39543-1-jdamato@fastly.com
====================

Link: https://patch.msgid.link/20250424002746.16891-1-jdamato@fastly.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents f74d14a7 2593a0a1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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);
	}

+1 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only
napi_id_helper
xdp_helper
+5 −1
Original line number Diff line number Diff line
@@ -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 \
+56 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#if !defined(__NET_KSFT_H__)
#define __NET_KSFT_H__

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static inline 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 inline 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
+23 −0
Original line number Diff line number Diff line
#!/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()
    listen_cmd = f"{cfg.test_dir}/napi_id_helper {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()
Loading