Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: james.hilliard1@gmail.com
Cc: netdev@vger.kernel.org, maxime.chevallier@bootlin.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	pabeni@redhat.com, mcoquelin.stm32@gmail.com,
	alexandre.torgue@foss.st.com, wens@kernel.org,
	jernej.skrabec@gmail.com, samuel@sholland.org,
	clabbe.montjoie@gmail.com, willemb@google.com, nbb@tipi-net.de,
	kuba@kernel.org, o.rempel@pengutronix.de,
	linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev
Subject: Re: [PATCH net-next v4 3/5] net: stmmac: dwmac-sun8i: serialize RX_CTL1 updates
Date: Sat, 05 Dec 2026 02:52:57 +0000	[thread overview]
Message-ID: <179643917741.3146.1099493879220373089@kernel.org> (raw)
In-Reply-To: <20261203-submit-sun8i-rxall-v1-v4-3-af22aec6ae13@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

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

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 commit message says it closes the case where "a link-up
  event can race with RX queue reconfiguration on sun8i".
- [Low] The subject and commit message describe a sun8i-only RX_CTL1 fix.

--

net: stmmac: dwmac-sun8i: serialize RX_CTL1 updates

This commit adds sun8i_dwmac_update_rx_ctl1(), which does the RX_CTL1
read-modify-write under a spinlock. The RX DMA start/stop, RX operation
mode and flow-control callbacks are converted to use it. It also renames
mac_device_info::irq_ctrl_lock to reg_lock and updates the generic
stmmac users of that lock.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
> index 95d272e87524e..08de79107c503 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/common.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/common.h
> @@ -655,10 +655,8 @@ struct mac_device_info {
>  	bool additional_32_addr;
>  	bool additional_64_addr;
>  
> -	/* This spinlock protects read-modify-write of the interrupt
> -	 * mask/enable registers.
> -	 */
> -	spinlock_t irq_ctrl_lock;
> +	/* Serializes updates to shared MAC control registers. */
> +	spinlock_t reg_lock;
>  };

[Severity: Low]
This isn't a bug, but the commit message doesn't mention this rename. It
says:

  Use the per-MAC register lock for live changes to RX_CTL1.

That reads as if reg_lock already exists. In fact the patch renames the
generic irq_ctrl_lock to reg_lock and widens its documented purpose.

The rename touches code outside sun8i: dwmac1000_irq_modify(),
dwmac4_irq_modify(), dwxgmac2_irq_modify(), stmmac_fpe_configure_pmac()
and stmmac_hwif_init().

The rename has no functional effect. Still, it is extra core churn in a
Fixes-tagged dwmac-sun8i patch.

Could the lock be reused under its current irq_ctrl_lock name? If the
rename is wanted, could it go in a separate preparatory patch, or at
least be described in the commit message?

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index 8377dc7985377..ada927fe943fb 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c

[ ... ]

> @@ -771,16 +769,13 @@ 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);
> +	v = 0;
>  	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);
> +		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);
> +	sun8i_dwmac_update_rx_ctl1(hw, EMAC_RX_FIFO_FLOW_CTL | EMAC_RX_FLOW_CTL_TH_ACT |
> +				   EMAC_RX_FLOW_CTL_TH_DEACT, v);

[Severity: Medium]
RX_CTL1 is now updated under reg_lock here. The RX_CTL0
read-modify-write just above it is still unlocked, though. Could the
link-up vs. RX reconfiguration race from the commit message lose the
EMAC_RX_FLOW_CTL_EN update?

sun8i_dwmac_set_mac() also does an unlocked read-modify-write of
RX_CTL0:

drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c:sun8i_dwmac_set_mac() {
    ...
	r = readl(ioaddr + EMAC_RX_CTL0);
	if (enable) {
		t |= EMAC_TX_TRANSMITTER_EN;
		r |= EMAC_RX_RECEIVER_EN | EMAC_RX_DO_CRC;
    ...
	writel(r, ioaddr + EMAC_RX_CTL0);
}

The link-up path runs from phylink_resolve(). It holds phydev->lock and
pl->state_mutex, but not rtnl:

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

The XDP reconfiguration path runs under rtnl only and does not stop
phylink:

stmmac_xdp_set_prog()
  stmmac_xdp_release()
    stmmac_mac_set(priv, priv->ioaddr, false)
  stmmac_xdp_open()
    stmmac_mac_set(priv, priv->ioaddr, true)
      sun8i_dwmac_set_mac()

Consider this order:

1. sun8i_dwmac_set_mac(), called from stmmac_xdp_open(), reads RX_CTL0.
2. sun8i_dwmac_flow_ctrl() writes the newly negotiated
   EMAC_RX_FLOW_CTL_EN.
3. sun8i_dwmac_set_mac() writes back its stale value.

The RX pause setting is then lost. The later sun8i_dwmac_set_mac(true)
call from link-up keeps the stale bit, so it would stay wrong until the
next link-up.

The RX_CTL0 read-modify-write in sun8i_dwmac_flow_ctrl() already existed
before the commit in the Fixes tag. However, the commit message says the
phylink flow-control callback now updates only its own fields under the
lock.

Would it make sense to also take reg_lock for RX_CTL0 in
sun8i_dwmac_flow_ctrl() and sun8i_dwmac_set_mac()?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-submit-sun8i-rxall-v1-v4-0-af22aec6ae13%40gmail.com

  reply	other threads:[~2026-12-05  2:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:37 [PATCH net-next v4 0/5] net: stmmac: support ethtool rx-all on sun8i James Hilliard
2026-12-04  2:37 ` [PATCH net-next v4 1/5] net: stmmac: dwmac-sun8i: deliver RX checksum errors to the stack James Hilliard
2026-12-05  2:52   ` netdev-bot+sashiko
2026-12-04  2:37 ` [PATCH net-next v4 2/5] net: stmmac: dwmac-sun8i: align EMAC_RX_MD with tabs James Hilliard
2026-12-04  2:37 ` [PATCH net-next v4 3/5] net: stmmac: dwmac-sun8i: serialize RX_CTL1 updates James Hilliard
2026-12-05  2:52   ` netdev-bot+sashiko [this message]
2026-12-04  2:37 ` [PATCH net-next v4 4/5] net: stmmac: add common RXALL handling James Hilliard
2026-12-05  2:52   ` netdev-bot+sashiko
2026-12-04  2:37 ` [PATCH net-next v4 5/5] net: stmmac: dwmac-sun8i: support ethtool rx-all James Hilliard
2026-12-04  2:42 ` [PATCH net-next v4 0/5] net: stmmac: support ethtool rx-all on sun8i netdev-bot+sinfo

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=179643917741.3146.1099493879220373089@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=clabbe.montjoie@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=nbb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=samuel@sholland.org \
    --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