From: Linkui Xiao <xiaolinkui@126.com>
To: netdev-bot+sashiko@kernel.org
Cc: andrew+netdev@lunn.ch, netdev@vger.kernel.org, andrew@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, rosenp@gmail.com, chunkeey@gmail.com,
jacob.e.keller@intel.com, kees+treewide@kernel.org,
daniel.machon@microchip.com, hkallweit1@gmail.com,
linux-kernel@vger.kernel.org, Linkui Xiao <xiaolinkui@kylinos.cn>
Subject: Re: [PATCH net v3] net: ibm: emac: attach and start the fixed-link PHY
Date: Fri, 27 Nov 2026 09:48:00 +0800 [thread overview]
Message-ID: <20261127014800.2909048-1-xiaolinkui@126.com> (raw)
In-Reply-To: <179559730279.3135.7318334257799287238@kernel.org>
Thanks for the review. All four are legitimate. v4 is posted as a new
thread; it also starts the fixed PHY through emac_mdio_init_phy(), which is
what Andrew asked for in his review of v3.
- [High] Unbind can leave a freed net_device queued on the linkwatch list.
Correct, including the chain, and the reason is not that the reference is
weak. unregister_netdev() -> netdev_run_todo() drains lweventlist through
linkwatch_sync_dev(), and it is also the only place that waits for the
refcount, in netdev_wait_allrefs_any(); it returns as soon as the count
reaches one. A carrier change after that queues an event nobody will ever
wait for again: linkwatch_add_event() does list_add_tail() + netdev_hold(),
and netdev_hold() is a real __dev_hold(), but free_netdev() does not wait
for refs and never takes dev->link_watch_list back off, it goes straight to
ref_tracker_dir_exit(), free_percpu(dev->pcpu_refcnt) and put_device() ->
netdev_release() -> kvfree(). devres frees the netdev as soon as
emac_remove() returns, and __linkwatch_run_queue() then walks the list,
calling netdev_tracker_free() and __dev_put() on freed memory.
Fixed by stopping the PHY before unregister_netdev():
if (dev->ndev->phydev)
phy_stop(dev->ndev->phydev);
phy_stop() is what turns the carrier off, so the event is queued while the
netdev is still registered and unregister_netdev() drains it.
phy_disconnect() stays below it: it only stops the PHY when
phy_is_started(), which is false by then, and moving it up would detach
from a registered netdev without RTNL, which phy_detach_internal() only
tolerates once reg_state != NETREG_REGISTERED.
I did not move phy_start()/phy_stop() into emac_open()/emac_close(). Andrew
asked for the fixed PHY to be started the way this driver starts a real
PHY, and that is emac_mdio_init_phy() from emac_init_phy(), not from
ndo_open. Splitting the two belongs to the phylib/phylink rewrite he also
asked for.
err_detach_tah keeps its order, with one caveat. A failure before
register_netdev() leaves reg_state at NETREG_UNINITIALIZED, where
netif_carrier_off() returns before it reaches linkwatch, so the
phy_disconnect() there cannot queue anything.
The caveat is a failed register_netdev(). It leaves the netdev
NETREG_UNREGISTERED, whether netdev_register_kobject() failed or the
NETDEV_REGISTER veto ran the rollback, so netif_carrier_off() no longer
returns early. If the state machine brought the carrier up between the
probe's own netif_carrier_off() and the failure, the phy_stop() inside
that phy_disconnect() queues one more event: after netdev_run_todo() has
drained the queue on the veto path, with no drain at all on the other.
That takes register_netdev() to fail, so I did not widen the error path
for it.
- [Medium] dev->phy is now filled in asynchronously.
The ordering is real: phy_start() only does phy_queue_state_machine(phydev,
0) and emac_adjust_link() just copies the resolved values into dev->phy, so
emac_open() can win the race and build MR1 from the probe defaults, and
since a fixed link never changes state again the callback will not fire a
second time to correct it.
I left the code alone in v4, but the commit message no longer implies the
speed is settled. It now carries this paragraph:
> phy_start() only queues the state machine, so an emac_open() that wins the
> race against the first emac_adjust_link() still builds MR1 from the probe
> defaults, and a fixed link never changes state again for a second callback
> to correct it. That window is the one the phy-handle path has always had,
> this driver starts its PHY at probe time rather than in ndo_open, and the
> next ifdown/ifup closes it.
Two things bound the window. It is not new: this driver has always started
its PHY from emac_init_phy() at probe time and never from ndo_open, so the
phy-handle path has the same race against its first ifup. And it is not
permanent: emac_open() runs emac_configure() on every open, so an
ifdown/ifup picks up the dev->phy values the callback filled in meanwhile.
What is permanent is the behaviour before this patch, where dev->phy.speed
stays SPEED_UNKNOWN, emac_configure() takes the default case, and the port
is programmed 10 Mbit/s half duplex with flow control off whatever the
fixed-link property says.
Making it deterministic means reading the link under link_lock before
emac_configure(), or reconfiguring from the callback, and the ethtool paths
already take link_lock before calling into phylib. That is the same
rewrite; I would rather do it there than bolt it onto a crash fix.
- [High, pre-existing] NULL mdio_read on the gpcs path.
Also correct. The branch returns before dev->phy.mdio_read, mdio_write and
gpcs_address are assigned, and emac_configure() reaches
emac_mii_reset_gpcs() -> gpcs_phy_read() on every open and reset_work, so a
sgmii/tbi/rtbi port in that branch dereferences NULL. arches.dts EMAC0
(sgmii, phy-map 0xffffffff, gpcs-address 0xa) is exactly that case. It is
untouched by this patch and predates it; I will send a separate fix.
- [Low] name baab9de385a8 in the commit message.
Done. The v4 commit message now says that baab9de385a8 ("net: ibm: emac:
use netdev's phydev directly") dropped
if (dev->phy_dev)
phy_disconnect(dev->phy_dev);
from emac_remove() along with dev->phy_dev, and that the emac_remove() hunk
restores it.
Cross compiled for powerpc out of ppc44x_defconfig with W=1, clean. No
hardware here, so no runtime test.
Regards,
Linkui
pw-bot: cr
prev parent reply other threads:[~2026-11-27 1:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 8:39 Linkui Xiao
2026-11-24 8:44 ` netdev-bot+sinfo
2026-11-24 13:50 ` Andrew Lunn
2026-11-27 1:47 ` Linkui Xiao
2026-11-25 9:01 ` netdev-bot+sashiko
2026-11-27 1:48 ` Linkui Xiao [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=20261127014800.2909048-1-xiaolinkui@126.com \
--to=xiaolinkui@126.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=chunkeey@gmail.com \
--cc=daniel.machon@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=jacob.e.keller@intel.com \
--cc=kees+treewide@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rosenp@gmail.com \
--cc=xiaolinkui@kylinos.cn \
/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
all inboxes | Powered by JetHome®