Skip to contentSkip to conversation

net: fix passive TFO socket having invalid NAPI ID

PATCH Applied David Wei 4 participants 8 messages Jun 17, 2025 – Jun 19, 2025

Subsystems (5)
lore
Share & tools
lore

David Wei

author
#0 lore raw

v2 cover net: fix passive TFO socket having invalid NAPI ID

Found a bug where an accepted passive TFO socket returns an invalid NAPI ID (i.e. 0) from SO_INCOMING_NAPI_ID. Add a selftest for this using netdevsim and fix the bug.

Patch 1 is a drive-by fix for the lib.sh include in an existing drivers/net/netdevsim/peer.sh selftest.

Patch 2 adds a test binary for a simple TFO server/client.

Patch 3 adds a selftest for checking that the NAPI ID of a passive TFO socket is valid. This will currently fail.

Patch 4 adds a fix for the bug.

Changes in v2:
--------------
* Use sk_mark_napi_id_set() instead
* Add fixes tag to patch 4

David Wei (4):
selftests: netdevsim: improve lib.sh include in peer.sh
selftests: net: add passive TFO test binary
selftests: net: add test for passive TFO socket NAPI ID
tcp: fix passive TFO socket having invalid NAPI ID

 net/ipv4/tcp_fastopen.c                       |   3 +
 .../selftests/drivers/net/netdevsim/peer.sh   |   3 +-
 tools/testing/selftests/net/.gitignore        |   1 +
 tools/testing/selftests/net/Makefile          |   2 +
 tools/testing/selftests/net/tfo.c             | 171 ++++++++++++++++++
 tools/testing/selftests/net/tfo_passive.sh    | 112 ++++++++++++
 6 files changed, 291 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/net/tfo.c
 create mode 100755 tools/testing/selftests/net/tfo_passive.sh
Signature · 1 line
2.47.1
author
#1 lore raw

PATCH v2 1/4 selftests: netdevsim: improve lib.sh include in peer.sh

Fix the peer.sh test to run from INSTALL_PATH.

---
 tools/testing/selftests/drivers/net/netdevsim/peer.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/netdevsim/peer.sh +2 -1
index 1bb46ec435d4..7f32b5600925 100755
@@ -1,7 +1,8 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0-only
 
-source ../../../net/lib.sh
+lib_dir=$(dirname $0)/../../../net
+source $lib_dir/lib.sh
 
 NSIM_DEV_1_ID=$((256 + RANDOM % 256))
 NSIM_DEV_1_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_DEV_1_ID
Signature · 1 line
2.47.1
author
#2 lore raw

PATCH v2 2/4 selftests: net: add passive TFO test binary

In reply to David Wei

Add a simple passive TFO server and client test binary. This will be used to test the SO_INCOMING_NAPI_ID of passive TFO accepted sockets.

---
 tools/testing/selftests/net/.gitignore |   1 +
 tools/testing/selftests/net/Makefile   |   1 +
 tools/testing/selftests/net/tfo.c      | 171 +++++++++++++++++++++++++
 3 files changed, 173 insertions(+)
 create mode 100644 tools/testing/selftests/net/tfo.c
tools/testing/selftests/net/.gitignore +1 -0
index 532bb732bc6d..c6dd2a335cf4 100644
@@ -50,6 +50,7 @@ tap
 tcp_fastopen_backup_key
 tcp_inq
 tcp_mmap
+tfo
 timestamping
 tls
 toeplitz
tools/testing/selftests/net/Makefile +1 -0
index ab996bd22a5f..ab8da438fd78 100644
@@ -110,6 +110,7 @@ TEST_GEN_PROGS += proc_net_pktgen
 TEST_PROGS += lwt_dst_cache_ref_loop.sh
 TEST_PROGS += skf_net_off.sh
 TEST_GEN_FILES += skf_net_off
+TEST_GEN_FILES += tfo
 
 # YNL files, must be before "include ..lib.mk"
 YNL_GEN_FILES := busy_poller netlink-dumps
tools/testing/selftests/net/tfo.c new file +171 -0

171 lines not on this page · raw message

Signature · 1 line
2.47.1
author
#3 lore raw

PATCH v2 3/4 selftests: net: add test for passive TFO socket NAPI ID

In reply to David Wei

Add a test that checks that the NAPI ID of a passive TFO socket is valid i.e. not zero.

---
 tools/testing/selftests/net/Makefile       |   1 +
 tools/testing/selftests/net/tfo_passive.sh | 112 +++++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100755 tools/testing/selftests/net/tfo_passive.sh
tools/testing/selftests/net/Makefile +1 -0
index ab8da438fd78..332f387615d7 100644
@@ -111,6 +111,7 @@ TEST_PROGS += lwt_dst_cache_ref_loop.sh
 TEST_PROGS += skf_net_off.sh
 TEST_GEN_FILES += skf_net_off
 TEST_GEN_FILES += tfo
+TEST_PROGS += tfo_passive.sh
 
 # YNL files, must be before "include ..lib.mk"
 YNL_GEN_FILES := busy_poller netlink-dumps
tools/testing/selftests/net/tfo_passive.sh new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.47.1
author
#4 lore raw

PATCH v2 4/4 tcp: fix passive TFO socket having invalid NAPI ID

In reply to David Wei

There is a bug with passive TFO sockets returning an invalid NAPI ID 0 from SO_INCOMING_NAPI_ID. Normally this is not an issue, but zero copy receive relies on a correct NAPI ID to process sockets on the right queue.

Fix by adding a sk_mark_napi_id_set().

Fixes e5907459ce7e ("tcp: Record Rx hash and NAPI ID in tcp_child_process")
---
 net/ipv4/tcp_fastopen.c | 3 +++
 1 file changed, 3 insertions(+)
net/ipv4/tcp_fastopen.c +3 -0
index 9b83d639b5ac..5107121c5e37 100644
@@ -3,6 +3,7 @@
 #include <linux/tcp.h>
 #include <linux/rcupdate.h>
 #include <net/tcp.h>
+#include <net/busy_poll.h>
 
 void tcp_fastopen_init_key_once(struct net *net)
 {
@@ -279,6 +280,8 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
 
 	refcount_set(&req->rsk_refcnt, 2);
 
+	sk_mark_napi_id_set(child, skb);
+
 	/* Now finish processing the fastopen child socket. */
 	tcp_init_transfer(child, BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, skb);
 
Signature · 1 line
2.47.1
Reviewed-by on v2 4/4
#5 lore raw

Re: [PATCH net v2 4/4] tcp: fix passive TFO socket having invalid NAPI ID

From: David Wei <[email protected]>
Date: Tue, 17 Jun 2025 14:21:02 -0700

Quoted 9 lines

There is a bug with passive TFO sockets returning an invalid NAPI ID 0 from SO_INCOMING_NAPI_ID. Normally this is not an issue, but zero copy receive relies on a correct NAPI ID to process sockets on the right queue.

Fix by adding a sk_mark_napi_id_set().

Fixes e5907459ce7e ("tcp: Record Rx hash and NAPI ID in tcp_child_process")
Reviewed-by
#6 lore raw

Re: [PATCH net v2 4/4] tcp: fix passive TFO socket having invalid NAPI ID

Quoted 8 lines · Kuniyuki Iwashima

From: David Wei <[email protected]>
Date: Tue, 17 Jun 2025 14:21:02 -0700

Quoted 5 lines

There is a bug with passive TFO sockets returning an invalid NAPI ID 0 from SO_INCOMING_NAPI_ID. Normally this is not an issue, but zero copy receive relies on a correct NAPI ID to process sockets on the right queue.

Quoted 6 lines
Quoted 4 lines

Fix by adding a sk_mark_napi_id_set().

Fixes e5907459ce7e ("tcp: Record Rx hash and NAPI ID in tcp_child_process")
#7 lore raw
In reply to David Wei
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 8 lines · On Tue, 17 Jun 2025 14:20:58 -0700 you wrote:

Found a bug where an accepted passive TFO socket returns an invalid NAPI ID (i.e. 0) from SO_INCOMING_NAPI_ID. Add a selftest for this using netdevsim and fix the bug.

Patch 1 is a drive-by fix for the lib.sh include in an existing drivers/net/netdevsim/peer.sh selftest.

[...]

Here is the summary with links:
- [net,v2,1/4] selftests: netdevsim: improve lib.sh include in peer.sh

    https://git.kernel.org/netdev/net/c/316827659121
  - [net,v2,2/4] selftests: net: add passive TFO test binary
    https://git.kernel.org/netdev/net/c/c65b5bb2329e
  - [net,v2,3/4] selftests: net: add test for passive TFO socket NAPI ID
    https://git.kernel.org/netdev/net/c/137e7b5cceda
  - [net,v2,4/4] tcp: fix passive TFO socket having invalid NAPI ID
    https://git.kernel.org/netdev/net/c/dbe0ca8da1f6

You are awesome, thank you!

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