🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25387

Re: [PATCH net-next v3] net: dsa: motorcomm: Add limited ACL flow statistics support

#25387
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 17:30
249 lines
16635 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 2

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] yt921x_acl_rule_ext_parse_flow_action() in
  drivers/net/dsa/motorcomm/tc.c treats FLOW_ACTION_HW_STATS_DONT_CARE…
- [Medium] A DELAYED-only stats request (tc `hw_stats delayed`,
  FLOW_ACTION_HW_STATS_DELAYED = 2) is accepted even though the hardware…
- [Low] The commit message says 'Enable the counter unless disabled by
  user', but yt921x_acl_rule_ext_parse_flow_action() never assigns a…
- [Low] yt921x_acl_add() enables a hardware FLOWSTAT counter (writes
  YT921X_FLOWSTATn_CTRL(statid) = TYPE_FLOW | CTRL_EN, then zeroes STAT)…

--

net: dsa: motorcomm: Add limited ACL flow statistics support

This commit adds .cls_flower_stats() support to the yt921x DSA driver. It
uses the 64 hardware FLOWSTAT counters in packet mode and assigns them to
ACL rules where possible. skip_sw rules with an unsatisfiable stats
configuration are rejected.

> diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
> index e3f057ed580f5..84875b311161e 100644
> --- a/drivers/net/dsa/motorcomm/tc.c
> +++ b/drivers/net/dsa/motorcomm/tc.c

[ ... ]

> @@ -1052,6 +1061,12 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
>  			goto fallback;
>  		}
>  
> +		if (act->hw_stats & FLOW_ACTION_HW_STATS_ANY) {
> +			ruleext->stat_applicable = true;
> +			ruleext->stat_required |= act->hw_stats !=
> +						  FLOW_ACTION_HW_STATS_ANY;
> +		}

[Severity: Medium]

Does this treat FLOW_ACTION_HW_STATS_DONT_CARE as an explicit stats
request?

DONT_CARE is 0x7 (IMMEDIATE | DELAYED | DISABLED). It passes the ANY mask
test and is also != ANY, so both stat_applicable and stat_required get set.

flow_rule_alloc() gives every action this value by default:

net/core/flow_offload.c:flow_rule_alloc() {
    ...
	rule->action.entries[i].hw_stats = FLOW_ACTION_HW_STATS_DONT_CARE;
    ...
}

nftables netdev hardware offload never changes it. Also,
nft_flow_cls_offload_setup() memsets cls_flow, so skip_sw is false. The
rule then reaches yt921x_dsa_cls_flower_add() through
dsa_user_setup_tc_block() as a CLSACT_INGRESS flower rule.

An nft "fwd to" rule that targets a port on the same switch becomes a
FLOW_ACTION_REDIRECT. redir stays true and stat_veto stays false, so each
such rule takes one of the 64 FLOWSTAT counters.

Once the counters run out, yt921x_acl_add() takes this branch:

	} else if (ruleext->stat_required) {
		if (!ruleext->r.sw_assisted) {
			...
			return -EOPNOTSUPP;
		}
		use_trap = true;

sw_assisted is true here, so the hardware redirect is replaced by FWD_TRAP
and all matching traffic goes to the CPU. This happens even though the
requester said it doesn't care about stats; the value even includes the
DISABLED bit.

These rules also use up counters that later tc "skip_sw hw_stats
immediate" rules then can't get ("No more flowstats, but HW stats
requested").

For comparison, mlxsw's spectrum_flower.c checks
hw_stats & FLOW_ACTION_HW_STATS_DISABLED first and installs no counter in
that case. Should DONT_CARE be handled the same way here?

[ ... ]

> @@ -1143,7 +1165,29 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
>  			break;
>  	}
>  
> +	/* Software counts frames for non-skip_sw rules; a hardware counter
> +	 * would double count those. Do not assign a counter if the frames may
> +	 * flow to CPU.
> +	 */
> +	if (!cls->common.skip_sw && !redir)
> +		stat_veto = true;
> +	if (stat_veto)
> +		ruleext->stat_applicable = false;

[Severity: Low]

The commit message says:

  "Enable the counter unless disabled by user"

With this veto, some rules never get a counter:

  - FLOW_ACTION_DROP rules
  - FLOW_ACTION_POLICE rules
  - non-skip_sw rules that don't end in a local redirect (accept,
    priority-only, trap and fallback)

For example, a non-skip_sw drop rule with an explicit "hw_stats immediate"
is accepted without any warning. Hardware drops the frames and tc reports
0. Non-skip_sw accept rules forwarded in hardware behave the same way.

Could the commit message describe when counters are actually assigned?

Separately, the commit message doesn't mention that the existing
meters_map updates in yt921x_acl_add() and yt921x_acl_del() change from
set_bit()/clear_bit() to __set_bit()/__clear_bit(). That looks safe, since
all meters_map accesses happen under priv->reg_lock. Should it be
mentioned in the commit message or split into its own patch?

> +	/* Do not check on non-skip_sw rules: we can't stop software from
> +	 * installing them.
> +	 */
> +	if (cls->common.skip_sw) {
> +		if (!flow_action_mixed_hw_stats_check(flow_action, extack))
> +			return -EOPNOTSUPP;
> +		if (ruleext->stat_required && !ruleext->stat_applicable) {
> +			NL_SET_ERR_MSG_MOD(extack,
> +					   "HW stats not available for rules that may drop frames");
> +			return -EOPNOTSUPP;
> +		}
> +	}

[Severity: Medium]

Is a DELAYED-only request (tc "hw_stats delayed") meant to be accepted
here?

FLOW_ACTION_HW_STATS_DELAYED is 2. In the loop above, (2 & ANY) sets
stat_applicable and (2 != ANY) sets stat_required.
flow_action_mixed_hw_stats_check() only checks that all actions use the
same type, not which type it is. Nothing here rejects a type the hardware
can't provide.

yt921x_acl_add() then allocates an immediate counter, and
yt921x_acl_stat() always reports IMMEDIATE:

	flow_stats_update(stats, aclrule->stat_pkt_mode ? 0 : diff,
			  !aclrule->stat_pkt_mode ? 0 : diff, 0,
			  diff ? jiffies : 0, FLOW_ACTION_HW_STATS_IMMEDIATE);

As a result, TCA_ACT_USED_HW_STATS reports a type outside the requested
mask.

For non-skip_sw rules, a DELAYED-only request is also treated as required.
When the counters run out, it triggers the CPU trap fallback in
yt921x_acl_add().

The commit message says:

  "reject rules with unsatisfiable stats configuration"

and the v2 changelog says "reject explicit delay request". This version
doesn't seem to have such a check. mlxsw's spectrum_flower.c returns
"Unsupported action HW stats type" for types that are neither immediate
nor disabled, and mlx5/nfp use flow_action_hw_stats_check(). Would a
similar check be needed here?

[ ... ]

> @@ -1467,6 +1558,42 @@ yt921x_acl_add(struct yt921x_priv *priv,
>  		}
>  	}
>  
> +	if (!ruleext->stat_applicable) {
> +		statid = YT921X_FLOWSTAT_NUM;
> +	} else {
> +		statid = find_first_zero_bit(priv->flowstats_map,
> +					     YT921X_FLOWSTAT_NUM);
> +		if (statid < YT921X_FLOWSTAT_NUM) {
> +			u32 zeros[2] = {};
> +
> +			ctrl = YT921X_FLOWSTAT_CTRL_TYPE_FLOW |
> +			       YT921X_FLOWSTAT_CTRL_EN;
> +			if (ruleext->r.stat_pkt_mode)
> +				ctrl |= YT921X_FLOWSTAT_CTRL_PKT_MODE;
> +			res = yt921x_reg_write(priv,
> +					       YT921X_FLOWSTATn_CTRL(statid),
> +					       ctrl);
> +			if (res)
> +				return res;

[Severity: Low]

The counter is enabled in hardware here, before several steps that can
still fail:

  - the STAT write just below
  - kvzalloc_obj() / kvmemdup()
  - the YT921X_ACL_PORT write
  - yt921x_acl_commit()

None of the error paths after this point write
YT921X_FLOWSTATn_CTRL(statid) back to disabled. Is that intended?

yt921x_acl_del() also only releases the ID in the software bitmap:

	if (aclrule->action[0] & YT921X_ACL_ACTa_FLOWSTAT_EN)
		__clear_bit(FIELD_GET(YT921X_ACL_ACTa_FLOWSTAT_ID_M,
				      aclrule->action[0]),
			    priv->flowstats_map);

In the normal path, nothing references the counter after it is released,
and reuse reprograms it.

After a register I/O failure, though, a stale hardware entry can still
reference it:

  - yt921x_acl_del() continues after a failed yt921x_acl_commit() ("the
    kernel never rolls back on failure").
  - A partially failed commit in yt921x_acl_add() can leave an ACL action
    with FLOWSTAT_EN | FLOWSTAT_ID(statid) in hardware.

Can that stale entry keep incrementing a counter the driver has released?
If so, the next rule given that ID would report traffic it never matched.

Disabling the counter on release and on add failure would keep hardware
in step with flowstats_map. A complete fix would also avoid releasing the
ID while hardware may still reference it. The meter handling has the same
lack of rollback.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130164502.1863422-1-mmyangfl%40gmail.com
Technical Details
Message-ID: <179614622659.3146.9681438198461859620@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375245-linux-kernel-netdev=dewy.ru
References: <20261130164502.1863422-1-mmyangfl@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375245-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3] net: dsa: motorcomm: Add limited ACL flow
 statistics support
Date: Tue, 01 Dec 2026 17:30:26 +0000
Organization: Usenet Network
Message-ID: <179614622659.3146.9681438198461859620@kernel.org>
References: <20261130164502.1863422-1-mmyangfl@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1778272"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VjSLPms3kg/vZTv/fR40Po1vfaQ= sha256:aesd1JTmW76lneFokALSdVy5cqwuOMJMMpC4hyl+XD4=
	sha1:F4mPr1hiBV6saEIVHWbJdjdvYKw= sha256:vTAZn5NJAvO02Eeb503ZuKBPkoPF3o35beotK9z04Mg=
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 646AF117437; Tue,  1 Dec 2026 20:30:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 4BgJ5hv6vSjA;
	Tue,  1 Dec 2026 20:30:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375245-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 C6C37117408; Tue,  1 Dec 2026 20:30:38 +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 2A8E1276B9; Tue,  1 Dec 2026 17:30:35 +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=1796146233;
	b=n7ly/dTmK20ijD6zIoRp7LKKvFqrgNTR7tjGst38RGset/AHQ51Pc41eQ3KcvqA8h6nC
	 bwyUGC0x8ptd36YUMEjP6mvKy2NlxnbQ4R8WH+CekwRe1pRyXMQUaL+lsfRC/lblg9onb
	 tBhmjwT7z1r1L/RpH9EcF0kqWRiK6/bAwccgIp9vet7E28/orAC4Z05YQWrP2VYFP6rLV
	 A7dDno2QJ8WtTrZsPRr0Fhqr4kXYw7YYexT/ykSzLrMxGgb//zL9x+cvOZjZ0aMpAiefW
	 qzUMK/t89qkKZl1HFre79zIVeU7QOtFfZ/cIqB9nacAIzgTafXTcDf7ewrzLgRaXcpQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796146233;
	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=Q2bUtIU8yL+m/fJtW/ElIP3SVMwxjjHmeea1pihmfmc=;
	b=iwquMRhnlpoNkLaCT2+rNXu5hnTwEd8QQka3BNctCqRDdFyJRVIFYaDMzGPGI+0wcSyl
	 Sb/fN5Ul17sIzuyvkfZNpU9T+hqxgnuQbMRw6rG4pIesq2Not9lL125EX2fuBaRlmMVd7
	 J1LOCjlVn35uF4AzaK2RFjBVe+l1Q3qk/Q3nzVjdiKUhoQUxAWbLB6Wm5vNTaNMlmHoV8
	 9PEzM0lWeCBhE/TV7CZ3TIaAbuq3Cab/nhCyfb3TAe2pQqDap5pqOrdAyGisW3qIjvTO7
	 fdMb9FbUBWSeQSLo2z5qNfq9DvEzEZrxaDb+CgUEoZPlgoMoLYFPBl8xC02OANwTJtQ==
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="RL/o6IFB";
	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 A02A0606A32D;
	Tue,  1 Dec 2026 17:30:33 +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=RL/o6IFB
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=1796146227;
	b=EA3sSfDawwih65v3Pox9stCNTwJnHm8+md0MWfDgM9nboXvCtIA+tY7qzcBjbC5hHtq3
	 yItLiZCysETX0UMDb6U0U0CSjY1QcrETHHkVhEvE3MDPOOiyyefgTesicxxfA/hisWH6k
	 gkQp2P3XzDn+It36MZY614iotUspGOwiaX3/nFEZUzQGRw0VJ3GHQ3hy5gLpSkq9Mud4o
	 vI7gqwyzTkYd8MYNx6vypV8mGpnO/uJ/Fe9tS2bIvBEEOwHw4PmZR22qhJfNB8Hvd0/5h
	 5297si9UN1n8dBtWyPyjAlq02ic8Jx0TVT1EAaVioduRR22pAqyzO9MlkikBxKlIjUw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796146227;
	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=Q2bUtIU8yL+m/fJtW/ElIP3SVMwxjjHmeea1pihmfmc=;
	b=Fr2tueOyjaWJ/LVeE5UzYMiswBgKvYqVfWXZSEQdOlMf++LS5AacZ/Fz9jY72G+8Tb3G
	 z65AXWZSBA4brDLdMDVwBZIitNnMiA6q/In1SZydXk1/gT2MIQzXI17dV+J0pIQuVZQFy
	 WcLFNPERLbNgztIJ3DzNEq27VC652UxVHaesgRkZbpQQXv51UjjZM5CxDJ24wKJB3g5sq
	 FfpodDlGmB5kV9/8SwSMycES9jtUBJpRDtH80uhG1jBgGCm38XXJdv+Qc/84Z523nwqV5
	 hCTNUmmvVf43jrrw6AUVrIt7W/b58qFk4H+VDSHwLvbunNpGJJ6O+1MsiTiXYLjzQsA==
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="RL/o6IFB";
	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 BBD1D606A32C
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 17:30:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1ACA51F00898;
	Tue,  1 Dec 2026 17:30:27 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796146227;
	bh=Q2bUtIU8yL+m/fJtW/ElIP3SVMwxjjHmeea1pihmfmc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=RL/o6IFBFdGb9DGguVRIhwL+SDPCqhL8MyHkDUrqxbkRG2TT8ocrUlzUm3H6LuimK
	 En0Jlz9hK1FdfllMWWrW5IdfDNfykbH3zH4TFx8/NIjSx8aGhpbVThHieBqjryxe8z
	 emPmaMEuskssDNuKePv4gofdLF0svgo9abU4iz/yHlKs9s1rkjHaxnZx2cBOijrNsu
	 OiL3x7chT/RNdpGMpClWdbDH8OXbknqAsatM6hviKDKtyWr3Nipd8lJMjN6HJQpXzb
	 1Y0QeWSBjCQl/z6uPWpjwP5MDTNu/5kCGNTTkwlZFVlzAFeCaVROkUBHuPBedvv/kB
	 0Kxuk/wPsYaZw==
X-Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com
X-In-Reply-To: <20261130164502.1863422-1-mmyangfl@gmail.com>
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