From: netdev-bot+sashiko@kernel.org
To: manuel.janocha@amperfied.com
Cc: s-vadapalli@ti.com, rogerq@kernel.org, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, linux-omap@vger.kernel.org,
netdev@vger.kernel.org, kuniyu@google.com,
stable@vger.kernel.org
Subject: Re: [PATCH net] net: ethernet: ti: cpsw_ale: serialize ALE table accesses
Date: Sat, 28 Nov 2026 12:17:56 +0000 [thread overview]
Message-ID: <179586827652.3135.4662043469697713881@kernel.org> (raw)
In-Reply-To: <20261127-cpsw-ale-lock-v1-1-a72772d9a5ae@amperfied.com>
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
prev parent reply other threads:[~2026-11-28 12:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179586827652.3135.4662043469697713881@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-omap@vger.kernel.org \
--cc=manuel.janocha@amperfied.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rogerq@kernel.org \
--cc=s-vadapalli@ti.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox