From: Linkui Xiao <xiaolinkui@126.com>
To: Stanislav Fomichev <sdf.kernel@gmail.com>
Cc: andrew@lunn.ch, kuba@kernel.org, davem@davemloft.net,
edumazet@kernel.org, pabeni@redhat.com, horms@kernel.org,
sdf@fomichev.me, jacob.e.keller@intel.com, bjorn@kernel.org,
alexanderduyck@fb.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Linkui Xiao <xiaolinkui@kylinos.cn>
Subject: Re: [PATCH net-next] net: ethtool: request rtnl_lock for ETHTOOL_MSG_PORT_GET
Date: Mon, 16 Nov 2026 10:54:21 +0800 [thread overview]
Message-ID: <cc161d10-9f0f-4074-888e-161f3399a10d@126.com> (raw)
In-Reply-To: <avX2MdTZePW5ssrq@devvm16445.scu0.facebook.com>
Hi Stanislav,
On 2026/11/13 01:24, Stanislav Fomichev wrote:
> On 11/11, Linkui Xiao wrote:
>> From: Linkui Xiao <xiaolinkui@kylinos.cn>
>>
>> port_prepare_data() resolves the requested port through
>> phy_link_topo_get_port(), which requires rtnl_lock to be held before it
>> reads topo->ports:
>>
>> /* ports in the topo are RTNL protected, but may be accessed under
>> * netdev_lock for ops-locked devices. For now keep them under rtnl
>> * protection, as no ops-locked devices have phy_port capabilities
>> * yet.
>> */
>> ASSERT_RTNL();
>>
>> The dump side honours this, port_dump_one_dev() takes rtnl_lock()
>> itself. The doit side does not. ETHTOOL_MSG_PORT_GET is served by
>> ethnl_default_doit(), which keeps rtnl_lock only when the device is not
>> ops-locked, or when ethtool_nl_msg_needs_rtnl() asks for it:
>>
>> need_rtnl = !netdev_need_ops_lock(req_info->dev) ||
>> ethtool_nl_msg_needs_rtnl(req_info->dev, cmd);
>>
>> ethtool_nl_msg_needs_rtnl() has no case for ETHTOOL_MSG_PORT_GET and
>> falls through to "return false", so on a device that opts into the
>> instance lock (request_ops_lock, queue_mgmt_ops or net_shaper_ops)
>> PORT_GET runs with netdev_lock only. Such a device that does have a
>> link topology trips the ASSERT_RTNL() warning and reads topo->ports
>> without the protection the xarray is documented to need.
>>
>> Add the missing case. Like TSCONFIG_GET/SET, PORT_GET has no
>> corresponding ethtool ioctl, so it is Netlink-only and always needs
>> rtnl_lock.
>
> [..]
>
>> The bug is latent as no device opts into the instance lock while also
>> carrying a link topology, so it cannot be observed yet and the change is
>> compile-tested only.
>
> Then why fix it if there is no bug? And phy_link_topo_add_port has
> a big comment explaining the expectations?
You are right, and I withdraw the patch. It fixes nothing, and the comment
you point at is why.
phy_link_topo_get_port() returns before the ASSERT_RTNL() when the netdev
has no topology:
struct phy_link_topology *topo = dev->link_topo;
if (!topo)
return NULL;
ASSERT_RTNL();
and dev->link_topo is only ever allocated from phy_link_topo_get_or_alloc(),
i.e. from phy_link_topo_add_port() and phy_link_topo_add_phy(). Both refuse
an ops-locked device before they get that far:
/* Ports can now be queried without rtnl for ops-locked devices, which
* we don't support now as port retrieval is done under rtnl.
*/
if (WARN_ON_ONCE(dev->netdev_ops && netdev_need_ops_lock(dev)))
return -EOPNOTSUPP;
(phy_link_topo_add_phy() has an equivalent check.) So an ops-locked device
never has a topology to begin with: port_prepare_data() gets NULL back from
phy_link_topo_get_port() and returns -ENODEV, well before the assert.
With my patch applied it would take rtnl_lock() and still return -ENODEV,
so the patch is a no-op that only adds a lock - not something I want to
send. For devices that are not ops-locked need_rtnl is already true, so
the assert is satisfied today.
My commit message was wrong on the point that mattered: it claimed such a
device trips the warning, when the guard at the producer makes that state
unrepresentable. I should have read the expected design out of that comment
first - retrieval stays rtnl-only until an ops-locked device actually grows
phy_ports, and whoever wires that up will have to move the reader to the
instance lock instead of threading rtnl_lock() through ethtool.
The other topology readers gate their assert on the topology existing as
well (ethnl_req_get_phydev() uses phy_link_topo_empty()), so they are not
separate instances of the same issue.
The patch is already marked rejected in patchwork. Thanks for the pointer.
Regards,
Linkui
next prev parent reply other threads:[~2026-11-16 2:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 7:27 Linkui Xiao
2026-11-12 17:24 ` Stanislav Fomichev
2026-11-16 2:54 ` Linkui Xiao [this message]
2026-11-15 7:42 ` netdev-bot+sashiko
2026-11-16 3:09 ` Linkui Xiao
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=cc161d10-9f0f-4074-888e-161f3399a10d@126.com \
--to=xiaolinkui@126.com \
--cc=alexanderduyck@fb.com \
--cc=andrew@lunn.ch \
--cc=bjorn@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf.kernel@gmail.com \
--cc=sdf@fomichev.me \
--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®