Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: mmyangfl@gmail.com
Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com
Subject: Re: [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes
Date: Mon, 30 Nov 2026 12:25:56 +0000	[thread overview]
Message-ID: <179604155661.3146.6089853869175513173@kernel.org> (raw)
In-Reply-To: <20261129115556.1669188-5-mmyangfl@gmail.com>

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

Critical: 0 · High: 1 · Medium: 0 · Low: 1

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).

- [High] yt921x_acl_recompute() in drivers/net/dsa/motorcomm/tc.c gets
  the rule's source port wrong.
- [Low] net: dsa: motorcomm: redundant ACL commits in
  yt921x_acl_recompute()

--

net: dsa: motorcomm: Recompute redirect rules on bridge changes

This adds yt921x_acl_recompute(), which re-evaluates non-skip_sw redirect
rules after bridge join, leave and flag changes rewrite the port isolation
masks. It is called from yt921x_bridge_flags(),
yt921x_dsa_port_bridge_join() and yt921x_dsa_port_bridge_leave().

> diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
> index 20edfd53b230d..146db2a37c268 100644
> --- a/drivers/net/dsa/motorcomm/tc.c
> +++ b/drivers/net/dsa/motorcomm/tc.c
> @@ -1394,6 +1394,56 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask)

[ ... ]

> +int yt921x_acl_recompute(struct yt921x_priv *priv, int port)
> +{

[ ... ]

> +			src = ffs(aclrule->entries[0].key[1] &
> +				  YT921X_ACL_KEYb_SPORTS_M) - 1;
> +			dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M,
> +					 action[2]);
> +			if (src != port && !(dsts & BIT(port)))
> +				continue;
> +
> +			aclrule->sw_assisting =
> +				!!(dsts & priv->ports[src].isolation_mask);
                                          ^^^^^^^^^^^^^^^^^

[Severity: High]
Can this read past the end of priv->ports[]? The source port field is not
shifted down before ffs(), and tc.h has:

#define  YT921X_ACL_KEYb_SPORTS_M		GENMASK(20, 10)
#define  YT921X_ACL_KEYb_SPORTn(port)		BIT((port) + 10)

So a rule on port p gives src = p + 10. For p >= 1 that is 11..20, but
ports[] only has YT921X_PORT_NUM (11) entries. For p == 0 it reads the
isolation_mask of port 10 instead.

The other decoders of this field, yt921x_acl_find(), yt921x_acl_add() and
yt921x_acl_del(), all use FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ...). Should
this be something like:

	src = ffs(FIELD_GET(YT921X_ACL_KEYb_SPORTS_M,
			    aclrule->entries[0].key[1])) - 1;

The same offset also breaks the filter above. Because src != port is
almost always true, rules sourced on the port whose bridge state changed
are skipped unless they also redirect to that port.

As an example, take a non-skip_sw flower rule on port 1 that redirects to
port 2. A bridge join or leave on port 2, or a BR_ISOLATED or
BR_HAIRPIN_MODE change there, calls yt921x_acl_recompute(priv, 2). The
rule passes the dsts & BIT(2) check, and priv->ports[11] is read. That
value then decides whether yt921x_acl_commit() writes a REDIR or a TRAP
action to YT921X_ACLn_ACT.

The later patch in this series, "net: dsa: motorcomm: Reject bridge flags
that break redirect rules", does not touch yt921x_acl_recompute(), so the
problem is still there at the end of the series.

> +			entid = YT921X_ACL_ENT_PER_BLK * blkid + i;
> +			res = yt921x_acl_commit(priv, entid, aclrule->mask);
> +			if (res)
> +				return res;
> +		}
> +	}
> +
> +	return 0;
> +}

[Severity: Low]
This calls yt921x_acl_commit() for every rule that passes the filter,
whether or not the newly computed sw_assisting value differs from the
one already programmed. Each commit rewrites the 96-bit action, the key
and mask of every entry in the rule, and the block KEEP, ENTRY and CMD
registers. All of that goes over MDIO while reg_lock is held in the
bridge join, leave and flags paths.

FLOW_ACTION_DROP rules also get past the action check here.
yt921x_acl_rule_ext_parse_flow_action() encodes them as
YT921X_ACL_ACTc_FWD_EN | YT921X_ACL_ACTc_FWD_REDIR with an empty DPORTS
field. For those rules dsts is 0, so sw_assisting always comes out false
and the commit just writes back the action that is already there. Once
src is decoded correctly, every non-skip_sw drop rule sourced on the
port would be reprogrammed on each bridge change. The same applies to
redirect rules whose destinations are not affected by the isolation
change.

Nothing breaks functionally, but would it make sense to skip rules with
dsts == 0? yt921x_acl_commit() could also be called only when
sw_assisting actually flips, for example by computing the new value into
a local, comparing it with aclrule->sw_assisting and continuing if they
match.

Or is the unconditional rewrite intended to resync the hardware after
an earlier failed commit? sw_assisting is updated before
yt921x_acl_commit() runs, so after a failure the software state and the
hardware can disagree.

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

  reply	other threads:[~2026-11-30 12:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 11:55 [PATCH net-next v2 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-11-29 11:55 ` [PATCH net-next v2 1/5] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-11-29 11:55 ` [PATCH net-next v2 2/5] net: dsa: motorcomm: Cache port isolation masks David Yang
2026-11-30 12:25   ` netdev-bot+sashiko
2026-11-29 11:55 ` [PATCH net-next v2 3/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-11-30 12:25   ` netdev-bot+sashiko
2026-11-29 11:55 ` [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
2026-11-30 12:25   ` netdev-bot+sashiko [this message]
2026-11-29 11:55 ` [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
2026-11-30 12:25   ` 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=179604155661.3146.6089853869175513173@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=mmyangfl@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    /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