netfilter: ctnetlink: remove refcounting in dying list dumping
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: ctnetlink: remove refcounting in dying list dumping
There is no need to keep the object alive via refcount, use a cookie and then use that as the skip hint for dump resumption.
Unlike the two earlier, similar changes to this file, this is a cleanup without intended side effects.
--- net/netfilter/nf_conntrack_netlink.c | 39 +++++++--------------------- 1 file changed, 10 insertions(+), 29 deletions(-)
net/netfilter/nf_conntrack_netlink.c +10 -29
@@ -60,7 +60,7 @@ MODULE_LICENSE("GPL");MODULE_DESCRIPTION ("List and change connection tracking table" );struct ctnetlink_list_dump_ctx { -struct nf_conn *last; +unsigned long last_id;unsigned int cpu;bool done; };
@@ -1731,16 +1731,6 @@ static int ctnetlink_get_conntrack(struct sk_buff *skb,return nfnetlink_unicast (skb2, info->net,NETLINK_CB (skb).portid); } -static int ctnetlink_done_list (struct netlink_callback *cb) -{ -struct ctnetlink_list_dump_ctx *ctx = (void *)cb->ctx; - -if (ctx->last) -nf_ct_put (ctx->last); - -return 0 ; -} -#ifdef CONFIG_NF_CONNTRACK_EVENTS static int ctnetlink_dump_one_entry(struct sk_buff *skb, struct netlink_callback *cb,
@@ -1755,11 +1745,11 @@ static int ctnetlink_dump_one_entry(struct sk_buff *skb,if (l3proto &&nf_ct_l3num (ct) != l3proto)return 0 ; -if (ctx->last) { -if (ct != ctx->last) +if (ctx->last_id) { +if (ctnetlink_get_id (ct) != ctx->last_id)return 0 ; - ctx->last =NULL ; + ctx->last_id =0 ; }/* We can't dump extension info for the unconfirmed
@@ -1773,12 +1763,8 @@ static int ctnetlink_dump_one_entry(struct sk_buff *skb, cb->nlh->nlmsg_seq,NFNL_MSG_TYPE (cb->nlh->nlmsg_type), ct, dying, 0); -if (res <0 ) { -if (!refcount_inc_not_zero (&ct->ct_general.use)) -return 0 ; - - ctx->last = ct; - } +if (res <0 ) + ctx->last_id =ctnetlink_get_id (ct);return res; }
@@ -1794,7 +1780,7 @@ static int ctnetlink_dump_dying(struct sk_buff *skb, struct netlink_callback *cb) { struct ctnetlink_list_dump_ctx *ctx = (void *)cb->ctx; -struct nf_conn *last = ctx->last; +unsigned long last_id = ctx->last_id;#ifdef CONFIG_NF_CONNTRACK_EVENTS const struct net *net =sock_net (skb->sk);struct nf_conntrack_net_ecache *ecache_net;
@@ -1805,7 +1791,7 @@ ctnetlink_dump_dying(struct sk_buff *skb, struct netlink_callback *cb)if (ctx->done)return 0 ; - ctx->last =NULL ; + ctx->last_id =0 ;#ifdef CONFIG_NF_CONNTRACK_EVENTS ecache_net =nf_conn_pernet_ecache (net);
@@ -1816,24 +1802,21 @@ ctnetlink_dump_dying(struct sk_buff *skb, struct netlink_callback *cb)int res; ct =nf_ct_tuplehash_to_ctrack (h); -if (last && last != ct) +if (last_id && last_id !=ctnetlink_get_id (ct))continue ; res =ctnetlink_dump_one_entry (skb, cb, ct, true);if (res <0 ) {spin_unlock_bh (&ecache_net->dying_lock); -nf_ct_put (last);return skb->len; } -nf_ct_put (last); - last = NULL; + last_id = 0; }spin_unlock_bh (&ecache_net->dying_lock);#endif ctx->done = true; -nf_ct_put (last);return skb->len; }
@@ -1845,7 +1828,6 @@ static int ctnetlink_get_ct_dying(struct sk_buff *skb,if (info->nlh->nlmsg_flags &NLM_F_DUMP ) {struct netlink_dump_control c = { .dump = ctnetlink_dump_dying, - .done = ctnetlink_done_list, };return netlink_dump_start (info->sk, skb, info->nlh, &c); }
@@ -1860,7 +1842,6 @@ static int ctnetlink_get_ct_unconfirmed(struct sk_buff *skb,if (info->nlh->nlmsg_flags &NLM_F_DUMP ) {struct netlink_dump_control c = { .dump = ctnetlink_dump_unconfirmed, - .done = ctnetlink_done_list, };return netlink_dump_start (info->sk, skb, info->nlh, &c); }
Signature · 1 line
2.49.1
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Florian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on netfilter-nf/main]
[also build test WARNING on linus/master v6.17-rc1 next-20250814] [cannot apply to nf-next/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Florian-Westphal/netfilter-ctnetlink-remove-refcounting-in-dying-list-dumping/20250815-003116 base: https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git main patch link: https://lore.kernel.org/r/20250814162307.26029-1-fw%40strlen.de patch subject: [PATCH nf-next] netfilter: ctnetlink: remove refcounting in dying list dumping config: hexagon-randconfig-001-20250815 (https://download.01.org/0day-ci/archive/20250815/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 3769ce013be2879bf0b329c14a16f5cb766f26ce) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250815/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> net/netfilter/nf_conntrack_netlink.c:1785:16: warning: unused variable 'last_id' [-Wunused-variable]
1785 | unsigned long last_id = ctx->last_id;
| ^~~~~~~1 warning generated.
vim +/last_id +1785 net/netfilter/nf_conntrack_netlink.c
1780
1781 static int
1782 ctnetlink_dump_dying(struct sk_buff *skb, struct netlink_callback *cb)
1783 {
1784 struct ctnetlink_list_dump_ctx *ctx = (void *)cb->ctx;
> 1785 unsigned long last_id = ctx->last_id;
1786 #ifdef CONFIG_NF_CONNTRACK_EVENTS
1787 const struct net *net = sock_net(skb->sk);
1788 struct nf_conntrack_net_ecache *ecache_net;
1789 struct nf_conntrack_tuple_hash *h;
1790 struct hlist_nulls_node *n;
1791 #endif
1792
1793 if (ctx->done)
1794 return 0;
1795
1796 ctx->last_id = 0;
1797
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki