From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.2 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== 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== 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 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 ; Sun, 29 Nov 2026 07:47:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 97471606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=GuKrBj5m 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= Message-ID: Date: Sun, 29 Nov 2026 15:46:29 +0800 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] net: phy: avoid synchronous module request in async probe context From: Hans Zhang <18255117159@163.com> To: Andrew Lunn 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 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> <04208d88-5611-4b08-b4a3-4030d75fa946@lunn.ch> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wBHNzlb2AtraGPlLA--.45164S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxKr1DCw47tFy8CryUJFy3CFg_yoW3uw4fpa 98Za4Yvr4ktr47Zw4kJw48ZFyrt3WxtrW2gr18u3sa9ws0yryDAryxtFW7ZF9rWr4vk3Wa qrn0v3yfCF98AFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U5hLnUUUUU= X-CM-SenderInfo: rpryjkyvrrlimvzbiqqrwthudrp/xtbC6xvpjWsL2Fv3XQAA3d 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 #include #include #include @@ -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