From: Hui Peng <benquike@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>, Jakub Kicinski <kuba@kernel.org>
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Kory Maincent <kory.maincent@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ethtool: tsinfo: release net_device reference in ethnl_tsinfo_start()
Date: Sat, 19 Sep 2026 20:48:03 +0000 [thread overview]
Message-ID: <20260919204803.2811673-1-benquike@gmail.com> (raw)
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
next reply other threads:[~2026-09-19 20:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 20:48 Hui Peng [this message]
2026-09-23 21:11 ` [PATCH] ethtool: tsinfo: release net_device reference in ethnl_tsinfo_start() netdev-bot+sashiko
2026-09-24 16:07 ` Jakub Kicinski
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=20260919204803.2811673-1-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.