From: Hans Zhang <18255117159@163.com>
To: Andrew Lunn <andrew@lunn.ch>
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
Subject: Re: [PATCH] net: phy: avoid synchronous module request in async probe context
Date: Sun, 29 Nov 2026 15:46:29 +0800 [thread overview]
Message-ID: <cc92cbe1-b65e-4fe8-be18-baae49dfb53b@163.com> (raw)
In-Reply-To: <c0834daa-176e-454b-8408-3818ead9c688@163.com>
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
prev parent reply other threads:[~2026-11-29 7:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 7:07 [PATCH] net: phy: avoid synchronous module request in async probe context Hans Zhang
2026-11-25 7:37 ` netdev-bot+sashiko
2026-11-25 7:55 ` Hans Zhang
2026-11-25 13:58 ` Andrew Lunn
2026-11-26 3:52 ` Hans Zhang
2026-11-26 14:35 ` Andrew Lunn
2026-11-29 7:16 ` Hans Zhang
2026-11-29 7:46 ` Hans Zhang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cc92cbe1-b65e-4fe8-be18-baae49dfb53b@163.com \
--to=18255117159@163.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox