Netdev List
 help / color / mirror / Atom feed
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 03/13] net: ethernet: mtk_ppe: update stats on flow deletion
Date: Tue, 17 Nov 2026 00:22:46 +0000	[thread overview]
Message-ID: <179487496641.3136.14593435463868891598@kernel.org> (raw)
In-Reply-To: <20261116001612.2806263-4-pablo@netfilter.org>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · 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] mtk_flow_offload_update_stats()
  (drivers/net/ethernet/mediatek/mtk_ppe_offload.c:539) uses…
- [Medium] mtk_flow_offload_destroy()
  (drivers/net/ethernet/mediatek/mtk_ppe_offload.c:557-559) takes the…
- [Medium] net: mtk_ppe: mtk_flow_offload_update_stats() reads MIB 0 on
  L2 flows

--

net: ethernet: mtk_ppe: update stats on flow deletion

This commit moves the stats collection out of mtk_flow_offload_stats()
and into a new helper, mtk_flow_offload_update_stats(). The helper is
also called from mtk_flow_offload_destroy(), so final counters are
reported when a flow is deleted, following "netfilter: flowtable:
retrieve stats on flow deletion".

> diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> index 99b28aaa7cc47..8ca694bb5e1b7 100644
> --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
> @@ -526,6 +526,24 @@ mtk_flow_offload_replace(struct mtk_eth *eth, struct flow_cls_offload *f,
>  	return err;
>  }
>  
> +static void
> +mtk_flow_offload_update_stats(struct mtk_eth *eth, struct flow_cls_offload *f,
> +			      struct mtk_flow_entry *entry)
> +{
> +	struct mtk_foe_accounting diff;
> +	u32 idle;
> +
> +	idle = mtk_foe_entry_idle_time(eth->ppe[entry->ppe_index], entry);
> +	f->stats.lastused = jiffies - idle * HZ;
> +
> +	if (entry->hash != 0xFFFF &&
> +	    mtk_foe_entry_get_mib(eth->ppe[entry->ppe_index], entry->hash,
> +				  &diff)) {

[Severity: Medium]
Does this hash check catch bridge flows?

mtk_flow_offload_replace() allocates the entry with kzalloc_obj(), so
entry->hash starts at 0. For MTK_PPE_PKT_TYPE_BRIDGE,
mtk_foe_entry_commit() returns via mtk_foe_entry_commit_l2() before
entry->hash is set to 0xffff:

drivers/net/ethernet/mediatek/mtk_ppe.c:mtk_foe_entry_commit() {
    ...
	if (type == MTK_PPE_PKT_TYPE_BRIDGE)
		return mtk_foe_entry_commit_l2(ppe, entry);

	hash = mtk_ppe_hash_entry(ppe->eth, &entry->data);
	entry->hash = 0xffff;
    ...
}

mtk_foe_entry_commit_l2() sets entry->type to MTK_FLOW_TYPE_L2 and adds
the template to ppe->l2_flows, but leaves entry->hash alone. Hardware
FOE slots only go to the MTK_FLOW_TYPE_L2_SUBFLOW entries on
entry->l2_flows. mtk_flow_entry_update() and __mtk_foe_entry_clear()
both check for MTK_FLOW_TYPE_L2 before using entry->hash, but this
helper only checks entry->hash != 0xFFFF.

So for a bridge flow it looks like mtk_foe_entry_get_mib() runs with
hash 0. Because mtk_ppe_start() enables MTK_PPE_MIB_CFG_RD_CLR, that
read also clears hardware MIB counter 0. The bridge rule is credited
with another flow's packets and bytes, and whatever L3/L4 flow is
bound at FOE index 0 loses them from its next FLOW_CLS_STATS delta.

This already happens on FLOW_CLS_STATS today, but calling the helper
from mtk_flow_offload_destroy() adds the same destructive read on
every FLOW_CLS_DESTROY of a bridge flow, and those bogus counts end
up in the final stats handed back to the caller.

Should the helper skip entry->type == MTK_FLOW_TYPE_L2, or should
mtk_foe_entry_commit_l2() initialize entry->hash to 0xffff? If bridge
flows are expected to report stats at all, would the counters of the
subflows on entry->l2_flows need to be summed instead?

[Severity: Medium]
Does this hash check work for bridge (MTK_FLOW_TYPE_L2) base entries?

mtk_flow_offload_replace() allocates the entry with kzalloc_obj(), so
hash starts at 0. For MTK_PPE_PKT_TYPE_BRIDGE, mtk_foe_entry_commit()
returns before hash is set to 0xffff:

drivers/net/ethernet/mediatek/mtk_ppe.c:mtk_foe_entry_commit() {
    ...
	if (type == MTK_PPE_PKT_TYPE_BRIDGE)
		return mtk_foe_entry_commit_l2(ppe, entry);

	hash = mtk_ppe_hash_entry(ppe->eth, &entry->data);
	entry->hash = 0xffff;
    ...
}

mtk_foe_entry_commit_l2() only sets entry->type. mtk_flow_entry_update()
takes the goto out path for L2 entries. L2 masters are never placed on
foe_flow[]. So the master's hash appears to stay at 0.

If so, mtk_foe_entry_get_mib(ppe, 0, &diff) runs for bridge flows.
mtk_ppe_start() enables MTK_PPE_MIB_CFG_RD_CLR, so this read also clears
hardware MIB slot 0.

With the new call in mtk_flow_offload_destroy(), every FLOW_CLS_DESTROY
of a bridge flow now read-clears slot 0. Would an unrelated L3/L4 flow
bound at FOE index 0 then lose those packets and bytes from its next
FLOW_CLS_STATS delta, and undercount its conntrack counters?

The bridge flow's own subflow counters (the cur->hash entries on
entry->l2_flows) also don't seem to be read before
__mtk_foe_entry_clear() frees them.

L2 masters keeping hash == 0 predates this patch and already affects
mtk_flow_offload_stats(). The destructive read on the destroy path is
new, though. Could the helper skip entries with
entry->type == MTK_FLOW_TYPE_L2? Alternatively, could
mtk_foe_entry_commit_l2() set hash to 0xffff?

> +		f->stats.pkts += diff.packets;
> +		f->stats.bytes += diff.bytes;
> +	}
> +}
> +
>  static int
>  mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
>  {
> @@ -536,6 +554,8 @@ mtk_flow_offload_destroy(struct mtk_eth *eth, struct flow_cls_offload *f)
>  	if (!entry)
>  		return -ENOENT;
>  
> +	mtk_flow_offload_update_stats(eth, f, entry);
> +
>  	mtk_foe_entry_clear(eth->ppe[entry->ppe_index], entry);

[Severity: Medium]
Can traffic forwarded between the stats snapshot and the invalidation
go missing from the final counters?

The read-clear happens in this chain:

mtk_flow_offload_update_stats()
  -> mtk_foe_entry_get_mib()
    -> mtk_mib_entry_read()

It runs while hwe->ib1 is still MTK_FOE_STATE_BIND, and it holds only
mtk_flow_offload_mutex, not ppe_lock. The entry is invalidated later, in
a separate critical section:

drivers/net/ethernet/mediatek/mtk_ppe.c:__mtk_foe_entry_clear() {
    ...
	if (entry->hash != 0xffff) {
		struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, entry->hash);

		hwe->ib1 &= ~MTK_FOE_IB1_STATE;
		hwe->ib1 |= FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_INVALID);
		dma_wmb();
		mtk_ppe_cache_clear(ppe);
		...
			acct->packets = 0;
			acct->bytes = 0;
	}
	entry->hash = 0xffff;
    ...
}

The PPE counts packets it forwards in that window into the MIB slot, but
they never reach f->stats. The flowtable core now passes f->stats to
nf_ct_acct_add() as the final sync. This can happen whenever traffic is
still flowing at deletion time (flowtable flush, conntrack -D, device
teardown).

__mtk_foe_entry_clear() zeroes only the software acct_table copy and
then drops the index, so the leftover hardware MIB counts are never
drained. If the hardware doesn't reset the slot on rebind, could those
counts be charged to the next flow bound at that index? That part
predates this patch, and the patch makes it smaller.

Just moving the helper call after mtk_foe_entry_clear() won't work,
because entry->hash is reset there. Could the code instead save the
hash, invalidate and flush the entry, and then do the final read-clear
on the saved index?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116001612.2806263-2-pablo%40netfilter.org

  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
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 [this message]
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=179487496641.3136.14593435463868891598@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