🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24081

Re: [PATCH] net: phy: avoid synchronous module request in async probe context

#24081
From: Hans Zhang
Date: Sun, 29 Nov 2026 07:46
238 lines
17278 bytes

On 11/29/26 15:16, Hans Zhang wrote:
> 
> 
> On 11/26/26 22:35, Andrew Lunn wrote:
>>> For v3 I'm considering moving the check to __mdiobus_register() itself,
>>> returning -EPROBE_DEFER before the scan when current_is_async() is true.
>>
>> Maybe. This code is tricky. There are quiet a lot of comments
>> explaining the issues, which the LLM quoted. You should look at the
>> comments, and what the LLM said, and think about all the corner cases
>> you can think of.
>>
>>> __mdiobus_register() already returns -EPROBE_DEFER for the reset-GPIO
>>> case, and the deferred-probe retry runs on a normal workqueue where
>>> current_is_async() is false, so the synchronous request_module() is safe
>>> again. Direct get_phy_device() callers would not be affected.
>>
>> This does seem like it could work. However, i'm considering the risks.
>> Are there MAC drivers which don't correctly handle EPROBE_DEFER from
>> the mdiobus_register variants?
>>
>> Such a change would solve it for all MAC drives which probe
>> async. However, i think there is a less risky option:
>>
>>         .probe_type = PROBE_FORCE_SYNCHRONOUS,
>>
>> for this one MAC driver.
>>
>> That is also probably faster. The MAC driver has often done a lot of
>> work setting stuff up before it calls mdiobus_register(), which it
>> then needs to undo, and do again later. I assume
>> PROBE_FORCE_SYNCHRONOUS will completely avoid that, the probe happens
>> later in synchronous context, and avoids all this.
>>
>> If we see more MAC drivers having this problem, we can then consider
>> your general solution.
>>
>>       Andrew
> 
> 
> Hi Andrew,
> 
> I tested PROBE_FORCE_SYNCHRONOUS on the r8169 MAC driver (and reverted
> Sky1 back to PROBE_PREFER_ASYNCHRONOUS). The WARN still fires.
> 
> The trace still starts at async_run_entry_fn and goes through:
> 
>    async_run_entry_fn
>    __driver_attach_async_helper
>    driver_probe_device
>    __driver_probe_device
>    really_probe
>    platform_probe
>    sky1_pcie_probe
>    cdns_pcie_hpa_host_setup
>    pci_host_probe
>    pci_bus_add_devices
>    pci_bus_add_device
>    device_initial_probe
>    __device_attach
>    __device_attach_driver
>    driver_probe_device
>    really_probe
>    pci_device_probe
>    local_pci_probe
>    rtl_init_one
>    __devm_mdiobus_register
>    __mdiobus_register
>    mdiobus_scan
>    get_phy_device
>    phy_device_create
>    phy_request_driver_module
>    __request_module
> 
> 
> 
> diff patch:
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ 
> ethernet/realtek/r8169_main.c
> index f151ab681393..85746643afbb 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -7074,7 +7074,10 @@ static struct pci_driver rtl8169_pci_driver = {
>       .probe        = rtl_init_one,
>       .remove        = rtl_remove_one,
>       .shutdown    = rtl_shutdown,
> -    .driver.pm    = pm_ptr(&rtl8169_pm_ops),
> +    .driver        = {
> +        .pm        = pm_ptr(&rtl8169_pm_ops),
> +        .probe_type    = PROBE_FORCE_SYNCHRONOUS,
> +    },
>   };
> 
>   module_pci_driver(rtl8169_pci_driver);
> 
> 
> 
> 
> 
> So the r8169 probe still runs inside the async worker of the parent Sky1
> controller. PROBE_FORCE_SYNCHRONOUS on the child PCI driver only prevents
> scheduling a new async probe for it; it does not change the context when
> the child is added during the parent's async probe.
> 
> Forcing the Sky1 controller probe synchronous is not an option on the PCI
> side: those controllers use PROBE_PREFER_ASYNCHRONOUS specifically so
> their multiple root complexes are enumerated in parallel, and serializing
> them would hurt boot time and PCIe enumeration. So the fix needs to be in
> the phylib/mdio path instead.
> 
> Could the phylib maintainers advise on the right way to avoid the
> synchronous request_module() when the MDIO bus is scanned from async
> context? I'm happy to implement and test whatever direction you suggest.
> 


Hi Andrew,

After testing PROBE_FORCE_SYNCHRONOUS on the r8169 MAC driver, the WARN
still fires. The trace still starts at async_run_entry_fn and goes
through the parent Sky1 controller probe, so a child driver's probe_type
does not move it out of the async context.

Forcing the PCIe controller synchronous is not acceptable on the PCI 
side because it would serialize the root complexes and add their 
enumeration and link-training time to the boot path.

I would therefore like to propose the following net/phy approach. If 
this direction looks reasonable to you, I will send it as a four-patch 
series.

   1. net: phy: defer __mdiobus_register() from async probe context
__mdiobus_register() returns -EPROBE_DEFER before the MDIO scan when 
current_is_async() is true. The deferred-probe retry runs on a normal 
workqueue where the synchronous request_module() is safe, and the PHY 
driver is still loaded before the PHY device is registered.

   2. net: ethernet: lantiq_etop: propagate mdiobus_register() errors
   3. net: ethernet: smsc911x: propagate mdiobus_register() errors
   4. net: ethernet: smsc9420: propagate mdiobus_register() errors

Patches 2-4 fix three callers that would otherwise convert -EPROBE_DEFER 
into a hard -ENXIO error.

Combined diff for review:



diff --git a/drivers/net/ethernet/lantiq_etop.c 
b/drivers/net/ethernet/lantiq_etop.c
index 83ce3bfefa5c..8c64687c3fd8 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -400,10 +400,9 @@ ltq_etop_mdio_init(struct net_device *dev)
  	priv->mii_bus->name = "ltq_mii";
  	snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
  		 priv->pdev->name, priv->pdev->id);
-	if (mdiobus_register(priv->mii_bus)) {
-		err = -ENXIO;
+	err = mdiobus_register(priv->mii_bus);
+	if (err)
  		goto err_out_free_mdiobus;
-	}

  	if (ltq_etop_mdio_probe(dev)) {
  		err = -ENXIO;
diff --git a/drivers/net/ethernet/smsc/smsc911x.c 
b/drivers/net/ethernet/smsc/smsc911x.c
index 3ebd0664c697..0d6d64b7c501 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -1101,7 +1101,8 @@ static int smsc911x_mii_init(struct 
platform_device *pdev,
  		pdata->mii_bus->phy_mask = ~(1 << 1);
  	}

-	if (mdiobus_register(pdata->mii_bus)) {
+	err = mdiobus_register(pdata->mii_bus);
+	if (err) {
  		SMSC_WARN(pdata, probe, "Error registering mii bus");
  		goto err_out_free_bus_2;
  	}
diff --git a/drivers/net/ethernet/smsc/smsc9420.c 
b/drivers/net/ethernet/smsc/smsc9420.c
index 0c97211b6254..6b563b0c7cb0 100644
--- a/drivers/net/ethernet/smsc/smsc9420.c
+++ b/drivers/net/ethernet/smsc/smsc9420.c
@@ -1153,7 +1153,8 @@ static int smsc9420_mii_init(struct net_device *dev)
  	/* Mask all PHYs except ID 1 (internal) */
  	pd->mii_bus->phy_mask = ~(1 << 1);

-	if (mdiobus_register(pd->mii_bus)) {
+	err = mdiobus_register(pd->mii_bus);
+	if (err) {
  		netif_warn(pd, probe, pd->dev, "Error registering mii bus\n");
  		goto err_out_free_bus_2;
  	}
diff --git a/drivers/net/phy/mdio_bus_provider.c 
b/drivers/net/phy/mdio_bus_provider.c
index ce3a607a40cb..3bdcbaf6b9cb 100644
--- a/drivers/net/phy/mdio_bus_provider.c
+++ b/drivers/net/phy/mdio_bus_provider.c
@@ -8,6 +8,7 @@

  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

+#include <linux/async.h>
  #include <linux/delay.h>
  #include <linux/device.h>
  #include <linux/errno.h>
@@ -560,6 +561,17 @@ int __mdiobus_register(struct mii_bus *bus, struct 
module *owner)
  	if (!bus || !bus->name)
  		return -EINVAL;

+	/*
+	 * mdiobus_scan() requests the PHY driver module with a synchronous
+	 * request_module() so the driver is present before the PHY device is
+	 * registered.  That is not safe from an async worker: module init may
+	 * call async_synchronize_full() and deadlock waiting for this worker.
+	 * Defer the probe instead; the retry runs on the deferred-probe
+	 * workqueue, where a synchronous module request is safe.
+	 */
+	if (current_is_async())
+		return -EPROBE_DEFER;
+
  	/* An access method always needs both read and write operations */
  	if (!!bus->read != !!bus->write || !!bus->read_c45 != !!bus->write_c45)
  		return -EINVAL;


Would you be OK with this direction?

Best regards,
Hans
Technical Details
Message-ID: <cc92cbe1-b65e-4fe8-be18-baae49dfb53b@163.com>
Path: mbox-mo1.pugleaf.net!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-373406-linux-kernel-netdev=dewy.ru
References: <20261124070753.25972-1-18255117159@163.com> <179559227928.3135.10596298102368144827@kernel.org> <0437f8be-41ca-4fb8-b775-ed02413ea16d@163.com> <24787f0c-e90e-45f1-a9f3-d0772fbafeaf@lunn.ch> <c1ee530d-21bc-4b50-881f-3be9b2654b9d@163.com> <04208d88-5611-4b08-b4a3-4030d75fa946@lunn.ch> <c0834daa-176e-454b-8408-3818ead9c688@163.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!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-373406-linux-kernel-netdev=dewy.ru
From: 18255117159@163.com (Hans Zhang)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] net: phy: avoid synchronous module request in async probe
 context
Date: Sun, 29 Nov 2026 15:46:29 +0800
Organization: Usenet Network
Message-ID: <cc92cbe1-b65e-4fe8-be18-baae49dfb53b@163.com>
References: <20261124070753.25972-1-18255117159@163.com>
 <179559227928.3135.10596298102368144827@kernel.org>
 <0437f8be-41ca-4fb8-b775-ed02413ea16d@163.com>
 <24787f0c-e90e-45f1-a9f3-d0772fbafeaf@lunn.ch>
 <c1ee530d-21bc-4b50-881f-3be9b2654b9d@163.com>
 <04208d88-5611-4b08-b4a3-4030d75fa946@lunn.ch>
 <c0834daa-176e-454b-8408-3818ead9c688@163.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1128116"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:uXxE2scacmICvNgBgLo23eQhm/k= sha256:a5PMf47amDodwVxCJt4xV5f4XTq0WIozhlPM3p+xT4w=
	sha1:sv+1PaqGkU0Xu9lQSMq2t/QKsTg= sha256:aVhpVpq0AWAwFT7yneb2b6TIvuPoEfnqgH28gFkfjuA=
Content-Language: en-US
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 CE96E125F95; Sun, 29 Nov 2026 10:47:44 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.717
X-Spam-Status: No, score=-2.717 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, FROM_LOCAL_DIGITS=0.001, FROM_LOCAL_HEX=0.331,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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 (1024-bit key)
	header.d=163.com
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 f1H38aodtKwq;
	Sun, 29 Nov 2026 10:47:37 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373406-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=163.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 26277125F94; Sun, 29 Nov 2026 10:47:26 +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 5401B26003; Sun, 29 Nov 2026 07:47:22 +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=1795938442;
	b=QT0tj6CUIl7DW1p7dwj68iKr260IHzukfwsLfmw2ajE5AaAJfpJE/tGmOseDO6Yi6cL5
	 rR9/T6QVeAjGiEsSF2nyD51GcZ/Yo+a3R+m2JVDT1QwlfMX0K/mn8C0oFbGo9BleBC7xt
	 A5qsPasuVHjU8U9nP9ihqmUXvIDibUyzvR+T7zZyLOWP7IVDTm8j5a/KxfvqzBg2Gync3
	 QG0rorHVFkTVyAUf97uQ3wZW4dlnCq2IyoQt3vApUXNczQVa1d7PUblSt3DwDQvLN54jV
	 Mhb9lZQfCClJexvZMSt6yMA9MuVWnSfpxzbBfOuJPU1JyxaN+TQzU+s68iy5jYNh08g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795938442;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:From:To:Cc:References:Content-Language:In-Reply-To:
	 Content-Type:Content-Transfer-Encoding:X-CM-TRANSID:
	 X-Coremail-Antispam:X-CM-SenderInfo;
	bh=Hyf0GIkkeIyfc7aKyysdbNB7LDz53qKaEE3wcZxycn8=;
	b=nUVnuN98rNOJrRFJL4kypdVZ1S+Kdhi/Oo2vRmpNZjoiixfDyFgN4vEHD+yZl+EYJmW+
	 NgBOBaWt5LG5BUK1rEyF8bwZGpQb0Cj54M/Bdy6cJsJkNTDtZp+elfTibMCasCUm4a8zT
	 UyqJYxuQjts8lkd5PpFEAFayU1sEc5yPHSkKpVBepaMyktyvET2aZ/pqrSQZQ5h6o91qo
	 h47UE4YRLf27GzDEUM6LZHrnT/V3fIqL2eHNfe9GZHeRz58XoDoBSQUXDGe/reK/Leo7e
	 /z+aWN/TdkigQ9s/+kiR72AD7obmZlQk+Lydd1iKWOvgMFiYxV8zDrxNYT0SpoMWz9A==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=GuKrBj5m;
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	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 0FB5E606A32A;
	Sun, 29 Nov 2026 07:47:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=GuKrBj5m
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.2
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795938441;
	b=kNMss3HBbQH0dUPriiM9W6CWPnQAZEFR/+AHTRdPJg54w3UuDbvs/tnR0oFaBDNOmQl9
	 fB2jSRxBJhQo5AOY4Gtnpf/vDFQanHIpgPOwHeOizjXx/31nSgaqIkTZheHSaOqQM8RVv
	 RfqSC+ce0k6+yMlOe9S3MpdeJrQb1Jd08rY+tLLEWjT4+lmYQpZuTtpljPcRwUdwsMhQ7
	 cJxST0wnSmIwVmVTQeN9ydYWIGplf14Em+qRfEMuKNEjo4iMDLdRaH8gfFvwxeclZJvYx
	 0DsJ1bKsFiXtGMGMnOYMEglpabTZqcRbPQn+zdLLVZhVf/R9fie75CX5Fu0O2JEmqdw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795938441;
	h=DMARC-Filter:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent:
	 Subject:From:To:Cc:References:Content-Language:In-Reply-To:
	 Content-Type:Content-Transfer-Encoding:X-CM-TRANSID:
	 X-Coremail-Antispam:X-CM-SenderInfo;
	bh=Hyf0GIkkeIyfc7aKyysdbNB7LDz53qKaEE3wcZxycn8=;
	b=UWLO278GfmtQo47sqtKgdCHxvnSwLFRRxx2PtgqRZxFl0F3adhrpnxSWWIbhcIKuEQnb
	 v0tqeI1Z8HE3ZPYqCvc0vI447rq5yaDThMjIQttWEJsDJ8h1trT2QL31yVQUuKHdwAFgZ
	 bt7BhK+Dtzfzfl9yPiuBuE6nI2hod0ti6SDrBlqhqf5xcOjUoWBc2oRCJuHRxxB4b6vHX
	 p8hVA2KaJd1tp8AIFRrfT2IC2pDNxvCnx7vr1D/5IHgcwGVJPBYid29JzpKvJ5KZHUWSp
	 qhuRMp0mCM6BOvO6m+cwuvZPdXyw8Mfh8e0mAmgQC3LDudX/BejVUNzLwfoH4DqvViQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=163.com;
	spf=pass smtp.mailfrom=163.com;
	dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=GuKrBj5m;
	arc=none smtp.remote-ip=220.197.31.2
X-Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97471606A31C
	for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 07:47:18 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 97471606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;
	s=s110527; h=Message-ID:Date:MIME-Version:Subject:From:To:
	Content-Type; bh=Hyf0GIkkeIyfc7aKyysdbNB7LDz53qKaEE3wcZxycn8=;
	b=GuKrBj5mfLr5BDoKqeHQS3wcf68Q2a+IZ+Y51Ru/20vB1WFR1++BwaJ8P1ycrs
	faVmS1df22g5PaIxExVPTyXI+aeozVUommjtxWlJ24mVFSxgR2d0OhhKT0TsCsqJ
	z3wE+1XUg9zXxmQ1vd9UXuisSvZS4EtxxqCRFVsanqP3c=
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
X-User-Agent: Mozilla Thunderbird
X-Cc: netdev-bot+sashiko@kernel.org, hkallweit1@gmail.com, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 linux@armlinux.org.uk, netdev@vger.kernel.org
X-In-Reply-To: <c0834daa-176e-454b-8408-3818ead9c688@163.com>
X-CM-TRANSID: _____wBHNzlb2AtraGPlLA--.45164S2
X-Coremail-Antispam: 1Uf129KBjvJXoWxKr1DCw47tFy8CryUJFy3CFg_yoW3uw4fpa
	98Za4Yvr4ktr47Zw4kJw48ZFyrt3WxtrW2gr18u3sa9ws0yryDAryxtFW7ZF9rWr4vk3Wa
	qrn0v3yfCF98AFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2
	9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U5hLnUUUUU=
X-CM-SenderInfo: rpryjkyvrrlimvzbiqqrwthudrp/xtbC6xvpjWsL2Fv3XQAA3d