Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v4] net: dsa: motorcomm: Add limited ACL flow statistics support
@ 2026-12-02 14:06 David Yang
  2026-12-03 14:49 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: David Yang @ 2026-12-02 14:06 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

The hardware supports flow statistics, which might be used to implement
.cls_flower_stats(). However, the number of flow counters is limited,
and the hardware counter only counts frames passed by the rule. Assign a
counter if feasible, and reject skip_sw rules with an unsatisfiable
stats configuration.

Non-skip_sw rules are never refused for hw_stats configuration: we
cannot stop software from installing them, even with an error code; such
traffic would never have a chance reaching CPU if not captured from the
hardware. When no counter is left, a non-skip_sw rule which explicitly
requested statistics is trapped to software, keeping both the
forwarding and the counting.

The counter supports byte and packet mode, but they are mutually
exclusive. Choose packet mode here but keep the code for byte mode, in
case you change your mind or a new API is available later.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
v4:
 - do not accept DELAYED stats and do not assign counter when DISABLED
v3: https://lore.kernel.org/r/20261130164502.1863422-1-mmyangfl@gmail.com
 - reword commit message
 - fix configuration checks
v2: https://lore.kernel.org/r/20261128031905.1355254-1-mmyangfl@gmail.com
 - do not assign counter for police rules
 - reject explicit delay request
 - update lastused only when the counter changes
v1: https://lore.kernel.org/r/20261126060127.185631-1-mmyangfl@gmail.com
 drivers/net/dsa/motorcomm/chip.c |   1 +
 drivers/net/dsa/motorcomm/chip.h |   3 +
 drivers/net/dsa/motorcomm/tc.c   | 167 ++++++++++++++++++++++++++++++-
 drivers/net/dsa/motorcomm/tc.h   |  18 +++-
 4 files changed, 184 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 82f364986aeb..9d5a50e95f7b 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -2643,6 +2643,7 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
 	.port_policer_add	= yt921x_dsa_port_policer_add,
 	.port_setup_tc		= yt921x_dsa_port_setup_tc,
 	/* acl */
+	.cls_flower_stats	= yt921x_dsa_cls_flower_stats,
 	.cls_flower_del		= yt921x_dsa_cls_flower_del,
 	.cls_flower_add		= yt921x_dsa_cls_flower_add,
 	/* hsr */
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index fc315f1d8f87..fe6cf03a09c8 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -424,6 +424,8 @@ enum yt921x_fdb_entry_status {
 /* Custom meters only, not including dedicated port meters (11) */
 #define YT921X_METER_NUM	64
 
+#define YT921X_FLOWSTAT_NUM	64
+
 #define YT921X_LAG_NUM		2
 #define YT921X_LAG_PORT_NUM	4
 
@@ -527,6 +529,7 @@ struct yt921x_priv {
 	u16 eee_ports_mask;
 
 	DECLARE_BITMAP(meters_map, YT921X_METER_NUM);
+	DECLARE_BITMAP(flowstats_map, YT921X_FLOWSTAT_NUM);
 
 	u8 acl_masks[YT921X_ACL_BLK_NUM];
 	struct yt921x_acl_blk *acl_blks[YT921X_ACL_BLK_NUM];
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index e3f057ed580f..043269f41fbc 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -565,6 +565,11 @@ struct yt921x_acl_rule_ext {
 	struct yt921x_acl_rule r;
 
 	struct yt921x_marker marker;
+
+	/* acquire a counter if possible */
+	bool stat_applicable:1;
+	/* HW stats requested */
+	bool stat_required:1;
 };
 
 static int
@@ -1034,13 +1039,25 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
 	u32 *action = ruleext->r.action;
 	bool seen_priority = false;
 	bool seen_police = false;
+	bool stat_veto = false;
 	bool terminal = false;
 	bool redir = false;
 	const char *reason;
 	unsigned int i;
 	int res;
 
+	/* Do not reject non-skip_sw rules for hw_stats: we can't stop software
+	 * from installing rules, such traffic would never have a chance
+	 * reaching CPU if not captured from the hardware.
+	 */
+	if (cls->common.skip_sw &&
+	    !flow_action_mixed_hw_stats_check(flow_action, extack))
+		return -EOPNOTSUPP;
+
 	memset(action, 0, 3 * sizeof(*action));
+	ruleext->stat_applicable = false;
+	ruleext->stat_required = false;
+
 	flow_action_for_each(i, act, flow_action) {
 		/* The flow action entry carries no mirred control, so there
 		 * is no way to tell whether software would continue past a
@@ -1052,6 +1069,21 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
 			goto fallback;
 		}
 
+		if (act->hw_stats & FLOW_ACTION_HW_STATS_DISABLED) {
+			stat_veto = true;
+		} else if (act->hw_stats & FLOW_ACTION_HW_STATS_IMMEDIATE) {
+			ruleext->stat_applicable = true;
+			ruleext->stat_required |= act->hw_stats !=
+						  FLOW_ACTION_HW_STATS_ANY;
+		} else if (!cls->common.skip_sw) {
+			/* Keep the rule offloaded, just without a counter */
+			stat_veto = true;
+		} else {
+			NL_SET_ERR_MSG_MOD(extack,
+					   "Unsupported action HW stats type");
+			return -EOPNOTSUPP;
+		}
+
 		switch (act->id) {
 		case FLOW_ACTION_ACCEPT:
 			action[2] |= YT921X_ACL_ACTc_FWD_EN |
@@ -1059,6 +1091,9 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
 			terminal = true;
 			break;
 		case FLOW_ACTION_DROP:
+			/* FLOWSTAT only counts passed frames */
+			stat_veto = true;
+
 			action[2] |= YT921X_ACL_ACTc_FWD_EN |
 				     YT921X_ACL_ACTc_FWD_REDIR;
 			terminal = true;
@@ -1117,6 +1152,9 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
 			if (res)
 				return res;
 
+			/* Meter may drop the exceeded frames */
+			stat_veto = true;
+
 			action[0] |= YT921X_ACL_ACTa_METER_EN;
 			break;
 		}
@@ -1136,6 +1174,7 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
 			action[2] |= YT921X_ACL_ACTc_FWD_EN |
 				     YT921X_ACL_ACTc_FWD_TRAP;
 			terminal = true;
+			redir = false;
 			break;
 		}
 
@@ -1143,7 +1182,24 @@ 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;
+	/* Do not reject non-skip_sw rules for hw_stats, see above */
+	if (cls->common.skip_sw && ruleext->stat_required &&
+	    !ruleext->stat_applicable) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "HW stats not available for rules that may drop frames");
+		return -EOPNOTSUPP;
+	}
+
 	ruleext->r.sw_assisted = !cls->common.skip_sw;
+
 	return 0;
 }
 
@@ -1208,6 +1264,9 @@ yt921x_acl_rule_ext_parse_flow(struct yt921x_acl_rule_ext *ruleext, int port,
 	yt921x_acl_rule_set_ports(&ruleext->r, ord, BIT(port));
 	ruleext->r.tag = cls->cookie;
 	ruleext->r.type = TC_SETUP_CLSFLOWER;
+	/* Align with sja1105 */
+	ruleext->r.stat_pkt_mode = true;
+	ruleext->r.laststat = 0;
 	return 0;
 }
 
@@ -1281,6 +1340,45 @@ yt921x_acl_reserve(struct yt921x_priv *priv, unsigned int entscnt,
 	return UINT_MAX;
 }
 
+static int
+yt921x_acl_stat(struct yt921x_priv *priv, enum tc_setup_type type,
+		unsigned long tag, u16 ports_mask, struct flow_stats *stats)
+{
+	struct yt921x_acl_rule *aclrule;
+	const struct yt921x_acl_blk *aclblk;
+	unsigned int statid;
+	unsigned int binid;
+	unsigned int blkid;
+	unsigned int entid;
+	u64 diff;
+	u64 stat;
+	int res;
+
+	entid = yt921x_acl_find(priv, type, tag, ports_mask);
+	if (entid == UINT_MAX)
+		return -ENOENT;
+
+	blkid = entid / YT921X_ACL_ENT_PER_BLK;
+	binid = entid % YT921X_ACL_ENT_PER_BLK;
+	aclblk = priv->acl_blks[blkid];
+	aclrule = aclblk->rules[binid];
+
+	if (!(aclrule->action[0] & YT921X_ACL_ACTa_FLOWSTAT_EN))
+		return -EOPNOTSUPP;
+
+	statid = FIELD_GET(YT921X_ACL_ACTa_FLOWSTAT_ID_M, aclrule->action[0]);
+	res = yt921x_counter_read(priv, YT921X_FLOWSTATn_STAT(statid), &stat);
+	if (res)
+		return res;
+
+	diff = stat - aclrule->laststat;
+	aclrule->laststat = stat;
+	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);
+	return 0;
+}
+
 static int
 yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask)
 {
@@ -1413,9 +1511,13 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type,
 	}
 
 	if (aclrule->action[0] & YT921X_ACL_ACTa_METER_EN)
-		clear_bit(FIELD_GET(YT921X_ACL_ACTa_METER_ID_M,
-				    aclrule->action[0]),
-			  priv->meters_map);
+		__clear_bit(FIELD_GET(YT921X_ACL_ACTa_METER_ID_M,
+				      aclrule->action[0]),
+			    priv->meters_map);
+	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);
 	priv->acl_masks[blkid] &= ~aclrule->mask;
 	kvfree(aclrule);
 	if (!priv->acl_masks[blkid]) {
@@ -1435,6 +1537,7 @@ yt921x_acl_add(struct yt921x_priv *priv,
 	struct yt921x_acl_blk *aclblk;
 	bool use_trap = false;
 	unsigned int meterid;
+	unsigned int statid;
 	unsigned int binid;
 	unsigned int blkid;
 	unsigned int entid;
@@ -1467,6 +1570,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;
+
+			res = yt921x_reg64_write(priv,
+						 YT921X_FLOWSTATn_STAT(statid),
+						 zeros);
+			if (res)
+				return res;
+		} else if (ruleext->stat_required) {
+			if (!ruleext->r.sw_assisted) {
+				NL_SET_ERR_MSG_MOD(extack,
+						   "No more flowstats, but HW stats requested");
+				return -EOPNOTSUPP;
+			}
+			use_trap = true;
+		} else {
+			NL_SET_ERR_MSG_MOD(extack,
+					   "No more flowstats, HW stats disabled");
+		}
+	}
+
 	/* Prepare acl block ctrlblk */
 	blkid = entid / YT921X_ACL_ENT_PER_BLK;
 	binid = entid % YT921X_ACL_ENT_PER_BLK;
@@ -1507,6 +1646,9 @@ yt921x_acl_add(struct yt921x_priv *priv,
 		aclrule->action[0] |= YT921X_ACL_ACTa_METER_ID(meterid);
 	else
 		aclrule->action[0] &= ~YT921X_ACL_ACTa_METER_EN;
+	if (statid < YT921X_FLOWSTAT_NUM)
+		aclrule->action[0] |= YT921X_ACL_ACTa_FLOWSTAT_EN |
+				      YT921X_ACL_ACTa_FLOWSTAT_ID(statid);
 
 	/* Activate ACL if needed */
 	ctrl = 0;
@@ -1535,7 +1677,9 @@ yt921x_acl_add(struct yt921x_priv *priv,
 		priv->ports[o].acl_cnt++;
 
 	if (meterid < YT921X_METER_NUM)
-		set_bit(meterid, priv->meters_map);
+		__set_bit(meterid, priv->meters_map);
+	if (statid < YT921X_FLOWSTAT_NUM)
+		__set_bit(statid, priv->flowstats_map);
 	priv->acl_masks[blkid] |= aclrule->mask;
 	return 0;
 
@@ -1548,6 +1692,21 @@ yt921x_acl_add(struct yt921x_priv *priv,
 	return res;
 }
 
+int
+yt921x_dsa_cls_flower_stats(struct dsa_switch *ds, int port,
+			    struct flow_cls_offload *cls, bool ingress)
+{
+	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
+	int res;
+
+	mutex_lock(&priv->reg_lock);
+	res = yt921x_acl_stat(priv, TC_SETUP_CLSFLOWER, cls->cookie,
+			      BIT(port), &cls->stats);
+	mutex_unlock(&priv->reg_lock);
+
+	return res;
+}
+
 int
 yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port,
 			  struct flow_cls_offload *cls, bool ingress)
diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h
index cc53f148d690..9e50285d66f6 100644
--- a/drivers/net/dsa/motorcomm/tc.h
+++ b/drivers/net/dsa/motorcomm/tc.h
@@ -299,6 +299,16 @@ enum yt921x_udf_type {
 #define  YT921X_METER_CTRLa_EIR_M		GENMASK(17, 0)
 #define   YT921X_METER_CTRLa_EIR(x)			FIELD_PREP(YT921X_METER_CTRLa_EIR_M, (x))
 #define YT921X_METERn_STAT(x)		(0x221000 + 8 * (x))
+#define YT921X_FLOWSTATn_STAT(x)	(0x221400 + 8 * (x))
+#define YT921X_FLOWSTATn_CTRL(x)	(0x221c00 + 4 * (x))
+#define  YT921X_FLOWSTAT_CTRL_EN		BIT(3)
+#define  YT921X_FLOWSTAT_CTRL_PKT_MODE		BIT(2)	/* 0: byte mode */
+#define  YT921X_FLOWSTAT_CTRL_TYPE_M		GENMASK(1, 0)
+#define   YT921X_FLOWSTAT_CTRL_TYPE(x)			FIELD_PREP(YT921X_FLOWSTAT_CTRL_TYPE_M, (x))
+#define   YT921X_FLOWSTAT_CTRL_TYPE_FLOW		YT921X_FLOWSTAT_CTRL_TYPE(0)
+#define   YT921X_FLOWSTAT_CTRL_TYPE_CPU_CODE		YT921X_FLOWSTAT_CTRL_TYPE(1)
+#define   YT921X_FLOWSTAT_CTRL_TYPE_DROP_CODE		YT921X_FLOWSTAT_CTRL_TYPE(2)
+#define   YT921X_FLOWSTAT_CTRL_TYPE_PORT		YT921X_FLOWSTAT_CTRL_TYPE(3)
 
 #define YT921X_MIRROR			0x300300
 #define  YT921X_MIRROR_IGR_PORTS_M		GENMASK(26, 16)
@@ -349,7 +359,10 @@ struct yt921x_acl_rule {
 	enum tc_setup_type type;
 
 	u32 action[3];
-	bool sw_assisted;
+	u64 laststat;
+
+	bool sw_assisted:1;
+	bool stat_pkt_mode:1;
 
 	u8 mask;
 	struct yt921x_acl_entry entries[YT921X_ACL_ENT_PER_BLK];
@@ -368,6 +381,9 @@ int
 yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port,
 			 enum tc_setup_type type, void *type_data);
 int
+yt921x_dsa_cls_flower_stats(struct dsa_switch *ds, int port,
+			    struct flow_cls_offload *cls, bool ingress);
+int
 yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port,
 			  struct flow_cls_offload *cls, bool ingress);
 int
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next v4] net: dsa: motorcomm: Add limited ACL flow statistics support
  2026-12-02 14:06 [PATCH net-next v4] net: dsa: motorcomm: Add limited ACL flow statistics support David Yang
@ 2026-12-03 14:49 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 14:49 UTC (permalink / raw)
  To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni

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

Critical: 0 · High: 0 · Medium: 1 · 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] Non-skip_sw flower rules that explicitly ask for immediate HW
  stats can end up with no counter, no trap and no warning.
- [Low] The patch adds a new limited hardware pool of YT921X_FLOWSTAT_NUM
  (64) flow counters, tracked in priv->flowstats_map, but does not…
- [Low] yt921x_acl_add() now writes the extack text "No more flowstats,
  HW stats disabled" as a success-path warning when the counter pool is…

--

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

This adds .cls_flower_stats() support using the 64 hardware flow
counters, which are assigned to flower ACL rules when that is possible.
skip_sw rules whose stats configuration cannot be met are rejected. A
non-skip_sw rule that explicitly asks for stats is trapped to software
when no counter is left.

> diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
> index fc315f1d8f87b..fe6cf03a09c8e 100644
> --- a/drivers/net/dsa/motorcomm/chip.h
> +++ b/drivers/net/dsa/motorcomm/chip.h
> @@ -424,6 +424,8 @@ enum yt921x_fdb_entry_status {
>  /* Custom meters only, not including dedicated port meters (11) */
>  #define YT921X_METER_NUM	64
>  
> +#define YT921X_FLOWSTAT_NUM	64
> +

[Severity: Low]
Should this new pool also be exposed as a devlink resource? The ACL and
meters pools are listed in yt921x_devlink_resources[] in
drivers/net/dsa/motorcomm/devlink.c, with yt921x_devlink_occ_get_acl()
and yt921x_devlink_occ_get_meter(). There is no entry for flowstats.

tc uses hw_stats any by default. This check in
yt921x_acl_rule_ext_parse_flow_action() is true for any:

	} else if (act->hw_stats & FLOW_ACTION_HW_STATS_IMMEDIATE) {
		ruleext->stat_applicable = true;

So rules that never asked for stats also use up counters. After 64 of
them, explicit immediate skip_sw rules fail. Non-skip_sw rules are
changed from a hardware redirect to a CPU trap, with no extack message.
Users currently have no way to see the pool occupancy.

>  #define YT921X_LAG_NUM		2
>  #define YT921X_LAG_PORT_NUM	4

[ ... ]

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

[ ... ]

> @@ -1052,6 +1069,21 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
>  			goto fallback;
>  		}
>  
> +		if (act->hw_stats & FLOW_ACTION_HW_STATS_DISABLED) {
> +			stat_veto = true;
> +		} else if (act->hw_stats & FLOW_ACTION_HW_STATS_IMMEDIATE) {
> +			ruleext->stat_applicable = true;
> +			ruleext->stat_required |= act->hw_stats !=
> +						  FLOW_ACTION_HW_STATS_ANY;
> +		} else if (!cls->common.skip_sw) {
> +			/* Keep the rule offloaded, just without a counter */
> +			stat_veto = true;
> +		} else {
> +			NL_SET_ERR_MSG_MOD(extack,
> +					   "Unsupported action HW stats type");
> +			return -EOPNOTSUPP;
> +		}
> +
>  		switch (act->id) {
>  		case FLOW_ACTION_ACCEPT:
>  			action[2] |= YT921X_ACL_ACTc_FWD_EN |
> @@ -1059,6 +1091,9 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
>  			terminal = true;
>  			break;
>  		case FLOW_ACTION_DROP:
> +			/* FLOWSTAT only counts passed frames */
> +			stat_veto = true;
> +
>  			action[2] |= YT921X_ACL_ACTc_FWD_EN |
>  				     YT921X_ACL_ACTc_FWD_REDIR;
>  			terminal = true;

[ ... ]

> @@ -1143,7 +1182,24 @@ 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;
> +	/* Do not reject non-skip_sw rules for hw_stats, see above */
> +	if (cls->common.skip_sw && 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]
What happens to a non-skip_sw rule that explicitly asks for immediate
stats and then gets vetoed? For example:

  tc filter add dev swp0 ingress flower ... action drop hw_stats immediate

The IMMEDIATE branch sets stat_applicable and stat_required. The
FLOW_ACTION_DROP case then sets stat_veto, and that clears
stat_applicable. The check above only covers skip_sw rules, so the
function returns 0 with stat_required set and stat_applicable clear.

In yt921x_acl_add(), the trap fallback can only be reached when
stat_applicable is true:

	if (!ruleext->stat_applicable) {
		statid = YT921X_FLOWSTAT_NUM;
	} else {
		...
		} else if (ruleext->stat_required) {
			...
			use_trap = true;

So the rule goes into hardware as a drop without FLOWSTAT_EN, with no
trap and no extack message. The software flower never sees the frames.
yt921x_dsa_cls_flower_stats()->yt921x_acl_stat() returns -EOPNOTSUPP
because FLOWSTAT_EN is clear.

Won't such a rule always report 0 packets, even though it asked for
immediate stats?

The other veto sources seem to lead to the same result. Examples are a
non-skip_sw police plus redirect rule with hw_stats immediate, DISABLED
or DELAYED hw_stats on another action, and the !redir check after the
loop.

Could this case trap to software, as the pool exhaustion case already
does? If not, could it at least set an extack warning?

[ ... ]

> @@ -1467,6 +1570,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) {

[ ... ]

> +		} else if (ruleext->stat_required) {
> +			if (!ruleext->r.sw_assisted) {
> +				NL_SET_ERR_MSG_MOD(extack,
> +						   "No more flowstats, but HW stats requested");
> +				return -EOPNOTSUPP;
> +			}
> +			use_trap = true;
> +		} else {
> +			NL_SET_ERR_MSG_MOD(extack,
> +					   "No more flowstats, HW stats disabled");
> +		}
> +	}
> +
>  	/* Prepare acl block ctrlblk */
>  	blkid = entid / YT921X_ACL_ENT_PER_BLK;
>  	binid = entid % YT921X_ACL_ENT_PER_BLK;

[Severity: Low]
This warning goes into extack before several steps in yt921x_acl_add()
that can still fail:

  - kvzalloc_obj() returning NULL (-ENOMEM)
  - kvmemdup() returning NULL (-ENOMEM)
  - yt921x_reg_write(priv, YT921X_ACL_PORT, ctrl) failing
  - yt921x_acl_commit() failing

None of these paths set their own extack message.

If one of them fails, won't userspace get the error code together with
"No more flowstats, HW stats disabled"? That would suggest the rule was
offloaded without a counter, when it was not offloaded at all.

Could the warning be set only after the rule has been committed?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202140644.3402265-1-mmyangfl%40gmail.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 14:06 [PATCH net-next v4] net: dsa: motorcomm: Add limited ACL flow statistics support David Yang
2026-12-03 14:49 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox