From: netdev-bot+sashiko@kernel.org
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
Subject: Re: [PATCH net-next 02/13] netfilter: flowtable: retrieve stats on flow deletion
Date: Tue, 17 Nov 2026 00:22:45 +0000 [thread overview]
Message-ID: <179487496533.3136.15267350352021671450@kernel.org> (raw)
In-Reply-To: <20261116001612.2806263-3-pablo@netfilter.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · 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] Destroy-time stats only work for drivers that fill `f->stats`
on FLOW_CLS_DESTROY, and the series converts only two.
- [Medium] netfilter: flowtable: broken timeout update in
flow_offload_update_stats()
--
netfilter: flowtable: retrieve stats on flow deletion
The flowtable offload code now passes a stats object to drivers with
FLOW_CLS_DESTROY. The result goes through a new flow_offload_update_stats()
helper, which the FLOW_CLS_STATS path also uses, so the last hardware
counters can be synced to conntrack when a flow is deleted. Drivers have
to be updated to fill in the stats at destroy time.
Closes: https://patch.msgid.link/netfilter-devel/20261021175030.4800-1-dreyksmail@gmail.com/
> diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
> index 3a18fa48cadb0..c302051489f23 100644
> --- a/net/netfilter/nf_flow_table_offload.c
> +++ b/net/netfilter/nf_flow_table_offload.c
[ ... ]
> +static void flow_offload_update_stats(struct flow_offload_work *offload,
> + struct flow_stats *stats)
> +{
[ ... ]
> + if (offload->flowtable->flags & NF_FLOWTABLE_COUNTER) {
> + if (stats[0].pkts)
> + nf_ct_acct_add(offload->flow->ct,
> + FLOW_OFFLOAD_DIR_ORIGINAL,
> + stats[0].pkts, stats[0].bytes);
> + if (stats[1].pkts)
> + nf_ct_acct_add(offload->flow->ct,
> + FLOW_OFFLOAD_DIR_REPLY,
> + stats[1].pkts, stats[1].bytes);
> + }
> +}
[ ... ]
> @@ -991,10 +1013,15 @@ static void flow_offload_work_add(struct flow_offload_work *offload)
>
> static void flow_offload_work_del(struct flow_offload_work *offload)
> {
> + struct flow_stats stats[FLOW_OFFLOAD_DIR_MAX] = {};
> +
> clear_bit(IPS_HW_OFFLOAD_BIT, &offload->flow->ct->status);
> - flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_ORIGINAL);
> + flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_ORIGINAL, &stats[0]);
> if (test_bit(NF_FLOW_HW_BIDIRECTIONAL, &offload->flow->flags))
> - flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_REPLY);
> + flow_offload_tuple_del(offload, FLOW_OFFLOAD_DIR_REPLY, &stats[1]);
> +
> + flow_offload_update_stats(offload, stats);
> +
[Severity: Medium]
Moving the timeout update into a shared helper means it now also runs
on FLOW_CLS_DESTROY. Is that safe?
flow->timeout is a u32 stamp that is compared against
nf_flowtable_time_stamp, which is (u32)jiffies. flow_stats.lastused is
a u64 that drivers fill from the full jiffies value. Once a 64-bit
kernel has been up for about five minutes, jiffies is above 2^32. At
that point lastused + flow_offload_get_timeout() always has upper bits
set, so max_t(u64, ...) always picks it over the zero-extended
flow->timeout. The result is then truncated back to u32. The hardware
value always wins, even when it is older than what software has
already recorded.
That u32/u64 mixing already exists in flow_offload_work_stats(), but
on deletion the flow is not necessarily going away.
nf_flow_offload_gc_step() calls nf_flow_offload_del() for
NF_FLOW_CLOSING flows and keeps them in the software flowtable until
flow->timeout expires. If software saw the FIN/RST and refreshed
flow->timeout, the stale hardware lastused can now move flow->timeout
backwards. The closing flow then expires early.
The opposite happens with drivers that don't fill cls_flow.stats on
destroy, which today is every driver until the later patches land.
stats[] stays zeroed and lastused is 0, so the helper computes
max(flow->timeout, offload_timeout). Whenever the u32 flow->timeout has
wrapped into [0, offload_timeout), it gets bumped to offload_timeout.
That silently extends the software lifetime of the flow.
For NF_FLOW_TEARDOWN flows, flow_offload_teardown() has already run
flow_offload_fixup_ct() before nf_flow_offload_del() is queued. So
updating flow->timeout at deletion time doesn't reach conntrack anyway.
Does flow_offload_work_del() need to touch flow->timeout at all, or
would syncing the packet and byte counters be enough there? If the
timeout update has to stay, could it be skipped when lastused is 0?
Could the comparison also be done on the truncated u32 values with a
wrap-safe check, similar to how nf_flow_has_expired() compares
flow->timeout, rather than max_t(u64, ...)?
[Severity: Medium]
This depends on each driver's FLOW_CLS_DESTROY handler filling in
cls_flow.stats. If a driver doesn't touch it, stats[] stays zeroed. Because
of the stats[i].pkts checks, flow_offload_update_stats() then skips
nf_ct_acct_add().
Later patches in this series convert mtk_ppe and airoha. Are there other
in-tree backends that still lose the final counter delta on deletion?
For mlx5 conntrack offload, mlx5_tc_ct_block_flow_offload() in
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c sends DESTROY straight
to the del handler:
case FLOW_CLS_DESTROY:
return mlx5_tc_ct_block_flow_offload_del(ft, f);
case FLOW_CLS_STATS:
return mlx5_tc_ct_block_flow_offload_stats(ft, f);
mlx5_tc_ct_block_flow_offload_del() removes the entry and drops the
counter reference. It never does a final mlx5_fc_query_cached() /
flow_stats_update(). The representor nft flowtable path
mlx5e_rep_setup_ft_cb()->mlx5e_delete_flower() seems to behave the same
way.
For nfp, nfp_fl_ct_offload_nft_flow() does:
case FLOW_CLS_DESTROY:
ct_map_ent = rhashtable_lookup_fast(&zt->priv->ct_map_table, &flow->cookie,
nfp_ct_map_params);
return nfp_fl_ct_del_flow(ct_map_ent);
This frees the entry without the delta accounting that nfp_fl_ct_stats()
does for FLOW_CLS_STATS.
act_ct always sets NF_FLOWTABLE_COUNTER in tcf_ct_flow_table_get(). On
these drivers, could packets and bytes counted in hardware between the
last FLOW_CLS_STATS poll and deletion still never reach the conntrack
counters? That looks like the same missing last stats sync that the
Closes: tag refers to.
sfc doesn't look affected, since efx_tc_ct_stats() only reports lastused.
Could the new driver contract also be documented? The DESTROY-time values
need to be deltas since the last FLOW_CLS_STATS, the same as the STATS
paths report, not cumulative totals. Otherwise nf_ct_acct_add() counts
some traffic twice. They also need to be read before the hardware counter
or MIB slot is released.
> set_bit(NF_FLOW_HW_DEAD, &offload->flow->flags);
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116001612.2806263-2-pablo%40netfilter.org
next prev parent reply other threads:[~2026-11-17 0:22 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 0:15 [PATCH net-next,v2 00/13] Netfilter updates for net-next Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 01/13] netfilter: flowtable: do not hw offload flows in teardown state Pablo Neira Ayuso
2026-11-16 0:23 ` netdev-bot+sinfo
2026-11-16 0:27 ` Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 02/13] netfilter: flowtable: retrieve stats on flow deletion Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko [this message]
2026-11-16 0:16 ` [PATCH net-next 03/13] net: ethernet: mtk_ppe: update " Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 04/13] net: airoha: " Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 05/13] netfilter: xt_time: fix monthday computation for dates past 2039 Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 06/13] netfilter: nft_flow_offload: do not offload multicast Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 07/13] netfilter: flowtable: purge entries immediately when destroying the flowtable Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 08/13] selftests: netfilter: nf_queue: drop the no-op loop initializer Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 09/13] netfilter: flowtable: do not scrub as crossing netns Pablo Neira Ayuso
2026-11-17 0:22 ` netdev-bot+sashiko
2026-11-16 0:16 ` [PATCH net-next 10/13] netfilter: flowtable: tunnel device poisons h_source of fast-path frames Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 11/13] netfilter: flowtable: do not clear the offload bit twice Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 12/13] netfilter: nfnetlink_queue: make skb writable before writing NFQA_L2HDR Pablo Neira Ayuso
2026-11-16 0:16 ` [PATCH net-next 13/13] selftests: netfilter: add UDP flowtable offload test Pablo Neira Ayuso
2026-11-17 0:22 ` 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=179487496533.3136.15267350352021671450@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
/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