🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21441

Re: [PATCH net-next v12 07/13] net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D

#21441
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 01:24
245 lines
17386 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] 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
Technical Details
Message-ID: <179548347774.3135.13746122531946897961@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369924-linux-kernel-netdev=dewy.ru
References: <2cc3faa1-c9a6-43d2-a3c2-7dccb12f0273@yahoo.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369924-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179548347774.3135.13746122531946897961@kernel.org>
References: <2cc3faa1-c9a6-43d2-a3c2-7dccb12f0273@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4025413"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:jCTEWh9s+CquS5dZmL5sSBcoKKo= sha256:JAZuA3KngEx6YY8dDlNrim1omqwyasCQtQ3bb7IfG8s=
	sha1:ZTK4mLi3J7VEgEYuTOdXS1ErJ18= sha256:/c+5LygVGjzHY3NS9AFG3cJrCKO4+1izKO6VhN8oFV0=
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 87329125DCB; Tue, 24 Nov 2026 04:24:56 +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 hTVXc4oesQjJ;
	Tue, 24 Nov 2026 04:24:52 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369924-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 2D1E5125DC9; Tue, 24 Nov 2026 04:24:43 +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 9213132367; Tue, 24 Nov 2026 01:24:40 +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=1795483480;
	b=IDK+DzRp+XIRepakaTreo63jDjBt6aiqLoOCo9E5Og5Hu7D9G01sRNUHC6NKQ6xzPli4
	 uGum6ox6TKxB4uAfiFXNGRq6tzFhDth9yRHVNb/mERWJiUYgBSUqdkqQrIvD7rIC/O+UO
	 BShxuWEoXri+0sig/6w426W0IXHdezTC3gSragl0b9bXjSdlHr3atPABKXhyFKmYk1cDI
	 Sk+vWuK5MkxPnrx2NyH6NtZ6/PaPAXAR4NoHymvw+TB6OTgTnICAqx/HnwGl0y6w3GVBX
	 VPfolmFfQkX6jyJTJYhY5swy0qdWNVc+mU9hkJxjbmeJGFp++KkJN+tu5qJeAj349yQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795483480;
	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=uJFY0RA5jNs+ZBcE+G+eI8Iqteu1G4u0DeLhYuNF3Ws=;
	b=DrX/kEVdf5PmuJ2mWi9njCqwA/P+f+WIrrNs0ACy0cE70sqpM53aexukHmRL1M3Z3tT2
	 bmtwqutwkP1jlIM1mDVJSe8fpfwAlhEKTffZnEgjPRm5/I+SsCLlp4CkZ6R/iRCIPKqOB
	 uvG6qPeFRASlaXBmrY5qBGl7kE/ZMP20JrgsqYu2JnOeZpVa3vZFU9C8j+0faFoxp8SKT
	 jNIXvK82C6NsOHVOoS0xEAhJjXd+L5jYS5bASzgp7eIBrCRufZ2jtTdT7nJcvDJm45SCF
	 zSGGQCmAukrqGdLYbHB1y+i4+jYodLtkNz2zYkaDqgHxppDwphJV5spxekhFxvtjKEQ==
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=aJa9iHpD;
	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 54AE6606A332;
	Tue, 24 Nov 2026 01:24:40 +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=aJa9iHpD
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=1795483479;
	b=JtyFa/rF/ayqQE921iL7Gs2wh3wcgJmZ/Q8aLEYsP8JjkScB5ynC1AnOa55EDGjY40ng
	 Klmtwp+0jfGh2NdpjfYqB8wTkBcUIqYzwdxmRDXBBOiLosPdaDNWT8PwE+3pyfU1JwNa4
	 dumbM5pBizzKOBcxZTPFqClcOE8Ol3ms2uwWePbGDmdgNazQHa6UjPln9ivJyZSuRzb8r
	 oemoidIVK66wXyZuPgCWUWSn4cciLhxuZL+pmY7FnC81mUAX92ZRqGaXz7/NoZcfK0qE/
	 DvFWswV+Xe9BolqS5apLRPS3i2TTUUD+rVMyQmhtIc2xZYACnVt4PHR1ZXBHLPj9WZw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795483479;
	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=uJFY0RA5jNs+ZBcE+G+eI8Iqteu1G4u0DeLhYuNF3Ws=;
	b=LsNhrARioW6H0pxKHV0plVV+h5fQv0YjhzUR4+DIdWhziNYmSbzDzBo4hON3luxiwvkb
	 L1EM7pJcFxrcbn2Eof+dG4071ZP0NxZMsytml0a/+vx32ZifKD/KT1rE+sR2llyq5ICeR
	 YGrGYcI0V6H4Gj48paSiLwHs2hpbOu9LrR/uquD2On+zAv+gclidB6obO2zTEM+1HdIiw
	 Np4lthBy+WqVl0ZuQ1nhAIV1h3e5rlxrQpmzR/WcwHUcP2Z1IMBt+47JnH6Tn3ekGfEba
	 haW1pcPLZw6drP8eTtZU0BXOovX4TYrWzABeC0boC/kIK8HYXSiL4I4ErQQdttpFd/g==
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=aJa9iHpD;
	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 722F5606A31E;
	Tue, 24 Nov 2026 01:24:39 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38D2D1F000C0;
	Tue, 24 Nov 2026 01:24:38 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795483479;
	bh=uJFY0RA5jNs+ZBcE+G+eI8Iqteu1G4u0DeLhYuNF3Ws=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=aJa9iHpDfRMF2Hr13OzlTCxPeXEnKDfBD+6BWSoaGrXx9Hi/V/UOvoOs14hx6F8w/
	 J/nJgc/Z4bccCuHrsyh9xo8XqUvh42oUDEs8kJZKQ0cxewmkon6m/P7qQ7LqygJz7F
	 LAdb9i7z9GtFxXIu2/N16tR9p+noHpJ+yiM+gNt3CMJpT3zbkjAjI7QC/bzKSxnHL2
	 o1JeVywzk4eS1GC71tBQNJ5G56aFsHQXHqnM68QsZ7AQtNUUqcvPJs8gvmg+mss1WC
	 yTcj0f/UA1S813I9P1Ye5w6zBYRVx9O4jOfYRZ+0xiILEt2NRDw5fqjoaVPY5JSP3j
	 t5uGOtTfMc+HQ==
X-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
X-In-Reply-To: <2cc3faa1-c9a6-43d2-a3c2-7dccb12f0273@yahoo.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