* [PATCH net 0/4] netfilter: flowtable: Preliminary fixes
@ 2026-11-18 20:12 Florian Fainelli
2026-11-18 20:12 ` [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY Florian Fainelli
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-18 20:12 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Pablo Neira Ayuso, Florian Westphal,
Phil Sutter, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Shuah Khan, Toshiaki Makita, open list,
open list:NETFILTER, open list:NETFILTER,
open list:KERNEL SELFTEST FRAMEWORK
This patch series was created based upon the Sashiko review of the
Broadcom Flow Accelerator support:
https://lore.kernel.org/all/20261116222519.1416501-1-florian.fainelli@broadcom.com/
These changes were not encountered in real world testing but appear to
be valid. Test cases were added to ensure there are no regressions
moving forward.
Florian Fainelli (4):
netfilter: flowtable: do not queue offload work after DESTROY
netfilter: flowtable: restore the GRE conntrack timeout on teardown
selftests: netfilter: check hardware offload work after DESTROY
selftests: netfilter: check the GRE timeout after flowtable teardown
net/netfilter/nf_flow_table_core.c | 12 ++
net/netfilter/nf_flow_table_offload.c | 13 ++
.../testing/selftests/net/netfilter/Makefile | 2 +
tools/testing/selftests/net/netfilter/config | 4 +
.../net/netfilter/nft_flowtable_gre.sh | 137 +++++++++++++++
.../net/netfilter/nft_flowtable_hw_destroy.sh | 162 ++++++++++++++++++
6 files changed, 330 insertions(+)
create mode 100755 tools/testing/selftests/net/netfilter/nft_flowtable_gre.sh
create mode 100755 tools/testing/selftests/net/netfilter/nft_flowtable_hw_destroy.sh
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY
2026-11-18 20:12 [PATCH net 0/4] netfilter: flowtable: Preliminary fixes Florian Fainelli
@ 2026-11-18 20:12 ` Florian Fainelli
2026-11-21 23:23 ` Pablo Neira Ayuso
2026-11-22 21:17 ` netdev-bot+sashiko
2026-11-18 20:12 ` [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown Florian Fainelli
` (2 subsequent siblings)
3 siblings, 2 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-18 20:12 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Pablo Neira Ayuso, Florian Westphal,
Phil Sutter, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Shuah Khan, Toshiaki Makita, open list,
open list:NETFILTER, open list:NETFILTER,
open list:KERNEL SELFTEST FRAMEWORK
nf_flow_offload_refresh() can be reached by a packet path reader which
looked the flow up before it was torn down. NF_FLOW_PENDING keeps the
DESTROY work from being queued while another work item is pending, but
once the DESTROY work has run and cleared the bit, a reader can take it
again and queue a REPLACE (or STATS) work for a flow which is already
being removed.
GC removes a hardware flow after NF_FLOW_HW_DEAD is set, and frees it after
an RCU grace period, which the reader can outlive in a preemptible RCU
read-side section. The queued work then dereferences a freed flow and
the flowtable, and can program the hardware again with a rule keyed by
the freed flow's cookie.
NF_FLOW_HW_DYING is set when DESTROY is queued, and DESTROY needs
NF_FLOW_PENDING, so a work item which holds the pending bit and finds
NF_FLOW_HW_DYING clear prevents DESTROY from being queued until it
completes. Check it after taking the pending bit, and do not queue
anything other than DESTROY when it is set.
Not reproduced: this is a race between a long RCU read-side section and
the GC and offload workers. Found by review of a related change.
Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
net/netfilter/nf_flow_table_offload.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 4365859220e6..62f460d38efa 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -1088,6 +1088,19 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
if (test_and_set_bit(NF_FLOW_PENDING, &flow->flags))
return NULL;
+ /* GC only removes a hardware flow after its DESTROY work has run, and
+ * NF_FLOW_PENDING keeps another one from being queued, so nothing can
+ * free the flow while this work is pending, unless DESTROY was queued
+ * before we took the pending bit. A reader which found the flow before
+ * it was torn down must not queue more work then, as the flow could be
+ * freed before that work runs.
+ */
+ if (cmd != FLOW_CLS_DESTROY &&
+ test_bit(NF_FLOW_HW_DYING, &flow->flags)) {
+ clear_bit(NF_FLOW_PENDING, &flow->flags);
+ return NULL;
+ }
+
offload = kmalloc_obj(struct flow_offload_work, GFP_ATOMIC);
if (!offload) {
clear_bit(NF_FLOW_PENDING, &flow->flags);
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown
2026-11-18 20:12 [PATCH net 0/4] netfilter: flowtable: Preliminary fixes Florian Fainelli
2026-11-18 20:12 ` [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY Florian Fainelli
@ 2026-11-18 20:12 ` Florian Fainelli
2026-11-21 23:10 ` Pablo Neira Ayuso
2026-11-22 21:17 ` netdev-bot+sashiko
2026-11-18 20:12 ` [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY Florian Fainelli
2026-11-18 20:12 ` [PATCH net 4/4] selftests: netfilter: check the GRE timeout after flowtable teardown Florian Fainelli
3 siblings, 2 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-11-18 20:12 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Pablo Neira Ayuso, Florian Westphal,
Phil Sutter, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Shuah Khan, Toshiaki Makita, open list,
open list:NETFILTER, open list:NETFILTER,
open list:KERNEL SELFTEST FRAMEWORK
flow_offload_add() sets the timeout of the conntrack entry to NF_CT_DAY
for every offloaded flow, and the GC keeps extending it for GRE too.
flow_offload_fixup_ct() only restores the conntrack timeout of TCP and
UDP flows when the flow is torn down, so an offloaded GRE entry which does
not see any other packet on the slow path stays for up to a day instead
of expiring after the GRE conntrack timeout.
Restore the GRE timeout, replied or unreplied, as for UDP. GRE has no
offload timeout of its own, flow_offload_get_timeout() uses the default
flowtable timeout for it, so use that one when the flow expired.
Fixes: 4e8d9584d154 ("netfilter: flowtable: Support GRE")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
net/netfilter/nf_flow_table_core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 2aa2647ed9df..051b15aecd89 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -237,6 +237,18 @@ static void flow_offload_fixup_ct(struct flow_offload *flow)
timeout = READ_ONCE(tn->timeouts[state]);
expired = nf_flow_has_expired(flow);
offload_timeout = READ_ONCE(tn->offload_timeout);
+#ifdef CONFIG_NF_CT_PROTO_GRE
+ } else if (l4num == IPPROTO_GRE) {
+ const struct nf_gre_net *tn = nf_gre_pernet(net);
+ enum gre_conntrack state =
+ test_bit(IPS_SEEN_REPLY_BIT, &ct->status) ?
+ GRE_CT_REPLIED : GRE_CT_UNREPLIED;
+
+ timeout = READ_ONCE(tn->timeouts[state]);
+ expired = nf_flow_has_expired(flow);
+ /* GRE has no offload timeout: see flow_offload_get_timeout(). */
+ offload_timeout = NF_FLOW_TIMEOUT;
+#endif
} else {
return;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY
2026-11-18 20:12 [PATCH net 0/4] netfilter: flowtable: Preliminary fixes Florian Fainelli
2026-11-18 20:12 ` [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY Florian Fainelli
2026-11-18 20:12 ` [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown Florian Fainelli
@ 2026-11-18 20:12 ` Florian Fainelli
2026-11-22 21:17 ` netdev-bot+sashiko
2026-11-18 20:12 ` [PATCH net 4/4] selftests: netfilter: check the GRE timeout after flowtable teardown Florian Fainelli
3 siblings, 1 reply; 11+ messages in thread
From: Florian Fainelli @ 2026-11-18 20:12 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Pablo Neira Ayuso, Florian Westphal,
Phil Sutter, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Shuah Khan, Toshiaki Makita, open list,
open list:NETFILTER, open list:NETFILTER,
open list:KERNEL SELFTEST FRAMEWORK
Add a test for "netfilter: flowtable: do not queue offload work after
DESTROY". A TCP flow in a hardware offload flowtable is closed: its
hardware rule is destroyed, and the flow stays in the flowtable until it
expires, where the garbage collector keeps finding it. No STATS or
REPLACE work may be queued for it once DESTROY was.
The flowtable devices are netdevsim ports, the only devices which accept a
hardware offload flowtable, and the work is told apart by its workqueue
with the workqueue_queue_work tracepoint, as netdevsim does not show it.
The REPLACE case of the fix is a race between a packet reader and the
garbage collector which cannot be triggered from user space; this
checks the same rule through the STATS work, which the garbage collector
queues after DESTROY without the fix.
Without the fix, 6 work items are queued after DESTROY in a 20 seconds TCP
flowtable timeout run in a VM, and the test fails. With it, none are.
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
.../testing/selftests/net/netfilter/Makefile | 1 +
tools/testing/selftests/net/netfilter/config | 1 +
.../net/netfilter/nft_flowtable_hw_destroy.sh | 162 ++++++++++++++++++
3 files changed, 164 insertions(+)
create mode 100755 tools/testing/selftests/net/netfilter/nft_flowtable_hw_destroy.sh
diff --git a/tools/testing/selftests/net/netfilter/Makefile b/tools/testing/selftests/net/netfilter/Makefile
index df3c20c90f5d..75d7d4495623 100644
--- a/tools/testing/selftests/net/netfilter/Makefile
+++ b/tools/testing/selftests/net/netfilter/Makefile
@@ -30,6 +30,7 @@ TEST_PROGS := \
nft_fib.sh \
nft_fib_nexthop.sh \
nft_flowtable.sh \
+ nft_flowtable_hw_destroy.sh \
nft_interface_stress.sh \
nft_meta.sh \
nft_nat.sh \
diff --git a/tools/testing/selftests/net/netfilter/config b/tools/testing/selftests/net/netfilter/config
index 629b2b29ed1a..bf7be95f7d25 100644
--- a/tools/testing/selftests/net/netfilter/config
+++ b/tools/testing/selftests/net/netfilter/config
@@ -16,6 +16,7 @@ CONFIG_DUMMY=m
CONFIG_FAIL_FUNCTION=y
CONFIG_FAULT_INJECTION=y
CONFIG_FAULT_INJECTION_DEBUG_FS=y
+CONFIG_FTRACE=y
CONFIG_FUNCTION_ERROR_INJECTION=y
CONFIG_INET_DIAG=m
CONFIG_INET_ESP=m
diff --git a/tools/testing/selftests/net/netfilter/nft_flowtable_hw_destroy.sh b/tools/testing/selftests/net/netfilter/nft_flowtable_hw_destroy.sh
new file mode 100755
index 000000000000..c0675378bd86
--- /dev/null
+++ b/tools/testing/selftests/net/netfilter/nft_flowtable_hw_destroy.sh
@@ -0,0 +1,162 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Once the hardware rule of a flow is destroyed, no more hardware offload work
+# must be queued for it. The flow is removed from the flowtable later, by the
+# garbage collector, which can still find it in the meantime.
+#
+# A TCP flow with a FIN has its hardware rule destroyed while it stays in the
+# flowtable until it expires. Check the workqueues used for the offload work,
+# which the netdevsim devices of the flowtable do not otherwise show.
+#
+# ns1 <-> (nsim) nsr1 (nsim) <-> ns2
+
+source lib.sh
+
+ret=0
+tracing=/sys/kernel/tracing
+trace_mounted=0
+tmpfile=$(mktemp)
+nsim_ids=""
+
+checktool "nft --version" "run test without nft tool"
+checktool "socat -h" "run test without socat"
+
+cleanup() {
+ if [ -d "$tracing/events/workqueue" ]; then
+ echo 0 > "$tracing/events/workqueue/workqueue_queue_work/enable"
+ echo > "$tracing/trace"
+ fi
+ [ "$trace_mounted" -eq 1 ] && umount "$tracing"
+ ip netns pids "$ns1" 2>/dev/null | xargs -r kill 2>/dev/null
+ ip netns pids "$ns2" 2>/dev/null | xargs -r kill 2>/dev/null
+ cleanup_all_ns
+ for id in $nsim_ids; do
+ cleanup_netdevsim "$id"
+ done
+ rm -f "$tmpfile"
+}
+
+trap cleanup EXIT
+
+setup_ns ns1 ns2 nsr1
+
+if [ ! -d "$tracing/events/workqueue" ]; then
+ mount -t tracefs nodev "$tracing" 2>/dev/null && trace_mounted=1
+fi
+if [ ! -d "$tracing/events/workqueue/workqueue_queue_work" ]; then
+ echo "SKIP: workqueue tracepoints are not available"
+ exit $ksft_skip
+fi
+
+modprobe -q netdevsim
+if [ ! -d /sys/bus/netdevsim ]; then
+ echo "SKIP: netdevsim is not available"
+ exit $ksft_skip
+fi
+
+nsim_new() {
+ local id="$1" ns="$2" name
+
+ echo "$id 1" > /sys/bus/netdevsim/new_device || return 1
+ nsim_ids="$nsim_ids $id"
+ name=$(ls /sys/bus/netdevsim/devices/netdevsim"$id"/net)
+ ip link set "$name" name "nsim$id" netns "$ns" || return 1
+ echo "nsim$id"
+}
+
+nsim_ifindex() {
+ ip netns exec "$1" cat /sys/class/net/"$2"/ifindex
+}
+
+base=$((256 + RANDOM % 128 * 4))
+a1=$(nsim_new "$base" "$ns1") || exit $ksft_skip
+a2=$(nsim_new $((base + 1)) "$nsr1") || exit $ksft_skip
+b1=$(nsim_new $((base + 2)) "$nsr1") || exit $ksft_skip
+b2=$(nsim_new $((base + 3)) "$ns2") || exit $ksft_skip
+
+# Link the peers: netdevsim takes a netns file descriptor and an ifindex.
+exec {fd1}</var/run/netns/"$ns1"
+exec {fdr}</var/run/netns/"$nsr1"
+exec {fd2}</var/run/netns/"$ns2"
+
+link=/sys/bus/netdevsim/link_device
+if ! echo "$fd1:$(nsim_ifindex "$ns1" "$a1") $fdr:$(nsim_ifindex "$nsr1" "$a2")" > $link ||
+ ! echo "$fdr:$(nsim_ifindex "$nsr1" "$b1") $fd2:$(nsim_ifindex "$ns2" "$b2")" > $link; then
+ echo "SKIP: Could not link the netdevsim devices"
+ exit $ksft_skip
+fi
+
+ip -net "$ns1" link set "$a1" up
+ip -net "$nsr1" link set "$a2" up
+ip -net "$nsr1" link set "$b1" up
+ip -net "$ns2" link set "$b2" up
+
+ip -net "$ns1" addr add 10.0.1.2/24 dev "$a1"
+ip -net "$nsr1" addr add 10.0.1.1/24 dev "$a2"
+ip -net "$nsr1" addr add 10.0.2.1/24 dev "$b1"
+ip -net "$ns2" addr add 10.0.2.2/24 dev "$b2"
+ip -net "$ns1" route add 10.0.2.0/24 via 10.0.1.1
+ip -net "$ns2" route add 10.0.1.0/24 via 10.0.2.1
+ip netns exec "$nsr1" sysctl -q net.ipv4.conf.all.forwarding=1
+
+# The statistics of a flow are polled once a tenth of its timeout went by, and
+# the flow must stay around for longer than that after it is closed.
+ip netns exec "$nsr1" sysctl -q net.netfilter.nf_flowtable_tcp_timeout=20
+
+if ! ip netns exec "$nsr1" nft -f - <<EOF
+table inet filter {
+ flowtable ft {
+ hook ingress priority 0
+ devices = { $a2, $b1 }
+ flags offload
+ }
+
+ chain forward {
+ type filter hook forward priority 0; policy accept
+ ip protocol tcp ct state established flow add @ft
+ }
+}
+EOF
+then
+ echo "SKIP: Could not load a hardware offload flowtable"
+ exit $ksft_skip
+fi
+
+if ! ip netns exec "$ns1" ping -q -c 1 -W 2 10.0.2.2 > /dev/null; then
+ echo "SKIP: no connectivity through the netdevsim devices"
+ exit $ksft_skip
+fi
+
+ip netns exec "$ns2" socat -u TCP-LISTEN:12345,reuseaddr /dev/null &
+sleep 1
+
+echo 1 > "$tracing/events/workqueue/workqueue_queue_work/enable"
+echo > "$tracing/trace"
+
+# Send data for the flow to be offloaded, then close the connection.
+(for _ in 1 2 3 4 5 6; do echo data; sleep 0.3; done) | \
+ ip netns exec "$ns1" socat -u - TCP:10.0.2.2:12345
+
+# The garbage collector runs every second: let it destroy the hardware rule,
+# and go through the flow a few more times before it expires.
+sleep 8
+
+cat "$tracing/trace" > "$tmpfile"
+echo 0 > "$tracing/events/workqueue/workqueue_queue_work/enable"
+
+destroy=$(grep -n "workqueue=nf_ft_offload_del" "$tmpfile" | head -n 1 | cut -d: -f1)
+if [ -z "$destroy" ]; then
+ echo "SKIP: the hardware rule of the flow was not destroyed"
+ exit $ksft_skip
+fi
+
+late=$(tail -n +"$((destroy + 1))" "$tmpfile" | grep -c "workqueue=nf_ft_offload_\(stats\|add\)")
+if [ "$late" -ne 0 ]; then
+ echo "FAIL: $late offload work items were queued after the hardware rule was destroyed"
+ ret=1
+else
+ echo "PASS: no offload work was queued after the hardware rule was destroyed"
+fi
+
+exit $ret
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH net 4/4] selftests: netfilter: check the GRE timeout after flowtable teardown
2026-11-18 20:12 [PATCH net 0/4] netfilter: flowtable: Preliminary fixes Florian Fainelli
` (2 preceding siblings ...)
2026-11-18 20:12 ` [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY Florian Fainelli
@ 2026-11-18 20:12 ` Florian Fainelli
2026-11-22 21:17 ` netdev-bot+sashiko
3 siblings, 1 reply; 11+ messages in thread
From: Florian Fainelli @ 2026-11-18 20:12 UTC (permalink / raw)
To: netdev
Cc: Florian Fainelli, Pablo Neira Ayuso, Florian Westphal,
Phil Sutter, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Shuah Khan, Toshiaki Makita, open list,
open list:NETFILTER, open list:NETFILTER,
open list:KERNEL SELFTEST FRAMEWORK
Add a test for "netfilter: flowtable: restore the GRE conntrack timeout on
teardown". A GRE tunnel between two namespaces goes through a router with a
flowtable offloading the GRE flow. The flowtable is removed, which tears
the flow down, and the timeout of the conntrack entry must be the GRE one,
not the day set when the flow was offloaded.
Without the fix, the entry has 86399 seconds left after teardown and the
test fails. With it, the entry has 179 seconds left, the GRE stream
timeout minus the time which went by.
Add the GRE tunnel and conntrack helper options to the config.
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
.../testing/selftests/net/netfilter/Makefile | 1 +
tools/testing/selftests/net/netfilter/config | 3 +
.../net/netfilter/nft_flowtable_gre.sh | 137 ++++++++++++++++++
3 files changed, 141 insertions(+)
create mode 100755 tools/testing/selftests/net/netfilter/nft_flowtable_gre.sh
diff --git a/tools/testing/selftests/net/netfilter/Makefile b/tools/testing/selftests/net/netfilter/Makefile
index 75d7d4495623..eefc520f3a0e 100644
--- a/tools/testing/selftests/net/netfilter/Makefile
+++ b/tools/testing/selftests/net/netfilter/Makefile
@@ -30,6 +30,7 @@ TEST_PROGS := \
nft_fib.sh \
nft_fib_nexthop.sh \
nft_flowtable.sh \
+ nft_flowtable_gre.sh \
nft_flowtable_hw_destroy.sh \
nft_interface_stress.sh \
nft_meta.sh \
diff --git a/tools/testing/selftests/net/netfilter/config b/tools/testing/selftests/net/netfilter/config
index bf7be95f7d25..5525f05d0eb6 100644
--- a/tools/testing/selftests/net/netfilter/config
+++ b/tools/testing/selftests/net/netfilter/config
@@ -55,6 +55,8 @@ CONFIG_NETFILTER_XT_MATCH_STATE=m
CONFIG_NETFILTER_XT_MATCH_STRING=m
CONFIG_NETFILTER_XT_NAT=m
CONFIG_NETFILTER_XT_TARGET_REDIRECT=m
+CONFIG_NET_IPGRE=m
+CONFIG_NET_IPGRE_DEMUX=m
CONFIG_NET_IPIP=m
CONFIG_NET_L3_MASTER_DEV=y
CONFIG_NET_NS=y
@@ -66,6 +68,7 @@ CONFIG_NF_CONNTRACK=m
CONFIG_NF_CONNTRACK_EVENTS=y
CONFIG_NF_CONNTRACK_FTP=m
CONFIG_NF_CONNTRACK_MARK=y
+CONFIG_NF_CONNTRACK_PPTP=m
CONFIG_NF_CONNTRACK_PROCFS=y
CONFIG_NF_CONNTRACK_ZONES=y
CONFIG_NF_CT_NETLINK=m
diff --git a/tools/testing/selftests/net/netfilter/nft_flowtable_gre.sh b/tools/testing/selftests/net/netfilter/nft_flowtable_gre.sh
new file mode 100755
index 000000000000..5efad6908b3f
--- /dev/null
+++ b/tools/testing/selftests/net/netfilter/nft_flowtable_gre.sh
@@ -0,0 +1,137 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Check the conntrack timeout of a GRE flow once its flowtable entry is
+# removed. A GRE flow is offloaded with the timeout of its conntrack entry set
+# to a day, which is restored to the GRE timeout when the flow is torn down.
+#
+# ns1 (10.0.1.2) <-> nsr1 (10.0.1.1, 10.0.2.1) <-> ns2 (10.0.2.2)
+#
+# A GRE tunnel connects ns1 and ns2, and nsr1 offloads the tunnel's flow.
+
+source lib.sh
+
+ret=0
+
+checktool "nft --version" "run test without nft tool"
+checktool "conntrack --version" "run test without conntrack tool"
+
+setup_ns ns1 ns2 nsr1
+
+cleanup() {
+ cleanup_all_ns
+}
+
+trap cleanup EXIT
+
+ip link add veth0 netns "$nsr1" type veth peer name eth0 netns "$ns1"
+ip link add veth1 netns "$nsr1" type veth peer name eth0 netns "$ns2"
+
+ip -net "$nsr1" link set veth0 up
+ip -net "$nsr1" link set veth1 up
+ip -net "$nsr1" addr add 10.0.1.1/24 dev veth0
+ip -net "$nsr1" addr add 10.0.2.1/24 dev veth1
+ip netns exec "$nsr1" sysctl -q net.ipv4.conf.all.forwarding=1
+
+ip -net "$ns1" link set eth0 up
+ip -net "$ns1" addr add 10.0.1.2/24 dev eth0
+ip -net "$ns1" route add 10.0.2.0/24 via 10.0.1.1
+
+ip -net "$ns2" link set eth0 up
+ip -net "$ns2" addr add 10.0.2.2/24 dev eth0
+ip -net "$ns2" route add 10.0.1.0/24 via 10.0.2.1
+
+if ! ip -net "$ns1" link add gre1 type gre local 10.0.1.2 remote 10.0.2.2 2>/dev/null; then
+ echo "SKIP: Could not create a GRE tunnel"
+ exit $ksft_skip
+fi
+ip -net "$ns2" link add gre1 type gre local 10.0.2.2 remote 10.0.1.2
+
+ip -net "$ns1" addr add 192.168.100.1/30 dev gre1
+ip -net "$ns1" link set gre1 up
+ip -net "$ns2" addr add 192.168.100.2/30 dev gre1
+ip -net "$ns2" link set gre1 up
+
+if ! ip netns exec "$nsr1" nft -f - <<EOF
+table inet filter {
+ flowtable ft {
+ hook ingress priority 0
+ devices = { veth0, veth1 }
+ }
+
+ chain forward {
+ type filter hook forward priority 0; policy accept
+ ip protocol gre ct state established flow add @ft
+ }
+}
+EOF
+then
+ echo "SKIP: Could not load the flowtable ruleset"
+ exit $ksft_skip
+fi
+
+# The timeout of an offloaded entry is not shown by the conntrack tool.
+gre_entry_offloaded()
+{
+ ip netns exec "$nsr1" conntrack -L -p gre 2>/dev/null | grep -q OFFLOAD
+}
+
+gre_entry_timeout()
+{
+ ip netns exec "$nsr1" conntrack -L -p gre 2>/dev/null | \
+ sed -n 's/^gre *47 \([0-9]*\) .*/\1/p' | head -n 1
+}
+
+gre_ping()
+{
+ ip netns exec "$ns1" ping -q -c 1 -W 1 192.168.100.2 > /dev/null
+}
+
+if ! gre_ping; then
+ echo "FAIL: no connectivity through the GRE tunnel"
+ exit 1
+fi
+
+# Keep sending, the flow needs a packet after the entry is established.
+offloaded=0
+for i in $(seq 1 10); do
+ gre_ping
+ if gre_entry_offloaded; then
+ offloaded=1
+ break
+ fi
+ sleep 0.5
+done
+
+if [ "$offloaded" -eq 0 ]; then
+ echo "SKIP: The GRE flow was not offloaded"
+ exit $ksft_skip
+fi
+
+# The entry has the timeout of an offloaded flow: remove the flowtable, which
+# tears down its flows. Nothing else refreshes the conntrack entry.
+if ! ip netns exec "$nsr1" nft delete table inet filter; then
+ echo "FAIL: could not remove the flowtable"
+ exit 1
+fi
+
+if gre_entry_offloaded; then
+ echo "FAIL: the GRE entry is still marked as offloaded"
+ ret=1
+fi
+
+timeout=$(gre_entry_timeout)
+max=$(ip netns exec "$nsr1" sysctl -n net.netfilter.nf_conntrack_gre_timeout_stream 2>/dev/null)
+[ -z "$max" ] && max=180
+
+if [ -z "$timeout" ]; then
+ echo "FAIL: no conntrack entry for the GRE flow"
+ ret=1
+elif [ "$timeout" -gt "$max" ]; then
+ echo "FAIL: the GRE entry timeout is $timeout seconds after teardown, expected at most $max"
+ ret=1
+else
+ echo "PASS: the GRE entry timeout was restored to $timeout seconds"
+fi
+
+exit $ret
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown
2026-11-18 20:12 ` [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown Florian Fainelli
@ 2026-11-21 23:10 ` Pablo Neira Ayuso
2026-11-22 21:17 ` netdev-bot+sashiko
1 sibling, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-21 23:10 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, Florian Westphal, Phil Sutter, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Shuah Khan, Toshiaki Makita, open list, open list:NETFILTER,
open list:NETFILTER, open list:KERNEL SELFTEST FRAMEWORK
Hi Florian,
On Wed, Nov 18, 2026 at 12:12:48PM -0800, Florian Fainelli wrote:
> flow_offload_add() sets the timeout of the conntrack entry to NF_CT_DAY
> for every offloaded flow, and the GC keeps extending it for GRE too.
> flow_offload_fixup_ct() only restores the conntrack timeout of TCP and
> UDP flows when the flow is torn down, so an offloaded GRE entry which does
> not see any other packet on the slow path stays for up to a day instead
> of expiring after the GRE conntrack timeout.
>
> Restore the GRE timeout, replied or unreplied, as for UDP. GRE has no
> offload timeout of its own, flow_offload_get_timeout() uses the default
> flowtable timeout for it, so use that one when the flow expired.
I think GRE has never worked then. I have been a bit skeptical about
this support, but tc/ct developers wanted to have this in.
I think no crash is going, so let's better route this through
nf-next.git.
> Fixes: 4e8d9584d154 ("netfilter: flowtable: Support GRE")
> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
> ---
> net/netfilter/nf_flow_table_core.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
> index 2aa2647ed9df..051b15aecd89 100644
> --- a/net/netfilter/nf_flow_table_core.c
> +++ b/net/netfilter/nf_flow_table_core.c
> @@ -237,6 +237,18 @@ static void flow_offload_fixup_ct(struct flow_offload *flow)
> timeout = READ_ONCE(tn->timeouts[state]);
> expired = nf_flow_has_expired(flow);
> offload_timeout = READ_ONCE(tn->offload_timeout);
> +#ifdef CONFIG_NF_CT_PROTO_GRE
> + } else if (l4num == IPPROTO_GRE) {
> + const struct nf_gre_net *tn = nf_gre_pernet(net);
> + enum gre_conntrack state =
> + test_bit(IPS_SEEN_REPLY_BIT, &ct->status) ?
> + GRE_CT_REPLIED : GRE_CT_UNREPLIED;
> +
> + timeout = READ_ONCE(tn->timeouts[state]);
> + expired = nf_flow_has_expired(flow);
> + /* GRE has no offload timeout: see flow_offload_get_timeout(). */
> + offload_timeout = NF_FLOW_TIMEOUT;
> +#endif
> } else {
> return;
> }
> --
> 2.53.0
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY
2026-11-18 20:12 ` [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY Florian Fainelli
@ 2026-11-21 23:23 ` Pablo Neira Ayuso
2026-11-22 21:17 ` netdev-bot+sashiko
1 sibling, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-21 23:23 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, Florian Westphal, Phil Sutter, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Shuah Khan, Toshiaki Makita, open list, open list:NETFILTER,
open list:NETFILTER, open list:KERNEL SELFTEST FRAMEWORK
On Wed, Nov 18, 2026 at 12:12:47PM -0800, Florian Fainelli wrote:
> nf_flow_offload_refresh() can be reached by a packet path reader which
> looked the flow up before it was torn down. NF_FLOW_PENDING keeps the
> DESTROY work from being queued while another work item is pending, but
> once the DESTROY work has run and cleared the bit, a reader can take it
> again and queue a REPLACE (or STATS) work for a flow which is already
> being removed.
>
> GC removes a hardware flow after NF_FLOW_HW_DEAD is set, and frees it after
> an RCU grace period, which the reader can outlive in a preemptible RCU
> read-side section. The queued work then dereferences a freed flow and
> the flowtable, and can program the hardware again with a rule keyed by
> the freed flow's cookie.
>
> NF_FLOW_HW_DYING is set when DESTROY is queued, and DESTROY needs
> NF_FLOW_PENDING, so a work item which holds the pending bit and finds
> NF_FLOW_HW_DYING clear prevents DESTROY from being queued until it
> completes. Check it after taking the pending bit, and do not queue
> anything other than DESTROY when it is set.
>
> Not reproduced: this is a race between a long RCU read-side section and
> the GC and offload workers. Found by review of a related change.
>
> Fixes: c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
> ---
> net/netfilter/nf_flow_table_offload.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 4365859220e6..62f460d38efa 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -1088,6 +1088,19 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
> if (test_and_set_bit(NF_FLOW_PENDING, &flow->flags))
> return NULL;
>
> + /* GC only removes a hardware flow after its DESTROY work has run, and
> + * NF_FLOW_PENDING keeps another one from being queued, so nothing can
> + * free the flow while this work is pending, unless DESTROY was queued
> + * before we took the pending bit. A reader which found the flow before
> + * it was torn down must not queue more work then, as the flow could be
> + * freed before that work runs.
> + */
> + if (cmd != FLOW_CLS_DESTROY &&
> + test_bit(NF_FLOW_HW_DYING, &flow->flags)) {
> + clear_bit(NF_FLOW_PENDING, &flow->flags);
> + return NULL;
> + }
Maybe address by checking for the _CLOSING + _TEARDOWN flag? If those
are set on, then hardware will be scheduled for removal soon.
I guess there is also another hypothetical case where _CLOSING is set
on, but HW_DYING was not set on yet?
Probably the HW_DYING bit can go away, _CLOSING was added for hw
offload specifically, to schedule the removal in hardware while the
flow still remains with IPS_OFFLOAD.
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 11434cfb105b..7104d332d98a 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -1132,7 +1132,8 @@ void nf_flow_offload_refresh(struct nf_flowtable *flowtable,
if (!offload)
return;
- if (test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
+ if (test_bit(NF_FLOW_CLOSING, &flow->flags) ||
+ test_bit(NF_FLOW_TEARDOWN, &flow->flags)) {
clear_bit(NF_FLOW_PENDING, &flow->flags);
kfree(offload);
return
> +
> offload = kmalloc_obj(struct flow_offload_work, GFP_ATOMIC);
> if (!offload) {
> clear_bit(NF_FLOW_PENDING, &flow->flags);
> --
> 2.53.0
>
>
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY
2026-11-18 20:12 ` [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY Florian Fainelli
2026-11-21 23:23 ` Pablo Neira Ayuso
@ 2026-11-22 21:17 ` netdev-bot+sashiko
1 sibling, 0 replies; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-11-22 21:17 UTC (permalink / raw)
To: florian.fainelli
Cc: netdev, pablo, fw, phil, davem, edumazet, kuba, pabeni, horms,
shuah, toshiaki.makita1, linux-kernel, netfilter-devel, coreteam,
linux-kselftest
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The new NF_FLOW_HW_DYING guard in nf_flow_offload_work_alloc()
(net/netfilter/nf_flow_table_offload.c) does not close the bug class…
- [Low] The commit message describes the race mechanism and the affected
work types imprecisely.
--
netfilter: flowtable: do not queue offload work after DESTROY
This patch makes nf_flow_offload_work_alloc() refuse to queue any work
other than FLOW_CLS_DESTROY once NF_FLOW_HW_DYING is set. The goal is to
stop a packet path reader from queueing REPLACE work for a flow that GC
is already removing, because the offload worker could then use the flow
after it has been freed.
> once the DESTROY work has run and cleared the bit, a reader can take it
> again and queue a REPLACE (or STATS) work for a flow which is already
> being removed.
[Severity: Low]
Is the STATS part accurate? The packet path only reaches
nf_flow_offload_refresh() through flow_offload_refresh(), and that queues
FLOW_CLS_REPLACE.
nf_flow_offload_stats() has a single caller, nf_flow_offload_gc_step(),
and GC skips any flow that has NF_FLOW_PENDING set:
if (test_bit(NF_FLOW_PENDING, &flow->flags))
return;
GC also never runs concurrently with itself. So STATS work that GC queues
cannot race with GC freeing the same flow.
For STATS, the only effect of this patch is that GC stops queueing STATS
for CLOSING && HW && DYING flows whose hardware rule DESTROY has already
removed.
> GC removes a hardware flow after NF_FLOW_HW_DEAD is set, and frees it after
> an RCU grace period, which the reader can outlive in a preemptible RCU
> read-side section.
Could this be worded more precisely? A reader cannot outlive a grace
period that started while it was inside its read-side section, because
the call_rcu() in flow_offload_free() waits for it.
What outlives the grace period is the REPLACE work that the reader queued
on nf_flow_offload_add_wq before rcu_read_unlock().
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 4365859220e6a..62f460d38efa2 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
> @@ -1088,6 +1088,19 @@ nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
> if (test_and_set_bit(NF_FLOW_PENDING, &flow->flags))
> return NULL;
>
> + /* GC only removes a hardware flow after its DESTROY work has run, and
> + * NF_FLOW_PENDING keeps another one from being queued, so nothing can
> + * free the flow while this work is pending, unless DESTROY was queued
> + * before we took the pending bit. A reader which found the flow before
> + * it was torn down must not queue more work then, as the flow could be
> + * freed before that work runs.
> + */
> + if (cmd != FLOW_CLS_DESTROY &&
> + test_bit(NF_FLOW_HW_DYING, &flow->flags)) {
> + clear_bit(NF_FLOW_PENDING, &flow->flags);
> + return NULL;
> + }
[Severity: High]
Does the claim that "nothing can free the flow while this work is pending"
hold for flows that GC frees through its software-only branch?
flow_offload_add() publishes both tuples in the rhashtable before
nf_flow_offload_add() sets NF_FLOW_HW:
net/netfilter/nf_flow_table_core.c:flow_offload_add() {
...
err = rhashtable_insert_fast(&flow_table->rhashtable,
&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
nf_flow_offload_rhash_params);
...
nf_ct_refresh(flow->ct, NF_CT_DAY);
if (nf_flowtable_hw_offload(flow_table))
nf_flow_offload_add(flow_table, flow);
...
}
In that window, nf_flow_offload_gc_step() can decide to tear the flow
down while NF_FLOW_HW is still clear. The teardown can come from a dying
ct, a stale dst, or NF_FLOW_TEARDOWN set by another CPU after a FIN/RST
arrives on the already-published REPLY tuple. GC then takes this branch:
if (teardown) {
if (test_bit(NF_FLOW_HW, &flow->flags)) {
...
} else {
flow_offload_del(flow_table, flow);
}
That path removes the rhashtable entries, releases the dsts and calls
call_rcu() on the flow. It never takes NF_FLOW_PENDING and never sets
NF_FLOW_HW_DYING.
The creating CPU then carries on:
CPU1 (creator) CPU2 (GC)
flow_offload_add()
rhashtable_insert_fast(REPLY)
rhashtable_insert_fast(ORIGINAL)
nf_flow_offload_gc_step()
teardown, NF_FLOW_HW clear
flow_offload_del()
flow_offload_free()
call_rcu()
nf_flow_offload_add()
set_bit(NF_FLOW_HW)
nf_flow_offload_refresh()
nf_flow_offload_work_alloc()
test_and_set_bit(NF_FLOW_PENDING) succeeds
NF_FLOW_HW_DYING clear, new check passes
queue FLOW_CLS_REPLACE
Suppose the work runs after CPU1 leaves its RCU read-side section and the
grace period ends. Would flow_offload_work_handler() then use the freed
flow in flow_offload_work_add(), in nf_flow_offload_alloc(), in
set_bit(IPS_HW_OFFLOAD_BIT, &flow->ct->status), and in
clear_bit(NF_FLOW_PENDING, &offload->flow->flags)?
If the work runs earlier, it seems it would still install a hardware rule
for a flow that is no longer in the table. GC would never DESTROY that
rule.
That is the same use-after-free and stale rule outcome the commit message
describes. As far as I can tell, no later change in this series touches
this path.
Would it make sense for GC's non-HW branch to claim NF_FLOW_PENDING, or
set a dying marker, before freeing the flow? Another option would be to
set NF_FLOW_HW before the flow is published.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118201250.2075007-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown
2026-11-18 20:12 ` [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown Florian Fainelli
2026-11-21 23:10 ` Pablo Neira Ayuso
@ 2026-11-22 21:17 ` netdev-bot+sashiko
1 sibling, 0 replies; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-11-22 21:17 UTC (permalink / raw)
To: florian.fainelli
Cc: netdev, pablo, fw, phil, davem, edumazet, kuba, pabeni, horms,
shuah, toshiaki.makita1, linux-kernel, netfilter-devel, coreteam,
linux-kselftest
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The patch adds a GRE branch to flow_offload_fixup_ct()
(net/netfilter/nf_flow_table_core.c).
--
netfilter: flowtable: restore the GRE conntrack timeout on teardown
This commit adds a GRE branch to flow_offload_fixup_ct(). When a GRE flow
is torn down, its conntrack timeout is restored to the GRE replied or
unreplied timeout. Without this, the entry keeps the NF_CT_DAY timeout it
got at offload time. GRE has no offload timeout of its own, so
NF_FLOW_TIMEOUT is subtracted when the flow has expired.
> diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
> index 2aa2647ed9df0..051b15aecd893 100644
> --- a/net/netfilter/nf_flow_table_core.c
> +++ b/net/netfilter/nf_flow_table_core.c
> @@ -237,6 +237,18 @@ static void flow_offload_fixup_ct(struct flow_offload *flow)
> timeout = READ_ONCE(tn->timeouts[state]);
> expired = nf_flow_has_expired(flow);
> offload_timeout = READ_ONCE(tn->offload_timeout);
> +#ifdef CONFIG_NF_CT_PROTO_GRE
> + } else if (l4num == IPPROTO_GRE) {
> + const struct nf_gre_net *tn = nf_gre_pernet(net);
> + enum gre_conntrack state =
> + test_bit(IPS_SEEN_REPLY_BIT, &ct->status) ?
> + GRE_CT_REPLIED : GRE_CT_UNREPLIED;
> +
> + timeout = READ_ONCE(tn->timeouts[state]);
[Severity: Medium]
Should this read the per-conntrack GRE timeouts instead of the per-netns
defaults?
The GRE tracker does not refresh entries with the pernet values directly.
In nf_conntrack_gre_packet(), the per-ct fields are set from an attached
timeout policy when one exists. The pernet defaults are only the fallback:
net/netfilter/nf_conntrack_proto_gre.c:nf_conntrack_gre_packet() {
...
if (!nf_ct_is_confirmed(ct)) {
unsigned int *timeouts = nf_ct_timeout_lookup(ct);
if (!timeouts)
timeouts = gre_get_timeouts(nf_ct_net(ct));
...
ct->proto.gre.stream_timeout = timeouts[GRE_CT_REPLIED];
ct->proto.gre.timeout = timeouts[GRE_CT_UNREPLIED];
}
...
}
Every later refresh then uses ct->proto.gre.stream_timeout or
ct->proto.gre.timeout.
GRE registers .ctnl_timeout, so an nft ct timeout object or an
nfnetlink_cttimeout policy can be attached. nft_flow_offload_eval()
rejects GRE flows that are NATed, keyed, or have a helper. It does not
reject flows that have a timeout policy.
As an example, take a policy that sets the GRE replied timeout to 2h. An
offloaded GRE v0 flow goes idle, and the GC tears it down with expired
set to true. This branch then computes the default 180s minus
NF_FLOW_TIMEOUT, which is 150s. Since nf_flow_timeout_delta(ct->timeout)
is larger than that, nf_ct_refresh() makes the entry expire in about 2.5
minutes instead of 2h.
The reverse also happens: with a policy shorter than the sysctl value, the
longer default replaces it.
Would reading ct->proto.gre.stream_timeout and ct->proto.gre.timeout here
match what the GRE tracker actually uses? The UDP branch above has the
same pattern, but that code predates this patch.
> + expired = nf_flow_has_expired(flow);
> + /* GRE has no offload timeout: see flow_offload_get_timeout(). */
> + offload_timeout = NF_FLOW_TIMEOUT;
> +#endif
> } else {
> return;
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118201250.2075007-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY
2026-11-18 20:12 ` [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY Florian Fainelli
@ 2026-11-22 21:17 ` netdev-bot+sashiko
0 siblings, 0 replies; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-11-22 21:17 UTC (permalink / raw)
To: florian.fainelli
Cc: netdev, pablo, fw, phil, davem, edumazet, kuba, pabeni, horms,
shuah, toshiaki.makita1, linux-kernel, netfilter-devel, coreteam,
linux-kselftest
Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 4
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The new test nft_flowtable_hw_destroy.sh uses the top-level
tracefs instance, which the whole system shares, and draws conclusions…
- [Medium] nft_flowtable_hw_destroy.sh never deletes the four netdevsim
devices it creates.
- [Medium] nft_flowtable_hw_destroy.sh reports SKIP instead of FAIL when
no DESTROY work is seen, even though every prerequisite has already…
- [Low] nft_flowtable_hw_destroy.sh sets
net.netfilter.nf_flowtable_tcp_timeout at line 105, before anything…
- [Low] In nft_flowtable_hw_destroy.sh, `tmpfile=$(mktemp)` runs at line
19, but `trap cleanup EXIT` is only installed at line 40.
- [Low] nft_flowtable_hw_destroy.sh starts the socat TCP listener in ns2
in the background (line 131) and then just does `sleep 1` (line 132)…
- [Low] selftests: netfilter: CONFIG_FTRACE=y alone does not enable
CONFIG_TRACING
--
selftests: netfilter: check hardware offload work after DESTROY
This adds a netdevsim based selftest. It closes a TCP flow in a hardware
offload flowtable, then uses the workqueue_queue_work tracepoint to check
that no STATS or REPLACE offload work is queued after the DESTROY work. It
also adds CONFIG_FTRACE to the netfilter selftest config.
> diff --git a/tools/testing/selftests/net/netfilter/nft_flowtable_hw_destroy.sh b/tools/testing/selftests/net/netfilter/nft_flowtable_hw_destroy.sh
> new file mode 100755
> index 0000000000000..c0675378bd86f
> --- /dev/null
> +++ b/tools/testing/selftests/net/netfilter/nft_flowtable_hw_destroy.sh
> @@ -0,0 +1,162 @@
> +#!/bin/bash
[ ... ]
> +ret=0
> +tracing=/sys/kernel/tracing
> +trace_mounted=0
> +tmpfile=$(mktemp)
> +nsim_ids=""
> +
> +checktool "nft --version" "run test without nft tool"
> +checktool "socat -h" "run test without socat"
[Severity: Low]
Is the temporary file leaked when nft or socat is missing?
checktool() in netfilter/lib.sh runs exit $ksft_skip when the tool is
missing. The trap cleanup EXIT line is only installed further down, so the
rm -f "$tmpfile" in cleanup() never runs on that path.
Could the mktemp be moved after the trap is installed?
[ ... ]
> +nsim_new() {
> + local id="$1" ns="$2" name
> +
> + echo "$id 1" > /sys/bus/netdevsim/new_device || return 1
> + nsim_ids="$nsim_ids $id"
> + name=$(ls /sys/bus/netdevsim/devices/netdevsim"$id"/net)
> + ip link set "$name" name "nsim$id" netns "$ns" || return 1
> + echo "nsim$id"
> +}
[ ... ]
> +base=$((256 + RANDOM % 128 * 4))
> +a1=$(nsim_new "$base" "$ns1") || exit $ksft_skip
> +a2=$(nsim_new $((base + 1)) "$nsr1") || exit $ksft_skip
> +b1=$(nsim_new $((base + 2)) "$nsr1") || exit $ksft_skip
> +b2=$(nsim_new $((base + 3)) "$ns2") || exit $ksft_skip
[Severity: Medium]
Are the four netdevsim devices ever deleted?
nsim_new() appends to nsim_ids, but every call here is a command
substitution, and each one runs in a subshell. The update is lost and the
parent's nsim_ids stays empty. So this loop in cleanup():
for id in $nsim_ids; do
cleanup_netdevsim "$id"
done
never writes anything to /sys/bus/netdevsim/del_device.
netdevsim's rtnl_link_ops has no netns_refund. When cleanup_all_ns deletes
the namespaces, default_device_exit_net() moves the netdevs back to
init_net, and the netdevsim$base..netdevsim$((base+3)) bus devices stay
registered. This happens on every run that gets past device creation,
whether it ends in PASS, FAIL or SKIP.
base can only take 128 values. A later run that picks the same base would
fail new_device and report SKIP.
Could nsim_ids be updated in the parent shell after each successful call
instead?
[ ... ]
> +# The statistics of a flow are polled once a tenth of its timeout went by, and
> +# the flow must stay around for longer than that after it is closed.
> +ip netns exec "$nsr1" sysctl -q net.netfilter.nf_flowtable_tcp_timeout=20
> +
> +if ! ip netns exec "$nsr1" nft -f - <<EOF
[Severity: Low]
Does this sysctl exist yet at this point?
nf_conntrack registers net.netfilter.nf_flowtable_tcp_timeout in
nf_ct_sysctl_table in nf_conntrack_standalone.c. The selftest config has
CONFIG_NF_CONNTRACK=m, and nothing before this line loads the module. The
first thing that loads it is the ct state rule in the nft -f ruleset below.
On a fresh boot, or when this test runs on its own, the write fails with
only a stderr message, and its exit status is ignored. The flow then keeps
the default 30 second timeout, not the 20 seconds the comment above relies
on. The current sleep values still give the right result, but the test is
not running with the timeout it configured.
Could the sysctl move after the ruleset is loaded, or could nf_conntrack be
loaded with modprobe first?
[ ... ]
> +ip netns exec "$ns2" socat -u TCP-LISTEN:12345,reuseaddr /dev/null &
> +sleep 1
[Severity: Low]
Is a fixed sleep 1 enough to be sure the listener is bound?
On a slow or loaded machine, the client below can connect before port 12345
is listening. The connection is then refused, no flow is added to the
flowtable, no DESTROY is queued, and the test exits with SKIP.
Other tests in this directory, such as nft_flowtable.sh, nft_nat.sh and
nft_queue.sh, use wait_local_port_listen or busywait for this. Could the
same be used here?
> +
> +echo 1 > "$tracing/events/workqueue/workqueue_queue_work/enable"
> +echo > "$tracing/trace"
> +
> +# Send data for the flow to be offloaded, then close the connection.
> +(for _ in 1 2 3 4 5 6; do echo data; sleep 0.3; done) | \
> + ip netns exec "$ns1" socat -u - TCP:10.0.2.2:12345
[ ... ]
> +destroy=$(grep -n "workqueue=nf_ft_offload_del" "$tmpfile" | head -n 1 | cut -d: -f1)
> +if [ -z "$destroy" ]; then
> + echo "SKIP: the hardware rule of the flow was not destroyed"
> + exit $ksft_skip
> +fi
[Severity: Medium]
Should this be a FAIL rather than a SKIP?
By this point the test has already shown that the offload flowtable loaded
and that forwarding works through the netdevsim devices. If no
nf_ft_offload_del work shows up, there are two possible causes. Either the
TCP connection never happened, or the kernel path that should queue DESTROY
for the closed flow is broken:
net/netfilter/nf_flow_table_core.c:nf_flow_offload_gc_step() {
...
} else if (test_bit(NF_FLOW_CLOSING, &flow->flags) &&
test_bit(NF_FLOW_HW, &flow->flags) &&
!test_bit(NF_FLOW_HW_DYING, &flow->flags)) {
nf_flow_offload_del(flow_table, flow);
...
}
Reporting either case as a skip could hide a regression in the very path
this test covers.
The exit status of the socat client pipeline above is never checked
either, so a refused or failed connection goes unnoticed. Would it make
sense to check that too?
> +
> +late=$(tail -n +"$((destroy + 1))" "$tmpfile" | grep -c "workqueue=nf_ft_offload_\(stats\|add\)")
[Severity: Medium]
Can unrelated flowtables make this fail on a fixed kernel?
nf_ft_offload_add, nf_ft_offload_del and nf_ft_offload_stats are single
module-global workqueues created in nf_flow_table_offload_init().
flow_offload_queue_work() uses them for every flowtable in every netns.
The workqueue_queue_work output only carries the work struct, function and
workqueue name. Nothing in it identifies the flow or the netns.
If any other hardware offload flowtable is active during the run, its GC
STATS work lands after this flow's DESTROY and gets counted here. The
DESTROY line picked by head -n 1 above may also belong to a different
flow.
The test also uses the top-level tracefs instance, which the whole system
shares. The enable and the buffer clear before the client connects both
act on it. On top of that, cleanup() runs:
if [ -d "$tracing/events/workqueue" ]; then
echo 0 > "$tracing/events/workqueue/workqueue_queue_work/enable"
echo > "$tracing/trace"
fi
This always disables the event and wipes the global buffer, even on early
exits that never enabled it, and the previous enable state is never
restored. Wouldn't that throw away the trace data and event setup of any
other ftrace user?
Would a private instance under $tracing/instances/ work better, removed in
cleanup() and filtered on the workqueue name? Telling flows apart would
still need some per-flow way to identify the work.
[ ... ]
> diff --git a/tools/testing/selftests/net/netfilter/config b/tools/testing/selftests/net/netfilter/config
> --- a/tools/testing/selftests/net/netfilter/config
> +++ b/tools/testing/selftests/net/netfilter/config
> @@ -16,6 +16,7 @@ CONFIG_DUMMY=m
> CONFIG_FAIL_FUNCTION=y
> CONFIG_FAULT_INJECTION=y
> CONFIG_FAULT_INJECTION_DEBUG_FS=y
> +CONFIG_FTRACE=y
> CONFIG_FUNCTION_ERROR_INJECTION=y
> CONFIG_INET_DIAG=m
> CONFIG_INET_ESP=m
[Severity: Low]
Is CONFIG_FTRACE=y enough to get the workqueue_queue_work event?
In kernel/trace/Kconfig, FTRACE is the "Tracers" menuconfig. It only
opens the if FTRACE block and does not select anything by itself.
TRACING is the hidden symbol that pulls in EVENT_TRACING, TRACEPOINTS
and tracefs. Only a tracer selects it, either FUNCTION_TRACER and
friends through GENERIC_TRACER, or ENABLE_DEFAULT_TRACERS. Nothing
else in this config fragment selects it. FTRACE also already defaults
to y with DEBUG_KERNEL, so this line adds little on its own.
Suppose a kernel is built from this fragment on top of a base config
that has no tracer enabled. It then has no tracefs and no
events/workqueue directory. nft_flowtable_hw_destroy.sh takes the
"workqueue tracepoints are not available" exit and reports SKIP, so a
CI setup that relies on the fragment never actually runs the test.
Would adding CONFIG_ENABLE_DEFAULT_TRACERS=y here pull in TRACING the
way you need? The landlock selftest config does this. Or is there
another tracer option you would rather depend on?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118201250.2075007-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net 4/4] selftests: netfilter: check the GRE timeout after flowtable teardown
2026-11-18 20:12 ` [PATCH net 4/4] selftests: netfilter: check the GRE timeout after flowtable teardown Florian Fainelli
@ 2026-11-22 21:17 ` netdev-bot+sashiko
0 siblings, 0 replies; 11+ messages in thread
From: netdev-bot+sashiko @ 2026-11-22 21:17 UTC (permalink / raw)
To: florian.fainelli
Cc: netdev, pablo, fw, phil, davem, edumazet, kuba, pabeni, horms,
shuah, toshiaki.makita1, linux-kernel, netfilter-devel, coreteam,
linux-kselftest
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In nft_flowtable_gre.sh the test treats `nft delete table inet
filter` as tearing down the offloaded GRE flow before the command…
- [Low] The timeout check in nft_flowtable_gre.sh (lines 127-135) fails
only when the restored timeout is greater than…
--
selftests: netfilter: check the GRE timeout after flowtable teardown
This adds a selftest that offloads a GRE flow through a flowtable in a
router namespace and then deletes the flowtable. It checks that the
conntrack entry timeout goes back to the GRE stream timeout instead of
the one-day offload timeout. The GRE and PPTP options are also added to
the selftest config.
> diff --git a/tools/testing/selftests/net/netfilter/nft_flowtable_gre.sh b/tools/testing/selftests/net/netfilter/nft_flowtable_gre.sh
> new file mode 100755
> index 0000000000000..5efad6908b3fc
> --- /dev/null
> +++ b/tools/testing/selftests/net/netfilter/nft_flowtable_gre.sh
> @@ -0,0 +1,137 @@
[ ... ]
> +# The entry has the timeout of an offloaded flow: remove the flowtable, which
> +# tears down its flows. Nothing else refreshes the conntrack entry.
> +if ! ip netns exec "$nsr1" nft delete table inet filter; then
> + echo "FAIL: could not remove the flowtable"
> + exit 1
> +fi
> +
> +if gre_entry_offloaded; then
> + echo "FAIL: the GRE entry is still marked as offloaded"
> + ret=1
> +fi
> +
> +timeout=$(gre_entry_timeout)
[Severity: Medium]
Is the flowtable teardown guaranteed to be finished by the time nft delete
table returns?
In net/netfilter/nf_tables_api.c, flowtable destruction seems to be
deferred to a workqueue:
nf_tables_commit_release()
schedule_work(&nft_net->destroy_work);
The work item also waits for an RCU grace period before it frees the
flowtable:
nf_tables_trans_destroy_work()
synchronize_rcu();
nft_commit_release()
nf_tables_flowtable_destroy()
nf_flow_table_free()
... flow_offload_teardown()
IPS_OFFLOAD_BIT is cleared and the GRE timeout restored only in
flow_offload_teardown():
net/netfilter/nf_flow_table_core.c:flow_offload_teardown() {
clear_bit(IPS_OFFLOAD_BIT, &flow->ct->status);
if (!test_and_set_bit(NF_FLOW_TEARDOWN, &flow->flags))
flow_offload_fixup_ct(flow);
}
If conntrack -L runs before the deferred work completes,
gre_entry_offloaded() would still see OFFLOAD and print "still marked as
offloaded".
gre_entry_timeout() would also return nothing. While the entry is
offloaded, ctnetlink_dump_info() in nf_conntrack_netlink.c does not dump
the timeout:
if (!test_bit(IPS_OFFLOAD_BIT, &ct->status) &&
(ctnetlink_dump_timeout(skb, ct, false) < 0 ||
In that case the test also prints the misleading "no conntrack entry for
the GRE flow" message, even though the entry exists.
Can this make the test fail at random on a fixed kernel? That seems most
likely on loaded or virtualized CI, where synchronize_rcu() can be slow.
Would polling with busywait or slowwait from lib.sh, until OFFLOAD clears
and a timeout is printed, avoid the race?
The comment above ("remove the flowtable, which tears down its flows") and
the commit message both describe the teardown as synchronous.
> +max=$(ip netns exec "$nsr1" sysctl -n net.netfilter.nf_conntrack_gre_timeout_stream 2>/dev/null)
> +[ -z "$max" ] && max=180
> +
> +if [ -z "$timeout" ]; then
> + echo "FAIL: no conntrack entry for the GRE flow"
> + ret=1
> +elif [ "$timeout" -gt "$max" ]; then
[Severity: Low]
This isn't a bug, but only an upper bound is checked here, so any timeout
from 0 to 180 is reported as PASS. The check does catch the 86399 regression
the commit targets.
The "ct state established" rule requires IPS_SEEN_REPLY, and the flow has
not expired. So flow_offload_fixup_ct() should pick
tn->timeouts[GRE_CT_REPLIED] without subtracting NF_FLOW_TIMEOUT, giving
about 179-180 seconds.
The following broken fixups would all still pass this check:
- one that picks GRE_CT_UNREPLIED (30s)
- one that wrongly subtracts NF_FLOW_TIMEOUT (about 150s)
- one that clamps the timeout to 0
Would a lower bound, such as max minus a small slack, better match the
"restored to the GRE timeout" behaviour described in the header comment?
> + echo "FAIL: the GRE entry timeout is $timeout seconds after teardown, expected at most $max"
> + ret=1
> +else
> + echo "PASS: the GRE entry timeout was restored to $timeout seconds"
> +fi
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118201250.2075007-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-11-22 21:17 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 20:12 [PATCH net 0/4] netfilter: flowtable: Preliminary fixes Florian Fainelli
2026-11-18 20:12 ` [PATCH net 1/4] netfilter: flowtable: do not queue offload work after DESTROY Florian Fainelli
2026-11-21 23:23 ` Pablo Neira Ayuso
2026-11-22 21:17 ` netdev-bot+sashiko
2026-11-18 20:12 ` [PATCH net 2/4] netfilter: flowtable: restore the GRE conntrack timeout on teardown Florian Fainelli
2026-11-21 23:10 ` Pablo Neira Ayuso
2026-11-22 21:17 ` netdev-bot+sashiko
2026-11-18 20:12 ` [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY Florian Fainelli
2026-11-22 21:17 ` netdev-bot+sashiko
2026-11-18 20:12 ` [PATCH net 4/4] selftests: netfilter: check the GRE timeout after flowtable teardown Florian Fainelli
2026-11-22 21:17 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox