🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22949

[PATCH net-next 2/5] net: dsa: microchip: ksz9477: do not keep the learned port in FDB entries

#22949
From: Oleksij Rempel
Date: Thu, 26 Nov 2026 08:07
64 lines
12860 bytes
Do not keep the learned port when adding a static FDB entry.

The ALU table of the switch keeps learned (dynamic) and static
entries, one entry per address. An example: the switch has learned
host H on lan1. Then a static FDB entry for H is added on lan2. The
driver does not add a new entry. It finds the learned entry, makes it
static and adds lan2 to its ports. The entry is now static and points
to lan1 and lan2.

When the FDB entry is deleted, the driver removes only lan2. The entry
stays static and still points to lan1. Static entries never age out.
So the switch keeps sending frames for H to lan1, even after H has
moved.

The bug is hit much more often once the driver sets
ds->assisted_learning_on_cpu_port, which the next ksz9477 change does.
DSA then adds a static entry on the CPU port for each address the
bridge learns on ports outside the switch, such as Wi-Fi. If H was
learned on lan1 and then moved to Wi-Fi, the entry for the CPU port
still points to lan1 too.

LAN937x uses the same code.

Found in code review. Confirmed on a KSZ9893; with H learned on lan1,
run:

  bridge fdb replace <H> dev lan2 master static
  bridge fdb del <H> dev lan2 master static
  bridge fdb show    # still shows "<H> dev lan1 self static"

Tested on a KSZ9893 with the commands above and with our labgrid
switch tests: with this patch, no static entry for <H> is left.

Fixes: b987e98e50ab ("dsa: add DSA switch driver for Microchip KSZ9477")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
If bridge fdb replace moves an existing static entry to another port,
the entry still keeps the old port. This patch does not change that.
---
 drivers/net/dsa/microchip/ksz9477.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 972703fe7454f2892b98dc507a1cba0a5c91dabd..98211d9835734c52f25dcbf7494df45166bcc8da 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -800,6 +800,13 @@ int ksz9477_fdb_add(struct dsa_switch *ds, int port,
 	/* read ALU entry */
 	ksz9477_read_table(dev, alu_table);
 
+	/* The ALU table holds learned and static entries. If the entry is
+	 * not static (learned, or none found), clear its port map, so that
+	 * the static entry lists only this port.
+	 */
+	if (!(alu_table[0] & ALU_V_STATIC_VALID))
+		alu_table[1] &= ~ALU_V_PORT_MAP;
+
 	/* update ALU entry */
 	alu_table[0] = ALU_V_STATIC_VALID;
 	alu_table[1] |= BIT(port);

-- 
2.47.3
Technical Details
Message-ID: <20261126-ksz-stp-link-local-v1-2-39aed15f6271@pengutronix.de>
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-371934-linux-kernel-netdev=dewy.ru
References: <20261126-ksz-stp-link-local-v1-0-39aed15f6271@pengutronix.de>

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-371934-linux-kernel-netdev=dewy.ru
From: o.rempel@pengutronix.de (Oleksij Rempel)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next 2/5] net: dsa: microchip: ksz9477: do not keep the
 learned port in FDB entries
Date: Thu, 26 Nov 2026 09:07:49 +0100
Organization: Usenet Network
Message-ID: <20261126-ksz-stp-link-local-v1-2-39aed15f6271@pengutronix.de>
References: <20261126-ksz-stp-link-local-v1-0-39aed15f6271@pengutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="412923"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:8tgby2KoKXy5dHawPoIisRJgYp8= sha256:8NZfOYWx/p7IdxXXO/VpLJLVXImc0+L0+QugF2oO1sQ=
	sha1:ZgVwLUM6luhxe8mahHGMtkp1whw= sha256:Go8c8cewMjd46lr1FVvBDYdS7iAqkYjX6dw83EG9NkQ=
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 8FEAC125EB0; Thu, 26 Nov 2026 11:08:38 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	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=pengutronix.de
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 woI54dauitvf;
	Thu, 26 Nov 2026 11:08:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-371934-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=pengutronix.de
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 82117125EB3; Thu, 26 Nov 2026 11:08:22 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 029C02BFB5; Thu, 26 Nov 2026 08:08:18 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795680491;
	b=MBdPlckhVoeH35/Cbh0tgHnnvpeTw7iMNfcIZP04Dl5p+uVfkx+GnWbr8jlM9Wsi+euR
	 kD57/HdIa4uEK1iuLWpXderFlxlMOK3rkKNJOYNVZ8dJI1J4g+8c9qCnlgUqM/OQ40LIh
	 YkfDdsuSa31Ty4Gi7ja/hTVORtSi5L931AJO/ltkhy7bwaUKXHHNmfUKcpSIkEmS4m6/s
	 YfpxXs6LQTAfkfNmXLfPsf0F1/nfmHcZAu7Qdnknz92w5Rm++iSTuOmUYN6RnNQrGqd1G
	 vjH3Cc1SYIGTWvE/kXwzVwdxGoagjffCRF1GHFeCwP3DI6xHXYOlpKT7XzbWDPcl4xw==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795680491;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:Received:
	 From:Date:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:References:
	 In-Reply-To:To:Cc:X-Mailer;
	bh=J5L7cdjb6qQ3NsyuVCvHf8W0Te3Ajc+ibnZSLdgukm8=;
	b=KgBWuvamBV5r9TBxPdoN24hR73Xo9joRUgXC3Iv9Yen17Q+OHfwPFOcW4Cf/3y0vvjGU
	 LYT0NxqABabvWlYMq4ReV90rvUp5g78zFWT+iofTAHAcWpoVx22XFL2paxQKlgkyYB7FR
	 5LKsMmDxJwBZsM9Dfm7aKSJTQTvjK+rZEsbEAMdVQP0QuhzJVUQ4VDOBc8BuHRy8PntfL
	 hbMl6xgKBx4c9QlX6yWaqQfw1r+SZFqiC9P+JBGc+38HH0a89RyGc0Ti1Y9HQ/gHFEEaN
	 XwyE6zlKuBlay53Zpco6TVtYE3AOILx7BGbyKWD7DwP+csugpSg+jVvv1+vJfTse10g==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b="V/LGefiQ";
	dmarc=none header.from=pengutronix.de;
	spf=pass smtp.mailfrom=pengutronix.de;
	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 F14AC606A334;
	Thu, 26 Nov 2026 08:08:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=V/LGefiQ
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795680485;
	b=Gv870Lfwx9p+Kw/lnJuu7vSRnfvnt9ncZ5hoKiO7XZqHqIj/HshWXHf3tZJqy81iSesv
	 Xgise9SvwdwWmwjv58sHSA0fTbIeR2+aGumllQQMi8HvZ/2gEZL4GPAdR6wGAVsINjw0/
	 ksqbuQHOImgWlYdZLjhDdm3chn32a11iZbj02PseRq6v0JRk66S4l3MpsmMQ8ns1A0GVC
	 saHe8Gb3SpKHpvWvM8Uvwmh5yUpWlqNeX4D2H/Hy/ZCVgbhwK/Y90n1cfATIoXJrOJY7h
	 p9FEyWhGIvhpTToHNtPTD9reOpwYjtd+sg5AhxUhW1KVzOZl7obocgXBFv9d9B+SFvg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795680485;
	h=DMARC-Filter:Received:DKIM-Signature:Received:From:Date:Subject:
	 MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:
	 References:In-Reply-To:To:Cc:X-Mailer;
	bh=J5L7cdjb6qQ3NsyuVCvHf8W0Te3Ajc+ibnZSLdgukm8=;
	b=GWrqf0B9lEUT64GQixb4iDoCzZqPpPh23CU1lFI/irCVXUeCZuFG8uHcIM7nuf/wVhZ/
	 9xS4WD2fYwqger/QiSoTCVLXinVmF0x1sZXIH+HupLU6KlyDmq3tRs+Tji5yvlvm3EII9
	 whfRPYsNEKVJWBuvM0rhrFhUi31mERVZGIeIu8vHL+MlVAa4onmTjUJxjL1Nzl3BkiT6d
	 zlCfZSZPlQ5NDXGoE95CIswlLhAF8t2U12adLZ7Knvm4VWvtQl86luruNeySx30KSEbCc
	 mxo+3kPfjc/vf7TcN+HtqWaIqBEPDS7HlX+7eftFdBM++0aolCxxU4/eUKc+ExhL6Og==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=pengutronix.de;
	spf=pass smtp.mailfrom=pengutronix.de;
	dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b="V/LGefiQ";
	arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13
X-Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 848A6606A32C
	for <netdev@vger.kernel.org>; Thu, 26 Nov 2026 08:08:03 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 848A6606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de
X-Received: from dude04.red.stw.pengutronix.de (dude04.red.stw.pengutronix.de [IPv6:2a0a:edc0:0:1101:1d::ac])
	(Authenticated sender: relay-from-dude04.red.stw.pengutronix.de)
	by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id C4241201AEF;
	Thu, 26 Nov 2026 09:08:00 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de;
	s=20260414; t=1795680480;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=J5L7cdjb6qQ3NsyuVCvHf8W0Te3Ajc+ibnZSLdgukm8=;
	b=V/LGefiQt1BlT3oDFveuoxfBINTf06Cm6xS+dP+UjjoMBdN0VI/gWJbwxReGVoWelq7FdI
	LCtH8W83sbMKClgvKtBq4Z/n/VVxRTjydluzj+1T6rQRr6dBTy8/+2pgzHqEJb1BvtNCvu
	w8uIQ3g3xskKtHrZTaR0nyCbod0VGJVsqE84f3yEbzZGZon17FrdkJDY2NF1S1+HYYAZC0
	t950yJofAz3Md3Cr6FWHvgxu1SfyjtwMi560P0+yy53qqqxffvRkIUl9OacvvT++mk2gIx
	BwFbqXQ7X7lVHUvcSK9kxAYfTf7S7zG9xQpVp9YDLQ+JqM/HsuDqHTvsa5eW8Q==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de;
	s=20260414; t=1795680480;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=J5L7cdjb6qQ3NsyuVCvHf8W0Te3Ajc+ibnZSLdgukm8=;
	b=WM9rsl6+QLo+H/WV/kTrEfLuJ9Kdbg+Ambrc4mwry49RIv+dHL7rBQqCKVXoPstWnlX68T
	iT53VJqCLOmo1jeiiwg2rnH3ICeEhIYAzjorGaMp4DZKM1vtinzsh6XysxcDs1tlkvKToL
	g6YwZawuCHaa1Tqte1Y1QyVhgKAR5114fBsdL93qCbLcWJpeWsbaplyYLD77FeofkVu7B/
	yftZ3VkGoOOCvrmL/iQn1NLmarfiOcLPuuklBxVaAqgRW3fGl3+Z3tBx0NzigD6PEp6M9J
	23GUzmVsfjViwv7Up386c+CRFQEiTf+6U4ZCaDSyCsbDucazn6Nljy3tmtdf0g==
X-ARC-Authentication-Results: i=1;
	ORIGINATING;
	auth=pass smtp.auth=relay-from-dude04.red.stw.pengutronix.de smtp.mailfrom=ore@pengutronix.de
X-ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1795680480; a=rsa-sha256;
	cv=none;
	b=HiJUPK4uJRY8lF0KiJN17zfK8TnnhsjpatTjAaISjkQDn0r385H882f61pT/bcQ+C/UYkj
	gqrd3Ux4iAG7Xd+hSo2qBlCFL16EpZi3xLKW8Y0fD71FWfPXWyGeYO2h9yMb1MIn+T25ID
	ptb4dOi1jh7NMlgiFCxuXiF/hiTaeLLwR+8VnXCFtf5BoHEInBMcXJQ+BKY0mB5QbVSOol
	tdpz3ETDg91Gd9aiIJ+CkT7nx+z0s7iGboYpSGcnDqQiNDQXIhNPlEcSqyZq8PEtPr3GoB
	zzS/iQBL29OKNDRcKbomsIJBuZE3J1MfR6vclAnX4wpLQi9lrFbAZDAbkcDKNg==
X-Received: by dude04.red.stw.pengutronix.de (Postfix, from userid 1058)
	id B33E83809FE; Thu, 26 Nov 2026 09:08:00 +0100 (CET)
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
X-In-Reply-To: <20261126-ksz-stp-link-local-v1-0-39aed15f6271@pengutronix.de>
X-Cc: Simon Horman <horms@kernel.org>, 
 Florian Fainelli <f.fainelli@gmail.com>, 
 Nikolay Aleksandrov <razor@blackwall.org>, Ido Schimmel <idosch@nvidia.com>, 
 netdev@vger.kernel.org, bridge@lists.linux.dev, kernel@pengutronix.de, 
 Oleksij Rempel <o.rempel@pengutronix.de>
X-Mailer: b4 0.14.2