Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: javen_xu@realsil.com.cn
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, nb@tipi-net.de, maxime.chevallier@bootlin.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	daniel@makrotopia.org, vladimir.oltean@nxp.com
Subject: Re: [PATCH net-next v5 2/4] r8169: hold MDIO bus lock while loading firmware
Date: Sat, 05 Dec 2026 10:32:37 +0000	[thread overview]
Message-ID: <179646675777.3146.12988826761903830464@kernel.org> (raw)
In-Reply-To: <20261201094454.1150-3-javen_xu@realsil.com.cn>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message reads as preventive hardening, but the patch
  fixes a race that already exists before this series.

--

r8169: hold MDIO bus lock while loading firmware

This patch takes the MDIO bus lock around rtl_fw_write_firmware() in
r8169_apply_firmware(). Other phylib users then cannot interleave their
PHY accesses with the firmware sequence. The lock is skipped when there
is no phydev, and tp->ocp_base is restored before the lock is released.

> rtl_fw_write_firmware() accesses PHY registers directly, bypassing
> phylib. Hold MDIO bus lock meanwhile, so other phylib users cannot
> interleave their accesses with the firmware sequence.

[Severity: Low]
The code change looks right. However, the message reads like
preventive hardening. Isn't this race already reachable before this
series?

Before this patch, r8169_apply_firmware() ran the firmware sequence
without the MDIO bus lock:

r8169_apply_firmware()
  rtl_fw_write_firmware()
    rtl_writephy() / rtl_readphy()
      r8168g_mdio_write() / r8168g_mdio_read()
        r8168_phy_ocp_write() / r8168_phy_ocp_read()

r8168_phy_ocp_read() writes, polls and then reads the shared GPHY_OCP
register. That is not atomic:

    RTL_W32(tp, GPHY_OCP, reg << 15);

    return rtl_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ?
        (RTL_R32(tp, GPHY_OCP) & 0xffff) : -ETIMEDOUT;

Firmware writes to register 0x1f also change the shared tp->ocp_base.

In the same tree, rtl822x_probe() in drivers/net/phy/realtek/ already
calls rtl822x_hwmon_init() for the internal NBASE-T PHYs (RTL_8221B,
RTL_8251B, RTL_8261C and 0x001cc841). A read of the 0444 temp1_input or
temp1_max file follows this path:

rtl822x_hwmon_read()
  phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSRR)
    rtl822x_read_mmd()
      r8169_mdio_read_reg_c45()
        r8168_phy_ocp_read()

That path holds only the MDIO bus lock.

Suppose the hwmon file is read while rtl_open(), the reset work or
resume runs this chain:

rtl8169_init_phy()
  r8169_hw_phy_config()
    rtl8125b_hw_phy_config() (or the 8125d/8126a/8127a variants)
      r8169_apply_firmware()

Can the two OCP access sequences interleave? That could corrupt a
firmware write, or a firmware PHY_READ could return the hwmon register
value, and the PHY would be left with a broken firmware patch.

If so, could the commit message say what goes wrong without the lock?
Could it also carry a Fixes: tag for the commit that added hwmon
support for these PHYs, so the patch is routed to net and stable?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201094454.1150-1-javen_xu%40realsil.com.cn

  parent reply	other threads:[~2026-12-05 10:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:44 [PATCH net-next v5 0/4] net: phy: realtek: add PTP support for RTL8127a javen
2026-12-01  9:44 ` [PATCH net-next v5 1/4] net: ethtool: tsconfig: allow selecting a provider javen
2026-12-01 10:06   ` Nicolai Buchwitz
2026-12-01 10:34   ` Maxime Chevallier
2026-12-01 10:44     ` Nicolai Buchwitz
2026-12-05 10:32   ` netdev-bot+sashiko
2026-12-01  9:44 ` [PATCH net-next v5 2/4] r8169: hold MDIO bus lock while loading firmware javen
2026-12-01 10:18   ` Nicolai Buchwitz
2026-12-02 13:17   ` Andrew Lunn
2026-12-03  2:07     ` Javen
2026-12-03  2:37       ` Andrew Lunn
2026-12-03  3:04         ` Javen
2026-12-04 19:23           ` Andrew Lunn
2026-12-05 10:32   ` netdev-bot+sashiko [this message]
2026-12-01  9:44 ` [PATCH net-next v5 3/4] net: phy: realtek: add PTP clock support for RTL8127a javen
2026-12-01 10:23   ` Nicolai Buchwitz
2026-12-02  8:55     ` Javen
2026-12-02 12:20       ` Nicolai Buchwitz
2026-12-02 13:21   ` Andrew Lunn
2026-12-05 10:32   ` netdev-bot+sashiko
2026-12-01  9:44 ` [PATCH net-next v5 4/4] net: phy: realtek: add hardware timestamping " javen
2026-12-01 10:36   ` Nicolai Buchwitz
2026-12-02  8:30     ` Javen
2026-12-05 10:32   ` netdev-bot+sashiko

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=179646675777.3146.12988826761903830464@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=javen_xu@realsil.com.cn \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maxime.chevallier@bootlin.com \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vladimir.oltean@nxp.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