Article View: linux.kernel.netdev
Article #20083Re: [PATCH net-next v3 1/3] r8169: hold MDIO bus lock while loading firmware
From: netdev-bot+sashiko
Date: Sat, 21 Nov 2026 06:39
Date: Sat, 21 Nov 2026 06:39
136 lines
12891 bytes
12891 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · 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).
- [High] NULL pointer dereference in r8169_apply_firmware()
(drivers/net/ethernet/realtek/r8169_main.c) on PHY-less RTL8116AF…
- [Medium] r8169_apply_firmware() drops mdio_lock (line 2692) before it
restores the PHY page shadow `tp->ocp_base = OCP_STD_PHY_BASE` (line…
--
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 sequence accesses PHY registers
directly and bypasses phylib, so the lock is meant to stop other phylib
users from interleaving their accesses with that sequence.
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index f151ab6813932..34ea4640467cf 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -2686,7 +2686,10 @@ 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, PTP) off the bus meanwhile. */
> + phy_lock_mdio_bus(tp->phydev);
[Severity: High]
Can tp->phydev be NULL here?
phy_lock_mdio_bus() dereferences phydev->mdio.bus->mdio_lock and does not
check for NULL. Further down, the same function already guards its phylib
call:
/* PHY soft reset may still be in progress */
if (tp->phydev)
phy_read_poll_timeout(tp->phydev, MII_BMCR, val, ...
That check came in with commit dab515216deff5 ("r8169: add support for
RTL8116af"). It suggests this function is expected to run with rtl_fw set
and phydev NULL on 8116AF.
On an RTL8116AF (RTL_GIGA_MAC_VER_52), rtl_get_sfp_mode() returns
RTL_SFP_8168_AF. rtl_init_one() then skips the MDIO registration:
if (tp->sfp_mode == RTL_SFP_NONE) {
rc = r8169_mdio_register(tp);
so tp->phydev is never set.
The VER_52 chip entry has FIRMWARE_8168FP_3 as its firmware name.
rtl_open() calls rtl_request_firmware() whether or not a PHY exists, so
tp->rtl_fw is set whenever that firmware file is installed.
rtl_hw_start_8117() checks tp->phydev before its own PHY access, but it
calls the firmware helper unconditionally:
/* firmware is for MAC only */
r8169_apply_firmware(tp);
So interface bring-up appears to reach the new lock call with a NULL
phydev:
rtl_open()
rtl8169_up()
rtl_reset_work()
rtl_hw_start()
rtl_hw_start_8117()
r8169_apply_firmware()
phy_lock_mdio_bus(NULL)
Runtime resume and the rtl_task reset path get there too.
Would it work to take and drop the bus lock only when tp->phydev is
non-NULL? Without a phydev there are no phylib bus users to keep out.
> rtl_fw_write_firmware(tp, tp->rtl_fw);
> + phy_unlock_mdio_bus(tp->phydev);
> /* At least one firmware doesn't reset tp->ocp_base. */
> tp->ocp_base = OCP_STD_PHY_BASE;
[Severity: Medium]
Should the tp->ocp_base restore move above phy_unlock_mdio_bus()?
Right now the bus lock is released before the page shadow left by the
firmware is reset. That makes the restore an unlocked write to state that
the Clause 22 bus ops depend on.
The firmware can change tp->ocp_base in two ways:
- r8168g_mdio_write() with reg 0x1f
- mac_mcu_write() with reg 0x1f after PHY_MDIO_CHG, which leaves a MAC
OCP base in it
The comment above the restore says at least one firmware doesn't reset
the value.
Every C22 access builds its address from that shadow:
r8168g_mdio_read() {
...
if (tp->ocp_base != OCP_STD_PHY_BASE)
reg -= 0x10;
return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2);
}
A C22 phylib user can be blocked on mdio_lock while this runs. One example
is the PHY state machine running read_status after a link change, during
the rtl_task reset or runtime resume. That user can wake as soon as
phy_unlock_mdio_bus() runs and do its BMSR/BMCR access before the restore.
The access would then go to a firmware vendor page or a MAC OCP derived
address.
Paged accesses have a worse case. phy_select_page() reads reg 0x1f and
gets the stale page from the shadow, and phy_restore_page() writes it back
later. If the unlocked restore runs between those two calls, the access
meant for the selected page goes to the standard page instead. The stale
page is then written back, and later C22 accesses keep going to the wrong
place.
This only affects C22 users. The hwmon and PTP users go through C45 with
absolute OCP addressing.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117060120.1175-1-javen_xu%40realsil.com.cn
Technical Details
Message-ID:
<179524315014.3135.14234749504647866339@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368280-linux-kernel-netdev=dewy.ruReferences:
<20261117060120.1175-2-javen_xu@realsil.com.cn>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368280-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v3 1/3] r8169: hold MDIO bus lock while loading firmware Date: Sat, 21 Nov 2026 06:39:10 +0000 Organization: Usenet Network Message-ID: <179524315014.3135.14234749504647866339@kernel.org> References: <20261117060120.1175-2-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="3349772"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:HWaqHVt79F4eN/5ZbC67hZ86iaw= sha256:n1Xsg01qg/Soxw/7gkJqYdcH56RQOufIQtAYfyb52AM= sha1:UCK6F+JjPo/Gl5gOIFAZM82JurI= sha256:hdjAfIBZ9H3RDhBR8zwrEA5fSiCponFMr9VBKtV9ZZs= 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 E1695115B29; Sat, 21 Nov 2026 09:39:33 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, 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] 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 vvLkBNaMDgGW; Sat, 21 Nov 2026 09:39:25 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-368280-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 5A35B114411; Sat, 21 Nov 2026 09:39:16 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 4FBB460F0C7; Sat, 21 Nov 2026 06:39:15 +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=1795243152; b=zVFuA7snwhVeJIp4G9bX4XiYVYBp3GmbbBsZk1Cn3thxzLgYDEiOYNgJcSbV1muIPhPW 1oODIanU/0GjQdOtq23b0O9nwVDFXMsV3XqPslQSAYCLg6JsU+8kPmOg7KCPaQAMVMN9W npLix1VVoWLdaj7AA0Uk7DQE37PqOWVC8Yfhrvpk+7vSMIsqZh2rGmPleki7OHBj0Xn2K pyQgw2JtAXTe62/hVTvnQHyeq+7cv9X501MJYK5bGZXGorYSeXYV+Wl6b1LDn+vjDg3IK xEaGR3MzNBV71Sqo4DssR2UuxHtyO+O0F7bpJ7ppoH69sWYP1zmi5f/FPlsReQsGBJg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795243152; 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=1c2Y6DLdeSlq9tmF9TErs1z/CKCH7BIITyy/dFDt3II=; b=SpIk5ws9cu9VmIu4zClQR1AxY3TqwrmxHvm+oeXZck2f4MJe3zfWqZ3EEE/DiHpwq0AV C4BHtukkkRE4tsYeGQsk4FmPI6tC93KukdqctSkdjWMB2vHGBiSOBN/lVDCjC4Y62cRck WqmkPZVDmjiKY4rE5KPzZIEb+eYKaXUMr2fV4iGUvmbXyiteWfqT3sPFzAmMz3Fxqm/8H 145sqKOTSSMK2yKc8RZ6goS21RDwqT3WR6ycLHvcmu5EjyD+6HkUirmI5o6OGeilanE8g Yx3JdISVYwe2E4zF/XhTh1NmCYHNqxrqOJgEHn5hcISrBIYZjrOqxJSOZNtQ6BAk1aw== 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=AZsaSQ6t; 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 9E517606A683; Sat, 21 Nov 2026 06:39:12 +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=AZsaSQ6t 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=1795243151; b=2nCicrDXvajv8YD2P4zMLZiE82DdF1BT6t4czz3lg5IyVgN7B6vYyuQHFwSj/RI5Sk1i 8wn7oT9YjifgYlWEUEccAEdxPZ70uYzQiJKQrFuBbHj3blET8dVbtxIYyFJItTMF9u+oB YbAgAu2NYC9ElbWp/ODBqZAw9dEDnDJkpSDRKC74nEQ/XyqAWj5iBSfLIFe53RsZSkvVN wTFXjnZlRL3GywLiRZqNoTBuLh5RPVlfxgwzcnloNkAS6X+bzqEjYdvBi7N7TIu/X5m6Y BkD7b7f7zE2l+eAMwmFm0YaqIyXNG9VwVOiq/lWIoHkRON6pfsFMGgqybwfkdmwAxnQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795243151; 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=1c2Y6DLdeSlq9tmF9TErs1z/CKCH7BIITyy/dFDt3II=; b=CWJK60BuL8VVuosxhhE5gM5RbNt47XAxgOPCh6kAbYakWN+jhYZ/kxUziqv19Sttd4eG h5wIbAOqfoSCBloBvXWnT+hBEKBh/VIyaWtiVgsYUsXoWEv3wxrm7V90Jy/wMukPSMqZb XBPdM8eNq1PLz3O4ZXUMz5jhaCDUQI89+cRFtQnc3rtCHFYUkU9VIp/xrClBWGZhBLrIw RNYVQNteAzbtOUXZ6ukEqkkcyrUOyAs6PatInbO9TYlpD5Id95ckSc8IOgPtnPp1YaBKv P7QJoeXT8VEUjgwcw2l3PYEWiuswmCg/USkC9O9aWI1k+CYVMzaQyiWGQ/Zh5daubCg== 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=AZsaSQ6t; 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 BC3F4606A335; Sat, 21 Nov 2026 06:39:11 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D0DA1F000C4; Sat, 21 Nov 2026 06:39:10 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795243151; bh=1c2Y6DLdeSlq9tmF9TErs1z/CKCH7BIITyy/dFDt3II=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=AZsaSQ6t1emdwE7mIuZN2eVvxba+/PsajWxmb6M+38yW0cIXiOOEgXn18+mbBplxH CR4gR1F+8jQaAN3uT7nOjIJPepH+JH44IVCJy90SNoaaIcY0PQiMc0GPYpb2i4eENR KuVPVNys0mJSW1AQ2sUorrefQ13UT/SaP0d7LrQvcVsu0S0QJoNY9TsNRYfnmc2J/f eHsxj5tNSAdCOzi6QuE85MmUE7eOUr2cmW7BFnw7CQ2Q4YU9YyfiOFZmb4wwhnlFYl VWx7bAiFuGrJVQvKFpmJswJtnE+d14WdTVzzCQ0+p6coNtBSLC1MWl761FycAeQq7D 8Hx3Xr4mgv0yQ== 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: <20261117060120.1175-2-javen_xu@realsil.com.cn> X-sashiko-severity: High 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