🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21092

Re: [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

#21092
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 14:51
104 lines
11987 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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] Unserialized read-modify-write of EMAC_RX_CTL1 in
  sun8i_dwmac_flow_ctrl() (drivers/net/ethernet/stmicro/stmmac/dwmac-…

--

net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills

This commit sets the RX FIFO flow control thresholds in EMAC_RX_CTL1 from
sun8i_dwmac_flow_ctrl(). With these thresholds, the MAC sends pause
frames when less than 2K is left in the RX FIFO and stops when more than
4K is free. The new bits are set only when TX flow control is requested.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index c63f4d87de509..75c743dfe3483 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c

[ ... ]

> @@ -766,6 +772,17 @@ static void sun8i_dwmac_flow_ctrl(struct mac_device_info *hw,
>  		v &= ~EMAC_RX_FLOW_CTL_EN;
>  	writel(v, ioaddr + EMAC_RX_CTL0);
>  
> +	v = readl(ioaddr + EMAC_RX_CTL1);
> +	v &= ~(EMAC_RX_FIFO_FLOW_CTL | EMAC_RX_FLOW_CTL_TH_ACT |
> +	       EMAC_RX_FLOW_CTL_TH_DEACT);
> +	if (fc & FLOW_TX)
> +		v |= EMAC_RX_FIFO_FLOW_CTL |
> +		     FIELD_PREP(EMAC_RX_FLOW_CTL_TH_ACT,
> +				EMAC_RX_FLOW_CTL_TH_2K) |
> +		     FIELD_PREP(EMAC_RX_FLOW_CTL_TH_DEACT,
> +				EMAC_RX_FLOW_CTL_TH_4K);
> +	writel(v, ioaddr + EMAC_RX_CTL1);

[Severity: Medium]
Can this read-modify-write of EMAC_RX_CTL1 race with the RX DMA start and
stop helpers?

EMAC_RX_CTL1 also holds EMAC_RX_DMA_EN and EMAC_RX_DMA_START.
sun8i_dwmac_dma_start_rx() and sun8i_dwmac_dma_stop_rx() update those bits
without a lock:

    v = readl(ioaddr + EMAC_RX_CTL1);
    v &= ~EMAC_RX_DMA_EN;
    writel(v, ioaddr + EMAC_RX_CTL1);

The phylink resolve worker reaches sun8i_dwmac_flow_ctrl() through this
path:

phylink_resolve()
  phylink_link_up()
    stmmac_mac_link_up()
      stmmac_mac_flow_ctrl()
        sun8i_dwmac_flow_ctrl()

That path holds pl->phydev_mutex and pl->state_mutex, but not rtnl.

On the XDP and XSK paths, the DMA start and stop callers hold only rtnl
and never call phylink_stop(). One example:

stmmac_xdp_set_prog()
  stmmac_xdp_release()
    stmmac_stop_all_dma()
    free_dma_desc_resources()

The same applies to stmmac_xdp_open()->stmmac_start_all_dma(), and to
stmmac_disable_rx_queue() and stmmac_enable_rx_queue() during XSK pool
setup.

If a link-up event is handled while an XDP program is being attached or
detached, two interleavings look possible.

In the first, flow_ctrl reads RX_CTL1 while DMA_EN is set. Then
stmmac_xdp_release() clears DMA_EN and frees the RX rings. Finally,
flow_ctrl writes back the stale value, which sets DMA_EN again.

If the sun8i RX DMA resumes on DMA_EN alone, could the hardware then
access the freed descriptors?

In the second, flow_ctrl reads DMA_EN as 0. Then stmmac_xdp_open() or
stmmac_enable_rx_queue() sets DMA_EN | DMA_START, and flow_ctrl writes
DMA_EN back as 0.

Would RX then stay stopped until the interface is reconfigured?

Before this patch, flow_ctrl did not touch EMAC_RX_CTL1, so these writers
could not overlap. Could accesses to this register be serialized, or could
the thresholds be programmed from a path that is already ordered against
DMA start and stop?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122144926.284857-1-maxime.chevallier%40bootlin.com
Technical Details
Message-ID: <179544551937.3135.9976133356956488963@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369495-linux-kernel-netdev=dewy.ru
References: <20261122144926.284857-3-maxime.chevallier@bootlin.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369495-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames
 when the RX FIFO fills
Date: Mon, 23 Nov 2026 14:51:59 +0000
Organization: Usenet Network
Message-ID: <179544551937.3135.9976133356956488963@kernel.org>
References: <20261122144926.284857-3-maxime.chevallier@bootlin.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3905390"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:h6cM/EBcKQ0cTcYdbFoG/KH7snw= sha256:HT3VREeN8cutjFvnlZJBzdMHTtxbqCeAXpSlmVaQGRY=
	sha1:KSTZHmU3xBFwP/G3+Qix+ZfylY4= sha256:iKlxSnQpqmO5tF+RJXRGBS6eGg0TJ87f2kE/SOaG/CU=
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 71040125DBC; Mon, 23 Nov 2026 17:52:26 +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 SG6SavE4MbuP;
	Mon, 23 Nov 2026 17:52:19 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369495-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 B9B3F125DB9; Mon, 23 Nov 2026 17:52:10 +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 4A0692D98A; Mon, 23 Nov 2026 14:52:03 +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=1795445522;
	b=Kga9ptgQHTMhLZEHTbv7o4bjIGKlxlcHDyqXQnXgf9eiGnIMxQyWB4tRWN502JsIOY1t
	 QqUk+h+M9/fCGXtaT849dSofnqfgwaRz5IlZc6mhcAzPBuBumQNA9xgUehlAVRgdx4E//
	 K6JGzcCrVXLiQi9WWwVM8FO3Ym/NA10HIu+sE21HkZs/uPHwG/5CW4f6OIvsZAsHkfpzh
	 qhrLb5F/j3Jv5u+b+IZfJ6HC4dwo87LIgBlqeOwk71Dpqb0FKUmyla3AePQEX3y/fi8rG
	 AFh+KtmzcC4pKK38/SBwFK9jz4UKc4GIyK/t9bRDzAKrtOsCdQ0LfAWQCfeC0F0OCIA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795445522;
	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=9JDW8BjO8pV2V62+zC72GsPlWIjoxqy4Dkv4PW8Y9/w=;
	b=VuKgj9OFfGALBQPp5SB1qz5/FV0chN9HyvG8FDERO1oR6uDysB6xFRRolZKavtDkbFqi
	 AifsCxXhF/EjMZ2aOOGi19kq0I6XgD5z/1XPDdD/WowqtnWcrgHNvjuoNFVu29O7U6Uza
	 XC0jUa+GNdXj49a1jzCJX9Y0/z8wboyanqodTXd8zFp88PIUVYhaowpC1gx7De2HqA6K4
	 G6W3G6AQC3yYwWgEy7bZK9sWNAFRfQzxsfh/cWNXo6FKHa3N5l65Rm8sxzGoAJtmyo97x
	 tLLfd7bLIQJmnguqbMZpdOhujc+R6PHgL+akBtTOzGVR7Crl7cx2xMuo1OPKwOgALjw==
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=Qak6zpwX;
	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 643A1606A681;
	Mon, 23 Nov 2026 14:52:02 +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=Qak6zpwX
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=1795445521;
	b=or2GsNjiQEDv4wrqTnEy3CMeW8w9l6AVYplC6xKv27HXgEcQwX3Qo1Hv97lGwkN0JhQc
	 U8W8v1nLd96OEKgNcsUXm0uk2RIA6RFNPBOXeNxtfNHmnjQLkQre2Y4foH1BPn+ox8T8f
	 9ZF60nlG2wH02n1YFS4QyX4sZxE4voofzLV/2p9It4EECBSkSBawj+V16efgucNfz0ynL
	 yT6oGwdczeF8M2ybaf1x8Oot7IdugWnPOsNCFLABG5BDGL7sanBtjetcoBHW0bXYk3rWg
	 Bvz+7iUc19nQNmTWCFGyJ6C+joDESrrZdVJMjAjglMDNJqbDhpIjEKsRwZr5qSbsCpQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795445521;
	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=9JDW8BjO8pV2V62+zC72GsPlWIjoxqy4Dkv4PW8Y9/w=;
	b=vRI2cjCXLaYyzTSRRp8hPORKqEnI1iEgRQcFT609M8usgSFLpL4VPEERuHZ4YmiqFORE
	 BAqySo1X+v7xlX/23ZaZSSqNIwH0b4i6n68rMaaSyMKkHbTK8mYj17bJejcrdnwKP+rY0
	 5YyK3gVdestvCq3hCE9x4zwnaWSHq3PaK6VehB3WvSOYmVQM4TnSk30tbLcT4cLELk10v
	 30hiCy/HAd2xudSWpjb1Rms2/MZxD66qdbNi+MdcFeJBuqyTkFGnA62tf4FoH8QCH0lzG
	 leA9f5CdcoBtiEVxIJ5+SypktXKKJrTT+GGZyMDvIATYHbR+1trbxay7l8e7N/D/ZoQ==
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=Qak6zpwX;
	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 84BB3606A32E;
	Mon, 23 Nov 2026 14:52:01 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C253E1F000D1;
	Mon, 23 Nov 2026 14:51:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795445521;
	bh=9JDW8BjO8pV2V62+zC72GsPlWIjoxqy4Dkv4PW8Y9/w=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Qak6zpwXQJLL3Kvq6BKWq53jr5EnQT+eXPjt5h9GM9HBjjdLh8vjMyXNOJ3ihQOmR
	 oKSJyZ0ARs+nkqN3CUTDERe7H7uXl1iFvONORXopVNbfNZajlZvSqpoXFRT/vXUFtm
	 4xxzBjadJV/vlVscAEFb1qk8HB+EX5nT3/2mSSQromZXe1m/UKTTqfa0ggEp0y0qnc
	 rxp1gwWEDnxihTYnd7RveF0HylGtogWM7lsHvmO7J9tXjoA1U/fRvz/sr4hx0BjwHI
	 D1CKEUYtXjsoErHwgqloaC9NIIwv+GBnPKFsLgqY3OYk4UzmAmuPzYN0enAOeu4jCh
	 Q2dGMnPGPwkCw==
X-Cc: andrew+netdev@lunn.ch, kuba@kernel.org, davem@davemloft.net,
 edumazet@google.com, pabeni@redhat.com, horms@kernel.org, willemb@google.com,
 wens@kernel.org, jernej.skrabec@gmail.com, samuel@sholland.org,
 mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
 linux@armlinux.org.uk, lorenzo.bianconi@oss.qualcomm.com, nb@tipi-net.de,
 thomas.petazzoni@bootlin.com, alexis.lothore@bootlin.com,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
 linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev
X-In-Reply-To: <20261122144926.284857-3-maxime.chevallier@bootlin.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