From: "Hubert Wiśniewski" <hubert.wisniewski.25632@gmail.com>
To: "Oleksij Rempel" <o.rempel@pengutronix.de>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>
Cc: "Marek Szyprowski" <m.szyprowski@samsung.com>,
<stable@vger.kernel.org>, <kernel@pengutronix.de>,
<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
"Lukas Wunner" <lukas@wunner.de>,
"Russell King" <linux@armlinux.org.uk>,
"Xu Yang" <xu.yang_2@nxp.com>, <linux-usb@vger.kernel.org>
Subject: Re: [PATCH net v1 1/1] net: usb: asix: forbid runtime PM to avoid PM/MDIO + RTNL deadlock
Date: Wed, 17 Sep 2025 13:26:23 +0200 [thread overview]
Message-ID: <DCV1EPLCX5L5.3MWOCVTH5AWM4@gmail.com> (raw)
In-Reply-To: <20250917095457.2103318-1-o.rempel@pengutronix.de>
On Wed Sep 17, 2025 at 11:54 AM CEST, Oleksij Rempel wrote:
> Forbid USB runtime PM (autosuspend) for AX88772* in bind.
>
> usbnet enables runtime PM by default in probe, so disabling it via the
> usb_driver flag is ineffective. For AX88772B, autosuspend shows no
> measurable power saving in my tests (no link partner, admin up/down).
> The ~0.453 W -> ~0.248 W reduction on 6.1 comes from phylib powering
> the PHY off on admin-down, not from USB autosuspend.
>
> With autosuspend active, resume paths may require calling phylink/phylib
> (caller must hold RTNL) and doing MDIO I/O. Taking RTNL from a USB PM
> resume can deadlock (RTNL may already be held), and MDIO can attempt a
> runtime-wake while the USB PM lock is held. Given the lack of benefit
> and poor test coverage (autosuspend is usually disabled by default in
> distros), forbid runtime PM here to avoid these hazards.
>
> This affects only AX88772* devices (per-interface in bind). System
> sleep/resume is unchanged.
>
> Fixes: 4a2c7217cd5a ("net: usb: asix: ax88772: manage PHY PM from MAC")
> Reported-by: Hubert Wiśniewski <hubert.wisniewski.25632@gmail.com>
> Closes: https://lore.kernel.org/all/20220622141638.GE930160@montezuma.acc.umu.se
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Closes: https://lore.kernel.org/all/b5ea8296-f981-445d-a09a-2f389d7f6fdd@samsung.com
> Cc: stable@vger.kernel.org
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> Link to the measurement results:
> https://lore.kernel.org/all/aMkPMa650kfKfmF4@pengutronix.de/
> ---
> drivers/net/usb/asix_devices.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
> index 792ddda1ad49..0d341d7e6154 100644
> --- a/drivers/net/usb/asix_devices.c
> +++ b/drivers/net/usb/asix_devices.c
> @@ -625,6 +625,22 @@ static void ax88772_suspend(struct usbnet *dev)
> asix_read_medium_status(dev, 1));
> }
>
> +/*
> + * Notes on PM callbacks and locking context:
> + *
> + * - asix_suspend()/asix_resume() are invoked for both runtime PM and
> + * system-wide suspend/resume. For struct usb_driver the ->resume()
> + * callback does not receive pm_message_t, so the resume type cannot
> + * be distinguished here.
> + *
> + * - The MAC driver must hold RTNL when calling phylink interfaces such as
> + * phylink_suspend()/resume(). Those calls will also perform MDIO I/O.
> + *
> + * - Taking RTNL and doing MDIO from a runtime-PM resume callback (while
> + * the USB PM lock is held) is fragile. Since autosuspend brings no
> + * measurable power saving for this device with current driver version, it is
> + * disabled below.
> + */
> static int asix_suspend(struct usb_interface *intf, pm_message_t message)
> {
> struct usbnet *dev = usb_get_intfdata(intf);
> @@ -919,6 +935,16 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
> if (ret)
> goto initphy_err;
>
> + /* Disable USB runtime PM (autosuspend) for this interface.
> + * Rationale:
> + * - No measurable power saving from autosuspend for this device.
> + * - phylink/phylib calls require caller-held RTNL and do MDIO I/O,
> + * which is unsafe from USB PM resume paths (possible RTNL already
> + * held, USB PM lock held).
> + * System suspend/resume is unaffected.
> + */
> + pm_runtime_forbid(&intf->dev);
> +
> return 0;
>
> initphy_err:
> @@ -948,6 +974,10 @@ static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
> phylink_destroy(priv->phylink);
> ax88772_mdio_unregister(priv);
> asix_rx_fixup_common_free(dev->driver_priv);
> + /* Re-allow runtime PM on disconnect for tidiness. The interface
> + * goes away anyway, but this balances forbid for debug sanity.
> + */
> + pm_runtime_allow(&intf->dev);
> }
>
> static void ax88178_unbind(struct usbnet *dev, struct usb_interface *intf)
> @@ -1600,6 +1630,10 @@ static struct usb_driver asix_driver = {
> .resume = asix_resume,
> .reset_resume = asix_resume,
> .disconnect = usbnet_disconnect,
> + /* usbnet will force supports_autosuspend=1; we explicitly forbid RPM
> + * per-interface in bind to keep autosuspend disabled for this driver
> + * by using pm_runtime_forbid().
> + */
> .supports_autosuspend = 1,
> .disable_hub_initiated_lpm = 1,
> };
Well, this fixes the issue for me. No suspend/resume -- no deadlock -- no
problem. Thanks.
Tested-by: Hubert Wiśniewski <hubert.wisniewski.25632@gmail.com>
next prev parent reply other threads:[~2025-09-17 11:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 9:54 [PATCH net v1 1/1] net: usb: asix: forbid runtime PM to avoid PM/MDIO + RTNL deadlock Oleksij Rempel
2025-09-17 10:10 ` Oliver Neukum
2025-09-17 11:52 ` Oleksij Rempel
2025-09-17 12:25 ` Oliver Neukum
2025-09-17 11:26 ` Hubert Wiśniewski [this message]
2025-09-17 13:54 ` Alan Stern
2025-09-17 14:31 ` Hubert Wiśniewski
2025-09-17 14:57 ` Alan Stern
2025-09-17 18:58 ` Lukas Wunner
2025-09-22 7:11 ` Oleksij Rempel
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=DCV1EPLCX5L5.3MWOCVTH5AWM4@gmail.com \
--to=hubert.wisniewski.25632@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lukas@wunner.de \
--cc=m.szyprowski@samsung.com \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=xu.yang_2@nxp.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