Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: florian.fainelli@broadcom.com
Cc: netdev@vger.kernel.org, pablo@netfilter.org, fw@strlen.de,
	phil@nwl.cc, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	shuah@kernel.org, toshiaki.makita1@gmail.com,
	linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net 3/4] selftests: netfilter: check hardware offload work after DESTROY
Date: Sun, 22 Nov 2026 21:17:27 +0000	[thread overview]
Message-ID: <179538224794.3135.4220034619044485875@kernel.org> (raw)
In-Reply-To: <20261118201250.2075007-4-florian.fainelli@broadcom.com>

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

  reply	other threads:[~2026-11-22 21:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179538224794.3135.4220034619044485875@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=shuah@kernel.org \
    --cc=toshiaki.makita1@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox