Netfilter updates for net-net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-net
Hi,
The following series contains Netfilter updates for net-next:
1) Fix sparse warning in nf_tables related to use of percpu counters, from Uros Bizjak.
2) use strscpy_pad in nft_meta_bridge, from Justin Stitt.
3) A series from patch #3 to patch #7 to reduce memory footprint of set element transactions, Florian Westphal says:
When doing a flush on a set or mass adding/removing elements from a set, each element needs to allocate 96 bytes to hold the transactional state.
In such cases, virtually all the information in struct nft_trans_elem is the same.
Change nft_trans_elem to a flex-array, i.e. a single nft_trans_elem can hold multiple set element pointers.
The number of elements that can be stored in one nft_trans_elem is limited by the slab allocator, this series limits the compaction to at most 62 elements as it caps the reallocation to 2048 bytes of memory.
4) Document legacy toggles for xtables packet classifiers, from Bruno Leitao.
5) Use kfree_rcu() instead of call_rcu() + kmem_cache_free(), from Julia Lawall.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git nf-next-24-10-14
Thanks.
----------------------------------------------------------------
The following changes since commit f66ebf37d69cc700ca884c6a18c2258caf8b151b:
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2024-10-03 10:05:55 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git tags/nf-next-24-10-14
for you to fetch changes up to 9539446cc659e390942b46df871f8abdd4750999:
netfilter: replace call_rcu by kfree_rcu for simple kmem_cache_free callback (2024-10-14 12:30:20 +0200)
----------------------------------------------------------------
netfilter pull request 24-10-14
----------------------------------------------------------------
Breno Leitao (1):
netfilter: Make legacy configs user selectable
Florian Westphal (5):
netfilter: nf_tables: prefer nft_trans_elem_alloc helper
netfilter: nf_tables: add nft_trans_commit_list_add_elem helper
netfilter: nf_tables: prepare for multiple elements in nft_trans_elem structure
netfilter: nf_tables: switch trans_elem to real flex array
netfilter: nf_tables: allocate element update information dynamically
Julia Lawall (1):
netfilter: replace call_rcu by kfree_rcu for simple kmem_cache_free callback
Justin Stitt (1):
netfilter: nf_tables: replace deprecated strncpy with strscpy_pad
Uros Bizjak (1):
netfilter: nf_tables: Fix percpu address space issues in nf_tables_api.c
include/net/netfilter/nf_tables.h | 25 +-- net/bridge/netfilter/Kconfig | 8 +- net/bridge/netfilter/nft_meta_bridge.c | 2 +- net/ipv4/netfilter/Kconfig | 16 +- net/ipv6/netfilter/Kconfig | 9 +- net/netfilter/nf_conncount.c | 10 +- net/netfilter/nf_conntrack_expect.c | 10 +- net/netfilter/nf_tables_api.c | 370 +++++++++++++++++++++++++-------- net/netfilter/xt_hashlimit.c | 9 +- 9 files changed, 330 insertions(+), 129 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/9 netfilter: nf_tables: Fix percpu address space issues in nf_tables_api.c
From: Uros Bizjak <[email protected]>
Compiling nf_tables_api.c results in several sparse warnings:
nf_tables_api.c:2077:31: warning: incorrect type in return expression (different address spaces) nf_tables_api.c:2080:31: warning: incorrect type in return expression (different address spaces) nf_tables_api.c:2084:31: warning: incorrect type in return expression (different address spaces)
nf_tables_api.c:2740:23: warning: incorrect type in assignment (different address spaces) nf_tables_api.c:2752:38: warning: incorrect type in assignment (different address spaces) nf_tables_api.c:2798:21: warning: incorrect type in argument 1 (different address spaces)
Use {ERR_PTR,IS_ERR,PTR_ERR}_PCPU() macros when crossing between generic and percpu address spaces and add __percpu annotation to *stats pointer to fix these warnings.
Found by GCC's named address space checks.
There were no changes in the resulting object files.
--- net/netfilter/nf_tables_api.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
net/netfilter/nf_tables_api.c +8 -8
@@ -2082,14 +2082,14 @@ static struct nft_stats __percpu *nft_stats_alloc(const struct nlattr *attr) err =nla_parse_nested_deprecated (tb,NFTA_COUNTER_MAX , attr, nft_counter_policy,NULL );if (err <0 ) -return ERR_PTR (err); +return ERR_PTR_PCPU (err);if (!tb[NFTA_COUNTER_BYTES ] || !tb[NFTA_COUNTER_PACKETS ]) -return ERR_PTR (-EINVAL ); +return ERR_PTR_PCPU (-EINVAL ); newstats = netdev_alloc_pcpu_stats(struct nft_stats);if (newstats ==NULL ) -return ERR_PTR (-ENOMEM ); +return ERR_PTR_PCPU (-ENOMEM );/* Restore old counters on this cpu, no problem. Per-cpu statistics * are not exposed to userspace.
@@ -2533,10 +2533,10 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,if (nla[NFTA_CHAIN_COUNTERS ]) { stats =nft_stats_alloc (nla[NFTA_CHAIN_COUNTERS ]); -if (IS_ERR (stats)) { +if (IS_ERR_PCPU (stats)) {nft_chain_release_hook (&hook);kfree (basechain); -return PTR_ERR (stats); +return PTR_ERR_PCPU (stats); }rcu_assign_pointer (basechain->stats, stats); }
@@ -2650,7 +2650,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,struct nft_table *table = ctx->table;struct nft_chain *chain = ctx->chain;struct nft_chain_hook hook = {}; -struct nft_stats *stats =NULL ; +struct nft_stats __percpu *stats =NULL ;struct nft_hook *h, *next;struct nf_hook_ops *ops;struct nft_trans *trans;
@@ -2746,8 +2746,8 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy, } stats =nft_stats_alloc (nla[NFTA_CHAIN_COUNTERS ]); -if (IS_ERR (stats)) { - err =PTR_ERR (stats); +if (IS_ERR_PCPU (stats)) { + err =PTR_ERR_PCPU (stats); goto err_hooks; } }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/9 netfilter: nf_tables: replace deprecated strncpy with strscpy_pad
In reply to Pablo Neira AyusoFrom: Justin Stitt <[email protected]>
strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces.
In this particular instance, the usage of strncpy() is fine and works as expected. However, towards the goal of [2], we should consider replacing it with an alternative as many instances of strncpy() are bug-prone. Its removal from the kernel promotes better long term health for the codebase.
The current usage of strncpy() likely just wants the NUL-padding behavior offered by strncpy() and doesn't care about the NUL-termination. Since the compiler doesn't know the size of @dest, we can't use strtomem_pad(). Instead, use strscpy_pad() which behaves functionally the same as strncpy() in this context -- as we expect br_dev->name to be NUL-terminated itself.
--- net/bridge/netfilter/nft_meta_bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/netfilter/nft_meta_bridge.c +1 -1
@@ -63,7 +63,7 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,return nft_meta_get_eval (expr, regs, pkt); } -strncpy ((char *)dest, br_dev ? br_dev->name :"" ,IFNAMSIZ ); +strscpy_pad ((char *)dest, br_dev ? br_dev->name :"" ,IFNAMSIZ );return ; err: regs->verdict.code =NFT_BREAK ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/9 netfilter: nf_tables: prefer nft_trans_elem_alloc helper
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Reduce references to sizeof(struct nft_trans_elem). Preparation patch to move this to a flexiable array to store elem references.
--- net/netfilter/nf_tables_api.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +2 -4
@@ -6409,7 +6409,7 @@ static void nf_tables_setelem_notify(const struct nft_ctx *ctx,nfnetlink_set_err (net, portid,NFNLGRP_NFTABLES , -ENOBUFS ); } -static struct nft_trans *nft_trans_elem_alloc (struct nft_ctx *ctx, +static struct nft_trans *nft_trans_elem_alloc (const struct nft_ctx *ctx,int msg_type,struct nft_set *set) {
@@ -7471,13 +7471,11 @@ static int __nft_set_catchall_flush(const struct nft_ctx *ctx, {struct nft_trans *trans; - trans =nft_trans_alloc_gfp (ctx,NFT_MSG_DELSETELEM , -sizeof (struct nft_trans_elem ),GFP_KERNEL ); + trans =nft_trans_elem_alloc (ctx,NFT_MSG_DELSETELEM , set);if (!trans)return -ENOMEM ;nft_setelem_data_deactivate (ctx->net, set, elem_priv); -nft_trans_elem_set (trans) = set;nft_trans_elem_priv (trans) = elem_priv;nft_trans_commit_list_add_tail (ctx->net, trans);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/9 netfilter: nf_tables: add nft_trans_commit_list_add_elem helper
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Add and use a wrapper to append trans_elem structures to the transaction log.
Unlike the existing helper, pass a gfp_t to indicate if sleeping is allowed.
This will be used by a followup patch to realloc nft_trans_elem structures after they gain a flexible array member to reduce number of such container structures on the transaction list.
--- net/netfilter/nf_tables_api.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_api.c +16 -5
@@ -421,6 +421,17 @@ static void nft_trans_commit_list_add_tail(struct net *net, struct nft_trans *tr } } +static void nft_trans_commit_list_add_elem (struct net *net,struct nft_trans *trans, +gfp_t gfp) +{ +WARN_ON_ONCE (trans->msg_type !=NFT_MSG_NEWSETELEM && + trans->msg_type !=NFT_MSG_DELSETELEM ); + +might_alloc (gfp); + +nft_trans_commit_list_add_tail (net, trans); +} +static int nft_trans_table_add (struct nft_ctx *ctx,int msg_type) {struct nft_trans *trans;
@@ -7183,7 +7194,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,if (update_flags) {nft_trans_elem_priv (trans) = elem_priv;nft_trans_elem_update_flags (trans) = update_flags; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL ); goto err_elem_free; } }
@@ -7207,7 +7218,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, }nft_trans_elem_priv (trans) = elem.priv; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL );return 0 ; err_set_full:
@@ -7424,7 +7435,7 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set,nft_setelem_data_deactivate (ctx->net, set, elem.priv);nft_trans_elem_priv (trans) = elem.priv; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL );return 0 ; fail_ops:
@@ -7460,7 +7471,7 @@ static int nft_setelem_flush(const struct nft_ctx *ctx,nft_setelem_data_deactivate (ctx->net, set, elem_priv);nft_trans_elem_set (trans) = set;nft_trans_elem_priv (trans) = elem_priv; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_ATOMIC );return 0 ; }
@@ -7477,7 +7488,7 @@ static int __nft_set_catchall_flush(const struct nft_ctx *ctx,nft_setelem_data_deactivate (ctx->net, set, elem_priv);nft_trans_elem_priv (trans) = elem_priv; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL );return 0 ; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 5/9 netfilter: nf_tables: prepare for multiple elements in nft_trans_elem structure
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Add helpers to release the individual elements contained in the trans_elem container structure.
No functional change intended.
Followup patch will add 'nelems' member and will turn 'priv' into a flexible array.
These helpers can then loop over all elements.
Care needs to be taken to handle a mix of new elements and existing elements that are being updated (e.g. timeout refresh).
Before this patch, NEWSETELEM transaction with update is released early so nft_trans_set_elem_destroy() won't get called, so we need to skip elements marked as update.
--- include/net/netfilter/nf_tables.h | 21 ++- net/netfilter/nf_tables_api.c | 221 +++++++++++++++++++++--------- 2 files changed, 168 insertions(+), 74 deletions(-)
include/net/netfilter/nf_tables.h +9 -12
@@ -1754,28 +1754,25 @@ enum nft_trans_elem_flags { NFT_TRANS_UPD_EXPIRATION = (1 << 1), }; -struct nft_trans_elem { -struct nft_trans nft_trans; -struct nft_set *set; -struct nft_elem_priv *elem_priv; +struct nft_trans_one_elem { +struct nft_elem_priv *priv;u64 timeout;u64 expiration;u8 update_flags; +}; + +struct nft_trans_elem { +struct nft_trans nft_trans; +struct nft_set *set;bool bound; +unsigned int nelems; + struct nft_trans_one_elem elems[] __counted_by(nelems); };#define nft_trans_container_elem (t) \ container_of(t, struct nft_trans_elem, nft_trans)#define nft_trans_elem_set (trans) \ nft_trans_container_elem(trans)->set -#define nft_trans_elem_priv (trans) \ - nft_trans_container_elem(trans)->elem_priv -#define nft_trans_elem_update_flags (trans) \ - nft_trans_container_elem(trans)->update_flags -#define nft_trans_elem_timeout (trans) \ - nft_trans_container_elem(trans)->timeout -#define nft_trans_elem_expiration (trans) \ - nft_trans_container_elem(trans)->expiration#define nft_trans_elem_set_bound (trans) \ nft_trans_container_elem(trans)->bound
net/netfilter/nf_tables_api.c +159 -62
354 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 6/9 netfilter: nf_tables: switch trans_elem to real flex array
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
When queueing a set element add or removal operation to the transaction log, check if the previous operation already asks for a the identical operation on the same set.
If so, store the element reference in the preceeding operation. This significantlty reduces memory consumption when many set add/delete operations appear in a single transaction.
Example: 10k elements require 937kb of memory (10k allocations from kmalloc-96 slab).
Assuming we can compact 4 elements in the same set, 468 kbytes are needed (64 bytes for base struct, nft_trans_elemn, 32 bytes for nft_trans_one_elem structure, so 2500 allocations from kmalloc-192 slab).
For large batch updates we can compact up to 62 elements
into one single nft_trans_elem structure (~65% mem reduction):
(64 bytes for base struct, nft_trans_elem, 32 byte for nft_trans_one_elem
struct).
We can halve size of nft_trans_one_elem struct by moving timeout/expire/update_flags into a dynamically allocated structure, this allows to store 124 elements in a 2k slab nft_trans_elem struct. This is done in a followup patch.
--- net/netfilter/nf_tables_api.c | 79 ++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +77 -2
@@ -25,6 +25,7 @@#define NFT_MODULE_AUTOLOAD_LIMIT (MODULE_NAME_LEN - sizeof("nft-expr-255-"))#define NFT_SET_MAX_ANONLEN 16 +#define NFT_MAX_SET_NELEMS ((2048 - sizeof(struct nft_trans_elem)) / sizeof(struct nft_trans_one_elem))unsigned int nf_tables_net_id__read_mostly ;
@@ -391,6 +392,69 @@ static void nf_tables_unregister_hook(struct net *net,return __nf_tables_unregister_hook (net, table, chain, false); } +static bool nft_trans_collapse_set_elem_allowed (const struct nft_trans_elem *a,const struct nft_trans_elem *b) +{ +return a->set == b->set && a->bound == b->bound && a->nelems <NFT_MAX_SET_NELEMS ; +} + +static bool nft_trans_collapse_set_elem (struct nftables_pernet *nft_net, +struct nft_trans_elem *tail, +struct nft_trans_elem *trans, +gfp_t gfp) +{ +unsigned int nelems, old_nelems = tail->nelems; +struct nft_trans_elem *new_trans; + +if (!nft_trans_collapse_set_elem_allowed (tail, trans)) +return false; + +if (WARN_ON_ONCE (trans->nelems !=1 )) +return false; + +if (check_add_overflow (old_nelems, trans->nelems, &nelems)) +return false; + +/* krealloc might free tail which invalidates list pointers */ +list_del_init (&tail->nft_trans.list); + + new_trans =krealloc (tail,struct_size (tail, elems, nelems), gfp); +if (!new_trans) { +list_add_tail (&tail->nft_trans.list, &nft_net->commit_list); +return false; + } + +INIT_LIST_HEAD (&new_trans->nft_trans.list); + new_trans->nelems = nelems; + new_trans->elems[old_nelems] = trans->elems[0 ]; +list_add_tail (&new_trans->nft_trans.list, &nft_net->commit_list); + +return true; +} + +static bool nft_trans_try_collapse (struct nftables_pernet *nft_net, +struct nft_trans *trans,gfp_t gfp) +{ +struct nft_trans *tail; + +if (list_empty (&nft_net->commit_list)) +return false; + + tail = list_last_entry(&nft_net->commit_list, struct nft_trans, list); + +if (tail->msg_type != trans->msg_type) +return false; + +switch (trans->msg_type) { +case NFT_MSG_NEWSETELEM : +case NFT_MSG_DELSETELEM : +return nft_trans_collapse_set_elem (nft_net, +nft_trans_container_elem (tail), +nft_trans_container_elem (trans), gfp); + } + +return false; +} +static void nft_trans_commit_list_add_tail (struct net *net,struct nft_trans *trans) {struct nftables_pernet *nft_net =nft_pernet (net);
@@ -424,11 +488,18 @@ static void nft_trans_commit_list_add_tail(struct net *net, struct nft_trans *trstatic void nft_trans_commit_list_add_elem (struct net *net,struct nft_trans *trans,gfp_t gfp) { +struct nftables_pernet *nft_net =nft_pernet (net); +WARN_ON_ONCE (trans->msg_type !=NFT_MSG_NEWSETELEM && trans->msg_type !=NFT_MSG_DELSETELEM );might_alloc (gfp); +if (nft_trans_try_collapse (nft_net, trans, gfp)) { +kfree (trans); +return ; + } +nft_trans_commit_list_add_tail (net, trans); }
@@ -6424,13 +6495,17 @@ static struct nft_trans *nft_trans_elem_alloc(const struct nft_ctx *ctx,int msg_type, struct nft_set *set) { + struct nft_trans_elem *te;struct nft_trans *trans; - trans =nft_trans_alloc (ctx, msg_type,sizeof (struct nft_trans_elem )); + trans =nft_trans_alloc (ctx, msg_type,struct_size (te, elems,1 ));if (trans ==NULL )return NULL ; -nft_trans_elem_set (trans) = set; + te =nft_trans_container_elem (trans); + te->nelems =1 ; + te->set = set; +return trans; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 7/9 netfilter: nf_tables: allocate element update information dynamically
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Move the timeout/expire/flag members from nft_trans_one_elem struct into a dybamically allocated structure, only needed when timeout update was requested.
This halves size of nft_trans_one_elem struct and allows to compact up to 124 elements in one transaction container rather than 62.
This halves memory requirements for a large flush or insert transaction, where ->update remains NULL.
Care has to be taken to release the extra data in all spots, including abort path.
--- include/net/netfilter/nf_tables.h | 10 +++-- net/netfilter/nf_tables_api.c | 61 ++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 25 deletions(-)
include/net/netfilter/nf_tables.h +7 -3
@@ -1754,11 +1754,15 @@ enum nft_trans_elem_flags { NFT_TRANS_UPD_EXPIRATION = (1 << 1), }; -struct nft_trans_one_elem { -struct nft_elem_priv *priv; +struct nft_elem_update {u64 timeout;u64 expiration; -u8 update_flags; +u8 flags; +}; + +struct nft_trans_one_elem { +struct nft_elem_priv *priv; +struct nft_elem_update *update; };struct nft_trans_elem {
net/netfilter/nf_tables_api.c +39 -22
123 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 8/9 netfilter: Make legacy configs user selectable
In reply to Pablo Neira AyusoFrom: Breno Leitao <[email protected]>
This option makes legacy Netfilter Kconfig user selectable, giving users the option to configure iptables without enabling any other config.
Make the following KConfig entries user selectable:
* BRIDGE_NF_EBTABLES_LEGACY
* IP_NF_ARPTABLES
* IP_NF_IPTABLES_LEGACY
* IP6_NF_IPTABLES_LEGACY
--- net/bridge/netfilter/Kconfig | 8 +++++++- net/ipv4/netfilter/Kconfig | 16 ++++++++++++++-- net/ipv6/netfilter/Kconfig | 9 ++++++++- 3 files changed, 29 insertions(+), 4 deletions(-)
net/bridge/netfilter/Kconfig +7 -1
@@ -41,7 +41,13 @@ config NF_CONNTRACK_BRIDGE # old sockopt interface and eval loop config BRIDGE_NF_EBTABLES_LEGACY - tristate + tristate "Legacy EBTABLES support" + depends on BRIDGE && NETFILTER_XTABLES + default n + help + Legacy ebtables packet/frame classifier. + This is not needed if you are using ebtables over nftables + (iptables-nft). menuconfig BRIDGE_NF_EBTABLES tristate "Ethernet Bridge tables (ebtables) support"
net/ipv4/netfilter/Kconfig +14 -2
@@ -12,7 +12,13 @@ config NF_DEFRAG_IPV4 # old sockopt interface and eval loop config IP_NF_IPTABLES_LEGACY - tristate + tristate "Legacy IP tables support" + default n + select NETFILTER_XTABLES + help + iptables is a legacy packet classifier. + This is not needed if you are using iptables over nftables + (iptables-nft). config NF_SOCKET_IPV4 tristate "IPv4 socket lookup support"
@@ -318,7 +324,13 @@ endif # IP_NF_IPTABLES # ARP tables config IP_NF_ARPTABLES - tristate + tristate "Legacy ARPTABLES support" + depends on NETFILTER_XTABLES + default n + help + arptables is a legacy packet classifier. + This is not needed if you are using arptables over nftables + (iptables-nft). config NFT_COMPAT_ARP tristate
net/ipv6/netfilter/Kconfig +8 -1
@@ -8,7 +8,14 @@ menu "IPv6: Netfilter Configuration" # old sockopt interface and eval loop config IP6_NF_IPTABLES_LEGACY - tristate + tristate "Legacy IP6 tables support" + depends on INET && IPV6 + select NETFILTER_XTABLES + default n + help + ip6tables is a legacy packet classifier. + This is not needed if you are using iptables over nftables + (iptables-nft). config NF_SOCKET_IPV6 tristate "IPv6 socket lookup support"
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 9/9 netfilter: replace call_rcu by kfree_rcu for simple kmem_cache_free callback
In reply to Pablo Neira AyusoFrom: Julia Lawall <[email protected]>
Since SLOB was removed and since
commit 6c6c47b063b5 ("mm, slab: call kvfree_rcu_barrier() from kmem_cache_destroy()"), it is not necessary to use call_rcu when the callback only performs kmem_cache_free. Use kfree_rcu() directly.
The changes were made using Coccinelle.
--- net/netfilter/nf_conncount.c | 10 +--------- net/netfilter/nf_conntrack_expect.c | 10 +--------- net/netfilter/xt_hashlimit.c | 9 +-------- 3 files changed, 3 insertions(+), 26 deletions(-)
net/netfilter/nf_conncount.c +1 -9
@@ -275,14 +275,6 @@ bool nf_conncount_gc_list(struct net *net, }EXPORT_SYMBOL_GPL (nf_conncount_gc_list); -static void __tree_nodes_free (struct rcu_head *h) -{ -struct nf_conncount_rb *rbconn; - - rbconn = container_of(h, struct nf_conncount_rb, rcu_head); -kmem_cache_free (conncount_rb_cachep, rbconn); -} -/* caller must hold tree nf_conncount_locks[] lock */ static void tree_nodes_free(struct rb_root *root, struct nf_conncount_rb *gc_nodes[],
@@ -295,7 +287,7 @@ static void tree_nodes_free(struct rb_root *root,spin_lock (&rbconn->list.list_lock);if (!rbconn->list.count) {rb_erase (&rbconn->node, root); -call_rcu (&rbconn->rcu_head, __tree_nodes_free); +kfree_rcu (rbconn, rcu_head); }spin_unlock (&rbconn->list.list_lock); }
net/netfilter/nf_conntrack_expect.c +1 -9
@@ -367,18 +367,10 @@ void nf_ct_expect_init(struct nf_conntrack_expect *exp, unsigned int class, }EXPORT_SYMBOL_GPL (nf_ct_expect_init); -static void nf_ct_expect_free_rcu (struct rcu_head *head) -{ -struct nf_conntrack_expect *exp; - - exp = container_of(head, struct nf_conntrack_expect, rcu); -kmem_cache_free (nf_ct_expect_cachep, exp); -} -void nf_ct_expect_put (struct nf_conntrack_expect *exp) {if (refcount_dec_and_test (&exp->use)) -call_rcu (&exp->rcu, nf_ct_expect_free_rcu); +kfree_rcu (exp, rcu); }EXPORT_SYMBOL_GPL (nf_ct_expect_put);
net/netfilter/xt_hashlimit.c +1 -8
@@ -256,18 +256,11 @@ dsthash_alloc_init(struct xt_hashlimit_htable *ht,return ent; } -static void dsthash_free_rcu (struct rcu_head *head) -{ - struct dsthash_ent *ent = container_of(head, struct dsthash_ent, rcu); - -kmem_cache_free (hashlimit_cachep, ent); -} -static inline void dsthash_free (struct xt_hashlimit_htable *ht,struct dsthash_ent *ent) {hlist_del_rcu (&ent->node); -call_rcu (&ent->rcu, dsthash_free_rcu); +kfree_rcu (ent, rcu); ht->count--; }static void htable_gc (struct work_struct *work);
Signature · 1 line
2.30.2
Jakub Kicinski
maintainerQuoted 22 lines · On Mon, 14 Oct 2024 13:14:11 +0200 Pablo Neira Ayuso wrote:
Hi,
The following series contains Netfilter updates for net-next:
1) Fix sparse warning in
nf_tablesrelated to use of percpu counters, from Uros Bizjak.2) use
strscpy_padinnft_meta_bridge, from Justin Stitt.3) A series from patch #3 to patch #7 to reduce memory footprint of set element transactions, Florian Westphal says:
When doing a flush on a set or mass adding/removing elements from a set, each element needs to allocate 96 bytes to hold the transactional state.
In such cases, virtually all the information in struct
nft_trans_elemis the same.Change
nft_trans_elemto a flex-array, i.e. a singlenft_trans_elemcan hold multiple set element pointers.
Quoted 8 lines
The number of elements that can be stored in one
nft_trans_elemis limited by the slab allocator, this series limits the compaction to at most 62 elements as it caps the reallocation to 2048 bytes of memory.4) Document legacy toggles for xtables packet classifiers, from Bruno Leitao.
5) Use
kfree_rcu()instead ofcall_rcu()+kmem_cache_free(), from Julia Lawall.
Hi! Are you seeing any failures in nft_audit? I haven't looked closely but it seems that this PR causes:
<snip>
# testing for cmd: nft reset quotas t1 ... OK
# testing for cmd: nft reset quotas t2 ... OK
# testing for cmd: nft reset quotas ... OK
# testing for cmd: nft delete rule t1 c1 handle 4 ... OK
# testing for cmd: nft delete rule t1 c1 handle 5; delete rule t1 c1 handle 6 ... OK
# testing for cmd: nft flush chain t1 c2 ... OK
# testing for cmd: nft flush table t2 ... OK
# testing for cmd: nft delete chain t2 c2 ... OK
# testing for cmd: nft delete element t1 s { 22 } ... OK
# testing for cmd: nft delete element t1 s { 80, 443 } ... FAIL
# -table=t1 family=2 entries=2 op=nft_unregister_setelem
# +table=t1 family=2 entries=1 op=nft_unregister_setelem
# testing for cmd: nft flush set t1 s2 ... FAIL
# -table=t1 family=2 entries=3 op=nft_unregister_setelem
# +table=t1 family=2 entries=1 op=nft_unregister_setelem
# testing for cmd: nft delete set t1 s2 ... OK
# testing for cmd: nft delete set t1 s3 ... OK
not ok 1 selftests: net/netfilter: nft_audit.sh # exit=251https://netdev-3.bots.linux.dev/vmksft-nf-dbg/results/815301/10-nft-audit-sh/stdout
Florian Westphal
maintainerQuoted 6 lines · Jakub Kicinski
Quoted 1 line
5) Use
kfree_rcu()instead ofcall_rcu()+kmem_cache_free(), from Julia Lawall.Hi! Are you seeing any failures in
nft_audit? I haven't looked closely but it seems that this PR causes:<snip>
Quoted 13 lines
# testing for cmd: nft reset quotas t1 ... OK
# testing for cmd: nft reset quotas t2 ... OK
# testing for cmd: nft reset quotas ... OK
# testing for cmd: nft delete rule t1 c1 handle 4 ... OK
# testing for cmd: nft delete rule t1 c1 handle 5; delete rule t1 c1 handle 6 ... OK
# testing for cmd: nft flush chain t1 c2 ... OK
# testing for cmd: nft flush table t2 ... OK
# testing for cmd: nft delete chain t2 c2 ... OK
# testing for cmd: nft delete element t1 s { 22 } ... OK
# testing for cmd: nft delete element t1 s { 80, 443 } ... FAIL
# -table=t1 family=2 entries=2 op=nft_unregister_setelem
# +table=t1 family=2 entries=1 op=nft_unregister_setelem
# testing for cmd: nft flush set t1 s2 ... FAILMy fault, Pablo, please toss all of my patches.
I do not know when I will resend, so do not wait.
Pablo Neira Ayuso
maintainerQuoted 21 lines · Florian Westphal
Quoted 6 lines · Jakub Kicinski
Quoted 1 line
5) Use
kfree_rcu()instead ofcall_rcu()+kmem_cache_free(), from Julia Lawall.Hi! Are you seeing any failures in
nft_audit? I haven't looked closely but it seems that this PR causes:<snip>
Quoted 13 lines
# testing for cmd: nft reset quotas t1 ... OK # testing for cmd: nft reset quotas t2 ... OK # testing for cmd: nft reset quotas ... OK # testing for cmd: nft delete rule t1 c1 handle 4 ... OK # testing for cmd: nft delete rule t1 c1 handle 5; delete rule t1 c1 handle 6 ... OK # testing for cmd: nft flush chain t1 c2 ... OK # testing for cmd: nft flush table t2 ... OK # testing for cmd: nft delete chain t2 c2 ... OK # testing for cmd: nft delete element t1 s { 22 } ... OK # testing for cmd: nft delete element t1 s { 80, 443 } ... FAIL # -table=t1 family=2 entries=2 op=nft_unregister_setelem # +table=t1 family=2 entries=1 op=nft_unregister_setelem # testing for cmd: nft flush set t1 s2 ... FAIL
Quoted 3 lines
My fault, Pablo, please toss all of my patches.
I do not know when I will resend, so do not wait.
At quick glance, I can see the audit logic is based in transaction objects, so now it counts one single entry for the two elements in one single transaction. I can look into this to fix this.
Florian, are you seing any other issues apart for this miscount?
Thanks.
Florian Westphal
maintainerQuoted 5 lines · Pablo Neira Ayuso
At quick glance, I can see the audit logic is based in transaction objects, so now it counts one single entry for the two elements in one single transaction. I can look into this to fix this.
Florian, are you seing any other issues apart for this miscount?
Yes, crash when bisecting (its "fixed" by later patch, hunk must be moved to earlier patch), nft_trans_elems_activate must emit notify also for update case.
Maybe more. Just remove these patches.
Pablo Neira Ayuso
maintainerQuoted 10 lines · Florian Westphal
Quoted 5 lines · Pablo Neira Ayuso
At quick glance, I can see the audit logic is based in transaction objects, so now it counts one single entry for the two elements in one single transaction. I can look into this to fix this.
Florian, are you seing any other issues apart for this miscount?
Yes, crash when bisecting (its "fixed" by later patch, hunk must be moved to earlier patch),
nft_trans_elems_activatemust emit notify also for update case.
Correct, event is missed.
Quoted 1 line
Maybe more. Just remove these patches.
OK, this needs more work.