]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: netpoll: flush skb pool during cleanup
authorBreno Leitao <leitao@debian.org>
Thu, 20 Nov 2025 19:43:02 +0000 (14:43 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Nov 2025 09:36:06 +0000 (10:36 +0100)
[ Upstream commit 6c59f16f1770481a6ee684720ec55b1e38b3a4b2 ]

The netpoll subsystem maintains a pool of 32 pre-allocated SKBs per
instance, but these SKBs are not freed when the netpoll user is brought
down. This leads to memory waste as these buffers remain allocated but
unused.

Add skb_pool_flush() to properly clean up these SKBs when netconsole is
terminated, improving memory efficiency.

Signed-off-by: Breno Leitao <leitao@debian.org>
Link: https://patch.msgid.link/20241114-skb_buffers_v2-v3-2-9be9f52a8b69@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: 49c8d2c1f94c ("net: netpoll: fix incorrect refcount handling causing incorrect cleanup")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/core/netpoll.c

index 76bdb6ce463784579bd5a6525f8387761bdb82ee..3f6dca03fa6009affba208cb967901fcec51f984 100644 (file)
@@ -536,6 +536,14 @@ static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr)
        return -1;
 }
 
+static void skb_pool_flush(struct netpoll *np)
+{
+       struct sk_buff_head *skb_pool;
+
+       skb_pool = &np->skb_pool;
+       skb_queue_purge_reason(skb_pool, SKB_CONSUMED);
+}
+
 int netpoll_parse_options(struct netpoll *np, char *opt)
 {
        char *cur=opt, *delim;
@@ -784,7 +792,7 @@ put_noaddr:
 
        err = __netpoll_setup(np, ndev);
        if (err)
-               goto put;
+               goto flush;
        rtnl_unlock();
 
        /* Make sure all NAPI polls which started before dev->npinfo
@@ -795,6 +803,8 @@ put_noaddr:
 
        return 0;
 
+flush:
+       skb_pool_flush(np);
 put:
        DEBUG_NET_WARN_ON_ONCE(np->dev);
        if (ip_overwritten)
@@ -842,6 +852,8 @@ 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);
 }
 EXPORT_SYMBOL_GPL(__netpoll_cleanup);