netfilter: nf_tables: prefer kfree_rcu(ptr, rcu) variant
Subsystems (3)
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
@@ -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
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.
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:
Quoted 3 lines
Reviewed-by Florian Westphal <[email protected]>
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 ifkvfree_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!