Skip to contentSkip to conversation

netfilter: nf_tables: prefer kfree_rcu(ptr, rcu) variant

PATCH Applied Eric Dumazet 4 participants 4 messages Feb 22, 2022 – Feb 23, 2022

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

PATCH 1/1 netfilter: nf_tables: prefer kfree_rcu(ptr, rcu) variant

From: Eric Dumazet <[email protected]>

While kfree_rcu(ptr) _is_ supported, it has some limitations.

Given that 99.99% of kfree_rcu() users [1] use the legacy two parameters variant, and @catchall objects do have an rcu head, simply use it.

Choice of kfree_rcu(ptr) variant was probably not intentional.

[1] including calls from net/netfilter/nf_tables_api.c

---
 net/netfilter/nf_tables_api.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +2 -2
index 5fa16990da95177791dfaa9e7bb31c92f3cae096..ef79d8d09773588cc399113fd5bcf584c592f039 100644
@@ -4502,7 +4502,7 @@ static void nft_set_catchall_destroy(const struct nft_ctx *ctx,
 	list_for_each_entry_safe(catchall, next, &set->catchall_list, list) {
 		list_del_rcu(&catchall->list);
 		nft_set_elem_destroy(set, catchall->elem, true);
-		kfree_rcu(catchall);
+		kfree_rcu(catchall, rcu);
 	}
 }
 
@@ -5669,7 +5669,7 @@ static void nft_setelem_catchall_remove(const struct net *net,
 	list_for_each_entry_safe(catchall, next, &set->catchall_list, list) {
 		if (catchall->elem == elem->priv) {
 			list_del_rcu(&catchall->list);
-			kfree_rcu(catchall);
+			kfree_rcu(catchall, rcu);
 			break;
 		}
 	}
Signature · 1 line
2.35.1.473.g83b2b277ed-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

While kfree_rcu(ptr) _is_ supported, it has some limitations.

Given that 99.99% of kfree_rcu() users [1] use the legacy two parameters variant, and @catchall objects do have an rcu head, simply use it.

Choice of kfree_rcu(ptr) variant was probably not intentional.

In case someone wondered, this causes expensive sycnhronize_rcu + kfree for each removal operation.

#2 lore raw
Quoted 6 lines · Florian Westphal
Quoted 4 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

While kfree_rcu(ptr) _is_ supported, it has some limitations.

Quoted 8 lines
Quoted 5 lines

Given that 99.99% of kfree_rcu() users [1] use the legacy two parameters variant, and @catchall objects do have an rcu head, simply use it.

Choice of kfree_rcu(ptr) variant was probably not intentional.

In case someone wondered, this causes expensive sycnhronize_rcu + kfree for each removal operation.

This fallback to synchronize_rcu() only happens if kvfree_call_rcu() has been unable to allocate a new block of memory.

But yes, I guess I would add a Fixes: tag, because we can easily avoid this potential issue.

Pablo, if not too late:

Fixes aaa31047a6d2 ("netfilter: nftables: add catch-all set element support")
Quoted 3 lines
maintainer Applied
#3 lore raw
Quoted 19 lines · Eric Dumazet
Quoted 6 lines · Florian Westphal
Quoted 4 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

While kfree_rcu(ptr) _is_ supported, it has some limitations.

Quoted 8 lines
Quoted 5 lines

Given that 99.99% of kfree_rcu() users [1] use the legacy two parameters variant, and @catchall objects do have an rcu head, simply use it.

Choice of kfree_rcu(ptr) variant was probably not intentional.

In case someone wondered, this causes expensive sycnhronize_rcu + kfree for each removal operation.

This fallback to synchronize_rcu() only happens if kvfree_call_rcu() has been unable to allocate a new block of memory.

Quoted 6 lines

But yes, I guess I would add a Fixes: tag, because we can easily avoid this potential issue.

Pablo, if not too late:

Fixes aaa31047a6d2 ("netfilter: nftables: add catch-all set element support")

Applied, thanks!