mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: namiltd@yahoo.com
Cc: linusw@kernel.org, andrew@lunn.ch, olteanv@gmail.com,
	kuba@kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, linux@armlinux.org.uk, luizluca@gmail.com,
	maxime.chevallier@bootlin.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, alvin.sipraga@analog.com,
	gusfmora@gmail.com, kuncy7@gmail.com, fabianotassotti@gmail.com,
	gabonpivovich@gmail.com, contact@c127.dev
Subject: Re: [PATCH net-next v12 07/13] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D
Date: Tue, 24 Nov 2026 01:24:37 +0000	[thread overview]
Message-ID: <179548347774.3135.13746122531946897961@kernel.org> (raw)
In-Reply-To: <2cc3faa1-c9a6-43d2-a3c2-7dccb12f0273@yahoo.com>

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] rtl8365mb_d_want_ivl()
  (drivers/net/dsa/realtek/rtl8365mb_vlan.c:364-376) makes one switch-…
- [Medium] net: dsa: realtek: stale ivl_en in
  rtl8365mb_vlan_4k_port_set() on family D
- [Low] The comment on the new realtek_priv::vlan_4k_used field in
  drivers/net/dsa/realtek/realtek.h (lines 70-74) says it holds "VIDs…
- [Low] The rollback in rtl8365mb_d_vlan_4k_refresh_ivl()
  (drivers/net/dsa/realtek/rtl8365mb_vlan.c:416-427) sets `failed = vid`…

--

net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

This adds read and write helpers for the two-word CVLAN (4K VLAN) table
entry used by family D. On family D, IVL_EN now follows one switch-wide
setting: it is on while any user port is VLAN-filtering. When that
setting flips, rtl8365mb_d_vlan_4k_refresh_ivl() rewrites the in-use
entries, which are tracked in a new vlan_4k_used bitmap.

> diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h
> index cfe56d30f5cb1..a3ecc13ec561e 100644
> --- a/drivers/net/dsa/realtek/realtek.h
> +++ b/drivers/net/dsa/realtek/realtek.h

[ ... ]

> @@ -65,6 +67,11 @@ struct realtek_priv {
>  	 * deleting port VLAN memberships and PVID configurations.
>  	 */
>  	struct mutex		vlan_lock;
> +	/* VIDs with a non-empty 4K VLAN entry, protected by vlan_lock. Lets
> +	 * a switch-wide update visit only the entries in use instead of
> +	 * reading all 4094 over the slow management bus.
> +	 */
> +	DECLARE_BITMAP(vlan_4k_used, VLAN_N_VID);

[Severity: Low]
This isn't a bug, but is this comment accurate for every user of struct
realtek_priv?

The only writer is rtl8365mb_vlan_4k_port_set(), and it only updates the
bitmap on family D:

	if (rtl8365mb_is_d(priv)) {
		if (vlan4k.member)
			set_bit(vlan->vid, priv->vlan_4k_used);
		else
			clear_bit(vlan->vid, priv->vlan_4k_used);
	}

On family C, and in rtl8366rb, which also uses struct realtek_priv, the
bitmap stays empty even when 4K entries exist. If later code relies on
this comment and does a switch-wide update on family C, it would visit
no entries.

Could the comment say that the bitmap is only maintained on family D?
Alternatively, the bitmap could be maintained for all families.

> diff --git a/drivers/net/dsa/realtek/rtl8365mb_vlan.c b/drivers/net/dsa/realtek/rtl8365mb_vlan.c
> index 566c6bc1449af..6317ea8fb6cde 100644
> --- a/drivers/net/dsa/realtek/rtl8365mb_vlan.c
> +++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.c

[ ... ]

> @@ -277,6 +323,110 @@ int rtl8365mb_c_vlan_4k_write(struct realtek_priv *priv,
>  				     data, ARRAY_SIZE(data));
>  }
>  

[ ... ]

> +/* Family D has no EFID, so a VLAN-unaware bridge must learn in SVL (IVL=0,
> + * FID=0) to match static FDB/MDB entries programmed with VID 0. Use IVL only
> + * while at least one user port is VLAN-filtering. @port/@filtering override
> + * the state of the port currently being changed, as DSA updates
> + * dp->vlan_filtering only after the driver callback returns.
> + */
> +static bool rtl8365mb_d_want_ivl(struct dsa_switch *ds, int port,
> +				 bool filtering)
> +{
> +	struct dsa_port *dp;
> +
> +	dsa_switch_for_each_user_port(dp, ds) {
> +		if (dp->index == port ? filtering :
> +					dsa_port_is_vlan_filtering(dp))
> +			return true;
> +	}
> +
> +	return false;
> +}

[Severity: Medium]
What happens when a VLAN-aware bridge and a VLAN-unaware bridge are both
offloaded on the same family D switch?

VLAN awareness is set per bridge, but this function makes one choice for
the whole switch. Both rtl8365mb_d_vlan_4k_refresh_ivl() and
rtl8365mb_vlan_4k_port_set() write that value into IVL_EN of every 4K
entry.

The driver sets ds->configure_vlan_while_not_filtering, so the
VLAN-unaware bridge also has 4K entries, for example its default_pvid
VLAN. Those entries get IVL=1 as well, so lookups and learning on that
bridge use the key {IVL=1, VID=PVID}.

Its static FDB/MDB entries come from DSA with vid 0. The family D L2
packer added later in the series programs them with the SVL key
{IVL=0, FID=0}:

rtl8365mb_d_l2_uc_to_data()
	bool ivl = uc->key.ivl && uc->key.vid;

Would those static entries ever be hit? If not, unicast to host or
static addresses is flooded. Static multicast is either flooded or
dropped, depending on mcast_flood.

That is the mismatch the commit message says this change avoids ("so
that static and learned FDB/MDB entries use the same key"). The commit
message does not mention this limitation.

The last patch in the series, "net: dsa: realtek: rtl8365mb: add support
for RTL8367S-VB", sets ds->max_num_bridges = 1 for family D. That narrows
the problem but does not close it.

dsa_bridge_num_get() returns a bridge number that is already allocated
without checking max. The comment added in that patch also says that a
bridge that already has a number from another switch can still be
offloaded. In multi-switch setups, it still seems possible to have two
bridges with different VLAN awareness on one family D switch.

Nothing sets ds->vlan_filtering_is_global, and
rtl8365mb_port_vlan_filtering() does not reject this case through extack.
Should one of these be done? If not, should the commit message document
the restriction?

> +
> +/* Must be called with &priv->vlan_lock held. */
> +int rtl8365mb_d_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port,
> +				    bool filtering)
> +{

[ ... ]

> +	for_each_set_bit(vid, priv->vlan_4k_used, VLAN_N_VID) {
> +		ret = fi->vlan_4k_read(priv, vid, &vlan4k);
> +		if (ret)
> +			goto rollback;
> +		if (!vlan4k.member || vlan4k.ivl_en == want_ivl)
> +			continue;
> +
> +		vlan4k.ivl_en = want_ivl;
> +		ret = fi->vlan_4k_write(priv, &vlan4k);
> +		if (ret)
> +			goto rollback;
> +	}
> +
> +	return 0;
> +
> +rollback:
> +	/* Best effort: restore the entries rewritten so far */
> +	failed = vid;
> +	for_each_set_bit(vid, priv->vlan_4k_used, failed) {
> +		if (fi->vlan_4k_read(priv, vid, &vlan4k))
> +			continue;
> +		if (!vlan4k.member || vlan4k.ivl_en != want_ivl)
> +			continue;
> +		vlan4k.ivl_en = !want_ivl;
> +		fi->vlan_4k_write(priv, &vlan4k);
> +	}
> +	return ret;
> +}

[Severity: Medium]
When the last port leaves a VLAN on family D while some user port is
still VLAN-filtering, does this leave IVL_EN set in a hardware entry
that the refresh can no longer reach?

In that case rtl8365mb_vlan_4k_port_set() computes vlan4k.member == 0.
It still sets vlan4k.ivl_en from rtl8365mb_d_want_ivl(ds, -1, false),
which returns true, and writes the entry with IVL_EN=1. It then clears
the VID from priv->vlan_4k_used.

When VLAN filtering is later turned off,
rtl8365mb_d_vlan_4k_refresh_ivl() only walks the bits set in
vlan_4k_used, and it also skips entries with no members. So that entry
keeps IVL_EN=1.

This is not limited to an explicit bridge vlan del. When the ports of
a VLAN-aware bridge leave it, dsa_port_pre_bridge_leave() unoffloads
all of the bridge VLANs while dp->vlan_filtering is still true. Only
after that does dsa_port_bridge_leave() call
dsa_port_reset_vlan_filtering(). So every VLAN of that bridge is
emptied with IVL_EN=1 and dropped from the bitmap before the refresh
runs.

Suppose the ports then join a VLAN-unaware bridge. Ingress membership
filtering is off and egress is transparent, so frames tagged with one
of those old VIDs are still looked up in the 4K table. If the chip
honours IVL_EN of an entry with no members, those frames would be
learned and looked up under {IVL=1, VID}. The static FDB/MDB entries
that DSA programs with vid 0 use the SVL key {IVL=0, FID=0}, so they
would not match.

Would it be enough to write ivl_en = 0, or an all-zero entry, when
vlan4k.member becomes empty? Or does the hardware ignore IVL_EN for an
entry with no members?

[Severity: Low]
The size bound passed to for_each_set_bit() is exclusive, so the rollback
never revisits the VID whose vlan_4k_write() failed. Could that entry
still end up written in hardware?

rtl8365mb_table_query() writes the data, address and command registers.
It then waits in rtl8365mb_table_poll_busy(), which has a 10 ms timeout:

	return regmap_read_poll_timeout(priv->map_nolock,
			RTL8365MB_TABLE_STATUS_REG, val,
			!FIELD_GET(RTL8365MB_TABLE_STATUS_BUSY_FLAG_MASK, val),
			10, 10000);

Suppose the poll times out after the command was issued, and the
hardware still commits the write. That VID keeps ivl_en == want_ivl
while the other entries are restored, and DSA keeps the old
dp->vlan_filtering. That one VLAN would then stay in the opposite
learning mode until something rewrites it.

The rollback loop already re-reads each entry and skips it when
ivl_en != want_ivl. Would it be safe to use failed + 1 as the bound
here?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/bc42ae96-dc7e-4b6e-b9cc-64cde5dc51ce%40yahoo.com

  parent reply	other threads:[~2026-11-24  1:24 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bc42ae96-dc7e-4b6e-b9cc-64cde5dc51ce.ref@yahoo.com>
2026-11-19 23:57 ` [PATCH net-next v12 00/13] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
2026-11-19 23:58   ` [PATCH net-next v12 01/13] dt-bindings: net: dsa: realtek: add RTL8367S-VB Mieczyslaw Nalewaj
2026-11-19 23:59   ` [PATCH net-next v12 02/13] net: dsa: realtek: rtl8365mb: add chip family infrastructure Mieczyslaw Nalewaj
2026-11-20  0:00   ` [PATCH net-next v12 03/13] net: dsa: realtek: rtl8365mb: refactor forcemode handling Mieczyslaw Nalewaj
2026-11-20  0:01   ` [PATCH net-next v12 04/13] net: dsa: realtek: rtl8365mb: set speed for family D Mieczyslaw Nalewaj
2026-11-20  0:02   ` [PATCH net-next v12 05/13] net: dsa: realtek: rtl8365mb: set RGMII mode " Mieczyslaw Nalewaj
2026-11-20  0:03   ` [PATCH net-next v12 06/13] net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling Mieczyslaw Nalewaj
2026-11-20  0:04   ` [PATCH net-next v12 07/13] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D Mieczyslaw Nalewaj
2026-11-20 14:17     ` Gustavo Foletto Mora
2026-11-21  1:30       ` Mieczyslaw Nalewaj
2026-11-21 18:24         ` Gustavo Foletto Mora
2026-11-24  1:24     ` netdev-bot+sashiko [this message]
2026-11-20  0:05   ` [PATCH net-next v12 08/13] net: dsa: realtek: rtl8365mb: refactor PVID handling Mieczyslaw Nalewaj
2026-11-20 14:18     ` Gustavo Foletto Mora
2026-11-20  0:06   ` [PATCH net-next v12 09/13] net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D Mieczyslaw Nalewaj
2026-11-20 14:26     ` Gustavo Foletto Mora
2026-11-24  1:24     ` netdev-bot+sashiko
2026-11-20  0:07   ` [PATCH net-next v12 10/13] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support Mieczyslaw Nalewaj
2026-11-24  1:24     ` netdev-bot+sashiko
2026-11-20  0:07   ` [PATCH net-next v12 11/13] net: dsa: realtek: rtl8365mb: refactor L2 MAC handling Mieczyslaw Nalewaj
2026-11-20  0:08   ` [PATCH net-next v12 12/13] net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D Mieczyslaw Nalewaj
2026-11-21  9:33     ` Mieczyslaw Nalewaj
2026-11-21 18:26       ` Gustavo Foletto Mora
2026-11-24  1:24     ` netdev-bot+sashiko
2026-11-20  0:09   ` [PATCH net-next v12 13/13] net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB Mieczyslaw Nalewaj
2026-11-20 20:56     ` Gustavo Foletto Mora
2026-11-21  1:46       ` Mieczyslaw Nalewaj
2026-11-21 18:29         ` Gustavo Foletto Mora
2026-11-23  8:01           ` Oleksij Rempel
2026-11-23 12:47             ` Mieczyslaw Nalewaj
2026-11-24  1:24     ` 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=179548347774.3135.13746122531946897961@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alvin.sipraga@analog.com \
    --cc=andrew@lunn.ch \
    --cc=contact@c127.dev \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fabianotassotti@gmail.com \
    --cc=gabonpivovich@gmail.com \
    --cc=gusfmora@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kuncy7@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luizluca@gmail.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=namiltd@yahoo.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

all inboxes | Powered by JetHome®