🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24784

[PATCH net v2 2/2] net: ethernet: ti: cpsw_ale: verify ALE table reads

#24784
From: Manuel Janocha via B4 Relay
Date: Mon, 30 Nov 2026 20:34
101 lines
14395 bytes
From: Manuel Janocha <manuel.janocha@amperfied.com>

On AM62x (CPSW3G) a read of an ALE table entry occasionally returns the
contents of a different table index, or all zeros, although the access
sequence is the documented one and is serialized by the ALE lock.
Reading the data words again does not help, the wrong value is latched;
writing the index to ALE_TBLCTL again and then reading returns the
right entry.

The TRM states that after a write to ALE_TBLCTL any access to an ALE
register is stalled until the table operation completes, so software is
not expected to wait or poll. TI tracks the same symptom for the J7
CPSW as EXT_EP-12856, unresolved, with the workaround to trigger the
read twice.

A wrong read is not harmless: when the entry at the index of the
untagged VLAN reads as free, cpsw_ale_match_free() hands that index out
and the next multicast address overwrites the VLAN entry. Untagged
receive on the port is then dead until the link goes down and up again.

In testing, either the first or the second of two consecutive reads was
the wrong one, so taking the second read is not sufficient. Read every
entry twice, each time after writing the index, and retry until both
reads match. After four unsuccessful tries warn (ratelimited) and
return the last read. Every table read now costs two index writes and
six data reads instead of one and three, and the loops over the table
hold the ALE lock correspondingly longer.

Testing: AM625 board (PHYTEC phyCORE-AM62x, two CPSW ports in dual EMAC
mode with VLAN interfaces), reproducer as in the previous patch
(multicast joins and leaves on both ports plus VLAN add and delete,
120 seconds per run). On the TI vendor kernel 6.18, which has the same
table access code, the previous patch alone failed in 1 of 29 runs and
this patch alone, without the lock, failed in the first run with torn
entries. With both patches 400 runs passed, and the retry corrected
mismatching reads at index 0 and index 64. On net v7.4-rc3 with both
patches 60 runs passed.

Tooling: this patch and its changelog were prepared with an AI coding
assistant (Claude).

Fixes: db82173f23c5 ("netdev: driver: ethernet: add cpsw address lookup engine support")
Signed-off-by: Manuel Janocha <manuel.janocha@amperfied.com>
---
 drivers/net/ethernet/ti/cpsw_ale.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
index 8434803335d5..bef324bc171e 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.c
+++ b/drivers/net/ethernet/ti/cpsw_ale.c
@@ -339,17 +339,42 @@ static inline void cpsw_ale_set_addr(u32 *ale_entry, const u8 *addr)
 		cpsw_ale_set_field(ale_entry, 40 - 8*i, 8, addr[i]);
 }
 
-static int cpsw_ale_read(struct cpsw_ale *ale, int idx, u32 *ale_entry)
+/*
+ * A table read occasionally returns the entry of another index or all
+ * zeros. Reading the data words again does not help, but writing the
+ * index again and reading returns the right entry. Either of two
+ * consecutive reads can be the wrong one, so read twice and compare.
+ */
+#define ALE_TABLE_READ_RETRIES	4
+
+static void cpsw_ale_read_entry(struct cpsw_ale *ale, int idx, u32 *ale_entry)
 {
 	int i;
 
-	WARN_ON(idx > ale->params.ale_entries);
-
 	writel_relaxed(idx, ale->params.ale_regs + ALE_TABLE_CONTROL);
 
 	for (i = 0; i < ALE_ENTRY_WORDS; i++)
 		ale_entry[i] = readl_relaxed(ale->params.ale_regs +
 					     ALE_TABLE + 4 * i);
+}
+
+static int cpsw_ale_read(struct cpsw_ale *ale, int idx, u32 *ale_entry)
+{
+	u32 prev[ALE_ENTRY_WORDS];
+	int tries;
+
+	WARN_ON(idx > ale->params.ale_entries);
+
+	for (tries = 0; tries < ALE_TABLE_READ_RETRIES; tries++) {
+		cpsw_ale_read_entry(ale, idx, prev);
+		cpsw_ale_read_entry(ale, idx, ale_entry);
+		if (!memcmp(prev, ale_entry, sizeof(prev)))
+			return idx;
+	}
+
+	dev_warn_ratelimited(ale->params.dev,
+			     "ALE table read of entry %d did not stabilize\n",
+			     idx);
 
 	return idx;
 }

-- 
2.34.1
Technical Details
Message-ID: <20261130-cpsw-ale-lock-v2-2-c7a59d2178bb@amperfied.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374458-linux-kernel-netdev=dewy.ru
References: <20261130-cpsw-ale-lock-v2-0-c7a59d2178bb@amperfied.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374458-linux-kernel-netdev=dewy.ru
From: devnull+manuel.janocha.amperfied.com@kernel.org (Manuel Janocha via B4 Relay)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2 2/2] net: ethernet: ti: cpsw_ale: verify ALE table reads
Date: Mon, 30 Nov 2026 20:34:47 +0000
Organization: Usenet Network
Message-ID: <20261130-cpsw-ale-lock-v2-2-c7a59d2178bb@amperfied.com>
References: <20261130-cpsw-ale-lock-v2-0-c7a59d2178bb@amperfied.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network; logging-data="1531762"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:hcu3TZRqZULkUftfnB7Yjmfm1aQ= sha256:XEvRb/7PDfVa6wchtPdWtOYvBOXlTsNepoWFz/EUdzs= sha1:rvJyb49sl4EfY6lHq7H7hzrqfM8= sha256:0o9E2sZOqqxgo7ds4GpLWh6TD07FOx9c66gBsJfmd3k=
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 0E7D1126006; Mon, 30 Nov 2026 23:35:15 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[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] 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 9h01Vu2dq26L; Mon, 30 Nov 2026 23:35:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-374458-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 5A551126007; Mon, 30 Nov 2026 23:35:02 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 171A6601BD6; Mon, 30 Nov 2026 20:35:02 +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=1796070900; b=5rWjyAdiE1Nqu30Z5xMA4kQiqz3Zp9+cTvjzz7CxvsB6z4WSgtjH2hsNVzaRNTGECod/ Q0/5FdnCQrGLI1WTLh3ikkeOwjl2mmWcNI4Uuqc3jZtQEzzgJL5fbV7klwwqpL79Qv4X7 19UONkv0l247x/v2ac0q2XWDN7tGv1sSrY97ybwsiCg4yO7d+iWiTnLGpZx61aHMFMJxN od4vcuYgQCsFBqqzfjgZTyOVnMOuBoL0mLPKHx3RviqmgalVyFBxhMd7ogdEj4C+1PMjk ITihqvqJj5UY7d0rP6bzgc2aXKx1GttrIOqma4Rw1xBKNl6vcoAEL0v2qXfcyBd/kSg==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796070900; h=X-Original-To:Received: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: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=JTc7U53sG6NN7A8lquxDHkY1ftoq2vpiKPer12LMGyg=; b=RE1cjVL1OhoMe2bdIF+djHgi/sh5WyBfSUw9B7vAd9j7oDZEiapzIjUBkyM0uP7UP5fb Y7IME7nMrLf3UyC94RDqufHumC3GRzqu48YGwP165zTOBqqBIZGgEyOytUWEMhVUaKyPk yb2IUxzsMwZS8sAuHyEcqIdbUOFGgzx2orimzVN1PdH8JLcEt+7itKLbJtZ7C+duCRHgf 1uaQuqyDUPYSTJ9qIMkcTQcOh+v6AI5R2TzNTcbaCn5nMIiUlZ9TsNQSNxtpIgIDc4gwQ pB3AfrLICMJC7X3PejIqrbj+feKKCfX+v20xm/CkZtoIdT6x5+1ezgjQBqoCUwnrmXQ==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UZMtGDKm; 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 3F41B606A683; Mon, 30 Nov 2026 20:35:00 +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=UZMtGDKm
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796070899; b=rAp9tP2Wx9Re8UAXNrRU8JahRDGDOnAbkJumeVl7ggJezXKEaEH3jpCYdbjYPLeds2vF MNCcIlzTfebZN3/rHmriMHlQ7t7R8KqGVvGTIB/gb6CsxBFWnZK4GGe7wEFOpHkmwHggN Q0XZDe0a5C+0ud31EYG9lIZn5x7SohWSPcFNS92JybUuS5pdegxFlEd1Kh3KUlsoZUc5Q 1oZeeHXfHTtdFhQ9UF5Cq6f0Ige3fAY7CBWJXNm4tdguTPJ34d5XflzyVcWgPzncPn7GV gCoBPU67JSzeLh2NzxQFJhZ48moZreWe3y8GT1nOrx2jDC6AGPaKybhPyeByx8VBO1A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796070899; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=JTc7U53sG6NN7A8lquxDHkY1ftoq2vpiKPer12LMGyg=; b=sUEi9A6KrKM4uffCip7r9XfgWIuycvsyHPpBc8A5PUOTHs6Y75SqtmriyS+In3y2CYnw V98KH8ATZsxAxmnfm+BBcMh1xtyQFBUWoBt3+JEqjKXAyks0TaIP4E9HkTPVH5pKIvyeQ 2XNKqADljyosMBOWe1l4M0ajU7iT8P0G4KY2ChMZFfXejLOAyDbWNWUVorfi9ibjtybKO vlVGqrwMGCJk0HZ56Dk3kx6PAPE0+mWnLkzRmrXPIYR9GDH0oNjZlWS8bFrj9w4NREl0j 092LFtv7wxvIudlyu2ustvWV+WJg2BTQF3hl8fY0n7TWkcPZCExX4VJ4TKsMbRm0AEw==
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=UZMtGDKm; arc=pass header.oldest-pass=0 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 5E533606A330; Mon, 30 Nov 2026 20:34:59 +0000 (UTC)
X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796070898; b=iYuc0COBkQo08Mk+e3VMjTXw/JeWPUGF+EE0V/OA+WoIQ2Odxh07oFfIXOO2IisI5g45 l8K8Cug5Cs0nprHzVPi885axsCBvBzBKuneDWOBzdWHedgRBfaZ8l/Lodr2UPakCrxbnX xQWuevNRooXr79/hn8d5n3lpM5rQ1/DwnX23pesZTpkyt577En5Ww6+5Xd1ClB8PB3+n9 xePLpcQxyOvhNdsyHelHiscdYwrktKrY5u8JVlPYdIiOzPde2hhWl16bUKE2wBFR1JRof D64Ds3WpvFh4mxki4DdepINjAYEzVdjY6L4zijuNPn0c+u3P3sdmhbcCnK77FiuqeGQ==
X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796070898; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=JTc7U53sG6NN7A8lquxDHkY1ftoq2vpiKPer12LMGyg=; b=R+lE5wyJuvcvqbVBK8xIlM9b3ra3I6Pa8ojOZ+DfAP29N5bK8uEvOBb78tHuskc6Rp0d sza4Duj/BC+khM1O32h9s5lrW1eyAORXPRdeQBupJWtwEgo0JMhn0tphGhATwThSujHI2 FvjF2M6RIIO5WKanXjQ3r2LaVHttKwC+INmekOMfLNXnbUytHAZtvfaErDUBNSz+ndIuo v4qaMzNx9weJhLoxXfYmRqgULxy82Y7SsEvPbO9vwq9vr0ScRh/42TgwRujAcIG6ouwuJ U+Sqejr3RYjQ2SH7z+9bqK/nZL9H2TV9IJJ0WSFpMb3zISAiTPg7fLjk/mB6D8s7Yzg==
X-ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77
X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (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.kernel.org (Postfix) with ESMTPS id 20F7D1F0089C; Mon, 30 Nov 2026 20:34:48 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796070898; bh=JTc7U53sG6NN7A8lquxDHkY1ftoq2vpiKPer12LMGyg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=UZMtGDKmHb3SE0L/kWvI76kXQMO8OeQOkJgK2QeIraKJf6QwbaG0Wl7Uzd15PUuUr bc0VY5/j/SuLS3e6RW9n+mcTXRTgrjwcNoaf5FBkFKGCZrtE4dvyX/sTww8Bzes3rH pUxmNEzN8n+/wBRZehSiLEGV7+Uh/lSHBL13MBaOY4jS7YO3SIDGWDiy5PE6E/h4e4 hFgxlJ3qVJaSMoSx2Dp+rpGKFFHcMMv6DvP5tFdlg1Gl8J5qIZcNPRxWK3rANDqKD9 YYpXpYBQZK6YQVKYK91rozWezVukffLz4EGKrhQEX+lNW0ShXMn38HMezSsWvGXhnv MPBvPgJKsZz1g==
X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id AB2784E9D9; Mon, 30 Nov 2026 20:34:47 +0000 (UTC)
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: <20261130-cpsw-ale-lock-v2-0-c7a59d2178bb@amperfied.com>
X-Cc: linux-omap@vger.kernel.org, netdev@vger.kernel.org, Kuniyuki Iwashima <kuniyu@google.com>, Manuel Janocha <manuel.janocha@amperfied.com>
X-Mailer: b4 0.15.2
X-Developer-Signature: v=1; a=ed25519-sha256; t=1796070886; l=4054; i=manuel.janocha@amperfied.com; s=20261127; h=from:subject:message-id; bh=7RW9eWWgCBKAnYltMR2+shV6F9Kok/Ap48Yu2E521FQ=; b=wImxsovYrqtBjVIz0/pt6iEMJP0eP6P08Fv2WfzeB6GcpJUEpY+xyfcsRiyUAON00Kip02QMF DFuR3t0YLo6C0IQFlg/Jqu8XZQgbH0/uGRgNZTMmeWwurfVWK/2e/1J
X-Developer-Key: i=manuel.janocha@amperfied.com; a=ed25519; pk=DEqXiAa78UfHuuvMWJsylc0F41gl8N+i7WtqrDb4xCQ=
X-Endpoint-Received: by B4 Relay for manuel.janocha@amperfied.com/20261127 with auth_id=1666
X-Original-From: Manuel Janocha <manuel.janocha@amperfied.com>
X-Reply-To: manuel.janocha@amperfied.com
X-Received-Bytes: 14136