๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22128

Re: [PATCH net 1/4] ixgbe: fix MDIO bus lifetime

#22128
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 22:00
122 lines
12425 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท 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).

- [Medium] The patch now clears adapter->mii_bus only after
  unregister_netdev() has returned.

--

ixgbe: fix MDIO bus lifetime

This commit changes ixgbe_mii_bus_init() to register the MDIO bus with
devm_mdiobus_register() on the netdev device. The bus is then unregistered
and freed when unregister_netdev() runs device_del(). The explicit
mdiobus_unregister() calls in the FW error path and in ixgbe_remove() are
dropped, and adapter->mii_bus is now cleared after unregister_netdev() in
both the unsupported SFP path and the FW error path.

> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> index b9496f0bee131..2b6d1177addab 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> @@ -8471,6 +8471,7 @@ static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
>  		e_dev_err("Reload the driver after installing a "
>  			  "supported module.\n");
>  		unregister_netdev(adapter->netdev);
> +		adapter->mii_bus = NULL;
>  	}
>  }
>  
> @@ -8693,11 +8694,8 @@ static void ixgbe_service_task(struct work_struct *work)
>  	}
>  	if (ixgbe_check_fw_error(adapter)) {
>  		if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
> -			if (adapter->mii_bus) {
> -				mdiobus_unregister(adapter->mii_bus);
> -				adapter->mii_bus = NULL;
> -			}
>  			unregister_netdev(adapter->netdev);
> +			adapter->mii_bus = NULL;

[Severity: Medium]

With the NULL store moved after unregister_netdev(), does adapter->mii_bus
point at a freed bus for a while?

The bus is now registered via devm on &adapter->netdev->dev in
ixgbe_mii_bus_init(), so unregister_netdev() itself unregisters and frees
it:

unregister_netdev()
  unregister_netdevice_many_notify()
    netdev_unregister_kobject()
      device_del()
        devres_release_all()
          mdiobus_unregister() + mdiobus_free()
            put_device() -> mdiobus_release() -> kfree(bus)

phy_mask is GENMASK(31, 0), so no PHY devices hold extra references. That
means the bus memory really is freed at this point.

Next, unregister_netdev() calls rtnl_unlock() -> netdev_run_todo(). That
function drops RTNL early and then sleeps in rcu_barrier() and
netdev_wait_allrefs_any(). During that whole wait, adapter->mii_bus still
holds the stale pointer and no lock is held.

The old FW error code cleared the pointer before it called
unregister_netdev(). The new hunk in ixgbe_sfp_detection_subtask() has the
same after-the-call ordering.

The reader is ixgbe_mdio_read() (and likewise ixgbe_mdio_write()). It
checks the pointer without a lock and then dereferences it:

	if (adapter->mii_bus) {
		...
			return mdiobus_c45_read(adapter->mii_bus, prtad,
						devad, regnum);

		return mdiobus_read(adapter->mii_bus, prtad, regnum);

Both calls take bus->mdio_lock, which is inside the freed object.

ixgbe_reset() can get to this reader without RTNL, for example from
ixgbe_io_slot_reset() or ixgbe_resume():

ixgbe_reset()
  hw->mac.ops.init_hw / reset_hw
    phy.ops.identify -> ixgbe_identify_phy_generic()
      ixgbe_probe_phy()
        mdio45_probe()
          hw->phy.mdio.mdio_read == ixgbe_mdio_read()

Nothing serializes these paths against the service task. The service task
is only cancelled in ixgbe_remove().

This chain only runs when hw->phy.type == ixgbe_phy_unknown. In the trigger
paths traced so far, phy.type was already known, so no concrete
interleaving has been shown. It also hasn't been ruled out for every
MAC/PHY combination.

Would it be safer to clear adapter->mii_bus before calling
unregister_netdev() in both ixgbe_service_task() and
ixgbe_sfp_detection_subtask(), as the old FW error path did?
WRITE_ONCE()/READ_ONCE() or a shared lock around the pointer might also be
worth considering.

>  		}
>  		ixgbe_service_event_complete(adapter);
>  		return;

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120220022.3133664-1-anthony.l.nguyen%40intel.com
Technical Details
Message-ID: <179555765601.3135.4530614438146845451@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-370807-linux-kernel-netdev=dewy.ru
References: <20261120220022.3133664-2-anthony.l.nguyen@intel.com>

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-370807-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/4] ixgbe: fix MDIO bus lifetime
Date: Tue, 24 Nov 2026 22:00:56 +0000
Organization: Usenet Network
Message-ID: <179555765601.3135.4530614438146845451@kernel.org>
References: <20261120220022.3133664-2-anthony.l.nguyen@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="48636"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:fgr/ojjjo0ckz2VfkmnDnGPYIwY= sha256:AuVbGYcnWaFllpk5BKYrE6NiQTP/6zvSMUiaVRQe7SI=
	sha1:fBqKSk19ZbBizwauxkm0rC0wgo0= sha256:9lK/l+JJYN5boI4088zZJOYs4OWwm4CQPt2/sUWQSt8=
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 9510A125E39; Wed, 25 Nov 2026 01:01:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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 PbtPKXtXDqHH;
	Wed, 25 Nov 2026 01:01:09 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-370807-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 3C4FD125E33; Wed, 25 Nov 2026 01:01:00 +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 030F829B04; Tue, 24 Nov 2026 22:00:58 +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=1795557658;
	b=PtXoF8yetPHFnKGsv7atWBWVQoObPhiVR7kve6xeMJrfkCrc5Ld26m910g7poYlPNIIo
	 axybJz1ttPKVHc1H9Ust3sf2qRTl+nn3sX91XHzSPuKlL149TM5aKKSR24DAURoscAwlp
	 qQTN8pHelICqLmA4F/NdKW9JtDf9A2juNkGLjedCV/LCSlEfjYP9MzyN94UZ/JhyKEx3w
	 l9Demvtk7So0w2QpLKdQ703m99Lym0iMChvoDmUWEjjhQ8kM6MDjfQPzF4iuBBp+uoZYL
	 u09eXTLywYOYPbbqvenCqISvYoOL5pKVmX2vub68Lm7QO4A9/Z3BjAzHw3Nnds8fHZg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795557658;
	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=FVH5FPtfJO7PCnnlFrVIHQchlOb+hJTsrV7TH24bPa0=;
	b=fOWJfyZarbJNvgQ+cH5tBSmeIMfwgbVrVqRuzPItoePd83c8FiWRmaRY6EwchBjG9Dcu
	 ks9W2PoR7BmkOee1ujJPuqngvDEuIXQy1o2sTbr91LPKg3q2F2T+QN0MsRot6ut07fhQv
	 1YMbve46EzU9B1w8EXGvnZzq+R0OTWbva4fQXHYm790DrklE4nOd/0QrlnEGYRrjXQp8i
	 VH0seg8r4Woxwc7I00uQ0ZfU6+BN/fBH8GZ1r+ElP2yc26oCFKwV/1vzMAFFHbYHgA7wu
	 wYiFEWm37Je3rQIaL2nPRfGDzImkm35PeqnAITIJCuqnjTRe8wkytNXsCvxCmDcjh4w==
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=kp23W1rt;
	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 C0771606A32D;
	Tue, 24 Nov 2026 22:00:58 +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=kp23W1rt
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=1795557657;
	b=2cA/ObksbVFbEueFXmr5RA/yEJsTRg3qxA4tVPAc5QlFWqHEj3dQ/58W4b/bAqiysZnM
	 9E/pCzrhW6cI5NS3z9kdNgyIuepTVB1orlq82O37r9pCmSel3u5Cm5K9PjYuvIQ8VrC/Y
	 MdViB4s3hlEVgd1CzAcrjYHD5t4EDct/yskZwbBe3U8xKjDzUHxwIScR5tApFg21y2QX4
	 ddiMbpJ9STv+hyXYLynLQ1ZRerZIeF0CdIZpaC2lw1NQznAJQW/y3wDfbmFaks7w9QF3e
	 DXZ0j+GbprgJNuQYSu4UelPrxqHfnIFXC1dY30iswsRdTiLP19An+D1YBEbhIyM+qUA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795557657;
	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=FVH5FPtfJO7PCnnlFrVIHQchlOb+hJTsrV7TH24bPa0=;
	b=HpIApohu+wrDBadDmzKtKmtinKSjzALdNiX+aWl/C2AjA1LQ6r8WCwUnpeiUpidt28sQ
	 HmOBSJhPsq0Jea/xY7cL17TW715WJBxk3dQyRUZnQe36Lu1fB85i+iCokos9pWkbgAHFI
	 e+H9nWRd1BUJHwSlb3xQAHQntgnN1N172jbwuZGeM9G9vXS8mFFzvzVJSPJYv5dBxPiMf
	 Qg9hUIFOS/xy/3cHWbiqdPd/f42e6E7OXh/tPZXwL/Ry+ksrJnjXLn7QDQaPM141Grj6W
	 3j1iKbeFPVq90JaRkVtu44exbeG2/9WzsUHppeXVw7wTHC/OKmTvJiiDWfJWdD3wMcA==
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=kp23W1rt;
	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 DE763606A31E
	for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 22:00:57 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81DBA1F000C4;
	Tue, 24 Nov 2026 22:00:56 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795557657;
	bh=FVH5FPtfJO7PCnnlFrVIHQchlOb+hJTsrV7TH24bPa0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=kp23W1rtlEdn3OD2E7JySTO+KlPpinOB7n9ZDXXzn8lrFSb816IrbMpWt6wpm5Uyv
	 EIcI+1CdV5hlbwkPof5ummZHUO7qukAgVOPv/SKMOop1QEIwHt/3aQOGO1qDpWridG
	 h+TtjsEAruyA71EuK0KKts85s3+X3KaAG+vz3vxzS+fvHZ7bq984JNumMkzkqT5Z2B
	 NfjapZyepyXGUt5SIC+bAD7TiWze/c3tSYlZbm/tcRaZ7Kv8vHRHRgwGbelD4+KPLX
	 Vu4Vagvi8TJrx+s7MDDpfdB01sLM0I1hXhHvX1AffDpjAy14K9SIqtf+/7ymSIc/PN
	 YV6k+qo6VoFvw==
X-Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
 edumazet@kernel.org, andrew+netdev@lunn.ch, netdev@vger.kernel.org,
 tomasz.lichwala@linux.intel.com, ripatel@wii.dev, xiaolinkui@kylinos.cn,
 xiaolinkui@126.com, runyu.xiao@seu.edu.cn, horms@kernel.org,
 marcin.szycik@linux.intel.com, przemyslaw.kitszel@intel.com,
 rafal.romanowski@intel.com
X-In-Reply-To: <20261120220022.3133664-2-anthony.l.nguyen@intel.com>
X-sashiko-severity: Medium
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