* [PATCH net] net: ethernet: ti: cpsw_ale: serialize ALE table accesses
@ 2026-11-27 11:17 Manuel Janocha via B4 Relay
2026-11-28 12:17 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Manuel Janocha via B4 Relay @ 2026-11-27 11:17 UTC (permalink / raw)
To: Siddharth Vadapalli, Roger Quadros, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: linux-omap, netdev, Kuniyuki Iwashima, stable, Manuel Janocha
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() runs
under netif_addr_lock_bh() of one port only and never took 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. spin_lock_bh() is used because
ndo_set_rx_mode() runs with bottom halves disabled
(netif_addr_lock_bh()) and the dev_mc_add()/dev_uc_add() family is not
restricted to process context, while the other callers run in process
context (RTNL, workqueue, ethtool, system suspend). None of them runs
in hard interrupt context, and a sleeping lock cannot be used because
of the atomic callers. The register accesses under the lock are plain
readl()/writel(); 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 covers the table (index and data registers) only. The
read-modify-write of the ALE control registers and the policer index
registers are separate and left alone.
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 23000 joins, 88 VLAN add/delete cycles of three VLANs): eth0
and the VLANs kept receiving and lockdep stayed silent. The same
result was seen earlier with a backport to the TI vendor kernel
6.18.59. The legacy cpsw, cpsw_new and netcp users of the ALE were
only compile-tested (arm64, 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 | 2 ++
2 files changed, 62 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..8e47261161fe 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.h
+++ b/drivers/net/ethernet/ti/cpsw_ale.h
@@ -96,6 +96,8 @@ 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 registers */
+ spinlock_t lock;
};
enum cpsw_ale_control {
---
base-commit: ef3e21c61baa74e39a49b75318bd4541562ec43f
change-id: 20261126-cpsw-ale-lock-cc05d5bea7a0
Best regards,
--
Manuel Janocha <manuel.janocha@amperfied.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: ethernet: ti: cpsw_ale: serialize ALE table accesses
2026-11-27 11:17 [PATCH net] net: ethernet: ti: cpsw_ale: serialize ALE table accesses Manuel Janocha via B4 Relay
@ 2026-11-28 12:17 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 12:17 UTC (permalink / raw)
To: manuel.janocha
Cc: s-vadapalli, rogerq, andrew+netdev, davem, edumazet, kuba, pabeni,
linux-omap, netdev, kuniyu, stable
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] netcp calls the ALE VLAN helpers with interrupts disabled, but
those helpers now use spin_lock_bh()/spin_unlock_bh().
- [Low] The changelog says that ndo_set_rx_mode() 'runs under
netif_addr_lock_bh() of one port only and never took RTNL', and…
- [Low] The new ale->lock serializes table sequences that use
writel_relaxed()/readl_relaxed() in cpsw_ale_read() and…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
cpsw_ale_control_set() (drivers/net/ethernet/ti/cpsw_ale.c) still does…
--
net: ethernet: ti: cpsw_ale: serialize ALE table accesses
This commit adds a spinlock to struct cpsw_ale and takes it with
spin_lock_bh() in all exported functions that access the ALE table. The
table is reached through the shared index and data registers. The goal is
to stop table corruption seen on am65-cpsw when ndo_set_rx_mode() runs
without RTNL after IPv6 multicast joins stopped holding RTNL, and
cpsw_ale_add_vlan() is split into a locked wrapper and an unlocked
__cpsw_ale_add_vlan() helper.
> 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() runs
> under netif_addr_lock_bh() of one port only and never took RTNL. Since
[Severity: Low]
Is this accurate for all ALE users?
For the legacy cpsw and cpsw_new drivers, commit 0b8c878d1173 ("net: cpsw:
Execute ndo_set_rx_mode callback in a work queue") already addressed the
same Fixes: commit, and it was also tagged for stable. There,
cpsw_ndo_set_rx_mode() only schedules work, and the work takes RTNL before
it touches the ALE:
drivers/net/ethernet/ti/cpsw.c:cpsw_ndo_set_rx_mode_work() {
rtnl_lock();
if (!netif_running(ndev))
goto unlock_rtnl;
netif_addr_lock_bh(ndev);
...
}
cpsw_new.c uses the same pattern. So in those two drivers, the rx_mode ALE
accesses are already serialized against VLAN and address operations by
RTNL.
The users that still reach the ALE table from rx_mode without RTNL seem to
be am65-cpsw and netcp. am65-cpsw does it through
am65_cpsw_nuss_ndo_slave_set_rx_mode(), which calls
cpsw_ale_set_allmulti(), cpsw_ale_flush_multicast() and
cpsw_ale_add_mcast() directly.
Could the changelog name the affected drivers and mention the earlier cpsw
fix? Could it also explain why a library-level lock was chosen over the
RTNL work approach used there?
> context (RTNL, workqueue, ethtool, system suspend). None of them runs
> in hard interrupt context, and a sleeping lock cannot be used because
> of the atomic callers. The register accesses under the lock are plain
> readl()/writel(); the regmap of the ALE is only used for the version,
[Severity: Low]
Is the "plain readl()/writel()" description correct? cpsw_ale_read() and
cpsw_ale_write() use the relaxed accessors:
drivers/net/ethernet/ti/cpsw_ale.c:cpsw_ale_write() {
...
writel_relaxed(idx | ALE_TABLE_WRITE, ale->params.ale_regs +
ALE_TABLE_CONTROL);
...
}
Documentation/memory-barriers.txt says readX_relaxed()/writeX_relaxed() do
not guarantee ordering with respect to locking.
The fix relies on one CPU's final ALE_TABLE_CONTROL write, or its index
write plus data reads, reaching the ALE before the next lock holder's
accesses. With relaxed accessors, that ordering comes from architecture
behaviour and not from the documented contract. On ARCH_HAS_MMIOWB
architectures, only the non-relaxed accessors call mmiowb_set_pending().
Outside COMPILE_TEST this driver only builds for ARM/ARM64, and the arm64
unlock probably orders these Device stores in practice. The hardware test
also passed. Should the changelog be corrected? Alternatively, should these
helpers use writel()/readl(), or at least use writel() for the final
ALE_TABLE_CONTROL write?
> The lock covers the table (index and data registers) only. The
> read-modify-write of the ALE control registers and the policer index
> registers are separate and left alone.
[Severity: High]
This isn't a bug introduced by this patch, but can the unlocked
read-modify-write in cpsw_ale_control_set() lose port state updates in a
similar way?
drivers/net/ethernet/ti/cpsw_ale.c:cpsw_ale_control_set() {
...
tmp = readl_relaxed(ale->params.ale_regs + offset);
tmp = (tmp & ~(mask << shift)) | (value << shift);
writel_relaxed(tmp, ale->params.ale_regs + offset);
...
}
ALE_PORT_STATE and ALE_PORT_MACONLY_CAF are both in ALE_PORTCTL[port]. On
am65-cpsw, the rx_mode path runs without RTNL and rewrites that register on
every call:
am65_cpsw_nuss_ndo_slave_set_rx_mode()
am65_cpsw_slave_set_promisc()
cpsw_ale_control_set(common->ale, port->port_id,
ALE_PORT_MACONLY_CAF, 0);
Other paths write ALE_PORT_STATE in the same word:
am65_cpsw_nuss_mac_link_up() and am65_cpsw_nuss_mac_link_down() from the
phylink worker, and am65_cpsw_port_stp_state_set() under RTNL.
A possible interleaving:
CPU0 (rx_mode) CPU1 (mac_link_up)
readl(PORTCTL) -> STATE=DISABLE
readl(PORTCTL)
writel(STATE=FORWARD)
writel(STATE=DISABLE | CAF=0)
This would leave the port disabled in the ALE while the driver thinks it is
forwarding. All ingress would then be dropped until the next link or STP
transition. That is the same symptom this patch fixes.
ALE_CONTROL looks similar. cpsw_ale_timer() sets the AGEOUT bit from
softirq, while the promisc paths modify BYPASS and P0_UNI_FLOOD in the same
register.
An unprivileged IPv6 multicast join can now trigger rx_mode without RTNL.
Would it make sense to serialize cpsw_ale_control_set() as well?
> diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
> index 9304405c9581a..dc550142ed822 100644
> --- a/drivers/net/ethernet/ti/cpsw_ale.c
> +++ b/drivers/net/ethernet/ti/cpsw_ale.c
[ ... ]
> @@ -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);
[Severity: High]
Can this spin_unlock_bh() run with hard interrupts disabled? netcp calls
the ALE VLAN helpers from inside an irqsave section:
drivers/net/ethernet/ti/netcp_core.c:netcp_rx_kill_vid() {
...
spin_lock_irqsave(&netcp->lock, flags);
for_each_module(netcp, intf_modpriv) {
module = intf_modpriv->netcp_module;
if (module->del_vid) {
err = module->del_vid(intf_modpriv->module_priv, vid);
...
}
netcp_rx_add_vid() does the same for module->add_vid(). For both the gbe
and xgbe modules, the call chains are:
gbe_add_vid() -> cpsw_ale_add_vlan()
gbe_del_vid() -> cpsw_ale_del_vlan()
Both ALE functions now take ale->lock with spin_lock_bh(). That includes
the -ENOENT early return in cpsw_ale_del_vlan().
On non-RT kernels, __local_bh_enable_ip() then triggers
lockdep_assert_irqs_enabled(). With CONFIG_TRACE_IRQFLAGS it also wraps
do_softirq() in local_irq_disable() ... local_irq_enable(). So hard IRQs
get re-enabled and pending softirqs run while netcp->lock is still held.
That allows re-entry into netcp code that takes the same lock, such as
netcp_set_rx_mode().
This looks easy to reach. netcp sets NETIF_F_HW_VLAN_CTAG_FILTER, so with
8021q loaded, every NETDEV_DOWN goes through:
vlan_vid0_del()
vlan_vid_del(dev, htons(ETH_P_8021Q), 0)
netcp_rx_kill_vid()
gbe_del_vid()
cpsw_ale_del_vlan()
netcp_rx_kill_vid() does not filter out vid 0. Creating any VLAN on a
netcp interface likewise reaches cpsw_ale_add_vlan() under the irqsave
lock.
The changelog says the other callers run in process context and that netcp
was only compile-tested. It doesn't seem to cover this IRQs-disabled
caller.
Would spin_lock_irqsave() work for ale->lock here? The other option would
be for netcp to stop calling into the ALE while holding netcp->lock.
> +
> + return ret;
> +}
> EXPORT_SYMBOL_GPL(cpsw_ale_add_vlan);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-cpsw-ale-lock-v1-1-a72772d9a5ae%40amperfied.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-28 12:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 11:17 [PATCH net] net: ethernet: ti: cpsw_ale: serialize ALE table accesses Manuel Janocha via B4 Relay
2026-11-28 12:17 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox