Netdev List
 help / color / mirror / Atom feed
* [PATCH net v4 0/4] net: ethernet: ti: cpsw_ale: fix lost ALE entries
@ 2026-12-03 12:14 Manuel Janocha via B4 Relay
  2026-12-03 12:14 ` [PATCH net v4 1/4] net: netcp: do not disable interrupts in the VLAN callbacks Manuel Janocha via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Manuel Janocha via B4 Relay @ 2026-12-03 12:14 UTC (permalink / raw)
  To: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vignesh Raghavendra
  Cc: linux-omap, netdev, Kuniyuki Iwashima, Manuel Janocha, stable

On AM62x/AM625 with both CPSW3G ports in dual EMAC mode and VLAN
interfaces on top, reception of untagged frames on a port can stop. The
port VLAN entry at ALE index 0 had been overwritten by an IPv6
multicast entry (33:33:...). Only link down/up recovers the port.

Two independent causes were found:

1. The ALE table is accessed through an index register and three data
   registers. The read-modify-write sequences in cpsw_ale.c run
   concurrently from different contexts, for example ndo_set_rx_mode()
   of one port against VLAN add/kill on the other, without any lock.
   Entries get lost or mixed. Patch 2 adds a lock to struct cpsw_ale
   and patch 3 extends it to the control register updates. Patch 1 is
   a prerequisite of patch 2: netcp calls into the ALE with interrupts
   disabled, which does not work with the lock taken by
   spin_lock_bh().

2. Even with the lock held, a table read occasionally returns the
   content of another index or all zeros. Reading the data words again
   without rewriting the index stays wrong, rewriting the index and
   reading again returns the right entry. Either of two consecutive
   reads can be the bad one. If the VLAN entry reads as free, its
   index is handed out as a free slot and overwritten. Patch 4 reads
   every entry twice, rewriting the index each time, and retries until
   both reads match. It is enabled for the am64-cpswxg ALE, on which
   the problem was seen; am65-cpsw-nuss also uses that ALE for the J7
   CPSWxG instances.

The AM62x TRM (SPRUIV7) says that after a write to ALE_TBLCTL any ALE
register access is stalled until the table operation completes, so the
access sequence in the driver is as documented. TI lists a matching
unresolved issue for the J7 CPSW in its public tracker as EXT_EP-12856
(workaround: trigger the read twice); AM62x is not listed there.

Measured on a PHYTEC phyCORE-AM62x (CPSW3G, two ports in dual EMAC
mode, VLAN sub-interfaces). Stress: multicast joins and leaves on
both ports plus VLAN add/remove, 120 seconds per run.

 - net v7.4-rc3, table lock only: 2 of 19 runs failed
 - net v7.4-rc3, table lock and read verification: 60 runs passed,
   lockdep enabled, no warnings
 - TI/PHYTEC 6.18 vendor kernel, table lock only: 1 of 29 runs failed
 - same kernel, read verification only (no lock): failed in the first
   run, with torn entries
 - same kernel, lock and read verification: 400 runs passed;
   mismatching reads were caught and corrected by the retry (seen at
   index 0 and index 64)
 - a 6.6 based kernel without the patches also fails (run 8); it does
   not have the commit named in patch 2, which points to cause 2
 - net v7.4-rc3, v3 of this series (all four patches): 60 runs
   passed, lockdep enabled, no warnings, the read verification never
   gave up

All results except the last one are from v1 and v2 of the patches
(table lock taken with spin_lock_bh() in v1 and spin_lock_irqsave() in
v2, read verification for all ALE variants).

Test coverage: the table lock and the read verification together were
run-tested on net v7.4-rc3 and on the 6.18 vendor kernel, which has the
same cpsw_ale.c table access code. The legacy cpsw, cpsw_new and netcp
users of the ALE, the netcp change in patch 1, the control register
lock in patch 3 and the suspend error path added to patch 4 in v4 are
compile-tested only.

Signed-off-by: Manuel Janocha <manuel.janocha@amperfied.com>
---
Changes in v4:
- Patch 1: changelog names the patch that depends on it and why; it
  carries the Fixes tag of patch 2 so both are backported together
- Patch 2: lock comment says that only the writers of
  p0_untag_vid_mask are serialized and the RX path reads it without
  the lock
- Patch 4: cpsw_ale_dump() returns -EIO if an entry could not be
  verified; am65_cpsw_nuss_suspend() then fails instead of saving the
  entry for cpsw_ale_restore()
- Patch 4: changelog says that am65-cpsw-nuss uses the am64-cpswxg ALE
  for the J7 CPSWxG instances too
- Link to v3: https://patch.msgid.link/20261202-cpsw-ale-lock-v3-0-b40dc361d6b9@amperfied.com

Changes in v3:
- New patch 1: netcp VLAN callbacks use spin_lock_bh() instead of
  spin_lock_irqsave()
- Patch 2: take the ALE lock with spin_lock_bh() instead of
  spin_lock_irqsave(), so hard interrupts stay enabled during the table
  scans; lock comment names what the lock protects
- New patch 3: the locking of cpsw_ale_control_set() is split out of
  the table lock patch, with its own Fixes tag
- Patch 4: verify reads only for am64-cpswxg through a feature flag,
  Fixes tag changed accordingly
- Patch 4: return -EIO if a read cannot be verified; the callers leave
  the entry alone
- Link to v2: https://patch.msgid.link/20261130-cpsw-ale-lock-v2-0-c7a59d2178bb@amperfied.com

Changes in v2:
- Patch 1: use spin_lock_irqsave() instead of spin_lock_bh(): netcp
  calls cpsw_ale_add_vlan()/cpsw_ale_del_vlan() with interrupts
  disabled
- Patch 1: also lock the read-modify-write in cpsw_ale_control_set()
- Patch 1: correct the changelog: affected drivers (cpsw/cpsw_new are
  already serialized by their rx_mode work item), accessors are the
  _relaxed variants; test results updated
- New patch 2: verify ALE table reads (hardware read glitch seen with
  the lock in place)
- Link to v1: https://patch.msgid.link/20261127-cpsw-ale-lock-v1-1-a72772d9a5ae@amperfied.com

---
Manuel Janocha (4):
      net: netcp: do not disable interrupts in the VLAN callbacks
      net: ethernet: ti: cpsw_ale: serialize ALE table accesses
      net: ethernet: ti: cpsw_ale: serialize control register updates
      net: ethernet: ti: cpsw_ale: verify ALE table reads

 drivers/net/ethernet/ti/am65-cpsw-nuss.c |   5 +-
 drivers/net/ethernet/ti/cpsw_ale.c       | 199 +++++++++++++++++++++++++------
 drivers/net/ethernet/ti/cpsw_ale.h       |   8 +-
 drivers/net/ethernet/ti/netcp_core.c     |  10 +-
 4 files changed, 176 insertions(+), 46 deletions(-)
---
base-commit: ef3e21c61baa74e39a49b75318bd4541562ec43f
change-id: 20261126-cpsw-ale-lock-cc05d5bea7a0

Best regards,
--  
Manuel Janocha <manuel.janocha@amperfied.com>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH net v4 1/4] net: netcp: do not disable interrupts in the VLAN callbacks
  2026-12-03 12:14 [PATCH net v4 0/4] net: ethernet: ti: cpsw_ale: fix lost ALE entries Manuel Janocha via B4 Relay
@ 2026-12-03 12:14 ` Manuel Janocha via B4 Relay
  2026-12-03 12:14 ` [PATCH net v4 2/4] net: ethernet: ti: cpsw_ale: serialize ALE table accesses Manuel Janocha via B4 Relay
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Manuel Janocha via B4 Relay @ 2026-12-03 12:14 UTC (permalink / raw)
  To: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vignesh Raghavendra
  Cc: linux-omap, netdev, Kuniyuki Iwashima, Manuel Janocha, stable

From: Manuel Janocha <manuel.janocha@amperfied.com>

netcp_rx_add_vid() and netcp_rx_kill_vid() take netcp->lock with
spin_lock_irqsave(). The lock only protects the module list walk and
is otherwise taken in netcp_set_rx_mode() with spin_lock() under
netif_addr_lock_bh(), and with spin_lock_irqsave() in the hook
registration functions, which run in process context. It is never taken
from hard interrupt context. Both callbacks are ndo_vlan_rx_add_vid and
ndo_vlan_rx_kill_vid, which the VLAN core calls in process context.

The callbacks end up in gbe_add_vid() and gbe_del_vid(), which call
cpsw_ale_add_vlan() and cpsw_ale_del_vlan(). These scan the whole ALE
table with MMIO accesses and run with interrupts disabled for that
time.

Use spin_lock_bh() instead. This keeps the exclusion against
netcp_set_rx_mode() and does not disable hard interrupts.

The next patch, "net: ethernet: ti: cpsw_ale: serialize ALE table
accesses", makes cpsw_ale_add_vlan() and cpsw_ale_del_vlan() take a
lock with spin_lock_bh(). With netcp->lock still taken by
spin_lock_irqsave(), spin_unlock_bh() would then run with hard
interrupts disabled, which trips lockdep_assert_irqs_enabled() in
__local_bh_enable_ip() and can run pending softirqs with interrupts
off. That patch needs this one to be correct, so this one carries the
same Fixes tag and both are backported together.

Testing: compile-tested only (arm, multi_v7_defconfig with the netcp
drivers enabled, W=1). No hardware with netcp was available.

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

Fixes: 1767bb2d47b7 ("ipv6: mcast: Don't hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.")
Cc: stable@vger.kernel.org
Signed-off-by: Manuel Janocha <manuel.janocha@amperfied.com>
---
 drivers/net/ethernet/ti/netcp_core.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c
index f5e093dc983b..09fa4c732155 100644
--- a/drivers/net/ethernet/ti/netcp_core.c
+++ b/drivers/net/ethernet/ti/netcp_core.c
@@ -1881,12 +1881,11 @@ static int netcp_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid)
 	struct netcp_intf *netcp = netdev_priv(ndev);
 	struct netcp_intf_modpriv *intf_modpriv;
 	struct netcp_module *module;
-	unsigned long flags;
 	int err = 0;
 
 	dev_dbg(netcp->ndev_dev, "adding rx vlan id: %d\n", vid);
 
-	spin_lock_irqsave(&netcp->lock, flags);
+	spin_lock_bh(&netcp->lock);
 	for_each_module(netcp, intf_modpriv) {
 		module = intf_modpriv->netcp_module;
 		if ((module->add_vid) && (vid != 0)) {
@@ -1898,7 +1897,7 @@ static int netcp_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid)
 			}
 		}
 	}
-	spin_unlock_irqrestore(&netcp->lock, flags);
+	spin_unlock_bh(&netcp->lock);
 
 	return err;
 }
@@ -1908,12 +1907,11 @@ static int netcp_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vid)
 	struct netcp_intf *netcp = netdev_priv(ndev);
 	struct netcp_intf_modpriv *intf_modpriv;
 	struct netcp_module *module;
-	unsigned long flags;
 	int err = 0;
 
 	dev_dbg(netcp->ndev_dev, "removing rx vlan id: %d\n", vid);
 
-	spin_lock_irqsave(&netcp->lock, flags);
+	spin_lock_bh(&netcp->lock);
 	for_each_module(netcp, intf_modpriv) {
 		module = intf_modpriv->netcp_module;
 		if (module->del_vid) {
@@ -1925,7 +1923,7 @@ static int netcp_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vid)
 			}
 		}
 	}
-	spin_unlock_irqrestore(&netcp->lock, flags);
+	spin_unlock_bh(&netcp->lock);
 	return err;
 }
 

-- 
2.34.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net v4 2/4] net: ethernet: ti: cpsw_ale: serialize ALE table accesses
  2026-12-03 12:14 [PATCH net v4 0/4] net: ethernet: ti: cpsw_ale: fix lost ALE entries Manuel Janocha via B4 Relay
  2026-12-03 12:14 ` [PATCH net v4 1/4] net: netcp: do not disable interrupts in the VLAN callbacks Manuel Janocha via B4 Relay
@ 2026-12-03 12:14 ` Manuel Janocha via B4 Relay
  2026-12-04 12:47   ` netdev-bot+sashiko
  2026-12-03 12:14 ` [PATCH net v4 3/4] net: ethernet: ti: cpsw_ale: serialize control register updates Manuel Janocha via B4 Relay
  2026-12-03 12:14 ` [PATCH net v4 4/4] net: ethernet: ti: cpsw_ale: verify ALE table reads Manuel Janocha via B4 Relay
  3 siblings, 1 reply; 10+ messages in thread
From: Manuel Janocha via B4 Relay @ 2026-12-03 12:14 UTC (permalink / raw)
  To: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vignesh Raghavendra
  Cc: linux-omap, netdev, Kuniyuki Iwashima, Manuel Janocha, stable

From: Manuel Janocha <manuel.janocha@amperfied.com>

The ALE table is accessed through a single index register
(ALE_TABLE_CONTROL) and three data registers (ALE_TABLE). Reading an
entry writes the index and then reads the data registers; writing an
entry fills the data registers and then writes the index with
ALE_TABLE_WRITE. Most operations (add/del ucast/mcast/vlan,
vlan_add_modify, flush_multicast, set_allmulti, set_unreg_mcast) are
read-modify-write sequences over several entries. The driver has no
lock around any of this.

This did not matter as long as the callers were serialized by someone
else. Both ports of a CPSW switch share one ALE, but the port VLAN
and address operations run under RTNL, while ndo_set_rx_mode() of
am65-cpsw and netcp runs under netif_addr_lock_bh() of one port only
and does not take RTNL. Since IPV6_ADD_MEMBERSHIP and friends no
longer hold RTNL, joining an IPv6 multicast group
(igmp6_group_added() -> dev_mc_add() -> ndo_set_rx_mode()) can run
concurrently with a VLAN or address operation on the other port, or
on the same port.

For example, on two CPUs:

  CPU0 (eth0 rx_mode, flush)     CPU1 (eth1 add_vid)
  cpsw_ale_read(A):
    writel(A, TABLE_CONTROL)
                                 cpsw_ale_read(B):
                                   writel(B, TABLE_CONTROL)
    readl(ALE_TABLE + 0..2)
      -> returns entry B
  cpsw_ale_write(A):
    entry B is written to index A

Entry A is lost and entry B exists twice. Interleaved writes can
equally mix the data words of two entries in one table slot. The same
happens inside the multi-entry loops, so entries are written back with
foreign data or are dropped.

Observed on an AM625 board with two am65-cpsw-nuss ports in dual EMAC
mode and seven VLANs on the second port: after boot the port VLAN
entry (VID 0), the unicast entry of the first port and two VLAN
entries were gone, copies of the unicast and of the broadcast entry
showed up at two other indexes. The switch then dropped every frame
received on the first port (p0_ale_vid_ingress_drop kept rising) while
the port could still transmit, and the board was unreachable.

Add a spinlock to struct cpsw_ale and take it in all exported
functions that access the table. cpsw and cpsw_new are not affected
in practice: since commit 0b8c878d1173 ("net: cpsw: Execute
ndo_set_rx_mode callback in a work queue") they run rx_mode from a
work item under RTNL and are already serialized. The lock is put into
the ALE library instead of repeating that approach in the other
drivers because the table protocol (index plus data registers) is an
invariant of the library itself, one lock covers all users including
the ageout timer, and it does not depend on every present and future
caller holding RTNL.

The lock is taken with spin_lock_bh(). ndo_set_rx_mode() already runs
with bottom halves disabled, and no caller runs in hard interrupt
context, so hard interrupts stay enabled while the table is scanned.
netcp was the only caller that took the lock with interrupts disabled
(netcp_rx_add_vid() and netcp_rx_kill_vid()); the previous patch
changed that. A sleeping lock cannot be used because of the atomic
callers. The register accesses under the lock are
readl_relaxed()/writel_relaxed() as before; this patch does not change
the accessors. The regmap of the ALE is only used for the version,
feature and policer fields and is not touched under the lock.

cpsw_ale_vlan_add_modify() calls cpsw_ale_add_vlan() with the lock
held, so the body of the latter moves into a static helper that does
not take the lock. The loops over all entries run with the lock held
for the number of table entries; that is the same amount of MMIO as
before, just not preemptible by the other port.

The lock is held longest when a VLAN is added: with the 512 entry
table of the AM625 a backport of this patch to the TI 6.18.59 vendor
kernel measured up to 1.1 ms in cpsw_ale_vlan_add_modify() called
from ndo_vlan_rx_add_vid(). That is the time with bottom halves
disabled, not with interrupts disabled. It is VLAN configuration, not
the data path; the multicast add and delete paths hold it for less.

Discovery: observed on a test system and reproduced on the same board.
The reproducer joins IPv6 multicast groups in parallel on eth0, eth1
and a VLAN interface of eth1 while adding and deleting a VLAN on eth1.
It needs no kernel modification and no error injection. Without this
change eth0 stops receiving after about 30 seconds.

Testing: hardware test on an AM625 board (two CPSW ports,
am65-cpsw-nuss) with net at v7.4-rc3 (ef3e21c61baa) plus an
out-of-tree board device tree, built with PROVE_LOCKING,
DEBUG_SPINLOCK and DEBUG_ATOMIC_SLEEP. Without this patch the
reproducer kills reception within 120 seconds
(p0_ale_vid_ingress_drop 0 -> 2366 and rising; link down/up
recovers). With this patch it ran for 120 and for 300 seconds
(about 21800 joins and 87 VLAN add/delete cycles of three VLANs in
the longer run): eth0 and the VLANs kept receiving and lockdep stayed
silent. p0_ale_vid_ingress_drop rose by 1 and by 3 during the two
runs. Over all 19 runs on net v7.4-rc3 with this patch alone, 2
failed with the VID 0 entry overwritten again. A backport to the TI
vendor kernel 6.18.59 passed 28 of 29 runs of 120 to 300 seconds; one
120 second run lost the VID 0 entry again. These remaining failures
are not missing serialization: with the lock held, a table read can
still return a wrong entry, which patch 4 handles. These numbers are
from v1 (spin_lock_bh()) and v2 (spin_lock_irqsave()) of this patch.
This version was run with the whole series on net v7.4-rc3: 60 runs
of 120 seconds passed and lockdep stayed silent. The legacy cpsw,
cpsw_new and netcp users of the ALE were only compile-tested (arm64
and arm, W=1).

Tooling: the port to net, the locking analysis and this changelog were
prepared with an AI coding assistant (Claude).

Fixes: 1767bb2d47b7 ("ipv6: mcast: Don't hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.")
Cc: stable@vger.kernel.org
Signed-off-by: Manuel Janocha <manuel.janocha@amperfied.com>
---
 drivers/net/ethernet/ti/cpsw_ale.c | 70 ++++++++++++++++++++++++++++++++------
 drivers/net/ethernet/ti/cpsw_ale.h |  5 +++
 2 files changed, 65 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
index 9304405c9581..dc550142ed82 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.c
+++ b/drivers/net/ethernet/ti/cpsw_ale.c
@@ -464,6 +464,7 @@ int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid)
 	u32 ale_entry[ALE_ENTRY_WORDS];
 	int ret, idx;
 
+	spin_lock_bh(&ale->lock);
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
 		cpsw_ale_read(ale, idx, ale_entry);
 		ret = cpsw_ale_get_entry_type(ale_entry);
@@ -491,6 +492,7 @@ int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid)
 
 		cpsw_ale_write(ale, idx, ale_entry);
 	}
+	spin_unlock_bh(&ale->lock);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_flush_multicast);
@@ -520,15 +522,19 @@ int cpsw_ale_add_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
 	cpsw_ale_set_blocked(ale_entry, (flags & ALE_BLOCKED) ? 1 : 0);
 	cpsw_ale_set_port_num(ale_entry, port, ale->port_num_bits);
 
+	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
 	if (idx < 0)
 		idx = cpsw_ale_match_free(ale);
 	if (idx < 0)
 		idx = cpsw_ale_find_ageable(ale);
-	if (idx < 0)
+	if (idx < 0) {
+		spin_unlock_bh(&ale->lock);
 		return -ENOMEM;
+	}
 
 	cpsw_ale_write(ale, idx, ale_entry);
+	spin_unlock_bh(&ale->lock);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_add_ucast);
@@ -539,12 +545,16 @@ int cpsw_ale_del_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
 	u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
 	int idx;
 
+	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
-	if (idx < 0)
+	if (idx < 0) {
+		spin_unlock_bh(&ale->lock);
 		return -ENOENT;
+	}
 
 	cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
 	cpsw_ale_write(ale, idx, ale_entry);
+	spin_unlock_bh(&ale->lock);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_del_ucast);
@@ -555,6 +565,7 @@ int cpsw_ale_add_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
 	u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
 	int idx, mask;
 
+	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
 	if (idx >= 0)
 		cpsw_ale_read(ale, idx, ale_entry);
@@ -575,10 +586,13 @@ int cpsw_ale_add_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
 		idx = cpsw_ale_match_free(ale);
 	if (idx < 0)
 		idx = cpsw_ale_find_ageable(ale);
-	if (idx < 0)
+	if (idx < 0) {
+		spin_unlock_bh(&ale->lock);
 		return -ENOMEM;
+	}
 
 	cpsw_ale_write(ale, idx, ale_entry);
+	spin_unlock_bh(&ale->lock);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_add_mcast);
@@ -590,9 +604,12 @@ int cpsw_ale_del_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
 	int mcast_members = 0;
 	int idx;
 
+	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
-	if (idx < 0)
+	if (idx < 0) {
+		spin_unlock_bh(&ale->lock);
 		return -ENOENT;
+	}
 
 	cpsw_ale_read(ale, idx, ale_entry);
 
@@ -609,6 +626,7 @@ int cpsw_ale_del_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
 		cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
 
 	cpsw_ale_write(ale, idx, ale_entry);
+	spin_unlock_bh(&ale->lock);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_del_mcast);
@@ -642,8 +660,8 @@ static void cpsw_ale_set_vlan_untag(struct cpsw_ale *ale, u32 *ale_entry,
 		bitmap_clear(ale->p0_untag_vid_mask, vid, 1);
 }
 
-int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port_mask, int untag,
-		      int reg_mcast, int unreg_mcast)
+static int __cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port_mask,
+			       int untag, int reg_mcast, int unreg_mcast)
 {
 	u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
 	int idx;
@@ -681,6 +699,19 @@ int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port_mask, int untag,
 	cpsw_ale_write(ale, idx, ale_entry);
 	return 0;
 }
+
+int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port_mask, int untag,
+		      int reg_mcast, int unreg_mcast)
+{
+	int ret;
+
+	spin_lock_bh(&ale->lock);
+	ret = __cpsw_ale_add_vlan(ale, vid, port_mask, untag, reg_mcast,
+				  unreg_mcast);
+	spin_unlock_bh(&ale->lock);
+
+	return ret;
+}
 EXPORT_SYMBOL_GPL(cpsw_ale_add_vlan);
 
 static void cpsw_ale_vlan_del_modify_int(struct cpsw_ale *ale,  u32 *ale_entry,
@@ -728,14 +759,18 @@ int cpsw_ale_vlan_del_modify(struct cpsw_ale *ale, u16 vid, int port_mask)
 	u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
 	int idx;
 
+	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_vlan(ale, vid);
-	if (idx < 0)
+	if (idx < 0) {
+		spin_unlock_bh(&ale->lock);
 		return -ENOENT;
+	}
 
 	cpsw_ale_read(ale, idx, ale_entry);
 
 	cpsw_ale_vlan_del_modify_int(ale, ale_entry, vid, port_mask);
 	cpsw_ale_write(ale, idx, ale_entry);
+	spin_unlock_bh(&ale->lock);
 
 	return 0;
 }
@@ -746,9 +781,12 @@ int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port_mask)
 	u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
 	int members, idx;
 
+	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_vlan(ale, vid);
-	if (idx < 0)
+	if (idx < 0) {
+		spin_unlock_bh(&ale->lock);
 		return -ENOENT;
+	}
 
 	cpsw_ale_read(ale, idx, ale_entry);
 
@@ -771,6 +809,7 @@ int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port_mask)
 	}
 
 	cpsw_ale_write(ale, idx, ale_entry);
+	spin_unlock_bh(&ale->lock);
 
 	return 0;
 }
@@ -784,6 +823,7 @@ int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask,
 	int vlan_members, untag_members;
 	int idx, ret = 0;
 
+	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_vlan(ale, vid);
 	if (idx >= 0)
 		cpsw_ale_read(ale, idx, ale_entry);
@@ -803,8 +843,9 @@ int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask,
 	reg_mcast_members = (reg_mcast_members & ~port_mask) | reg_mask;
 	unreg_mcast_members = (unreg_mcast_members & ~port_mask) | unreg_mask;
 
-	ret = cpsw_ale_add_vlan(ale, vid, vlan_members, untag_members,
-				reg_mcast_members, unreg_mcast_members);
+	ret = __cpsw_ale_add_vlan(ale, vid, vlan_members, untag_members,
+				  reg_mcast_members, unreg_mcast_members);
+	spin_unlock_bh(&ale->lock);
 	if (ret) {
 		dev_err(ale->params.dev, "Unable to add vlan\n");
 		return ret;
@@ -823,6 +864,7 @@ void cpsw_ale_set_unreg_mcast(struct cpsw_ale *ale, int unreg_mcast_mask,
 	int unreg_members = 0;
 	int type, idx;
 
+	spin_lock_bh(&ale->lock);
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
 		cpsw_ale_read(ale, idx, ale_entry);
 		type = cpsw_ale_get_entry_type(ale_entry);
@@ -841,6 +883,7 @@ void cpsw_ale_set_unreg_mcast(struct cpsw_ale *ale, int unreg_mcast_mask,
 				      unreg_members);
 		cpsw_ale_write(ale, idx, ale_entry);
 	}
+	spin_unlock_bh(&ale->lock);
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_set_unreg_mcast);
 
@@ -885,6 +928,7 @@ void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti, int port)
 	u32 ale_entry[ALE_ENTRY_WORDS];
 	int type, idx;
 
+	spin_lock_bh(&ale->lock);
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
 		int vlan_members;
 
@@ -907,6 +951,7 @@ void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti, int port)
 
 		cpsw_ale_write(ale, idx, ale_entry);
 	}
+	spin_unlock_bh(&ale->lock);
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_set_allmulti);
 
@@ -1540,6 +1585,7 @@ struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params)
 	ale = devm_kzalloc_obj(params->dev, *ale);
 	if (!ale)
 		return ERR_PTR(-ENOMEM);
+	spin_lock_init(&ale->lock);
 	ale->regmap = devm_regmap_init_mmio(params->dev, params->ale_regs,
 					    &ale_regmap_cfg);
 	if (IS_ERR(ale->regmap)) {
@@ -1641,10 +1687,12 @@ void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data)
 {
 	int i;
 
+	spin_lock_bh(&ale->lock);
 	for (i = 0; i < ale->params.ale_entries; i++) {
 		cpsw_ale_read(ale, i, data);
 		data += ALE_ENTRY_WORDS;
 	}
+	spin_unlock_bh(&ale->lock);
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_dump);
 
@@ -1652,10 +1700,12 @@ void cpsw_ale_restore(struct cpsw_ale *ale, u32 *data)
 {
 	int i;
 
+	spin_lock_bh(&ale->lock);
 	for (i = 0; i < ale->params.ale_entries; i++) {
 		cpsw_ale_write(ale, i, data);
 		data += ALE_ENTRY_WORDS;
 	}
+	spin_unlock_bh(&ale->lock);
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_restore);
 
diff --git a/drivers/net/ethernet/ti/cpsw_ale.h b/drivers/net/ethernet/ti/cpsw_ale.h
index 87b7d1b3a34a..7276c47ede52 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.h
+++ b/drivers/net/ethernet/ti/cpsw_ale.h
@@ -96,6 +96,11 @@ struct cpsw_ale {
 	u32			vlan_field_bits;
 	unsigned long		*p0_untag_vid_mask;
 	const struct ale_entry_fld *vlan_entry_tbl;
+	/* serializes access to the ALE table (index and data registers),
+	 * the VLAN mask mux registers and the writers of p0_untag_vid_mask
+	 * (the RX path reads it without the lock)
+	 */
+	spinlock_t		lock;
 };
 
 enum cpsw_ale_control {

-- 
2.34.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net v4 3/4] net: ethernet: ti: cpsw_ale: serialize control register updates
  2026-12-03 12:14 [PATCH net v4 0/4] net: ethernet: ti: cpsw_ale: fix lost ALE entries Manuel Janocha via B4 Relay
  2026-12-03 12:14 ` [PATCH net v4 1/4] net: netcp: do not disable interrupts in the VLAN callbacks Manuel Janocha via B4 Relay
  2026-12-03 12:14 ` [PATCH net v4 2/4] net: ethernet: ti: cpsw_ale: serialize ALE table accesses Manuel Janocha via B4 Relay
@ 2026-12-03 12:14 ` Manuel Janocha via B4 Relay
  2026-12-04 12:47   ` netdev-bot+sashiko
  2026-12-03 12:14 ` [PATCH net v4 4/4] net: ethernet: ti: cpsw_ale: verify ALE table reads Manuel Janocha via B4 Relay
  3 siblings, 1 reply; 10+ messages in thread
From: Manuel Janocha via B4 Relay @ 2026-12-03 12:14 UTC (permalink / raw)
  To: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vignesh Raghavendra
  Cc: linux-omap, netdev, Kuniyuki Iwashima, Manuel Janocha, stable

From: Manuel Janocha <manuel.janocha@amperfied.com>

cpsw_ale_control_set() updates a control field with an unlocked
read-modify-write of a register that holds other fields as well. Two
concurrent updates of fields in the same register can lose each other's
change.

ALE_PORTCTL holds several fields of one port in a single word. The
am65-cpsw rx_mode path clears ALE_PORT_MACONLY_CAF and can overwrite an
ALE_PORT_STATE write from phylink mac_link_up()/mac_link_down() or from
STP, or the other way round. In the same way cpsw_ale_timer() sets
ALE_AGEOUT in ALE_CONTROL and can overwrite a concurrent update of the
bypass or flood bits in the same register.

This does not depend on the RTNL change named in the previous patch.
The ageout timer runs in softirq context and phylink mac_link_up() and
mac_link_down() are not called under RTNL either, so these updates were
never serialized against each other. The problem was not observed on
hardware, it was found by review while adding the lock for the table
accesses.

Take the ALE lock around the read-modify-write in
cpsw_ale_control_set(). The lock is only taken with spin_lock_bh() and
does not nest with the table functions, none of which calls
cpsw_ale_control_set() with the lock held. All callers run in process
or softirq context with interrupts enabled. cpsw_ale_control_get() stays
unlocked, as it is a single read. The policer index registers are
separate and left alone.

Testing: compile-tested only (arm64 and arm, W=1). The race was not
reproduced.

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")
Cc: stable@vger.kernel.org
Signed-off-by: Manuel Janocha <manuel.janocha@amperfied.com>
---
 drivers/net/ethernet/ti/cpsw_ale.c | 2 ++
 drivers/net/ethernet/ti/cpsw_ale.h | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
index dc550142ed82..69861d451ce4 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.c
+++ b/drivers/net/ethernet/ti/cpsw_ale.c
@@ -1205,9 +1205,11 @@ int cpsw_ale_control_set(struct cpsw_ale *ale, int port, int control,
 	offset = info->offset + (port * info->port_offset);
 	shift  = info->shift  + (port * info->port_shift);
 
+	spin_lock_bh(&ale->lock);
 	tmp = readl_relaxed(ale->params.ale_regs + offset);
 	tmp = (tmp & ~(mask << shift)) | (value << shift);
 	writel_relaxed(tmp, ale->params.ale_regs + offset);
+	spin_unlock_bh(&ale->lock);
 
 	return 0;
 }
diff --git a/drivers/net/ethernet/ti/cpsw_ale.h b/drivers/net/ethernet/ti/cpsw_ale.h
index 7276c47ede52..28c1fa8e38a3 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.h
+++ b/drivers/net/ethernet/ti/cpsw_ale.h
@@ -97,8 +97,9 @@ struct cpsw_ale {
 	unsigned long		*p0_untag_vid_mask;
 	const struct ale_entry_fld *vlan_entry_tbl;
 	/* serializes access to the ALE table (index and data registers),
-	 * the VLAN mask mux registers and the writers of p0_untag_vid_mask
-	 * (the RX path reads it without the lock)
+	 * the VLAN mask mux registers, the writers of p0_untag_vid_mask (the
+	 * RX path reads it without the lock) and the control registers
+	 * written by cpsw_ale_control_set()
 	 */
 	spinlock_t		lock;
 };

-- 
2.34.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net v4 4/4] net: ethernet: ti: cpsw_ale: verify ALE table reads
  2026-12-03 12:14 [PATCH net v4 0/4] net: ethernet: ti: cpsw_ale: fix lost ALE entries Manuel Janocha via B4 Relay
                   ` (2 preceding siblings ...)
  2026-12-03 12:14 ` [PATCH net v4 3/4] net: ethernet: ti: cpsw_ale: serialize control register updates Manuel Janocha via B4 Relay
@ 2026-12-03 12:14 ` Manuel Janocha via B4 Relay
  2026-12-04 12:47   ` netdev-bot+sashiko
  3 siblings, 1 reply; 10+ messages in thread
From: Manuel Janocha via B4 Relay @ 2026-12-03 12:14 UTC (permalink / raw)
  To: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Vignesh Raghavendra
  Cc: linux-omap, netdev, Kuniyuki Iwashima, Manuel Janocha

From: Manuel Janocha <manuel.janocha@amperfied.com>

On the AM64 CPSW3G ALE (am64-cpswxg, as used on AM62x/AM625) 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 ("j721e-cpswxg") as EXT_EP-12856, unresolved, with the workaround
to trigger the read twice. The evidence in this patch is only for the
am64-cpswxg ALE on AM625.

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. Add the
feature flag CPSW_ALE_F_TBL_READ_VERIFY and set it for am64-cpswxg.
am65-cpsw-nuss selects that ALE not only for AM64 and AM62x but also for
the J7200, J721E, J784S4 and J722S CPSWxG instances, so the flag applies
there as well. It was tested only on AM625; on the other SoCs it costs
the additional reads described below. The "j721e-cpswxg" ALE entry has
no user and is left unchanged. With the flag, read every entry twice,
each time after writing the index, and retry until both reads match.
Every table read then 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. Without the flag a read is one index write and
one read of the data words, as before.

After four unsuccessful tries warn (ratelimited) and return -EIO. The
callers leave the hardware entry alone in that case:

 - cpsw_ale_match_addr() and cpsw_ale_match_vlan() return -EIO at once.
   Skipping the entry would turn a match into "not found" and create a
   duplicate entry. The add functions return -EIO without allocating a
   free slot or writing, the delete functions return -EIO instead of
   -ENOENT.
 - The add, delete and modify functions that read a matched entry
   return -EIO if that read fails.
 - cpsw_ale_match_free() and cpsw_ale_find_ageable() skip the
   unreadable index.
 - cpsw_ale_flush_multicast(), cpsw_ale_set_unreg_mcast() and
   cpsw_ale_set_allmulti() skip the unreadable index and do not write
   it back.
 - cpsw_ale_dump() dumps all entries and returns -EIO if one of them
   could not be read. am65_cpsw_nuss_suspend() then fails the suspend
   before anything is stopped, so cpsw_ale_restore() never writes an
   unverified entry back on resume. The ethtool register dumps ignore
   the return value.

The check has a limit: two reads that latch the same wrong value are not
detected. In testing the two reads of a failing pair differed. The
give-up path was not seen on hardware.

Testing: AM625 board (PHYTEC phyCORE-AM62x, two CPSW ports in dual
EMAC mode with VLAN interfaces), reproducer as in the earlier
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 lock 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.

Those runs used v2 of this patch (verification for all variants, no
error return). v3 was run with the whole series on net v7.4-rc3: 60 runs
passed (about 309000 multicast joins and 1196 VLAN add/delete cycles in
total), lockdep stayed silent and the give-up warning did not appear. v4
only adds the error return of cpsw_ale_dump() and its check in the
suspend path, which is compile-tested only.

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

Fixes: 1dd3841033b3 ("net: ti: cpsw_ale: add driver data for AM64 CPSW3g")
Signed-off-by: Manuel Janocha <manuel.janocha@amperfied.com>
---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c |   5 +-
 drivers/net/ethernet/ti/cpsw_ale.c       | 127 ++++++++++++++++++++++++-------
 drivers/net/ethernet/ti/cpsw_ale.h       |   2 +-
 3 files changed, 104 insertions(+), 30 deletions(-)

diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
index 0ad614582244..9c969f5af1b6 100644
--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
@@ -3723,7 +3723,10 @@ static int am65_cpsw_nuss_suspend(struct device *dev)
 	struct net_device *ndev;
 	int i, ret;
 
-	cpsw_ale_dump(common->ale, common->ale_context);
+	ret = cpsw_ale_dump(common->ale, common->ale_context);
+	if (ret)
+		return ret;
+
 	host_p->vid_context = readl(host_p->port_base + AM65_CPSW_PORT_VLAN_REG_OFFSET);
 	for (i = 0; i < common->port_num; i++) {
 		port = &common->ports[i];
diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
index 69861d451ce4..9d0d9fdb716c 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.c
+++ b/drivers/net/ethernet/ti/cpsw_ale.c
@@ -81,6 +81,7 @@ struct ale_entry_fld {
 enum {
 	CPSW_ALE_F_STATUS_REG = BIT(0), /* Status register present */
 	CPSW_ALE_F_HW_AUTOAGING = BIT(1), /* HW auto aging */
+	CPSW_ALE_F_TBL_READ_VERIFY = BIT(2), /* Table reads must be verified */
 
 	CPSW_ALE_F_COUNT
 };
@@ -339,19 +340,50 @@ 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);
+}
 
-	return idx;
+/* Returns idx, or -EIO if the entry could not be read reliably */
+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);
+
+	if (!(ale->features & CPSW_ALE_F_TBL_READ_VERIFY)) {
+		cpsw_ale_read_entry(ale, idx, ale_entry);
+		return idx;
+	}
+
+	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 -EIO;
 }
 
 static int cpsw_ale_write(struct cpsw_ale *ale, int idx, u32 *ale_entry)
@@ -378,7 +410,8 @@ static int cpsw_ale_match_addr(struct cpsw_ale *ale, const u8 *addr, u16 vid)
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
 		u8 entry_addr[6];
 
-		cpsw_ale_read(ale, idx, ale_entry);
+		if (cpsw_ale_read(ale, idx, ale_entry) < 0)
+			return -EIO;
 		type = cpsw_ale_get_entry_type(ale_entry);
 		if (type != ALE_TYPE_ADDR && type != ALE_TYPE_VLAN_ADDR)
 			continue;
@@ -397,7 +430,8 @@ static int cpsw_ale_match_vlan(struct cpsw_ale *ale, u16 vid)
 	int type, idx;
 
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
-		cpsw_ale_read(ale, idx, ale_entry);
+		if (cpsw_ale_read(ale, idx, ale_entry) < 0)
+			return -EIO;
 		type = cpsw_ale_get_entry_type(ale_entry);
 		if (type != ALE_TYPE_VLAN)
 			continue;
@@ -413,7 +447,8 @@ static int cpsw_ale_match_free(struct cpsw_ale *ale)
 	int type, idx;
 
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
-		cpsw_ale_read(ale, idx, ale_entry);
+		if (cpsw_ale_read(ale, idx, ale_entry) < 0)
+			continue;
 		type = cpsw_ale_get_entry_type(ale_entry);
 		if (type == ALE_TYPE_FREE)
 			return idx;
@@ -427,7 +462,8 @@ static int cpsw_ale_find_ageable(struct cpsw_ale *ale)
 	int type, idx;
 
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
-		cpsw_ale_read(ale, idx, ale_entry);
+		if (cpsw_ale_read(ale, idx, ale_entry) < 0)
+			continue;
 		type = cpsw_ale_get_entry_type(ale_entry);
 		if (type != ALE_TYPE_ADDR && type != ALE_TYPE_VLAN_ADDR)
 			continue;
@@ -466,7 +502,8 @@ int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid)
 
 	spin_lock_bh(&ale->lock);
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
-		cpsw_ale_read(ale, idx, ale_entry);
+		if (cpsw_ale_read(ale, idx, ale_entry) < 0)
+			continue;
 		ret = cpsw_ale_get_entry_type(ale_entry);
 		if (ret != ALE_TYPE_ADDR && ret != ALE_TYPE_VLAN_ADDR)
 			continue;
@@ -524,6 +561,10 @@ int cpsw_ale_add_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
 
 	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
+	if (idx == -EIO) {
+		spin_unlock_bh(&ale->lock);
+		return -EIO;
+	}
 	if (idx < 0)
 		idx = cpsw_ale_match_free(ale);
 	if (idx < 0)
@@ -549,7 +590,7 @@ int cpsw_ale_del_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
 	idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
 	if (idx < 0) {
 		spin_unlock_bh(&ale->lock);
-		return -ENOENT;
+		return idx;
 	}
 
 	cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
@@ -567,8 +608,14 @@ int cpsw_ale_add_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
 
 	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
-	if (idx >= 0)
-		cpsw_ale_read(ale, idx, ale_entry);
+	if (idx == -EIO) {
+		spin_unlock_bh(&ale->lock);
+		return -EIO;
+	}
+	if (idx >= 0 && cpsw_ale_read(ale, idx, ale_entry) < 0) {
+		spin_unlock_bh(&ale->lock);
+		return -EIO;
+	}
 
 	cpsw_ale_set_vlan_entry_type(ale_entry, flags, vid);
 
@@ -608,10 +655,13 @@ int cpsw_ale_del_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
 	idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
 	if (idx < 0) {
 		spin_unlock_bh(&ale->lock);
-		return -ENOENT;
+		return idx;
 	}
 
-	cpsw_ale_read(ale, idx, ale_entry);
+	if (cpsw_ale_read(ale, idx, ale_entry) < 0) {
+		spin_unlock_bh(&ale->lock);
+		return -EIO;
+	}
 
 	if (port_mask) {
 		mcast_members = cpsw_ale_get_port_mask(ale_entry,
@@ -667,8 +717,10 @@ static int __cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port_mask,
 	int idx;
 
 	idx = cpsw_ale_match_vlan(ale, vid);
-	if (idx >= 0)
-		cpsw_ale_read(ale, idx, ale_entry);
+	if (idx == -EIO)
+		return -EIO;
+	if (idx >= 0 && cpsw_ale_read(ale, idx, ale_entry) < 0)
+		return -EIO;
 
 	cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_VLAN);
 	cpsw_ale_set_vlan_id(ale_entry, vid);
@@ -763,10 +815,13 @@ int cpsw_ale_vlan_del_modify(struct cpsw_ale *ale, u16 vid, int port_mask)
 	idx = cpsw_ale_match_vlan(ale, vid);
 	if (idx < 0) {
 		spin_unlock_bh(&ale->lock);
-		return -ENOENT;
+		return idx;
 	}
 
-	cpsw_ale_read(ale, idx, ale_entry);
+	if (cpsw_ale_read(ale, idx, ale_entry) < 0) {
+		spin_unlock_bh(&ale->lock);
+		return -EIO;
+	}
 
 	cpsw_ale_vlan_del_modify_int(ale, ale_entry, vid, port_mask);
 	cpsw_ale_write(ale, idx, ale_entry);
@@ -785,10 +840,13 @@ int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port_mask)
 	idx = cpsw_ale_match_vlan(ale, vid);
 	if (idx < 0) {
 		spin_unlock_bh(&ale->lock);
-		return -ENOENT;
+		return idx;
 	}
 
-	cpsw_ale_read(ale, idx, ale_entry);
+	if (cpsw_ale_read(ale, idx, ale_entry) < 0) {
+		spin_unlock_bh(&ale->lock);
+		return -EIO;
+	}
 
 	/* if !port_mask - force remove VLAN (legacy).
 	 * Check if there are other VLAN members ports
@@ -825,8 +883,14 @@ int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask,
 
 	spin_lock_bh(&ale->lock);
 	idx = cpsw_ale_match_vlan(ale, vid);
-	if (idx >= 0)
-		cpsw_ale_read(ale, idx, ale_entry);
+	if (idx == -EIO) {
+		spin_unlock_bh(&ale->lock);
+		return -EIO;
+	}
+	if (idx >= 0 && cpsw_ale_read(ale, idx, ale_entry) < 0) {
+		spin_unlock_bh(&ale->lock);
+		return -EIO;
+	}
 
 	vlan_members = cpsw_ale_vlan_get_fld(ale, ale_entry,
 					     ALE_ENT_VID_MEMBER_LIST);
@@ -866,7 +930,8 @@ void cpsw_ale_set_unreg_mcast(struct cpsw_ale *ale, int unreg_mcast_mask,
 
 	spin_lock_bh(&ale->lock);
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
-		cpsw_ale_read(ale, idx, ale_entry);
+		if (cpsw_ale_read(ale, idx, ale_entry) < 0)
+			continue;
 		type = cpsw_ale_get_entry_type(ale_entry);
 		if (type != ALE_TYPE_VLAN)
 			continue;
@@ -932,7 +997,8 @@ void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti, int port)
 	for (idx = 0; idx < ale->params.ale_entries; idx++) {
 		int vlan_members;
 
-		cpsw_ale_read(ale, idx, ale_entry);
+		if (cpsw_ale_read(ale, idx, ale_entry) < 0)
+			continue;
 		type = cpsw_ale_get_entry_type(ale_entry);
 		if (type != ALE_TYPE_VLAN)
 			continue;
@@ -1518,7 +1584,8 @@ static const struct cpsw_ale_dev_id cpsw_ale_id_match[] = {
 	},
 	{
 		.dev_id = "am64-cpswxg",
-		.features = CPSW_ALE_F_STATUS_REG | CPSW_ALE_F_HW_AUTOAGING,
+		.features = CPSW_ALE_F_STATUS_REG | CPSW_ALE_F_HW_AUTOAGING |
+			    CPSW_ALE_F_TBL_READ_VERIFY,
 		.reg_fields = ale_fields_cpsw_nu,
 		.num_fields = ARRAY_SIZE(ale_fields_cpsw_nu),
 		.vlan_entry_tbl = vlan_entry_k3_cpswxg,
@@ -1685,16 +1752,20 @@ struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params)
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_create);
 
-void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data)
+/* Returns -EIO if an entry could not be read reliably */
+int cpsw_ale_dump(struct cpsw_ale *ale, u32 *data)
 {
-	int i;
+	int i, ret = 0;
 
 	spin_lock_bh(&ale->lock);
 	for (i = 0; i < ale->params.ale_entries; i++) {
-		cpsw_ale_read(ale, i, data);
+		if (cpsw_ale_read(ale, i, data) < 0)
+			ret = -EIO;
 		data += ALE_ENTRY_WORDS;
 	}
 	spin_unlock_bh(&ale->lock);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(cpsw_ale_dump);
 
diff --git a/drivers/net/ethernet/ti/cpsw_ale.h b/drivers/net/ethernet/ti/cpsw_ale.h
index 28c1fa8e38a3..9d66d79677e0 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.h
+++ b/drivers/net/ethernet/ti/cpsw_ale.h
@@ -186,7 +186,7 @@ int cpsw_ale_rx_ratelimit_mc(struct cpsw_ale *ale, int port, unsigned int rateli
 int cpsw_ale_control_get(struct cpsw_ale *ale, int port, int control);
 int cpsw_ale_control_set(struct cpsw_ale *ale, int port,
 			 int control, int value);
-void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data);
+int cpsw_ale_dump(struct cpsw_ale *ale, u32 *data);
 void cpsw_ale_restore(struct cpsw_ale *ale, u32 *data);
 u32 cpsw_ale_get_num_entries(struct cpsw_ale *ale);
 

-- 
2.34.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 2/4] net: ethernet: ti: cpsw_ale: serialize ALE table accesses
  2026-12-03 12:14 ` [PATCH net v4 2/4] net: ethernet: ti: cpsw_ale: serialize ALE table accesses Manuel Janocha via B4 Relay
@ 2026-12-04 12:47   ` netdev-bot+sashiko
  0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 12:47 UTC (permalink / raw)
  To: manuel.janocha
  Cc: s-vadapalli, rogerq, andrew+netdev, davem, edumazet, kuba, pabeni,
	vigneshr, linux-omap, netdev, kuniyu

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The changelog of "net: ethernet: ti: cpsw_ale: serialize ALE
  table accesses" refers to other patches by their position in the…

--

net: ethernet: ti: cpsw_ale: serialize ALE table accesses

This adds a spinlock to struct cpsw_ale and takes it with spin_lock_bh()
in all exported cpsw_ale functions that access the ALE table. Without it,
ndo_set_rx_mode() running without RTNL on one am65-cpsw/netcp port can
interleave its index and data register accesses with a VLAN or address
operation on another port. cpsw_ale_add_vlan() is split into a locked
wrapper and an unlocked __cpsw_ale_add_vlan() helper, which
cpsw_ale_vlan_add_modify() calls with the lock held.

> The lock is taken with spin_lock_bh(). ndo_set_rx_mode() already runs
> with bottom halves disabled, and no caller runs in hard interrupt
> context, so hard interrupts stay enabled while the table is scanned.
> netcp was the only caller that took the lock with interrupts disabled
> (netcp_rx_add_vid() and netcp_rx_kill_vid()); the previous patch
> changed that.

[ ... ]

> are not missing serialization: with the lock held, a table read can
> still return a wrong entry, which patch 4 handles. These numbers are
> from v1 (spin_lock_bh()) and v2 (spin_lock_irqsave()) of this patch.
> This version was run with the whole series on net v7.4-rc3: 60 runs
> of 120 seconds passed and lockdep stayed silent.

[Severity: Low]
This isn't a bug, but once this is merged, nothing in git identifies "the
previous patch" or "patch 4".

Could the changelog name these patches by subject instead? From the
series, they look like "net: netcp: do not disable interrupts in the VLAN
callbacks" and "net: ethernet: ti: cpsw_ale: verify ALE table reads".

The changelog says 2 of 19 runs on net and 1 of 29 runs on 6.18 still
lost the VID 0 entry. A stable backporter reading only this commit can't
tell which commit fixes those failures.

The netcp prerequisite does name this patch by subject and says the two
must be backported together, so the dependency is only recorded in one
direction. The "verify ALE table reads" follow-up has no Cc: stable tag.
It only has a Fixes: tag for 1dd3841033b3. Should it be tagged for stable
as well?

Also, could the v1/v2 revision history move below the --- line?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-cpsw-ale-lock-v4-0-4ecfbc4bb042%40amperfied.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 3/4] net: ethernet: ti: cpsw_ale: serialize control register updates
  2026-12-03 12:14 ` [PATCH net v4 3/4] net: ethernet: ti: cpsw_ale: serialize control register updates Manuel Janocha via B4 Relay
@ 2026-12-04 12:47   ` netdev-bot+sashiko
  2026-12-04 13:18     ` Janocha, Manuel
  0 siblings, 1 reply; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 12:47 UTC (permalink / raw)
  To: manuel.janocha
  Cc: s-vadapalli, rogerq, andrew+netdev, davem, edumazet, kuba, pabeni,
	vigneshr, linux-omap, netdev, kuniyu

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] This patch has an undeclared stable-backport dependency, and its
  Fixes tag does not match the tag on the patch it depends on.

--

net: ethernet: ti: cpsw_ale: serialize control register updates

This patch takes the ALE spinlock around the read-modify-write in
cpsw_ale_control_set(). Without it, two concurrent updates of different
fields in the same control register, such as ALE_PORTCTL or ALE_CONTROL,
can lose each other's change. It also extends the comment on the lock in
struct cpsw_ale to cover the control registers.

> diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
> index dc550142ed822..69861d451ce41 100644
> --- a/drivers/net/ethernet/ti/cpsw_ale.c
> +++ b/drivers/net/ethernet/ti/cpsw_ale.c
> @@ -1205,9 +1205,11 @@ int cpsw_ale_control_set(struct cpsw_ale *ale, int port, int control,
>  	offset = info->offset + (port * info->port_offset);
>  	shift  = info->shift  + (port * info->port_shift);
>  
> +	spin_lock_bh(&ale->lock);
>  	tmp = readl_relaxed(ale->params.ale_regs + offset);
>  	tmp = (tmp & ~(mask << shift)) | (value << shift);
>  	writel_relaxed(tmp, ale->params.ale_regs + offset);
> +	spin_unlock_bh(&ale->lock);

[Severity: Low]
Will this patch backport cleanly to the stable trees its tags select?

The baseline has neither ale->lock nor the comment that the cpsw_ale.h
hunk edits. The previous patch in the series, "net: ethernet: ti:
cpsw_ale: serialize ALE table accesses", adds both, along with the
spin_lock_init().

The two patches have different Fixes tags:

  previous patch:
    Fixes: 1767bb2d47b7 ("ipv6: mcast: Don't hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.")

  this patch:
    Fixes: db82173f23c5 ("netdev: driver: ethernet: add cpsw address lookup engine support")
    Cc: stable@vger.kernel.org

db82173f23c5 dates from 2012, so stable tooling would queue this patch
for every maintained branch. The prerequisite would only be picked for
branches that contain 1767bb2d47b7, which dates from July 2025.

Older LTS branches such as 5.10, 5.15, 6.1, 6.6 and 6.12 don't contain
1767bb2d47b7. There the cpsw_ale.h hunk wouldn't apply. If only the
cpsw_ale.c hunk were taken, the build would fail with 'struct cpsw_ale'
has no member named 'lock'.

The changelog also says:

  This does not depend on the RTNL change named in the previous patch.

That holds for the race itself. Could it lead a backporter to treat the
code change as standalone, though?

Would it help to add a stable dependency annotation, for example:

  Cc: stable@vger.kernel.org # depends on "net: ethernet: ti: cpsw_ale: serialize ALE table accesses"

Another option is to align the Fixes tags so both patches go to the same
stable branches.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-cpsw-ale-lock-v4-0-4ecfbc4bb042%40amperfied.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 4/4] net: ethernet: ti: cpsw_ale: verify ALE table reads
  2026-12-03 12:14 ` [PATCH net v4 4/4] net: ethernet: ti: cpsw_ale: verify ALE table reads Manuel Janocha via B4 Relay
@ 2026-12-04 12:47   ` netdev-bot+sashiko
  2026-12-04 13:18     ` Janocha, Manuel
  0 siblings, 1 reply; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 12:47 UTC (permalink / raw)
  To: manuel.janocha
  Cc: s-vadapalli, rogerq, andrew+netdev, davem, edumazet, kuba, pabeni,
	vigneshr, linux-omap, netdev, kuniyu

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

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

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] This patch adds a new -EIO return to the cpsw_ale add, delete
  and modify paths for the case where a verified read never stabilizes.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  am65_cpsw_nuss_probe() allocates common->ale_context with…

--

net: ethernet: ti: cpsw_ale: verify ALE table reads

The commit adds the feature flag CPSW_ALE_F_TBL_READ_VERIFY for the
am64-cpswxg ALE. With the flag set, every table read is done twice and
retried until both reads match. After four failed tries cpsw_ale_read()
returns -EIO, and the add, delete, modify and dump paths in cpsw_ale.c
now pass that -EIO back to their callers.

> diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> index 0ad6145822445..9c969f5af1b64 100644
> --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
> @@ -3723,7 +3723,10 @@ static int am65_cpsw_nuss_suspend(struct device *dev)
>  	struct net_device *ndev;
>  	int i, ret;
>  
> -	cpsw_ale_dump(common->ale, common->ale_context);
> +	ret = cpsw_ale_dump(common->ale, common->ale_context);
> +	if (ret)
> +		return ret;
> +

[Severity: High]
This is a pre-existing issue, but now that the suspend result depends
on this dump: can common->ale_context be NULL here?

am65_cpsw_nuss_probe() allocates it and does not check the result:

drivers/net/ethernet/ti/am65-cpsw-nuss.c:am65_cpsw_nuss_probe() {
    ...
	common->ale_context = devm_kzalloc(dev,
					   ale_entries * ALE_ENTRY_WORDS * sizeof(u32),
					   GFP_KERNEL);
	ret = am65_cpsw_init_cpts(common);
    ...
}

If that allocation fails, probe still completes. On the next system
suspend, this call chain writes through the NULL pointer:

am65_cpsw_nuss_suspend()->cpsw_ale_dump()->cpsw_ale_read()->cpsw_ale_read_entry()

On resume, cpsw_ale_restore(common->ale, common->ale_context) would also
read through it.

Should probe return -ENOMEM when this allocation fails?

> diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
> index 69861d451ce41..9d0d9fdb716c0 100644
> --- a/drivers/net/ethernet/ti/cpsw_ale.c
> +++ b/drivers/net/ethernet/ti/cpsw_ale.c

[ ... ]

> @@ -397,7 +430,8 @@ static int cpsw_ale_match_vlan(struct cpsw_ale *ale, u16 vid)
>  	int type, idx;
>  
>  	for (idx = 0; idx < ale->params.ale_entries; idx++) {
> -		cpsw_ale_read(ale, idx, ale_entry);
> +		if (cpsw_ale_read(ale, idx, ale_entry) < 0)
> +			return -EIO;
>  		type = cpsw_ale_get_entry_type(ale_entry);
>  		if (type != ALE_TYPE_VLAN)
>  			continue;

[ ... ]

> @@ -667,8 +717,10 @@ static int __cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port_mask,
>  	int idx;
>  
>  	idx = cpsw_ale_match_vlan(ale, vid);
> -	if (idx >= 0)
> -		cpsw_ale_read(ale, idx, ale_entry);
> +	if (idx == -EIO)
> +		return -EIO;

[Severity: Medium]
Does this -EIO reach anything that acts on it?

cpsw_ale_match_vlan() and cpsw_ale_match_addr() stop at the first
index whose read fails. That index does not have to be the entry being
looked up. When that happens, __cpsw_ale_add_vlan(), cpsw_ale_add_ucast()
and cpsw_ale_add_mcast() return before cpsw_ale_match_free() or
cpsw_ale_write() runs, so nothing is written to the table.

The am65-cpsw-nuss callers that program the entries the port needs
ignore the return value. For example, in am65_cpsw_nuss_common_open():

	cpsw_ale_add_vlan(common->ale, 0, port_mask,
			  port_mask, port_mask,
			  port_mask & ~ALE_PORT_HOST);

If this fails, no VID 0 entry exists and untagged receive is dead, but
open still returns 0. That is the symptom the commit message describes
as its motivation.

am65_cpsw_nuss_ndo_slave_set_mac_address() ignores both results. It then
commits the new MAC and returns 0:

	cpsw_ale_del_ucast(common->ale, ndev->dev_addr,
			   HOST_PORT_NUM, 0, 0);
	cpsw_ale_add_ucast(common->ale, sockaddr->sa_data,
			   HOST_PORT_NUM, ALE_SECURE, 0);

am65_cpsw_nuss_ndo_slave_set_rx_mode() flushes the port from every mcast
entry first and then ignores the result of each re-add:

	cpsw_ale_flush_multicast(common->ale, port_mask, -1);
	...
			cpsw_ale_add_mcast(common->ale, ha->addr,
					   port_mask, 0, 0, 0);

When a re-add fails, that group is gone from hardware and nothing retries
it.

am65_cpsw_init_port_emac_ale(), am65_cpsw_init_port_switch_ale() and
am65_cpsw_init_stp_ale_entry() also ignore the add_ucast/add_mcast
results for the host MAC, broadcast and STP entries.

The commit message says:

    After four unsuccessful tries warn (ratelimited) and return -EIO. The
    callers leave the hardware entry alone in that case:
    ...
       The add functions return -EIO without allocating a free slot or
       writing, the delete functions return -EIO instead of
       -ENOENT.

That is true inside cpsw_ale.c. In am65-cpsw-nuss.c, where these entries
are actually programmed, the error is dropped and the driver reports
success.

Should these callers propagate or retry on -EIO? Alternatively, should
the match functions skip the unreadable index when it cannot be the
entry being looked up?

> +	if (idx >= 0 && cpsw_ale_read(ale, idx, ale_entry) < 0)
> +		return -EIO;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-cpsw-ale-lock-v4-0-4ecfbc4bb042%40amperfied.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 3/4] net: ethernet: ti: cpsw_ale: serialize control register updates
  2026-12-04 12:47   ` netdev-bot+sashiko
@ 2026-12-04 13:18     ` Janocha, Manuel
  0 siblings, 0 replies; 10+ messages in thread
From: Janocha, Manuel @ 2026-12-04 13:18 UTC (permalink / raw)
  To: netdev-bot+sashiko@kernel.org
  Cc: s-vadapalli@ti.com, rogerq@kernel.org, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, vigneshr@ti.com, linux-omap@vger.kernel.org,
	netdev@vger.kernel.org, kuniyu@google.com

> Will this patch backport cleanly to the stable trees its tags select?

No. I will drop Cc: stable from this patch in the next revision. The
race was found by review and never seen on hardware, so it does not
need a stable backport. The Fixes tag stays.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v4 4/4] net: ethernet: ti: cpsw_ale: verify ALE table reads
  2026-12-04 12:47   ` netdev-bot+sashiko
@ 2026-12-04 13:18     ` Janocha, Manuel
  0 siblings, 0 replies; 10+ messages in thread
From: Janocha, Manuel @ 2026-12-04 13:18 UTC (permalink / raw)
  To: netdev-bot+sashiko@kernel.org
  Cc: s-vadapalli@ti.com, rogerq@kernel.org, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, vigneshr@ti.com, linux-omap@vger.kernel.org,
	netdev@vger.kernel.org, kuniyu@google.com

> Does this -EIO reach anything that acts on it?
[...]
> Should these callers propagate or retry on -EIO? Alternatively, should
> the match functions skip the unreadable index when it cannot be the
> entry being looked up?

As for v3: am65-cpsw-nuss drops the -EIO, as it drops the add and
delete results today. It only comes after four read pairs that did not
match. The hardware entry then stays as it is and a ratelimited warning
names the index. Acting on the result in the am65 callers would be a
separate driver change, not part of this fix.

Skipping the unreadable index is not safe. The match functions cannot
tell whether that index holds the entry being looked up, and if it
does, an add would allocate a second entry for the same VLAN or
address.

> This is a pre-existing issue, but now that the suspend result depends
> on this dump: can common->ale_context be NULL here?

Yes, the allocation in am65_cpsw_nuss_probe() is not checked. This does
not depend on this series, because the dump already wrote through that
pointer before it. I will send a separate fix for net.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-12-04 13:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 12:14 [PATCH net v4 0/4] net: ethernet: ti: cpsw_ale: fix lost ALE entries Manuel Janocha via B4 Relay
2026-12-03 12:14 ` [PATCH net v4 1/4] net: netcp: do not disable interrupts in the VLAN callbacks Manuel Janocha via B4 Relay
2026-12-03 12:14 ` [PATCH net v4 2/4] net: ethernet: ti: cpsw_ale: serialize ALE table accesses Manuel Janocha via B4 Relay
2026-12-04 12:47   ` netdev-bot+sashiko
2026-12-03 12:14 ` [PATCH net v4 3/4] net: ethernet: ti: cpsw_ale: serialize control register updates Manuel Janocha via B4 Relay
2026-12-04 12:47   ` netdev-bot+sashiko
2026-12-04 13:18     ` Janocha, Manuel
2026-12-03 12:14 ` [PATCH net v4 4/4] net: ethernet: ti: cpsw_ale: verify ALE table reads Manuel Janocha via B4 Relay
2026-12-04 12:47   ` netdev-bot+sashiko
2026-12-04 13:18     ` Janocha, Manuel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox