Article View: linux.kernel.netdev
Article #17535Re: [PATCH net-next 02/13] netfilter: flowtable: retrieve stats on flow deletion
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 00:22
Date: Tue, 17 Nov 2026 00:22
167 lines
14759 bytes
14759 bytes
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
Technical Details
Message-ID:
<179487496533.3136.15267350352021671450@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364849-linux-kernel-netdev=dewy.ruReferences:
<20261116001612.2806263-3-pablo@netfilter.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364849-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next 02/13] netfilter: flowtable: retrieve stats on flow deletion Date: Tue, 17 Nov 2026 00:22:45 +0000 Organization: Usenet Network Message-ID: <179487496533.3136.15267350352021671450@kernel.org> References: <20261116001612.2806263-3-pablo@netfilter.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2202565"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:+ZBD8JL8IoC8gtHTAx+Au0uS5pE= sha256:b+nmiKU6Oa82TrJ5JNKi7qHeMCgCTIFIBgeTObmY78k= sha1:KXc9Gt8sOIVf30ytL8PHOrtkBWM= sha256:puEIbIIEYNZn2GlIwygxCXSB0CpEPRKAFsZWlC+L9kA= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id DED12114DDF; Tue, 17 Nov 2026 03:23:12 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B79jXX0Lh5xm; Tue, 17 Nov 2026 03:23:09 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364849-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 6571E114DDA; Tue, 17 Nov 2026 03:22:57 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id E4A5630DDE; Tue, 17 Nov 2026 00:22:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794874967; b=EbKt+oKuVg+IPt7BHaLxxsnigofGp9QHgZsO+oz0Zku4OILTwZ1MXzhsRYvsjKhf6E8R OxBTnCbw3NjQw0PGbprDs2fZuvu5NcwW7CQ97kLmqWzReAD7BKJJPe+3PUK2QzSZQICaC vDSQ0XY2kuMgT02zEVwCqX22nsl1+ayNXvdpMVnMdO7lKPzlb47zTqr00Qaxphnn1lSFC lOEbASumY+etjYXzDTxcI1W4TmKA8de6p1WdjMmKAByjykXqUBNoGIKOPQjEPr1ys7XSX BtiHHrXKpXIOY/DaKVTBkUGJVUD4Clnuzf65UOzNU7KiinX4B9M5bqsGfn+D9sodqmQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794874967; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=tTwP+TYbtyv9AfS6DHhWvTmxGIqrXHsxpagAs0d6eLA=; b=RyBTsZjCF4UMRgb093FLfEdy697Db+R0nCi2NHZAY8PpS8ZoLRPplhFueHKwH17lad5v GlSA/fiLqxUKWOBbD0SjA3Wc4N6vrH5IM1UCb/gFCksZ1TAKcFs/VDx7OUHW2C2kve0am ZWNsf6/auruE/RKnC64pAhbIwXBqdqgEAGgJPDtl/xk7CBfJEp0YMTRX9KVZWvUylb5cD NjIGodptkKOpZRKN+WJETMHtGe71jNsaeiOUdkG5mSALPdQhmVH5VdFOz89WkO2u3LKoA 2cvHeAj65V3EMVOnhb/Rgx4/r6kBw6elIbzPwUo0hanNt4H+rMfN3C8dLlA3Ng4yqiw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="bRsk+T/z"; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C6E4606A333; Tue, 17 Nov 2026 00:22:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bRsk+T/z X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794874966; b=EnxffAIwJmQUyIGyDj6VpZFuqI6hvOco2ewzW7yP2g4tjFhl8yAgX8shxjNNGXLr44D1 1qDKYj2dTba7gzTKeTy6ZchCTtsZNat8/MNroapTVh/SkZrqhP1cOsSI1cww0vRrvEPNn yIsHNb5Ai9/IQjf03j9BUcLn+3AnjpxAMoZ1rjRqRHXrXKWbrkS37yXhE4wqjc+RkT8BQ RiksnL334G5jLblUV1vBYXyx4Rx8W+fYgY4W2HrxIrQzNUaXaRkYpIH7WaY1zqOzu72yn 8unFQSuUTlshI2Feif3b6n+zAGBQ/6tWniEYyUlGEZe5LICs4TN+mpDa/sM5XHXnbww== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794874966; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=tTwP+TYbtyv9AfS6DHhWvTmxGIqrXHsxpagAs0d6eLA=; b=CKUowns6nRURralS4PlL+tE6dVV0s5iqWbz9bNe2fXsHfpFSUhfYvje7SklqwPWKTioH iRw47aHvC1Td0By5xzYcNtWNZVIZ8xGxhoz4ubPzIrnP9pW9WuXt3aNC00PtSxvisK7Ib MJF8Inl3bb4dRZwdd1z7TRdurR/OuIRSZ4HG2K4HBuuCswkMNSA2Gb1ZWoClqZ7WEMLDd GTa5x3TDokrkDbc6riJywtV5O5uxMzY03JJ8xRCwwO+lrrw0A4AFXsMV4vKuUpnc+M9mB wvYshCZ29BSdNxBQIN8VOGCYFV+btK3jek52ABOscu/94dLzcKRXmO5AYhVVZU1KvZw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="bRsk+T/z"; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6005F606A334; Tue, 17 Nov 2026 00:22:46 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA2031F000C4; Tue, 17 Nov 2026 00:22:45 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794874966; bh=tTwP+TYbtyv9AfS6DHhWvTmxGIqrXHsxpagAs0d6eLA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=bRsk+T/z5TI1Sfcb4VB2aeDANy5yTXxiiCwROQN+GIGpwXa7MsWi6z8N+8OZ6bVnf CXtNHFwvfaVNZ53sTr+FpzdbC6vNfcrHWoBPfuFztkaCaU779JipvsYnZv3RkkHqke SLuLRkkW6ZPH25NIF0FGqHRvVMgCXi+ussLUYteYUu5mCQp/m24pzb6zsqROOeJwvd FjzwlEFq/IbG3pTMsdHhXtUi3xX4yeo/UR7zFo+kNpUoZWoZdG+O/z9AA9fbLbGQWw Q//4FZWRRnDZwPZxzrpoRpOF6WFydCbxpeI4YySmjOo17LI19W0dugH/NpWlkzqbWv 4XPTyKZw9x0dg== X-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 X-In-Reply-To: <20261116001612.2806263-3-pablo@netfilter.org> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list