Skip to contentSkip to conversation

udp_tunnel_nic: add net device refcount tracker

PATCH In review [email protected] 3 participants 3 messages Aug 4, 2023 – Aug 5, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udp_tunnel_nic: add net device refcount tracker

From: xu xin <[email protected]>

Add net device refcount tracker to udp_tunnel_nic.c.

---
 net/ipv4/udp_tunnel_nic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv4/udp_tunnel_nic.c +5 -2
index 029219749785..ce8f5c82b0a1 100644
@@ -55,6 +55,9 @@ struct udp_tunnel_nic {
  */
 static struct workqueue_struct *udp_tunnel_nic_workqueue;
 
+/* To track netdev_hold and netdev_put */
+static netdevice_tracker udp_tunnel_nic_devtracker;
+
 static const char *udp_tunnel_nic_tunnel_type_name(unsigned int type)
 {
 	switch (type) {
@@ -825,7 +828,7 @@ static int udp_tunnel_nic_register(struct net_device *dev)
 	}
 
 	utn->dev = dev;
-	dev_hold(dev);
+	netdev_hold(dev, &udp_tunnel_nic_devtracker, GFP_KERNEL);
 	dev->udp_tunnel_nic = utn;
 
 	if (!(info->flags & UDP_TUNNEL_NIC_INFO_OPEN_ONLY))
@@ -879,7 +882,7 @@ udp_tunnel_nic_unregister(struct net_device *dev, struct udp_tunnel_nic *utn)
 	udp_tunnel_nic_free(utn);
 release_dev:
 	dev->udp_tunnel_nic = NULL;
-	dev_put(dev);
+	netdev_put(dev, &udp_tunnel_nic_devtracker);
 }
 
 static int
Signature · 1 line
2.15.2
#1 lore raw
Quoted 17 lines · On Fri, Aug 4, 2023 at 10:50 AM <[email protected]> wrote:

From: xu xin <[email protected]>

Add net device refcount tracker to udp_tunnel_nic.c.

---
 net/ipv4/udp_tunnel_nic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv4/udp_tunnel_nic.c +0 -0
index 029219749785..ce8f5c82b0a1 100644

net/ipv4/udp_tunnel_nic.c struct udp_tunnel_nic { · line 59

Quoted 5 lines
net/ipv4/udp_tunnel_nic.c +2 -0
@@ -55,6 +55,9 @@ struct udp_tunnel_nic {
  */
 static struct workqueue_struct *udp_tunnel_nic_workqueue;
 
+/* To track netdev_hold and netdev_put */
+static netdevice_tracker udp_tunnel_nic_devtracker;

This looks wrong.

net/ipv4/udp_tunnel_nic.c static int udp_tunnel_nic_register(struct net_device *dev) · line 831

Quoted 10 lines
net/ipv4/udp_tunnel_nic.c +2 -1
+
 static const char *udp_tunnel_nic_tunnel_type_name(unsigned int type)
 {
        switch (type) {
@@ -825,7 +828,7 @@ static int udp_tunnel_nic_register(struct net_device *dev)
        }
 
        utn->dev = dev;
-       dev_hold(dev);
+       netdev_hold(dev, &udp_tunnel_nic_devtracker, GFP_KERNEL);

This is wrong. You need a separate netdevice_tracker per netdev_hold()

For instance, this would need to be in "(struct udp_tunnel_nic)->dev_tracker"

Quoted 14 lines
net/ipv4/udp_tunnel_nic.c +1 -2
        dev->udp_tunnel_nic = utn;
 
        if (!(info->flags & UDP_TUNNEL_NIC_INFO_OPEN_ONLY))
@@ -879,7 +882,7 @@ udp_tunnel_nic_unregister(struct net_device *dev, struct udp_tunnel_nic *utn)
        udp_tunnel_nic_free(utn);
 release_dev:
        dev->udp_tunnel_nic = NULL;
-       dev_put(dev);
+       netdev_put(dev, &udp_tunnel_nic_devtracker);
 }
 
 static int
--

2.15.2

#2 lore raw
Quoted 24 lines
Quoted 9 lines
---
 net/ipv4/udp_tunnel_nic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv4/udp_tunnel_nic.c +0 -0
index 029219749785..ce8f5c82b0a1 100644

net/ipv4/udp_tunnel_nic.c struct udp_tunnel_nic { · line 59

Quoted 5 lines
net/ipv4/udp_tunnel_nic.c +2 -0
@@ -55,6 +55,9 @@ struct udp_tunnel_nic {
  */
 static struct workqueue_struct *udp_tunnel_nic_workqueue;
 
+/* To track netdev_hold and netdev_put */
+static netdevice_tracker udp_tunnel_nic_devtracker;

This looks wrong.

Quoted 7 lines
net/ipv4/udp_tunnel_nic.c +1 -0
+
 static const char *udp_tunnel_nic_tunnel_type_name(unsigned int type)
 {
        switch (type) {
@@ -825,7 +828,7 @@ static int udp_tunnel_nic_register(struct net_device *dev)
        }
 
Quoted 7 lines

net/ipv4/udp_tunnel_nic.c static int udp_tunnel_nic_register(struct net_device *dev) · line 831

Quoted 3 lines
net/ipv4/udp_tunnel_nic.c +1 -1
        utn->dev = dev;
-       dev_hold(dev);
+       netdev_hold(dev, &udp_tunnel_nic_devtracker, GFP_KERNEL);

This is wrong. You need a separate netdevice_tracker per netdev_hold()

For instance, this would need to be in "(struct udp_tunnel_nic)->dev_tracker"

Oh, Sorry, I misunderstand the usage of netdev_hold and its netdevice_tracker.

But cound you please add this this useful information into netdev_hold()' comment,

to prevent others from making the same mistakes with me.

Thanks!