🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25462

Re: [PATCH net v2 1/2] net: ethernet: ti: cpsw_ale: serialize ALE table accesses

#25462
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 20:35
173 lines
14888 bytes
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
Technical Details
Message-ID: <179615735313.3146.5568019864174331553@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375349-linux-kernel-netdev=dewy.ru
References: <20261130-cpsw-ale-lock-v2-1-c7a59d2178bb@amperfied.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375349-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179615735313.3146.5568019864174331553@kernel.org>
References: <20261130-cpsw-ale-lock-v2-1-c7a59d2178bb@amperfied.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1814437"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:9YT0uQFspX2xqsHgtfMecWsxGTM= sha256:AZy1HvwLRn5Um7bjZgHGl2ZuKez32ZmgtC8t67GVmXU=
	sha1:joRssjiBBDDxQcSOEgT4fMjqiy4= sha256:RCCs5oCl0Xwl0w4hmBcTv0uPxXBwMSi7tLiXAsoitqA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 77DF0117496; Tue,  1 Dec 2026 23:36:14 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id q9prDNfThT62;
	Tue,  1 Dec 2026 23:36:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375349-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 5E30A11747B; Tue,  1 Dec 2026 23:36:02 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 915E327E86; Tue,  1 Dec 2026 20:36:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796157360;
	b=T6QcMiHp4zucnaUOEJp8gL4D4oIeo3YdBpBA2noQymZ/MXnrRJmNOk2baC5CR2IOQn9F
	 4lqlCp1MkH7uXWteu6O9Y/eCPXGmg/iWCMAYozLTVDQcLkMmSA511MuafZQrH1gl+KiqB
	 9PPqtIhrQwm2g+4K1CCLO7d9iwe8EsCd/EJi7uSmUdQwJmLmwer2Z3HuNpUP6mPbf807P
	 eL5OLturzIoA1aB7xnuhL4ZRABPDz0VxSV5LDJU3KEp/kOARB7ONx88aLqGXSwOuW9pYp
	 +zLXuF3N/J1ASTLeasf+xe5EtbWhrfsoMxcYl9SLg4VAm1KU+xedWNHuxCdSXc6x4kw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796157360;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=pB5o9z4rMCxOyz+mWP7w9fU4YVlM7A1ZdAWOcwWXxMo=;
	b=AOfqyfHQ9P4l+FoSD9Krp6+leTBDoNY8YE0gxpEYF31Nikq3VxR38IND327clVEuBTbN
	 wEberp+8cdUNJqbJLWyQjTpASNLCWXOkDCpiGSUFekfrNKFBRgGx0AyV6XMFUnZk/gswi
	 6lY14fUmtlTrfGxKkWnH80WJoroB/zT6qzhFmldRJRLvXJYX2u/Dc+wqXNWeuZUXb4VX9
	 IKjg+X29J+2j8LZ8p+r+axJIZ5w+ygNpzV3qtcgZVw+UbMC7UcVIEvFnq1mKY5cR0EGK5
	 GXPGLLywJypgbHJswlisYoO9TXlovxoOwvUxmMTk/X3YJKB4A2KZNYKd9/WC6Wm4wJg==
X-ARC-Authentication-Results: i=2; 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=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A688606A329;
	Tue,  1 Dec 2026 20:36:00 +0000 (UTC)
X-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
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-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==
X-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==
X-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
X-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)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DD311F000C1;
	Tue,  1 Dec 2026 20:35:53 +0000 (UTC)
X-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==
X-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
X-In-Reply-To: <20261130-cpsw-ale-lock-v2-1-c7a59d2178bb@amperfied.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list