mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v2 1/2] net: ethtool: don't match a hwtstamp provider on a device without a PHC
       [not found] <20260923121644.2194183-1-nb@tipi-net.de>
@ 2026-09-23 12:16 ` Nicolai Buchwitz
  2026-09-23 13:00   ` Nicolai Buchwitz
  2026-09-23 12:16 ` [PATCH net v2 2/2] net: ethtool: let tsconfig reach a PHY-only timestamp provider Nicolai Buchwitz
  1 sibling, 1 reply; 3+ messages in thread
From: Nicolai Buchwitz @ 2026-09-23 12:16 UTC (permalink / raw)
  To: Andrew Lunn, Jakub Kicinski, David S. Miller, Eric Dumazet,
	Paolo Abeni, Simon Horman, Kory Maincent
  Cc: vadim.fedorenko, Nicolai Buchwitz, netdev, linux-kernel

A device without a PHC reports phc_index -1. A request for index
0xFFFFFFFF is stored in an int and becomes -1 too, so the two match and
a netdev provider is selected on a device that has none.

Fix this and only match a real PHC index.

Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
 net/ethtool/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index 23db40618fed..23e8282563cc 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -980,7 +980,7 @@ int ethtool_net_get_ts_info_by_phc(struct net_device *dev,
 	if (err)
 		return err;
 
-	if (info->phc_index == hwprov_desc->index &&
+	if (info->phc_index >= 0 && info->phc_index == hwprov_desc->index &&
 	    net_support_hwtstamp_qualifier(dev, hwprov_desc->qualifier))
 		return 0;
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net v2 2/2] net: ethtool: let tsconfig reach a PHY-only timestamp provider
       [not found] <20260923121644.2194183-1-nb@tipi-net.de>
  2026-09-23 12:16 ` [PATCH net v2 1/2] net: ethtool: don't match a hwtstamp provider on a device without a PHC Nicolai Buchwitz
@ 2026-09-23 12:16 ` Nicolai Buchwitz
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolai Buchwitz @ 2026-09-23 12:16 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Andrew Lunn, Kory Maincent
  Cc: vadim.fedorenko, Nicolai Buchwitz, netdev, linux-kernel

TSCONFIG_GET and TSCONFIG_SET reject a device that implements neither
hwtstamp NDO, even when its PHY can serve the request. The ioctls they
meant to replace handle it, so the two interfaces disagree on the same
hardware and user space has to pick one.

Drop the check on the get side, dev_get_hwtstamp_phylib() already fails
when there is no provider. On the set side also accept the default
timestamping PHY and move the check into ethnl_set_tsconfig() as the
validate callback runs without rtnl.

As this makes a netdev provider reachable without ndo_hwtstamp_get, test
for the callback before calling it.

Fixes: 6e9e2eed4f39 ("net: ethtool: Add support for tsconfig command to get/set hwtstamp config")
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
 net/core/dev_ioctl.c   |  3 ++-
 net/ethtool/tsconfig.c | 20 +++++---------------
 2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 164643140a52..f6029f60c1dc 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -267,7 +267,8 @@ int dev_get_hwtstamp_phylib(struct net_device *dev,
 		    hwprov->phydev)
 			return phy_hwtstamp_get(hwprov->phydev, cfg);
 
-		if (hwprov->source == HWTSTAMP_SOURCE_NETDEV)
+		if (hwprov->source == HWTSTAMP_SOURCE_NETDEV &&
+		    dev->netdev_ops->ndo_hwtstamp_get)
 			return dev->netdev_ops->ndo_hwtstamp_get(dev, cfg);
 
 		return -EOPNOTSUPP;
diff --git a/net/ethtool/tsconfig.c b/net/ethtool/tsconfig.c
index 6be3aa5d4bc1..2b1cdd9b5a23 100644
--- a/net/ethtool/tsconfig.c
+++ b/net/ethtool/tsconfig.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
 #include <linux/net_tstamp.h>
+#include <linux/phy.h>
 #include <linux/ptp_clock_kernel.h>
 #include <net/netdev_lock.h>
 
@@ -42,9 +43,6 @@ static int tsconfig_prepare_data(const struct ethnl_req_info *req_base,
 	struct kernel_hwtstamp_config cfg = {};
 	int ret;
 
-	if (!dev->netdev_ops->ndo_hwtstamp_get)
-		return -EOPNOTSUPP;
-
 	ret = ethnl_ops_begin(dev);
 	if (ret < 0)
 		return ret;
@@ -248,17 +246,6 @@ static int tsconfig_send_reply(struct net_device *dev, struct genl_info *info)
 	return ret;
 }
 
-static int ethnl_set_tsconfig_validate(struct ethnl_req_info *req_base,
-				       struct genl_info *info)
-{
-	const struct net_device_ops *ops = req_base->dev->netdev_ops;
-
-	if (!ops->ndo_hwtstamp_set || !ops->ndo_hwtstamp_get)
-		return -EOPNOTSUPP;
-
-	return 1;
-}
-
 static struct hwtstamp_provider *
 tsconfig_set_hwprov_from_desc(struct net_device *dev,
 			      struct genl_info *info,
@@ -313,6 +300,10 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
 	if (!netif_device_present(dev))
 		return -ENODEV;
 
+	if (!dev->netdev_ops->ndo_hwtstamp_set &&
+	    !phy_is_default_hwtstamp(dev->phydev))
+		return -EOPNOTSUPP;
+
 	if (tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER]) {
 		struct hwtstamp_provider_desc __hwprov_desc = {.index = -1};
 		struct hwtstamp_provider *__hwprov;
@@ -459,6 +450,5 @@ const struct ethnl_request_ops ethnl_tsconfig_request_ops = {
 	.reply_size		= tsconfig_reply_size,
 	.fill_reply		= tsconfig_fill_reply,
 
-	.set_validate		= ethnl_set_tsconfig_validate,
 	.set			= ethnl_set_tsconfig,
 };
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2 1/2] net: ethtool: don't match a hwtstamp provider on a device without a PHC
  2026-09-23 12:16 ` [PATCH net v2 1/2] net: ethtool: don't match a hwtstamp provider on a device without a PHC Nicolai Buchwitz
@ 2026-09-23 13:00   ` Nicolai Buchwitz
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolai Buchwitz @ 2026-09-23 13:00 UTC (permalink / raw)
  To: Andrew Lunn, Jakub Kicinski, David S. Miller, Eric Dumazet,
	Paolo Abeni, Simon Horman, Kory Maincent
  Cc: vadim.fedorenko, netdev, linux-kernel, maxime.chevallier, bjorn

+CC Maxime & Bjorn

On 23.9.2026 14:16, Nicolai Buchwitz wrote:
> A device without a PHC reports phc_index -1. A request for index
> 0xFFFFFFFF is stored in an int and becomes -1 too, so the two match and
> a netdev provider is selected on a device that has none.
> 
> Fix this and only match a real PHC index.
> 
> Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support 
> several hwtstamp by net topology")
> Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
> ---
>  net/ethtool/common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ethtool/common.c b/net/ethtool/common.c
> index 23db40618fed..23e8282563cc 100644
> --- a/net/ethtool/common.c
> +++ b/net/ethtool/common.c
> @@ -980,7 +980,7 @@ int ethtool_net_get_ts_info_by_phc(struct 
> net_device *dev,
>  	if (err)
>  		return err;
> 
> -	if (info->phc_index == hwprov_desc->index &&
> +	if (info->phc_index >= 0 && info->phc_index == hwprov_desc->index &&
>  	    net_support_hwtstamp_qualifier(dev, hwprov_desc->qualifier))
>  		return 0;

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-23 13:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20260923121644.2194183-1-nb@tipi-net.de>
2026-09-23 12:16 ` [PATCH net v2 1/2] net: ethtool: don't match a hwtstamp provider on a device without a PHC Nicolai Buchwitz
2026-09-23 13:00   ` Nicolai Buchwitz
2026-09-23 12:16 ` [PATCH net v2 2/2] net: ethtool: let tsconfig reach a PHY-only timestamp provider Nicolai Buchwitz

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®