Re: [PATCH v4 7/7] net: register debugfs file for net_device refcnt tracker

From: Eric Dumazet
Date: Thu Apr 24 2025 - 19:07:38 EST


On Thu, Apr 24, 2025 at 3:52 PM Jakub Kicinski <kuba@xxxxxxxxxx> wrote:

> But with all that said, I guess you still want the "meaningful" ID for
> the netns, and that one is in fact stable :S

We could add a stable id for net devices, and use it for this purpose

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 0321fd952f70887735ac789d72f72948a3879832..339d09167eaf7f58fc877fa470c94175237ce534
100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2544,6 +2544,8 @@ struct net_device {

struct hwtstamp_provider __rcu *hwprov;

+ u64 permanent_id;
+
u8 priv[] ____cacheline_aligned
__counted_by(priv_len);
} ____cacheline_aligned;
diff --git a/net/core/dev.c b/net/core/dev.c
index d1a8cad0c99c47996e8bda44bf220266a5e51102..9d2d45e0246fab99ad3e7523885224bd114fa686
100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10954,6 +10954,9 @@ int register_netdevice(struct net_device *dev)
{
int ret;
struct net *net = dev_net(dev);
+ static atomic64_t permanent_id;
+
+ dev->permanent_id = atomic64_inc_return(&permanent_id);

BUILD_BUG_ON(sizeof(netdev_features_t) * BITS_PER_BYTE <
NETDEV_FEATURE_COUNT);