mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ethtool: tsinfo: release net_device reference in ethnl_tsinfo_start()
@ 2026-09-19 20:48 Hui Peng
  0 siblings, 0 replies; only message in thread
From: Hui Peng @ 2026-09-19 20:48 UTC (permalink / raw)
  To: Andrew Lunn, Jakub Kicinski
  Cc: David S . Miller, Eric Dumazet, Paolo Abeni, Kory Maincent,
	netdev, linux-kernel

Unlike ethnl_default_start(), ethnl_tsinfo_start() keeps the net_device
reference acquired by ethnl_parse_header_dev_get() in
ctx->req_info->base.dev until ethnl_tsinfo_done().

When a Netlink dump (NLM_F_DUMP) of ETHTOOL_MSG_TSINFO_GET specifying a
device header fails on its initial netlink_dump() invocation (for
example, with -ENOBUFS when sk_rmem_alloc >= sk_rcvbuf), Netlink keeps
cb->cb_running = true without calling cb->done(). As long as the Netlink
socket remains open, the netdev_hold() reference is held, causing
unregister_netdevice() to hang indefinitely when the device is removed.

Save dev->ifindex in ctx->pos_ifindex with ctx->single_dev = true and
immediately release req_info->base.dev via ethnl_parse_header_dev_put()
in ethnl_tsinfo_start(), looking up the device transiently by ifindex
inside ethnl_tsinfo_dumpit().

Fixes: b9e3f7dc9ed9 ("net: ethtool: tsinfo: Enhance tsinfo to support several hwtstamp by net topology")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c
--- a/net/ethtool/tsinfo.c
+++ b/net/ethtool/tsinfo.c
@@ -295,6 +295,7 @@ struct ethnl_tsinfo_dump_ctx {
 	struct tsinfo_reply_data	*reply_data;
 	unsigned long			pos_ifindex;
 	bool				netdev_dump_done;
+	bool				single_dev;
 	unsigned long			pos_phyindex;
 	enum hwtstamp_provider_qualifier pos_phcqualifier;
 };
@@ -476,12 +477,15 @@ int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 	struct net *net = sock_net(skb->sk);
 	int ret = 0;
 
-	if (ctx->req_info->base.dev) {
-		struct net_device *dev = ctx->req_info->base.dev;
+	if (ctx->single_dev) {
+		struct net_device *dev = dev_get_by_index(net, ctx->pos_ifindex);
 
+		if (!dev)
+			return -ENODEV;
 		netdev_lock_ops_compat(dev);
 		ret = ethnl_tsinfo_dump_one_net_topo(skb, dev, cb);
 		netdev_unlock_ops_compat(dev);
+		dev_put(dev);
 		return ret;
 	}
 
@@ -533,6 +537,13 @@ int ethnl_tsinfo_start(struct netlink_callback *cb)
 	ctx->req_info = req_info;
 	ctx->reply_data = reply_data;
 	ctx->pos_ifindex = 0;
+	ctx->single_dev = false;
+	if (req_info->base.dev) {
+		ctx->pos_ifindex = req_info->base.dev->ifindex;
+		ctx->single_dev = true;
+		ethnl_parse_header_dev_put(&req_info->base);
+		req_info->base.dev = NULL;
+	}
 	ctx->pos_phyindex = 0;
 	ctx->netdev_dump_done = false;
 	ctx->pos_phcqualifier = HWTSTAMP_PROVIDER_QUALIFIER_PRECISE;
-- 
2.43.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-19 20:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-19 20:48 [PATCH] ethtool: tsinfo: release net_device reference in ethnl_tsinfo_start() Hui Peng

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®