Skip to contentSkip to conversation

neighbour: Move the netdev_put() out of RCU callback

PATCH In review Zqiang 2 participants 5 messages Oct 9 – Nov 7

Subsystems (2)
lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 neighbour: Move the netdev_put() out of RCU callback

For builts with CONFIG_NET_DEV_REFCNT_TRACKER=y kernels, netdev_put() records the caller's stack trace via ref_tracker_free() for debugging reference leaks. however, the netdev_put() is within pneigh_destroy() RCU callback, this recorded stack is uninformative, it does not reveal which code path initiated the deletion.

This commit therefore move netdev_put() from the RCU callback into the caller's process context, and replace call_rcu() with kfree_rcu().

Fixes d539d8fbd8fc ("neighbour: Free pneigh_entry after RCU grace period.")
---
 net/core/neighbour.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
net/core/neighbour.c +4 -10
index 6ed8eb075146..4263689fc415 100644
@@ -818,14 +818,6 @@ int pneigh_create(struct neigh_table *tbl,
 	return err;
 }
 
-static void pneigh_destroy(struct rcu_head *rcu)
-{
-	struct pneigh_entry *n = container_of(rcu, struct pneigh_entry, rcu);
-
-	netdev_put(n->dev, &n->dev_tracker);
-	kfree(n);
-}
-
 int pneigh_delete(struct neigh_table *tbl, const void *pkey,
 		  struct net_device *dev)
 {
@@ -849,7 +841,8 @@ int pneigh_delete(struct neigh_table *tbl, const void *pkey,
 			if (tbl->pdestructor)
 				tbl->pdestructor(n);
 
-			call_rcu(&n->rcu, pneigh_destroy);
+			netdev_put(n->dev, &n->dev_tracker);
+			kfree_rcu(n, rcu);
 			return 0;
 		}
 	}
@@ -891,7 +884,8 @@ static void pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev,
 		if (tbl->pdestructor)
 			tbl->pdestructor(n);
 
-		call_rcu(&n->rcu, pneigh_destroy);
+		netdev_put(n->dev, &n->dev_tracker);
+		kfree_rcu(n, rcu);
 	}
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · Zqiang

For builts with CONFIG_NET_DEV_REFCNT_TRACKER=y kernels, netdev_put() records the caller's stack trace via ref_tracker_free() for debugging reference leaks. however, the netdev_put() is within pneigh_destroy() RCU callback, this recorded stack is uninformative, it does not reveal which code path initiated the deletion.

Have you seen pneigh double-free ? What motivates this change ?

Quoted 5 lines

This commit therefore move netdev_put() from the RCU callback into the caller's process context, and replace call_rcu() with kfree_rcu().

Fixes d539d8fbd8fc ("neighbour: Free pneigh_entry after RCU grace period.")

Please elaborate why your change is safe in the commit message and remove the tag.

Quoted 1 line

nit: full name

Quoted 46 lines
---
 net/core/neighbour.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
net/core/neighbour.c +4 -11
index 6ed8eb075146..4263689fc415 100644
@@ -818,14 +818,6 @@ int pneigh_create(struct neigh_table *tbl,
        return err;
 }
 
-static void pneigh_destroy(struct rcu_head *rcu)
-{
-       struct pneigh_entry *n = container_of(rcu, struct pneigh_entry, rcu);
-
-       netdev_put(n->dev, &n->dev_tracker);
-       kfree(n);
-}
-
 int pneigh_delete(struct neigh_table *tbl, const void *pkey,
                  struct net_device *dev)
 {
@@ -849,7 +841,8 @@ int pneigh_delete(struct neigh_table *tbl, const void *pkey,
                        if (tbl->pdestructor)
                                tbl->pdestructor(n);
 
-                       call_rcu(&n->rcu, pneigh_destroy);
+                       netdev_put(n->dev, &n->dev_tracker);
+                       kfree_rcu(n, rcu);
                        return 0;
                }
        }
@@ -891,7 +884,8 @@ static void pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev,
                if (tbl->pdestructor)
                        tbl->pdestructor(n);
 
-               call_rcu(&n->rcu, pneigh_destroy);
+               netdev_put(n->dev, &n->dev_tracker);
+               kfree_rcu(n, rcu);
        }
 }
 
--

2.17.1

author
#2 lore raw
Quoted 11 lines · Zqiang
Quoted 8 lines

For builts with CONFIG_NET_DEV_REFCNT_TRACKER=y kernels, netdev_put()
records the caller's stack trace via ref_tracker_free() for debugging reference leaks. however, the netdev_put() is within pneigh_destroy() RCU callback, this recorded stack is uninformative, it does not reveal which code path initiated the deletion.

Have you seen pneigh double-free ? What motivates this change ?

Firstly, Apologies for delayed reply.

Actually, I didn't see any double-free happening, just wanted it to record a meaningful callstack which on release path. After all, if double-free really occurs, the callstack of the RCU callback execution path will not be helpful.

Quoted 9 lines
Quoted 7 lines

This commit therefore move netdev_put() from the RCU callback into the
caller's process context, and replace call_rcu() with kfree_rcu().

Fixes d539d8fbd8fc ("neighbour: Free pneigh_entry after RCU grace period.")

Please elaborate why your change is safe in the commit message and remove the tag.

Does it refer to using kfree_rcu instead of call_rcu ensures safely ?

Thanks
Zqiang

Quoted 54 lines
Quoted 4 lines

nit: full name

Quoted 47 lines
---
 net/core/neighbour.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 6ed8eb075146..4263689fc415 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -818,14 +818,6 @@ int pneigh_create(struct neigh_table *tbl, return err;
}

-static void pneigh_destroy(struct rcu_head *rcu)
-{
- struct pneigh_entry *n = container_of(rcu, struct pneigh_entry, rcu); -
- netdev_put(n->dev, &n->dev_tracker);
- kfree(n);
-}
-
int pneigh_delete(struct neigh_table *tbl, const void *pkey,
struct net_device *dev)
{
@@ -849,7 +841,8 @@ int pneigh_delete(struct neigh_table *tbl, const void *pkey, if (tbl->pdestructor)
tbl->pdestructor(n);

- call_rcu(&n->rcu, pneigh_destroy);
+ netdev_put(n->dev, &n->dev_tracker);
+ kfree_rcu(n, rcu);
return 0;
}
}
@@ -891,7 +884,8 @@ static void pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev, if (tbl->pdestructor)
tbl->pdestructor(n);

- call_rcu(&n->rcu, pneigh_destroy);
+ netdev_put(n->dev, &n->dev_tracker);
+ kfree_rcu(n, rcu);
}
}

--
2.17.1

#3 lore raw
Quoted 26 lines · Zqiang
Quoted 11 lines · Zqiang
Quoted 8 lines

For builts with CONFIG_NET_DEV_REFCNT_TRACKER=y kernels, netdev_put()
records the caller's stack trace via ref_tracker_free() for debugging reference leaks. however, the netdev_put() is within pneigh_destroy() RCU callback, this recorded stack is uninformative, it does not reveal which code path initiated the deletion.

Have you seen pneigh double-free ? What motivates this change ?

Firstly, Apologies for delayed reply.

Actually, I didn't see any double-free happening, just wanted it to record a meaningful callstack which on release path. After all, if double-free really occurs, the callstack of the RCU callback execution path will not be helpful.

Quoted 5 lines
Quoted 5 lines

This commit therefore move netdev_put() from the RCU callback into the
caller's process context, and replace call_rcu() with kfree_rcu().

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Fixes d539d8fbd8fc ("neighbour: Free pneigh_entry after RCU grace period.")

Please elaborate why your change is safe in the commit message and remove the tag.

Does it refer to using kfree_rcu instead of call_rcu ensures safely ?

I mean why dropping netdev refcnt waiting RCU gp is safe.

Quoted 58 lines

Thanks
Zqiang

Quoted 54 lines
Quoted 4 lines

nit: full name

Quoted 47 lines
---
 net/core/neighbour.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 6ed8eb075146..4263689fc415 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -818,14 +818,6 @@ int pneigh_create(struct neigh_table *tbl, return err;
}

-static void pneigh_destroy(struct rcu_head *rcu)
-{
- struct pneigh_entry *n = container_of(rcu, struct pneigh_entry, rcu); -
- netdev_put(n->dev, &n->dev_tracker);
- kfree(n);
-}
-
int pneigh_delete(struct neigh_table *tbl, const void *pkey,
struct net_device *dev)
{
@@ -849,7 +841,8 @@ int pneigh_delete(struct neigh_table *tbl, const void *pkey, if (tbl->pdestructor)
tbl->pdestructor(n);

- call_rcu(&n->rcu, pneigh_destroy);
+ netdev_put(n->dev, &n->dev_tracker);
+ kfree_rcu(n, rcu);
return 0;
}
}
@@ -891,7 +884,8 @@ static void pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev, if (tbl->pdestructor)
tbl->pdestructor(n);

- call_rcu(&n->rcu, pneigh_destroy);
+ netdev_put(n->dev, &n->dev_tracker);
+ kfree_rcu(n, rcu);
}
}

--
2.17.1

#4 lore raw
Quoted 27 lines · Kuniyuki Iwashima
Quoted 26 lines · Zqiang
Quoted 11 lines · Zqiang
Quoted 8 lines

For builts with CONFIG_NET_DEV_REFCNT_TRACKER=y kernels, netdev_put()
records the caller's stack trace via ref_tracker_free() for debugging reference leaks. however, the netdev_put() is within pneigh_destroy() RCU callback, this recorded stack is uninformative, it does not reveal which code path initiated the deletion.

Have you seen pneigh double-free ? What motivates this change ?

Firstly, Apologies for delayed reply.

Actually, I didn't see any double-free happening, just wanted it to record a meaningful callstack which on release path. After all, if double-free really occurs, the callstack of the RCU callback execution path will not be helpful.

Quoted 5 lines
Quoted 5 lines

This commit therefore move netdev_put() from the RCU callback into the
caller's process context, and replace call_rcu() with kfree_rcu().

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Fixes d539d8fbd8fc ("neighbour: Free pneigh_entry after RCU grace period.")

Please elaborate why your change is safe in the commit message and remove the tag.

Does it refer to using kfree_rcu instead of call_rcu ensures safely ?

I mean why dropping netdev refcnt waiting RCU gp is safe.

*without waiting

Quoted 60 lines
Quoted 60 lines

Thanks
Zqiang

Quoted 54 lines
Quoted 4 lines

nit: full name

Quoted 47 lines
---
 net/core/neighbour.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 6ed8eb075146..4263689fc415 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -818,14 +818,6 @@ int pneigh_create(struct neigh_table *tbl, return err;
}

-static void pneigh_destroy(struct rcu_head *rcu)
-{
- struct pneigh_entry *n = container_of(rcu, struct pneigh_entry, rcu); -
- netdev_put(n->dev, &n->dev_tracker);
- kfree(n);
-}
-
int pneigh_delete(struct neigh_table *tbl, const void *pkey,
struct net_device *dev)
{
@@ -849,7 +841,8 @@ int pneigh_delete(struct neigh_table *tbl, const void *pkey, if (tbl->pdestructor)
tbl->pdestructor(n);

- call_rcu(&n->rcu, pneigh_destroy);
+ netdev_put(n->dev, &n->dev_tracker);
+ kfree_rcu(n, rcu);
return 0;
}
}
@@ -891,7 +884,8 @@ static void pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev, if (tbl->pdestructor)
tbl->pdestructor(n);

- call_rcu(&n->rcu, pneigh_destroy);
+ netdev_put(n->dev, &n->dev_tracker);
+ kfree_rcu(n, rcu);
}
}

--
2.17.1