Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message for "net: ethtool: tsconfig: allow selecting a
provider" is inaccurate and leaves out user-visible effects.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but this patch
makes it reachable on more devices: dev->hwprov->phydev can be left…
--
net: ethtool: tsconfig: allow selecting a provider
This patch relaxes the early check in ethnl_set_tsconfig(). A request that
carries ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER is now accepted even when the
device has no ndo_hwtstamp_set(), no default PHY time stamper and no
previously selected dev->hwprov. In that case the call that disables the
current time stamping config is skipped before the new provider is
installed.
> A hwtstamp provider can obly ne selected with ETHTOOL_MSG_TSCONFIG_SET
> when the device already has an active time stamping source: a MAC
> implementing ndo_hwtstamp_set(), a PHY flagged as default_timestamp, or
> a previously selected dev->hwprov.
>
> This patch makes it possible to select a PHY time stamper on a MAC
> without time stamping support. New phy drivers are expected to reply on
> dev->hwprov rather than default_timestamp.
[ ... ]
> Changes in v5:
> - new file.
[Severity: Low]
This isn't a bug, but there are some typos and inaccuracies here:
"obly ne selected" should be "only be selected".
"expected to reply on" should be "expected to rely on".
"new file" is wrong, since the patch doesn't add a file.
The subject "allow selecting a provider" sounds as if provider selection
wasn't possible before. What is actually new is that a provider can be
selected on a device with no hw timestamping source at all. Could the
subject say that?
The message sets a policy that PHY drivers should rely on dev->hwprov
rather than default_timestamp. Should it also say what this means for the
legacy interfaces?
Take a MAC without ndo_hwtstamp_set, such as r8169, with no hwprov selected
and default_timestamp false. In that case dev_set_hwtstamp_phylib() ends up
with phy_ts == false:
net/core/dev_ioctl.c:dev_set_hwtstamp_phylib() {
...
if (!phy_ts || dev->see_all_hwtstamp_requests) {
if (!ops->ndo_hwtstamp_set)
return -EOPNOTSUPP;
...
}
On the same device:
dev_get_hwtstamp_phylib() also returns -EOPNOTSUPP.
__ethtool_get_ts_info() reports only the MAC's get_ts_info.
So users of SIOCSHWTSTAMP, SIOCGHWTSTAMP and ETHTOOL_GET_TS_INFO, such as
ptp4l, can't find or use the PHY time stamper until something selects it
with ETHTOOL_MSG_TSCONFIG_SET. The RTL8127a PHY driver later in the series
doesn't set default_timestamp, so it is affected. The kernel-doc of
phy_is_default_hwtstamp() may also be a good place to document this
policy.
The errno that userspace sees also changes. Before this patch, a
TSCONFIG_SET with a provider on a device without hw timestamping failed
right away with -EOPNOTSUPP. It now goes through
tsconfig_set_hwprov_from_desc():
net/ethtool/tsconfig.c:tsconfig_set_hwprov_from_desc() {
...
ret = ethtool_net_get_ts_info_by_phc(dev, &ts_info, hwprov_desc);
if (!ret && dev->netdev_ops->ndo_hwtstamp_set) {
/* Found */
source = HWTSTAMP_SOURCE_NETDEV;
} else {
phy = ethtool_phy_get_ts_info_by_phc(dev, &ts_info, hwprov_desc);
if (IS_ERR(phy)) {
if (PTR_ERR(phy) == -ENODEV)
NL_SET_ERR_MSG_ATTR(info->extack,
tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER],
"phc not in this net device topology");
...
}
This path can return -ENODEV with "phc not in this net device topology" in
three cases:
The PHC is not a topology PHY.
The qualifier is not PRECISE.
The PHC is the MAC's own, as reported by get_ts_info, but the MAC lacks
ndo_hwtstamp_set.
In the last case the message is misleading. Should the commit message
mention the errno change? Is this extack text right for the MAC PHC case?
> diff --git a/net/ethtool/tsconfig.c b/net/ethtool/tsconfig.c
> index 2db0e7ba8b9f5..9c983666a1b02 100644
> --- a/net/ethtool/tsconfig.c
> +++ b/net/ethtool/tsconfig.c
> @@ -300,14 +300,16 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
[ ... ]
> - if (!dev->netdev_ops->ndo_hwtstamp_set &&
> - !phy_is_default_hwtstamp(dev->phydev) &&
> - !netdev_ops_lock_dereference(dev->hwprov, dev))
> + has_hwts = dev->netdev_ops->ndo_hwtstamp_set ||
> + phy_is_default_hwtstamp(dev->phydev) ||
> + netdev_ops_lock_dereference(dev->hwprov, dev);
> + if (!has_hwts && !tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER])
> return -EOPNOTSUPP;
[Severity: High]
This isn't a bug introduced by this patch, but the patch makes it reachable
on more devices. PHY-only provider selection now works on MACs without hw
timestamping. Can dev->hwprov->phydev then be left pointing at a freed SFP
module PHY on those devices too?
tsconfig_set_hwprov_from_desc() stores the phy_device pointer without
taking a reference:
hwprov->phydev = phy;
That phy comes from ethtool_phy_get_ts_info_by_phc(). It walks every PHY in
dev->link_topo, including a module PHY behind a PHY-driven SFP cage.
The only teardown code that clears a PHY-backed dev->hwprov is in
phy_detach():
drivers/net/phy/phy_device.c:phy_detach() {
...
if (hwprov && hwprov->phydev == phydev) {
rcu_assign_pointer(dev->hwprov, NULL);
kfree_rcu(hwprov, rcu_head);
}
...
}
A module PHY behind a PHY-driven cage is never attached with
phy_attach_direct(). When the module is removed, this is the path:
sfp_sm_phy_detach()
sfp_remove_phy()
phy_sfp_disconnect_phy()
phy_link_topo_del_phy(dev, phy);
phy_device_remove(sfp->mod_phy);
phy_device_free(sfp->mod_phy);
Nothing on that path checks or clears dev->hwprov. Afterwards,
skb_clone_tx_timestamp() and skb_defer_rx_timestamp() would load
hwprov->phydev, read phydev->mii_ts, and call mii_ts->txtstamp() or
mii_ts->rxtstamp() through freed memory. dev_set_hwtstamp_phylib() and
dev_get_hwtstamp_phylib() dereference the same stale pointer.
Before this patch, selecting such a PHY needed a MAC with ndo_hwtstamp_set
or another hw timestamping source. Does anything clear dev->hwprov when the
SFP module PHY is removed from the link topology?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40realsil.com.cn