[PATCH 7/7] netpoll: Flush skb_pool as part of netconsole cleanup

Breno Leitao posted 7 patches 1 month ago
[PATCH 7/7] netpoll: Flush skb_pool as part of netconsole cleanup
Posted by Breno Leitao 1 month ago
Transfer the skb_pool_flush() function from netpoll to netconsole, and
call it within netpoll_cleanup() to ensure skb pool resources are
properly released once the device is down.

The invocation of skb_pool_flush() was removed from netpoll_setup(), as
the pool is now only managed after successful allocation.

This complete the move of skb pool management from netpoll to
netconsole.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 drivers/net/netconsole.c | 10 ++++++++++
 net/core/netpoll.c       | 15 +--------------
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index bf7bab7a9c2f0..b9bfb78560b3c 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -300,12 +300,22 @@ static struct netconsole_target *alloc_and_init(void)
 	return nt;
 }
 
+static void skb_pool_flush(struct netpoll *np)
+{
+	struct sk_buff_head *skb_pool;
+
+	cancel_work_sync(&np->refill_wq);
+	skb_pool = &np->skb_pool;
+	skb_queue_purge_reason(skb_pool, SKB_CONSUMED);
+}
+
 static void netpoll_cleanup(struct netpoll *np)
 {
 	rtnl_lock();
 	if (!np->dev)
 		goto out;
 	do_netpoll_cleanup(np);
+	skb_pool_flush(np);
 out:
 	rtnl_unlock();
 }
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 5aa83c9c09e05..c0eeeb9ac3daf 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -326,15 +326,6 @@ netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
 }
 EXPORT_SYMBOL(netpoll_send_skb);
 
-static void skb_pool_flush(struct netpoll *np)
-{
-	struct sk_buff_head *skb_pool;
-
-	cancel_work_sync(&np->refill_wq);
-	skb_pool = &np->skb_pool;
-	skb_queue_purge_reason(skb_pool, SKB_CONSUMED);
-}
-
 int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
 {
 	struct netpoll_info *npinfo;
@@ -547,7 +538,7 @@ int netpoll_setup(struct netpoll *np)
 
 	err = __netpoll_setup(np, ndev);
 	if (err)
-		goto flush;
+		goto put;
 	rtnl_unlock();
 
 	/* Make sure all NAPI polls which started before dev->npinfo
@@ -558,8 +549,6 @@ int netpoll_setup(struct netpoll *np)
 
 	return 0;
 
-flush:
-	skb_pool_flush(np);
 put:
 	DEBUG_NET_WARN_ON_ONCE(np->dev);
 	if (ip_overwritten)
@@ -607,8 +596,6 @@ static void __netpoll_cleanup(struct netpoll *np)
 		call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
 	} else
 		RCU_INIT_POINTER(np->dev->npinfo, NULL);
-
-	skb_pool_flush(np);
 }
 
 void __netpoll_free(struct netpoll *np)

-- 
2.47.3
Re: [PATCH 7/7] netpoll: Flush skb_pool as part of netconsole cleanup
Posted by Jakub Kicinski 1 month ago
On Tue, 02 Sep 2025 07:36:29 -0700 Breno Leitao wrote:
> @@ -607,8 +596,6 @@ static void __netpoll_cleanup(struct netpoll *np)
>  		call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
>  	} else
>  		RCU_INIT_POINTER(np->dev->npinfo, NULL);
> -
> -	skb_pool_flush(np);
>  }
>  

Please don't post conflicting patches to net and net-next.
Fixes have to go in first, trees converge, and then the net-next patches
can be posted.
Re: [PATCH 7/7] netpoll: Flush skb_pool as part of netconsole cleanup
Posted by Breno Leitao 4 weeks, 1 day ago
On Tue, Sep 02, 2025 at 05:09:38PM -0700, Jakub Kicinski wrote:
> On Tue, 02 Sep 2025 07:36:29 -0700 Breno Leitao wrote:
> > @@ -607,8 +596,6 @@ static void __netpoll_cleanup(struct netpoll *np)
> >  		call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
> >  	} else
> >  		RCU_INIT_POINTER(np->dev->npinfo, NULL);
> > -
> > -	skb_pool_flush(np);
> >  }
> >  
> 
> Please don't post conflicting patches to net and net-next.
> Fixes have to go in first, trees converge, and then the net-next patches
> can be posted.

Ack. I will wait until the invalid cleanup patch[1] lands in net-next
before submitting a v2 for this change.

Link: https://lore.kernel.org/all/20250901-netpoll_memleak-v1-1-34a181977dfc@debian.org/ [1]
Re: [PATCH 7/7] netpoll: Flush skb_pool as part of netconsole cleanup
Posted by Willem de Bruijn 1 month ago
Breno Leitao wrote:
> Transfer the skb_pool_flush() function from netpoll to netconsole, and
> call it within netpoll_cleanup() to ensure skb pool resources are
> properly released once the device is down.
> 
> The invocation of skb_pool_flush() was removed from netpoll_setup(), as
> the pool is now only managed after successful allocation.
> 
> This complete the move of skb pool management from netpoll to
> netconsole.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Reviewed-by: Willem de Bruijn <willemb@google.com>