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 v2 1/2] net: ethernet: ti: cpsw_ale: serialize ALE table accesses
Date: Tue, 01 Dec 2026 20:35:53 +0000 [thread overview]
Message-ID: <179615735313.3146.5568019864174331553@kernel.org> (raw)
In-Reply-To: <20261130-cpsw-ale-lock-v2-1-c7a59d2178bb@amperfied.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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).
- [Medium] The new spinlock is always taken with spin_lock_irqsave() and
held across one or more full scans of the ALE table.
- [Low] The patch fixes two races but the Fixes: tag covers only one.
- [Low] The new field comment in struct cpsw_ale (cpsw_ale.h:99, '/*
serializes access to the ALE table registers */') describes less than…
--
net: ethernet: ti: cpsw_ale: serialize ALE table accesses
This patch adds a spinlock to struct cpsw_ale. The lock is taken with
spin_lock_irqsave() in every exported function that touches the ALE
table, and around the read-modify-write in cpsw_ale_control_set(). The
locked body of cpsw_ale_add_vlan() moves into a new
__cpsw_ale_add_vlan() helper, so that cpsw_ale_vlan_add_modify() can
call it with the lock already held.
> diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
> index 9304405c9581a..8434803335d5b 100644
> --- a/drivers/net/ethernet/ti/cpsw_ale.c
> +++ b/drivers/net/ethernet/ti/cpsw_ale.c
> @@ -462,8 +462,10 @@ static void cpsw_ale_flush_mcast(struct cpsw_ale *ale, u32 *ale_entry,
> int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid)
> {
> u32 ale_entry[ALE_ENTRY_WORDS];
> + unsigned long irq_flags;
> int ret, idx;
>
> + spin_lock_irqsave(&ale->lock, irq_flags);
> for (idx = 0; idx < ale->params.ale_entries; idx++) {
> cpsw_ale_read(ale, idx, ale_entry);
> ret = cpsw_ale_get_entry_type(ale_entry);
[Severity: Medium]
On non-PREEMPT_RT kernels, does taking ale->lock with spin_lock_irqsave()
here keep local hard interrupts disabled for a whole ALE table walk?
Before this patch the am65-cpsw rx_mode path ran only under
netif_addr_lock_bh(), so hard IRQs stayed enabled. With this patch each
call of am65_cpsw_nuss_ndo_slave_set_rx_mode() does:
cpsw_ale_set_allmulti() full table scan, IRQs off
cpsw_ale_flush_multicast() full table read and write-back, IRQs off
cpsw_ale_add_mcast() once per mc address, up to three scans
(match_addr, match_free, find_ageable)
in one IRQ-off section
An unprivileged user can reach this path, and it does not take RTNL:
setsockopt(IPV6_ADD_MEMBERSHIP)
igmp6_group_added()
dev_mc_add()
am65_cpsw_nuss_ndo_slave_set_rx_mode()
cpsw_ale_vlan_add_modify() first calls cpsw_ale_match_vlan(). It then
calls __cpsw_ale_add_vlan(), which runs match_vlan, match_free and
find_ageable again, all in the same IRQ-off section. The changelog
measured up to 1.1 ms there on the 512-entry AM625 table.
cpsw_ale_dump() and cpsw_ale_restore() also walk the whole table with
IRQs off. They are called from ethtool get_regs and from
suspend/resume.
NetCP NU ALEs read their table size from ALE_STATUS in multiples of
1024 entries, so the scans there can take longer still.
The later commit "net: ethernet: ti: cpsw_ale: verify ALE table reads"
makes each cpsw_ale_read() at least two index writes and six data
reads. By the end of the series each of these IRQ-off windows is at
least twice as long.
The irqsave variant seems to be needed only for netcp_rx_add_vid() and
netcp_rx_kill_vid(), which already hold netcp->lock with IRQs off.
The changelog says:
"That is VLAN configuration, not the data path"
and:
"just not preemptible by the other port"
It does not say that hard IRQs are now off for the whole scan. Is this
interrupt latency intended? If so, could the changelog say so? If not,
could the lock be taken so that the am65-cpsw paths avoid long hard
IRQ-off windows?
[ ... ]
> @@ -1160,9 +1217,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_irqsave(&ale->lock, irq_flags);
> tmp = readl_relaxed(ale->params.ale_regs + offset);
> tmp = (tmp & ~(mask << shift)) | (value << shift);
> writel_relaxed(tmp, ale->params.ale_regs + offset);
> + spin_unlock_irqrestore(&ale->lock, irq_flags);
>
> return 0;
> }
[Severity: Low]
The Fixes: tag points to 1767bb2d47b7 ("ipv6: mcast: Don't hold RTNL
for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP."). That commit explains
the ALE table race. Does the lost-update race in cpsw_ale_control_set()
depend on it?
cpsw_ale_timer() runs in timer softirq and calls:
cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
RTNL does not exclude this timer. cpsw_ale_aging_start() arms it for
every ALE without CPSW_ALE_F_HW_AUTOAGING, including legacy cpsw and
cpsw_new. The changelog says those two drivers "are not affected in
practice".
The phylink resolve work also does not run under RTNL. It calls
am65_cpsw_nuss_mac_link_up() and am65_cpsw_nuss_mac_link_down(), which
set ALE_PORT_STATE with a read-modify-write of the same ALE_PORTCTL word
that am65_cpsw_slave_set_promisc() changes for ALE_PORT_MACONLY_CAF.
Stable trees without 1767bb2d47b7 (6.12, 6.6, 6.1 and so on) would not
get this part of the fix. Could the cpsw_ale_control_set() change go
into a separate patch with its own Fixes: tag? Alternatively, the
changelog could say that this part fixes an older bug.
[ ... ]
> diff --git a/drivers/net/ethernet/ti/cpsw_ale.h b/drivers/net/ethernet/ti/cpsw_ale.h
> index 87b7d1b3a34a9..8e47261161fea 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;
> };
[Severity: Low]
This isn't a bug, but the comment describes less than the lock actually
protects. Besides the table registers, the code also relies on
ale->lock for:
- the read-modify-write of non-table registers in
cpsw_ale_control_set() (ALE_CONTROL, ALE_UNKNOWNVLAN*,
ALE_PORTCTL(n), AM65_CPSW_ALE_THREAD_DEF_REG)
- the read-modify-write of ALE_VLAN_MASK_MUX(idx) in
cpsw_ale_vlan_set_unreg_mcast_idx(), and the writes in
cpsw_ale_set_vlan_mcast()
- the non-atomic bitmap_set() and bitmap_clear() on
ale->p0_untag_vid_mask in cpsw_ale_set_vlan_untag()
The later commit "net: ethernet: ti: cpsw_ale: verify ALE table reads"
leaves the comment unchanged. Could the comment be extended to cover
these as well?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-cpsw-ale-lock-v2-0-c7a59d2178bb%40amperfied.com
prev parent reply other threads:[~2026-12-01 20:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 20:34 [PATCH net v2 0/2] net: ethernet: ti: cpsw_ale: fix lost ALE entries Manuel Janocha via B4 Relay
2026-11-30 20:34 ` [PATCH net v2 1/2] net: ethernet: ti: cpsw_ale: serialize ALE table accesses Manuel Janocha via B4 Relay
2026-12-01 20:35 ` 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=179615735313.3146.5568019864174331553@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