From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796157354; b=GwgmSWlLTuK66LpzOaF4vBpKIbov4YzKfGu/8OE1NVV8e4ZypxrXJkGRoYcl8azMmgyd LqoXoEOKvbqatBJYjdqEtsiPuSQPmbv6TRM/QNTrcIvrIBMkLfvOsi4yP53V0crN/1fC/ KZuYD9qEuxGkuZty+I6raZCWTARis5vHqR3EKyUuA2nl1B3nCvrOKB57ua+vbtOMyDe7S m9kQGQTUtxBtyoeoulx1DoMRW1tArIEprBpkr01tAru74KtHYQ2fx1/zGLJHHrHDnk79y ENPl3oqw7w1rH48gi2hRGGsqVjLIDic5eK9RodJ9Y6iOhviY9HeRqKgM2H7lNfxGR7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796157354; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=pB5o9z4rMCxOyz+mWP7w9fU4YVlM7A1ZdAWOcwWXxMo=; b=IIOKsC/c5K1Ii7g9ECbk8knP5adq0QzBrrRCzTp9Vux543dvpConAJzQwfzH5svhzrp2 RoXiJFT7Xl6+HWNsUhIW1+7HhYtwNjkTNcTZgz5V+AjTrW5fQK27V0MH5dZk3kTqMaFGr YlzzwVLBFKNtJxm8m/ovuyKuQPe37V/OHbQKmZZkSiCqeAz84KIqo686Dzlxb3jdl+dgF gUBOAr5tL7lXQuOJ5qjoSVkQox4d+ErtL81OZXYWOZTZ1tCvFwNhf7rLHYuv5sr6BIifB KRwsNFF3+gC1efknDj6oUCkpYkF0dZoe7rYM5pIEJZTWAwcjQtSQJCMQeh8sGGGI1vQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Jl4q6JqL; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88143606A31A; Tue, 1 Dec 2026 20:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Jl4q6JqL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DD311F000C1; Tue, 1 Dec 2026 20:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796157354; bh=pB5o9z4rMCxOyz+mWP7w9fU4YVlM7A1ZdAWOcwWXxMo=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Jl4q6JqLxS0Ffvnr1jIY7HGTfVAA8ZTxYxsRyfO/IUj6R8yz+ux3ad149r9Da1ayl KJLUulOH1PXYHOrDz7hzrSuAHGLzOSeJZU8n6S+NcrLTshVWLqo0w3Y0Lj/zRGkeex 3nTowgohao035l/OfV1ojUeaPSbcia4YIM/GBuUcrHHLe2eDYqSnGKAE4kN98nhiIh OMQ7wPD9WZ9q6B/2V0upVcZzsxMrKSS3Ivf6qrSYd6XxCOOpJXJ7HWG63UCDwY4w4R /dXoGXXpf+OdlfQH0QK79BHvru5CsnPPJAHgPfv869vIR6Dl/vrAIM9iYrzmR+Im9Z MxNJz6TyboqUA== Subject: Re: [PATCH net v2 1/2] net: ethernet: ti: cpsw_ale: serialize ALE table accesses 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 Date: Tue, 01 Dec 2026 20:35:53 +0000 Message-ID: <179615735313.3146.5568019864174331553@kernel.org> In-Reply-To: <20261130-cpsw-ale-lock-v2-1-c7a59d2178bb@amperfied.com> References: <20261130-cpsw-ale-lock-v2-1-c7a59d2178bb@amperfied.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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