🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27221

Re: [PATCH net-next v6 2/4] r8169: hold MDIO bus lock while loading firmware

#27221
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 02:59
90 lines
11257 bytes
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 patch "r8169: hold MDIO bus lock while loading firmware"
  fixes a race that is already in mainline, but the commit message…

--

r8169: hold MDIO bus lock while loading firmware

This patch takes the MDIO bus lock around rtl_fw_write_firmware() in
r8169_apply_firmware(). The firmware loader accesses PHY registers
directly and bypasses phylib. The lock is skipped on PHY-less parts where
tp->phydev is NULL.

> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index f151ab6813932..b9068957ffa4f 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -2686,9 +2686,14 @@ void r8169_apply_firmware(struct rtl8169_private *tp)
>  
>  	/* TODO: release firmware if rtl_fw_write_firmware signals failure. */
>  	if (tp->rtl_fw) {
> +		/* Keep phylib users (hwmon) off the bus meanwhile. */
> +		if (tp->phydev)
> +			phy_lock_mdio_bus(tp->phydev);
>  		rtl_fw_write_firmware(tp, tp->rtl_fw);

[Severity: Low]
Can this race already be hit in mainline? If so, should the commit carry
a Fixes: tag?

The "Realtek Internal NBASE-T PHY" entry uses rtl822x_probe(). When
CONFIG_REALTEK_PHY_HWMON is enabled, that function registers a hwmon
device for the internal PHY:

drivers/net/phy/realtek/realtek_main.c:rtl822x_probe() {
    ...
	if (IS_ENABLED(CONFIG_REALTEK_PHY_HWMON) &&
	    phydev->phy_id != RTL_GENERIC_PHYID)
		return rtl822x_hwmon_init(phydev);
    ...
}

That code came in with:

33700ca45b7d ("net: phy: realtek: add hwmon support for temp sensor on RTL822x")

A hwmon sysfs read takes only the MDIO bus lock, not RTNL:

rtl822x_hwmon_read()
  phy_read_mmd(phydev, MDIO_MMD_VEND2, ...)
    r8169_mdio_read_reg_c45()
      r8168_phy_ocp_read()

r8168_phy_ocp_read() writes the address to GPHY_OCP and then reads the
data back from the same register.

Before this patch, rtl_fw_write_firmware() drove GPHY_OCP through
r8168g_mdio_read() and r8168g_mdio_write() without holding that lock. It
runs during ifup, reset work and resume.

If a sensor read overlaps the firmware load, could the PHY_READ,
PHY_DATA_OR/AND and PHY_WRITE_PREVIOUS sequences read from or write to the
wrong PHY register? Could hwmon also report a wrong temperature?

The new comment names hwmon as the competing user. The commit message
does not say that the race exists today or what users see when it hits.
The later patches in the series do not add a Fixes: tag either, so
kernels that already have the hwmon support (v6.14 and later) would not
pick this up. Would a tag like this be appropriate?

Fixes: 33700ca45b7d ("net: phy: realtek: add hwmon support for temp sensor on RTL822x")

Could this also go to net on its own, instead of as part of the RTL8127a
PTP series?

>  		/* At least one firmware doesn't reset tp->ocp_base. */
>  		tp->ocp_base = OCP_STD_PHY_BASE;
> +		if (tp->phydev)
> +			phy_unlock_mdio_bus(tp->phydev);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204021116.66-1-javen_xu%40realsil.com.cn
Technical Details
Message-ID: <179643955446.3146.5909024155497379151@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!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-377803-linux-kernel-netdev=dewy.ru
References: <20261204021116.66-3-javen_xu@realsil.com.cn>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!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-377803-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v6 2/4] r8169: hold MDIO bus lock while loading firmware
Date: Sat, 05 Dec 2026 02:59:14 +0000
Organization: Usenet Network
Message-ID: <179643955446.3146.5909024155497379151@kernel.org>
References: <20261204021116.66-3-javen_xu@realsil.com.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2939584"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:vMoG27G6a0DrYAfiJKrlYSOxIL8= sha256:bPYjf92ZduoW6Tm0Zxu1yaS/8Iscnoqbs+eRkAtzh54=
	sha1:PqzrGBaniIKVGaxIpt0ruorQdZo= sha256:vaCi0fXHPCN20/ESYQX+GRKErq7eP2LmNouwdFPlS0A=
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 6EC46117D53; Sat,  5 Dec 2026 05:59:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, 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 KhrysdIGsh74;
	Sat,  5 Dec 2026 05:59:45 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377803-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 45E6A117D22; Sat,  5 Dec 2026 05:59:37 +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 3F6B836F1B; Sat,  5 Dec 2026 02:59:27 +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=1796439567;
	b=cS99JEER95kQwcOSM0CLPUF0XZrKvSwMlM9YjEKXCaAThmgwTHHUS1A3OhZ4jLQ7nmlN
	 2GU6BGp38aA8v9/CaPUmz3P3iK5tVWGwtXreqAD+FbrLco04u2FK+Qwvj3p7Xom73Nl9+
	 72hJ8eMsVy2UP/ip0vB5qWISeBg4QuMUeWV/UdE3e+y8PaImnXz+8Mak4NcBNMjDXDkYL
	 YP6Zh2rFOh8k2epX8xfU+E6N5+/+Byjm3Leim47lotuOIECvqzsczWe0RALuuvaXqxtGP
	 0/Sz0BEJo/jT3M2z84YpTyJzRGYAgLMUy95UW2qkXwKSWYuwrVPVoGExZvRRp3SFClg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796439567;
	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=npe10QCFpajcqSgLyK781ke54hZ8ShjxTLZEBoRjDVI=;
	b=3dUENK07FPUS1uVryp8+mammBPxC26KUJq+vJbS7bPngjMZoNGoAb5NqDF5V7LJ/PUQW
	 O6ZtFD135NyDqwhMueo4eQLrxLOwkHMH13eacJvd7QxtpQA2VqzfNFVoTfOARPBbikuSY
	 /Ej0a+Wd+GRskwNXt+4p7QbZIT3lcy8Z/yAkoMH+M/64BYrz5yFmQklxPVbNSxGmNrfjr
	 UvJpcmemgf816o88ft3OmTkPoqQhCI/tnwjPyQ2SETGlbZ0NZ7dDlIpG/YuzZq84pw47H
	 yQxTIm+n1KEOpsI2BeS/8QJ3mxCD7m4avSlaexr/lciYxDmIPDzc+Klq27RCoAsqnyw==
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=DYpWGtWE;
	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 03E8F606A32F;
	Sat,  5 Dec 2026 02:59:27 +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=DYpWGtWE
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=1796439556;
	b=15Otkr/H2CmxA61JxzK9wf1o2HouLvqjnnqnTyKhIucbDqcEOZwO/12+2Sg1kYpyviF9
	 h2ArKM/gmp2baxNrn4P/3ch3o3B3J/IiRL3sbdvnshwUAI0xsgWDdEBkgPLUQ+CxQqkp5
	 XHlaRMvDHNhn3dedK/0hiC8A6zyju1oowo0v4KAziwcVrOy39KjH7LOwx89/30e06ci3P
	 BNQb+sRTqxwmQL0oKGrZFXudV/ZyG32AIVw8DVuMwEO6nB5CR3sHZ5E764xiAwDxsXga1
	 0Z3L0vF9GZBf1hMKspPhOPBJlw8lkskPPRV3hj3w5A0GwE5HY0hbV4wnA1WftKL9qjA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796439556;
	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=npe10QCFpajcqSgLyK781ke54hZ8ShjxTLZEBoRjDVI=;
	b=38gxIP8wIeTILyeE3ZkmMx1k13GQEdVDcvGHWz+mvnqrQBaDgZVbem8OFfuRMIZD3pXj
	 +W/QYuvqYwRKQDx4/eVewRLyVqjmAdtC3RVX5Ou5xMD49E5JL1MQMxnxzevie5INieo5L
	 tT1lMglwqRMBRBgoeIA9D6W0MqTI6vWlvOUJSOZg+oTcYZLaz1hpkioRDb/TjOpD0AAfr
	 ZklP2TrfjWyc4TkRcerZ5bI+K7qH3Z0HYUSD2bE8P5YnnOCPgIg2x7Bo2LU3/m6a2vvU5
	 RAFuO0uOJ2bnKY0gXf91IzWmc5PjUtrmIZ7XfLpZHXOJXKdl4L18dtPK3QPgLdOrgyQ==
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=DYpWGtWE;
	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 1E7AA606A32D;
	Sat,  5 Dec 2026 02:59:15 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA7D51F00936;
	Sat,  5 Dec 2026 02:59:14 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796439555;
	bh=npe10QCFpajcqSgLyK781ke54hZ8ShjxTLZEBoRjDVI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=DYpWGtWEy96fXz8foXlBlHJt4mwRlMam2BGA22EVwoUNGW1nRAGxVZ5CRGbLXr798
	 YPTKuken+Ssc2HXz7n9iDu2YKUIAtDPr/ICBLXVOUaBZ5oeAEKBQOg/h0PV19F/1wi
	 NVtXizo55uB8s4Ct/C2OGUYIjCNSj1RL9YhqqOQ/OQ/P+I7tBf+ZbKoW1q7gU1kOEH
	 XLs5fQxEYta8oT3Xh3ejFAGtiwV3jrw7xG4R2wuX24PqosMakknQwRERt0Gs2sie7v
	 b7KMDMs83JxO0pduVQG4CnR3s4/LoD62wPjee1zcuR8cuAelWMyZFlwpEfAo7Lp9dR
	 mZJDPD3GS92GQ==
X-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
X-In-Reply-To: <20261204021116.66-3-javen_xu@realsil.com.cn>
X-sashiko-severity: Low
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