Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: maxime.chevallier@bootlin.com
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
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	[thread overview]
Message-ID: <179544551937.3135.9976133356956488963@kernel.org> (raw)
In-Reply-To: <20261122144926.284857-3-maxime.chevallier@bootlin.com>

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


  parent reply	other threads:[~2026-11-23 14:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 14:49 [PATCH net-next 0/3] net: stmmac: dwmac-sun8i: enable Flow Control Maxime Chevallier
2026-11-22 14:49 ` [PATCH net-next 1/3] net: stmmac: dwmac-sun8i: allow controlling TX and RX flow control separately Maxime Chevallier
2026-11-22 15:54   ` Nicolai Buchwitz
2026-11-22 16:00   ` Chen-Yu Tsai
2026-11-23 14:51   ` netdev-bot+sashiko
2026-11-22 14:49 ` [PATCH net-next 2/3] net: stmmac: dwmac-sun8i: emit pause frames when the RX FIFO fills Maxime Chevallier
2026-11-22 15:57   ` Nicolai Buchwitz
2026-11-22 16:11   ` Chen-Yu Tsai
2026-11-23 14:51   ` netdev-bot+sashiko [this message]
2026-11-22 14:49 ` [PATCH net-next 3/3] net: stmmac: dwmac-sun8i: configure the pause time for TX flow control Maxime Chevallier
2026-11-22 15:58   ` Nicolai Buchwitz

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=179544551937.3135.9976133356956488963@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=alexis.lothore@bootlin.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=linux@armlinux.org.uk \
    --cc=lorenzo.bianconi@oss.qualcomm.com \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=samuel@sholland.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=wens@kernel.org \
    --cc=willemb@google.com \
    /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