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/2026…%40realsil.com.cn