netfilter: nf_tables: rewrite gc again
Subsystems (2)
Florian Westphal
maintainercover netfilter: nf_tables: rewrite gc again
First couple of patches could be applied, as they add more warns/checks to the control plane.
Actual gc changes are not for merging, this is for archive only; I don't see a compelling reason at this time to do this.
The implemeneted strategy is to have the async gc (rhashtable) enqueue the *key* of *gc candidates*, rather than the actual expired elements.
Therefore no races with control plane are possible and the "gc sequence" can be removed.
If async gc enqueues element e and control plane removes it before gc has a chance to run, then gc will no longer find it -> no op.
If control plane removes and re-adds -> gc candidate is not expired -> no op.
Downside is the vast increase in memory (instead of just storing a pointer, we need to be able to store the max key size, i.e. 64 byte).
I'll mark most of this as RFC in patchwork so we can recover this work later if there is any issue with the exising gc mechanism that this approach would avoid.
Florian Westphal (9):
netfilter: nf_tables: warn if set being destroyed is still active
netfilter: nf_tables: decrement element counters on set removal/flush
netfilter: nf_tables: add lockdep assertion for chain use counter
netfilter: remove nft_trans_gc_catchall_async handling
netfilter: nf_tables: condense catchall gc
netfilter: nf_tables: add in-kernel only query that will return
expired/dead elements
netfilter: nf_tables: prepare for key-based deletion from workqueue
netfilter: nf_tables: remove expired elements based on key lookup only
netfilter: nf_tables: remove gc sequence counter
include/net/netfilter/nf_tables.h | 27 +-- include/uapi/linux/netfilter/nf_tables.h | 5 + net/netfilter/nf_tables_api.c | 280 ++++++++++++++--------- net/netfilter/nft_set_bitmap.c | 5 +- net/netfilter/nft_set_hash.c | 39 ++-- net/netfilter/nft_set_pipapo.c | 6 +- net/netfilter/nft_set_rbtree.c | 8 +- 7 files changed, 216 insertions(+), 154 deletions(-)
Signature · 1 line
2.43.0
Florian Westphal
maintainerPATCH 1/9 netfilter: nf_tables: warn if set being destroyed is still active
Control plane should mark a to-be-destroyed set as dead before the ->destroy function gets called.
This needs to be done while control plane still holds the transaction mutex.
--- net/netfilter/nf_tables_api.c | 3 +++ net/netfilter/nft_set_hash.c | 2 ++ 2 files changed, 5 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
@@ -5276,6 +5276,9 @@ static void nft_set_destroy(const struct nft_ctx *ctx, struct nft_set *set)for (i =0 ; i < set->num_exprs; i++)nft_expr_destroy (ctx, set->exprs[i]); +if (WARN_ON_ONCE (!set->dead)) + set->dead =1 ; + set->ops->destroy (ctx, set);nft_set_catchall_destroy (ctx, set);nft_set_put (set);
net/netfilter/nft_set_hash.c +2 -0
@@ -451,6 +451,8 @@ static void nft_rhash_destroy(const struct nft_ctx *ctx, .set = set, }; +WARN_ON_ONCE (!set->dead); +cancel_delayed_work_sync (&priv->gc_work);rhashtable_free_and_destroy (&priv->ht, nft_rhash_elem_destroy, (void *)&rhash_ctx);
Signature · 1 line
2.43.0
Florian Westphal
maintainerPATCH 2/9 netfilter: nf_tables: decrement element counters on set removal/flush
In reply to Florian WestphalNot a bug fix, idea is that this allows us to add runtime assertions, when set is free'd counter should be 0 as well.
--- net/netfilter/nf_tables_api.c | 5 +++++ net/netfilter/nft_set_bitmap.c | 5 ++++- net/netfilter/nft_set_hash.c | 6 ++++++ net/netfilter/nft_set_pipapo.c | 2 ++ net/netfilter/nft_set_rbtree.c | 2 ++ 5 files changed, 19 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +5 -0
@@ -5261,6 +5261,10 @@ static void nft_set_catchall_destroy(const struct nft_ctx *ctx,static void nft_set_put (struct nft_set *set) {if (refcount_dec_and_test (&set->refs)) { +unsigned int nelems =atomic_read (&set->nelems); + +WARN (nelems,"set %s (%ps) has element count of %u\n" , + set->name, set->ops->lookup, nelems);kfree (set->name);kvfree (set); }
@@ -9663,6 +9667,7 @@ static void nft_trans_gc_trans_free(struct rcu_head *rcu)if (!nft_setelem_is_catchall (trans->set, elem_priv))atomic_dec (&trans->set->nelems); +WARN_ON_ONCE (atomic_read (&trans->set->nelems) <0 );nf_tables_set_elem_destroy (&ctx, trans->set, elem_priv); }
net/netfilter/nft_set_bitmap.c +4 -1
@@ -275,9 +275,12 @@ static void nft_bitmap_destroy(const struct nft_ctx *ctx, {struct nft_bitmap *priv =nft_set_priv (set);struct nft_bitmap_elem *be, *n; +struct nft_set *mset = (void *)set; -list_for_each_entry_safe (be, n, &priv->list, head) +list_for_each_entry_safe (be, n, &priv->list, head) {nf_tables_set_elem_destroy (ctx, set, &be->priv); +atomic_dec (&mset->nelems); + } } static bool nft_bitmap_estimate(const struct nft_set_desc *desc, u32 features,
net/netfilter/nft_set_hash.c +6 -0
@@ -438,8 +438,12 @@ static void nft_rhash_elem_destroy(void *ptr, void *arg) {struct nft_rhash_ctx *rhash_ctx = arg;struct nft_rhash_elem *he = ptr; +struct nft_set *set;nf_tables_set_elem_destroy (&rhash_ctx->ctx, rhash_ctx->set, &he->priv); + + set = (struct nft_set *)rhash_ctx->set; +atomic_dec (&set->nelems); } static void nft_rhash_destroy(const struct nft_ctx *ctx,
@@ -688,6 +692,7 @@ static int nft_hash_init(const struct nft_set *set,static void nft_hash_destroy (const struct nft_ctx *ctx,const struct nft_set *set) { +struct nft_set *mset = (struct nft_set *)set;struct nft_hash *priv =nft_set_priv (set);struct nft_hash_elem *he;struct hlist_node *next;
@@ -697,6 +702,7 @@ static void nft_hash_destroy(const struct nft_ctx *ctx,hlist_for_each_entry_safe (he, next, &priv->table[i], node) {hlist_del_rcu (&he->node);nf_tables_set_elem_destroy (ctx, set, &he->priv); +atomic_dec (&mset->nelems); } } }
net/netfilter/nft_set_pipapo.c +2 -0
@@ -2295,6 +2295,7 @@ static void nft_set_pipapo_match_destroy(const struct nft_ctx *ctx,const struct nft_set *set, struct nft_pipapo_match *m) { + struct nft_set *mset = (void *)set;struct nft_pipapo_field *f;unsigned int i, r;
@@ -2310,6 +2311,7 @@ static void nft_set_pipapo_match_destroy(const struct nft_ctx *ctx, e = f->mt[r].e;nf_tables_set_elem_destroy (ctx, set, &e->priv); +atomic_dec (&mset->nelems); } }
net/netfilter/nft_set_rbtree.c +2 -0
@@ -709,6 +709,7 @@ static void nft_rbtree_destroy(const struct nft_ctx *ctx, const struct nft_set *set) {struct nft_rbtree *priv =nft_set_priv (set); +struct nft_set *mset = (void *)set;struct nft_rbtree_elem *rbe;struct rb_node *node;
@@ -716,6 +717,7 @@ static void nft_rbtree_destroy(const struct nft_ctx *ctx,rb_erase (node, &priv->root); rbe = rb_entry(node, struct nft_rbtree_elem, node);nf_tables_set_elem_destroy (ctx, set, &rbe->priv); +atomic_dec (&mset->nelems); } }
Signature · 1 line
2.43.0
Florian Westphal
maintainerPATCH 3/9 netfilter: nf_tables: add lockdep assertion for chain use counter
In reply to Florian Westphalnft_set_elem_destroy() callers need to hold the transaction mutex for maps holding chain or object references.
This helper is also called from the nft_dynset error path, without mutex.
nft_dynset doesn't support verdict or objref maps, however.
--- net/netfilter/nf_tables_api.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +20 -1
@@ -6404,7 +6404,19 @@ static void nft_set_elem_expr_destroy(const struct nft_ctx *ctx,__nft_set_elem_expr_destroy (ctx, expr); } -/* Drop references and destroy. Called from gc, dynset and abort path. */ +/** +* nft_set_elem_destroy - free a set element instantly +* @set: the set the element was supposed to be added to +* @elem: the private element pointer to be free'd +* @destroy_expr: true if embedded expression was initialised before +* +* Immediately releases an element without going through any synchronization. +* This function can only be used for error unwinding BEFORE the element was +* added to the set, else concurrent data path access may result in +* use-after-free. +* For datapath error unwinding, jumps-to-chain or objref are +* not supported. +*/ void nft_set_elem_destroy (const struct nft_set *set,const struct nft_elem_priv *elem_priv,bool destroy_expr)
@@ -6415,6 +6427,13 @@ void nft_set_elem_destroy(const struct nft_set *set, .family = set->table->family, }; +/* We can only do error unwind for vmaps or objref types +* if the caller is holding the transaction mutex. +*/ +if (set->dtype ==NFT_DATA_VERDICT || +nft_set_ext_exists (ext,NFT_SET_EXT_OBJREF )) +WARN_ON_ONCE (!lockdep_commit_lock_is_held (read_pnet (&set->net))); +nft_data_release (nft_set_ext_key (ext),NFT_DATA_VALUE );if (nft_set_ext_exists (ext,NFT_SET_EXT_DATA ))nft_data_release (nft_set_ext_data (ext), set->dtype);
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH nf-next 3/9] netfilter: nf_tables: add lockdep assertion for chain use counter
kernel test robot noticed the following build warnings:
Hi Florian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20240307]
[also build test WARNING on linus/master v6.8-rc7]
[cannot apply to nf-next/master netfilter-nf/main v6.8-rc7 v6.8-rc6 v6.8-rc5] [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-nf_tables-warn-if-set-being-destroyed-is-still-active/20240307-171729 base: next-20240307 patch link: https://lore.kernel.org/r/20240307084018.2219-4-fw%40strlen.de patch subject: [PATCH nf-next 3/9] netfilter: nf_tables: add lockdep assertion for chain use counter config: s390-defconfig (https://download.01.org/0day-ci/archive/20240310/[email protected]/config) compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 503c55e17037436dcd45ac69dea8967e67e3f5e8) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240310/[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_tables_api.c:6423: warning: Function parameter or struct member 'elem_priv' not described in 'nft_set_elem_destroy' >> net/netfilter/nf_tables_api.c:6423: warning: Excess function parameter 'elem' description in 'nft_set_elem_destroy'
vim +6423 net/netfilter/nf_tables_api.c
563125a73ac30d Pablo Neira Ayuso 2020-12-09 6406
60cf9e02aac6c9 Florian Westphal 2024-03-07 6407 /**
60cf9e02aac6c9 Florian Westphal 2024-03-07 6408 * nft_set_elem_destroy - free a set element instantly
60cf9e02aac6c9 Florian Westphal 2024-03-07 6409 * @set: the set the element was supposed to be added to
60cf9e02aac6c9 Florian Westphal 2024-03-07 6410 * @elem: the private element pointer to be free'd
60cf9e02aac6c9 Florian Westphal 2024-03-07 6411 * @destroy_expr: true if embedded expression was initialised before
60cf9e02aac6c9 Florian Westphal 2024-03-07 6412 *
60cf9e02aac6c9 Florian Westphal 2024-03-07 6413 * Immediately releases an element without going through any synchronization.
60cf9e02aac6c9 Florian Westphal 2024-03-07 6414 * This function can only be used for error unwinding BEFORE the element was
60cf9e02aac6c9 Florian Westphal 2024-03-07 6415 * added to the set, else concurrent data path access may result in
60cf9e02aac6c9 Florian Westphal 2024-03-07 6416 * use-after-free.
60cf9e02aac6c9 Florian Westphal 2024-03-07 6417 * For datapath error unwinding, jumps-to-chain or objref are
60cf9e02aac6c9 Florian Westphal 2024-03-07 6418 * not supported.
60cf9e02aac6c9 Florian Westphal 2024-03-07 6419 */
9dad402b89e81a Pablo Neira Ayuso 2023-10-18 6420 void nft_set_elem_destroy(const struct nft_set *set,
9dad402b89e81a Pablo Neira Ayuso 2023-10-18 6421 const struct nft_elem_priv *elem_priv,
61f9e2924f4981 Liping Zhang 2016-10-22 6422 bool destroy_expr)
61edafbb47e9f4 Patrick McHardy 2015-03-25 @6423 {
9dad402b89e81a Pablo Neira Ayuso 2023-10-18 6424 struct nft_set_ext *ext = nft_set_elem_ext(set, elem_priv);
3453c92731884b Pablo Neira Ayuso 2018-06-02 6425 struct nft_ctx ctx = {
3453c92731884b Pablo Neira Ayuso 2018-06-02 6426 .net = read_pnet(&set->net),
3453c92731884b Pablo Neira Ayuso 2018-06-02 6427 .family = set->table->family,
3453c92731884b Pablo Neira Ayuso 2018-06-02 6428 };
61edafbb47e9f4 Patrick McHardy 2015-03-25 6429
60cf9e02aac6c9 Florian Westphal 2024-03-07 6430 /* We can only do error unwind for vmaps or objref types
60cf9e02aac6c9 Florian Westphal 2024-03-07 6431 * if the caller is holding the transaction mutex.
60cf9e02aac6c9 Florian Westphal 2024-03-07 6432 */
60cf9e02aac6c9 Florian Westphal 2024-03-07 6433 if (set->dtype == NFT_DATA_VERDICT ||
60cf9e02aac6c9 Florian Westphal 2024-03-07 6434 nft_set_ext_exists(ext, NFT_SET_EXT_OBJREF))
60cf9e02aac6c9 Florian Westphal 2024-03-07 6435 WARN_ON_ONCE(!lockdep_commit_lock_is_held(read_pnet(&set->net)));
60cf9e02aac6c9 Florian Westphal 2024-03-07 6436
591054469b3eef Pablo Neira Ayuso 2017-05-15 6437 nft_data_release(nft_set_ext_key(ext), NFT_DATA_VALUE);
61edafbb47e9f4 Patrick McHardy 2015-03-25 6438 if (nft_set_ext_exists(ext, NFT_SET_EXT_DATA))
591054469b3eef Pablo Neira Ayuso 2017-05-15 6439 nft_data_release(nft_set_ext_data(ext), set->dtype);
563125a73ac30d Pablo Neira Ayuso 2020-12-09 6440 if (destroy_expr && nft_set_ext_exists(ext, NFT_SET_EXT_EXPRESSIONS))
475beb9c8de122 Pablo Neira Ayuso 2020-03-18 6441 nft_set_elem_expr_destroy(&ctx, nft_set_ext_expr(ext));
8aeff920dcc9b3 Pablo Neira Ayuso 2016-11-28 6442 if (nft_set_ext_exists(ext, NFT_SET_EXT_OBJREF))
1689f25924ada8 Pablo Neira Ayuso 2023-06-28 6443 nft_use_dec(&(*nft_set_ext_obj(ext))->use);
9dad402b89e81a Pablo Neira Ayuso 2023-10-18 6444
9dad402b89e81a Pablo Neira Ayuso 2023-10-18 6445 kfree(elem_priv);
61edafbb47e9f4 Patrick McHardy 2015-03-25 6446 }
61edafbb47e9f4 Patrick McHardy 2015-03-25 6447 EXPORT_SYMBOL_GPL(nft_set_elem_destroy);
61edafbb47e9f4 Patrick McHardy 2015-03-25 6448 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Florian Westphal
maintainerPATCH 4/9 netfilter: remove nft_trans_gc_catchall_async handling
In reply to Florian WestphalIts not needed: async gc *must* defer removal of expired elements to the work queue, as it cannot acquire the transaction mutex.
Therefore, just walk the catchall list from the work queue, where we do hold the transaction mutex.
Then, just do what the catchall_sync() handling is already doing:
1. Detach the element via list_del_rcu
2. release the container structure via kfree_rcu
3. decrement the use counters
4. kfree the real element from call_rcu().
--- include/net/netfilter/nf_tables.h | 2 - net/netfilter/nf_tables_api.c | 79 ++++++++++++++++++------------- net/netfilter/nft_set_hash.c | 2 - 3 files changed, 47 insertions(+), 36 deletions(-)
include/net/netfilter/nf_tables.h +0 -2
@@ -1758,8 +1758,6 @@ void nft_trans_gc_queue_sync_done(struct nft_trans_gc *trans);void nft_trans_gc_elem_add (struct nft_trans_gc *gc,void *priv); -struct nft_trans_gc *nft_trans_gc_catchall_async (struct nft_trans_gc *gc, -unsigned int gc_seq);struct nft_trans_gc *nft_trans_gc_catchall_sync (struct nft_trans_gc *gc); void nft_setelem_data_deactivate(const struct net *net,
net/netfilter/nf_tables_api.c +47 -32
103 lines not on this page · raw message
net/netfilter/nft_set_hash.c +0 -2
@@ -376,8 +376,6 @@ static void nft_rhash_gc(struct work_struct *work)nft_trans_gc_elem_add (gc, he); } - gc =nft_trans_gc_catchall_async (gc, gc_seq); - try_later:/* catchall list iteration requires rcu read side lock. */ rhashtable_walk_stop (&hti);
Signature · 1 line
2.43.0
Florian Westphal
maintainerPATCH 5/9 netfilter: nf_tables: condense catchall gc
In reply to Florian Westphalnft_trans_gc_catchall_sync can now re-use the helper added in previous commit.
--- include/net/netfilter/nf_tables.h | 2 +- net/netfilter/nf_tables_api.c | 31 ++++++------------------------- net/netfilter/nft_set_pipapo.c | 2 +- net/netfilter/nft_set_rbtree.c | 2 +- 4 files changed, 9 insertions(+), 28 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -1758,7 +1758,7 @@ void nft_trans_gc_queue_sync_done(struct nft_trans_gc *trans);void nft_trans_gc_elem_add (struct nft_trans_gc *gc,void *priv); -struct nft_trans_gc *nft_trans_gc_catchall_sync (struct nft_trans_gc *gc); +void nft_trans_gc_catchall_sync (const struct nft_trans_gc *gc); void nft_setelem_data_deactivate(const struct net *net, const struct nft_set *set,
net/netfilter/nf_tables_api.c +6 -25
@@ -9876,33 +9876,14 @@ void nft_trans_gc_queue_sync_done(struct nft_trans_gc *trans)call_rcu (&trans->rcu, nft_trans_gc_trans_free); } -struct nft_trans_gc *nft_trans_gc_catchall_sync (struct nft_trans_gc *gc) +void nft_trans_gc_catchall_sync (const struct nft_trans_gc *gc) { -struct nft_set_elem_catchall *catchall, *next; -u64 tstamp =nft_net_tstamp (gc->net); -const struct nft_set *set = gc->set; -struct nft_elem_priv *elem_priv; -struct nft_set_ext *ext; - -WARN_ON_ONCE (!lockdep_commit_lock_is_held (gc->net)); - -list_for_each_entry_safe (catchall, next, &set->catchall_list, list) { - ext =nft_set_elem_ext (set, catchall->elem); - -if (!__nft_set_elem_expired (ext, tstamp)) -continue ; - - gc =nft_trans_gc_queue_sync (gc,GFP_KERNEL ); -if (!gc) -return NULL ; - - elem_priv = catchall->elem; -nft_setelem_data_deactivate (gc->net, gc->set, elem_priv); -nft_setelem_catchall_destroy (catchall); -nft_trans_gc_elem_add (gc, elem_priv); - } +struct nft_ctx ctx = { + .table = gc->set->table, + .net = gc->net, + }; -return gc; +nft_trans_gc_catchall (&ctx, gc->set); }static void nf_tables_module_autoload_cleanup (struct net *net)
net/netfilter/nft_set_pipapo.c +1 -1
@@ -1716,8 +1716,8 @@ static void pipapo_gc(struct nft_set *set, struct nft_pipapo_match *m) } } - gc =nft_trans_gc_catchall_sync (gc);if (gc) { +nft_trans_gc_catchall_sync (gc);nft_trans_gc_queue_sync_done (gc); priv->last_gc = jiffies; }
net/netfilter/nft_set_rbtree.c +1 -1
@@ -678,7 +678,7 @@ static void nft_rbtree_gc(struct nft_set *set) try_later:if (gc) { - gc =nft_trans_gc_catchall_sync (gc); +nft_trans_gc_catchall_sync (gc);nft_trans_gc_queue_sync_done (gc); priv->last_gc = jiffies; }
Signature · 1 line
2.43.0
Florian Westphal
maintainerPATCH 6/9 netfilter: nf_tables: add in-kernel only query that will return expired/dead elements
In reply to Florian WestphalExtend the rhashtable backend so that nf_tables core can lookup a dead or expired entry.
As-is, a set lookup will never return a matching entry that has expired, which is the desired behaviour.
This has to be toggleable, else a dead element can shadow an alive one, or vice versa.
Add internal NFT_SET_ELEM_GET_DEAD: if set, return a dead/expired element, or null.
This is used in a follow patch that will switch the current gc collection scheme from 'collect expired elements' to 'collect the keys of expired elements'.
The difference is that in the former case, extra assurances are needed to prevent the collected pointers from being free'd, or (this is the current solution) a way to detect when the element pointers might have gone stale.
With this approach, we can just copy the key and then query those keys
later: If the element got removed (or replaced!) in between, we just move on to the next candidate key.
--- include/uapi/linux/netfilter/nf_tables.h | 5 +++++ net/netfilter/nf_tables_api.c | 12 ++++++++++-- net/netfilter/nft_set_hash.c | 9 +++++++-- 3 files changed, 22 insertions(+), 4 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +5 -0
@@ -428,6 +428,11 @@ enum nft_set_attributes {enum nft_set_elem_flags {NFT_SET_ELEM_INTERVAL_END =0x1 ,NFT_SET_ELEM_CATCHALL =0x2 , + +#ifdef __KERNEL__ +/* not visisble to userspace, should be rejected if seen */ +NFT_SET_ELEM_GET_DEAD =0x80000000 , +#endif };/**
net/netfilter/nf_tables_api.c +10 -2
@@ -6007,7 +6007,8 @@ static int nft_setelem_parse_data(struct nft_ctx *ctx, struct nft_set *set, }static void *nft_setelem_catchall_get (const struct net *net, -const struct nft_set *set) +const struct nft_set *set, +u32 flags) {struct nft_set_elem_catchall *catchall;u8 genmask =nft_genmask_cur (net);
@@ -6016,6 +6017,13 @@ static void *nft_setelem_catchall_get(const struct net *net,list_for_each_entry_rcu (catchall, &set->catchall_list, list) { ext =nft_set_elem_ext (set, catchall->elem); + +if ((flags &NFT_SET_ELEM_GET_DEAD ) && +nft_set_elem_expired (ext)) { + priv = catchall->elem; +break ; + } +if (!nft_set_elem_active (ext, genmask) ||nft_set_elem_expired (ext))continue ;
@@ -6037,7 +6045,7 @@ static int nft_setelem_get(struct nft_ctx *ctx, const struct nft_set *set,if (IS_ERR (priv))return PTR_ERR (priv); }else { - priv =nft_setelem_catchall_get (ctx->net, set); + priv =nft_setelem_catchall_get (ctx->net, set, flags &NFT_SET_ELEM_GET_DEAD );if (!priv)return -ENOENT ; }
net/netfilter/nft_set_hash.c +7 -2
@@ -35,6 +35,7 @@ struct nft_rhash_elem {struct nft_rhash_cmp_arg {const struct nft_set *set;const u32 *key; +bool dead;u8 genmask;u64 tstamp; };
@@ -61,13 +62,16 @@ static inline int nft_rhash_cmp(struct rhashtable_compare_arg *arg,if (memcmp (nft_set_ext_key (&he->ext), x->key, x->set->klen))return 1 ; +if (nft_set_elem_is_dead (&he->ext))return 1 ;if (__nft_set_elem_expired (&he->ext, x->tstamp)) -return 1 ; +return x->dead ?0 :1 ;if (!nft_set_elem_active (&he->ext, x->genmask))return 1 ; -return 0 ; + +/* don't want valid element to shadow expired one */ +return x->dead ?1 :0 ; }static const struct rhashtable_params nft_rhash_params = {
@@ -109,6 +113,7 @@ nft_rhash_get(const struct net *net, const struct nft_set *set, .set = set, .key = elem->key.val.data, .tstamp = get_jiffies_64(), + .dead = flags & NFT_SET_ELEM_GET_DEAD, }; he =rhashtable_lookup (&priv->ht, &arg, nft_rhash_params);
Signature · 1 line
2.43.0
Florian Westphal
maintainerPATCH 7/9 netfilter: nf_tables: prepare for key-based deletion from workqueue
In reply to Florian WestphalAt the moment async gc stores pointers to the to-be-removed elements, async workqueue removes and them.
This works but has a few drawbacks:
Care must be taken so no pointers is posted twice, else we get double-free.
This makes it necessary to skip a gc cycle if the work queue is still scheduled, even though the given set has no pending gc deletions.
Because pointers are used, we also have to consider userspace transactions flushing/altering the set while gc is pending, for this reason we have to back out if userspace made some changes, even though the set might not have been affected at all and all queued element pointers are still valid.
Now that rhashtable backend is the only remaining async gc worker, lets simplify this.
Instead of storing pointers, store a copy of the element keys that have expired.
Then, from work queue with transaction mutex held, query the set for the given key.
If its found and expired, remove it.
IOW, the idea is to collect *candidates* to examine for expiration, not element pointers.
If the element got removed, element lookup will return no match and key is skipped, same if the key isn't expired (i.e. userspace flushed and repopulated the set with
identical, active key).
This is an intermediate step:
We still store pointers and use them, but also store the keys. We then validate that lookup does returns the expected pointer.
Use WARN()s, they are not expected to trigger because the gc sequence checks are still in place.
Next patch can remove the gc sequence counter and only rely on the key lookup.
The batchcount is lowered so that the nft_trans_gc allocations are taken from kmalloc-2k cache.
"struct nft_trans_gc_key" could be "union nft_trans_gc_key", but this only provides space for 4 more keyslots per nft_trans_gc object, so this is probably not worth the extra risk from aliasing key and to_free stash pointer.
--- include/net/netfilter/nf_tables.h | 10 ++++-- net/netfilter/nf_tables_api.c | 58 +++++++++++++++++++++++++++---- net/netfilter/nft_set_hash.c | 2 +- 3 files changed, 61 insertions(+), 9 deletions(-)
include/net/netfilter/nf_tables.h +8 -2
@@ -1733,7 +1733,12 @@ struct nft_trans_flowtable {#define nft_trans_flowtable_flags (trans) \ (((struct nft_trans_flowtable *)trans->data)->flags) -#define NFT_TRANS_GC_BATCHCOUNT 256 +#define NFT_TRANS_GC_BATCHCOUNT 27 + +struct nft_trans_gc_key { +u32 key[NFT_DATA_VALUE_MAXLEN /sizeof (u32)]; +struct nft_elem_priv *priv; +};struct nft_trans_gc {struct list_head list;
@@ -1741,7 +1746,7 @@ struct nft_trans_gc {struct nft_set *set;u32 seq;u16 count; -struct nft_elem_priv *priv[NFT_TRANS_GC_BATCHCOUNT ]; +struct nft_trans_gc_key keys[NFT_TRANS_GC_BATCHCOUNT ];struct rcu_head rcu; };
@@ -1756,6 +1761,7 @@ void nft_trans_gc_queue_async_done(struct nft_trans_gc *gc);struct nft_trans_gc *nft_trans_gc_queue_sync (struct nft_trans_gc *gc,gfp_t gfp);void nft_trans_gc_queue_sync_done (struct nft_trans_gc *trans); +void nft_async_gc_key_add (struct nft_trans_gc *gc,struct nft_elem_priv *priv);void nft_trans_gc_elem_add (struct nft_trans_gc *gc,void *priv);void nft_trans_gc_catchall_sync (const struct nft_trans_gc *gc);
net/netfilter/nf_tables_api.c +52 -6
87 lines not on this page · raw message
net/netfilter/nft_set_hash.c +1 -1
@@ -378,7 +378,7 @@ static void nft_rhash_gc(struct work_struct *work)if (!gc) goto try_later; -nft_trans_gc_elem_add (gc, he); +nft_async_gc_key_add (gc, &he->priv); } try_later:
Signature · 1 line
2.43.0
Florian Westphal
maintainerPATCH 8/9 netfilter: nf_tables: remove expired elements based on key lookup only
In reply to Florian WestphalPrevious change looks up the candidate keys in the set, then removes those that are expired or marked dead.
Keys that yield no result are skipped, keys where result is not expired or dead are kept too.
We add new to_free pointer to store those elements that have been deactivated and await release via call_rcu.
Because sequence checks are still in place, the key lookup cannot fail and elements are always dead or expired.
Next patch will remove the gc sequence counters.
--- include/net/netfilter/nf_tables.h | 2 +- net/netfilter/nf_tables_api.c | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -1737,7 +1737,7 @@ struct nft_trans_flowtable {struct nft_trans_gc_key {u32 key[NFT_DATA_VALUE_MAXLEN /sizeof (u32)]; -struct nft_elem_priv *priv; +struct nft_elem_priv *to_free; };struct nft_trans_gc {
net/netfilter/nf_tables_api.c +23 -5
@@ -9686,14 +9686,22 @@ static void nft_trans_gc_setelem_remove(struct nft_ctx *ctx,memcpy (&elem.key, key->key,sizeof (elem.key)); err =nft_setelem_get (ctx, trans->set, &elem,NFT_SET_ELEM_GET_DEAD ); -WARN_ON (err <0 ); -WARN_ON (key->priv != elem.priv); +if (err <0 ) { + trans->keys[i].to_free =NULL ; +continue ; + } ext =nft_set_elem_ext (trans->set, elem.priv); + +WARN_ON (nft_setelem_is_catchall (trans->set, elem.priv)); +/* nft_dynset can mark non-expired as DEAD, remove those too */ if (nft_set_elem_expired (ext) ||nft_set_elem_is_dead (ext)) { + key->to_free = elem.priv;nft_setelem_data_deactivate (ctx->net, trans->set, elem.priv);nft_setelem_remove (ctx->net, trans->set, elem.priv); + }else { + trans->keys[i].to_free =NULL ; } }
@@ -9718,7 +9726,11 @@ static void nft_trans_gc_trans_free(struct rcu_head *rcu) ctx.net =read_pnet (&trans->set->net);for (i =0 ; i < trans->count; i++) { - elem_priv = trans->keys[i].priv; + elem_priv = trans->keys[i].to_free; + +if (!elem_priv) +continue ; +if (!nft_setelem_is_catchall (trans->set, elem_priv))atomic_dec (&trans->set->nelems);
@@ -9734,6 +9746,13 @@ static int nft_trans_gc_space(struct nft_trans_gc *trans)return NFT_TRANS_GC_BATCHCOUNT - trans->count; } +static void nft_trans_gc_catchall_elem_add (struct nft_trans_gc *trans, +struct nft_elem_priv *to_free) +{ + trans->keys[trans->count].to_free = to_free; + trans->count++; +} +static void nft_trans_gc_catchall (struct nft_ctx *ctx,struct nft_set *set) {struct nft_set_elem_catchall *catchall, *next;
@@ -9769,7 +9788,7 @@ static void nft_trans_gc_catchall(struct nft_ctx *ctx, struct nft_set *set) elem_priv = catchall->elem;nft_setelem_data_deactivate (ctx->net, set, elem_priv);nft_setelem_catchall_destroy (catchall); -nft_trans_gc_elem_add (gc, elem_priv); +nft_trans_gc_catchall_elem_add (gc, elem_priv); }call_rcu (&gc->rcu, nft_trans_gc_trans_free);
@@ -9865,7 +9884,6 @@ void nft_async_gc_key_add(struct nft_trans_gc *gc, struct nft_elem_priv *priv) ext =nft_set_elem_ext (set, priv);memcpy (gc->keys[gc->count].key,nft_set_ext_key (ext), set->klen); - gc->keys[gc->count].priv = priv; gc->count++; }
Signature · 1 line
2.43.0
Florian Westphal
maintainerPATCH 9/9 netfilter: nf_tables: remove gc sequence counter
In reply to Florian WestphalRemove gc sequence counter, rely only on the DEAD lookup.
Concurrent set removal is fine, we still hold a reference to the set structure.
netns can't go away, the trans_gc structure increments the netns refcount.
--- include/net/netfilter/nf_tables.h | 13 ++------ net/netfilter/nf_tables_api.c | 55 +++++-------------------------- net/netfilter/nft_set_hash.c | 18 ++-------- net/netfilter/nft_set_pipapo.c | 2 +- net/netfilter/nft_set_rbtree.c | 4 +-- 5 files changed, 16 insertions(+), 76 deletions(-)
include/net/netfilter/nf_tables.h +2 -11
@@ -605,11 +605,6 @@ static inline void *nft_set_priv(const struct nft_set *set)return (void *)set->data; } -static inline bool nft_set_gc_is_pending (const struct nft_set *s) -{ -return refcount_read (&s->refs) !=1 ; -} -static inline struct nft_set *nft_set_container_of (const void *priv) {return (void *)priv - offsetof(struct nft_set , data);
@@ -1744,18 +1739,15 @@ struct nft_trans_gc {struct list_head list;struct net *net;struct nft_set *set; -u32 seq;u16 count;struct nft_trans_gc_key keys[NFT_TRANS_GC_BATCHCOUNT ];struct rcu_head rcu; }; -struct nft_trans_gc *nft_trans_gc_alloc (struct nft_set *set, -unsigned int gc_seq,gfp_t gfp); +struct nft_trans_gc *nft_trans_gc_alloc (struct nft_set *set,gfp_t gfp);void nft_trans_gc_destroy (struct nft_trans_gc *trans); -struct nft_trans_gc *nft_trans_gc_queue_async (struct nft_trans_gc *gc, -unsigned int gc_seq,gfp_t gfp); +struct nft_trans_gc *nft_trans_gc_queue_async (struct nft_trans_gc *gc,gfp_t gfp);void nft_trans_gc_queue_async_done (struct nft_trans_gc *gc);struct nft_trans_gc *nft_trans_gc_queue_sync (struct nft_trans_gc *gc,gfp_t gfp);
@@ -1797,7 +1789,6 @@ struct nftables_pernet {u64 table_handle;u64 tstamp;unsigned int base_seq; -unsigned int gc_seq;u8 validate_state; };
net/netfilter/nf_tables_api.c +9 -46
172 lines not on this page · raw message
net/netfilter/nft_set_hash.c +2 -16
@@ -323,25 +323,18 @@ static bool nft_rhash_expr_needs_gc_run(const struct nft_set *set,static void nft_rhash_gc (struct work_struct *work) { -struct nftables_pernet *nft_net;struct nft_set *set;struct nft_rhash_elem *he;struct nft_rhash *priv;struct rhashtable_iter hti;struct nft_trans_gc *gc;struct net *net; -u32 gc_seq; priv = container_of(work, struct nft_rhash, gc_work.work); set =nft_set_container_of (priv); net =read_pnet (&set->net); - nft_net =nft_pernet (net); - gc_seq =READ_ONCE (nft_net->gc_seq); -if (nft_set_gc_is_pending (set)) - goto done; - - gc =nft_trans_gc_alloc (set, gc_seq,GFP_KERNEL ); + gc =nft_trans_gc_alloc (set,GFP_KERNEL );if (!gc) goto done;
@@ -355,13 +348,6 @@ static void nft_rhash_gc(struct work_struct *work) goto try_later; } -/* Ruleset has been updated, try later. */ -if (READ_ONCE (nft_net->gc_seq) != gc_seq) { -nft_trans_gc_destroy (gc); - gc =NULL ; - goto try_later; - } -if (nft_set_elem_is_dead (&he->ext)) goto dead_elem;
@@ -374,7 +360,7 @@ static void nft_rhash_gc(struct work_struct *work) needs_gc_run:nft_set_elem_dead (&he->ext); dead_elem: - gc =nft_trans_gc_queue_async (gc, gc_seq,GFP_ATOMIC ); + gc =nft_trans_gc_queue_async (gc,GFP_ATOMIC );if (!gc) goto try_later;
net/netfilter/nft_set_pipapo.c +1 -1
@@ -1667,7 +1667,7 @@ static void pipapo_gc(struct nft_set *set, struct nft_pipapo_match *m)struct nft_pipapo_elem *e;struct nft_trans_gc *gc; - gc =nft_trans_gc_alloc (set,0 ,GFP_KERNEL ); + gc =nft_trans_gc_alloc (set,GFP_KERNEL );if (!gc)return ;
net/netfilter/nft_set_rbtree.c +2 -2
@@ -242,7 +242,7 @@ nft_rbtree_gc_elem(const struct nft_set *__set, struct nft_rbtree *priv,struct nft_rbtree_elem *rbe_prev;struct nft_trans_gc *gc; - gc =nft_trans_gc_alloc (set,0 ,GFP_ATOMIC ); + gc =nft_trans_gc_alloc (set,GFP_ATOMIC );if (!gc)return ERR_PTR (-ENOMEM );
@@ -634,7 +634,7 @@ static void nft_rbtree_gc(struct nft_set *set) set =nft_set_container_of (priv); net =read_pnet (&set->net); - gc =nft_trans_gc_alloc (set,0 ,GFP_KERNEL ); + gc =nft_trans_gc_alloc (set,GFP_KERNEL );if (!gc)return ;
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH nf-next 9/9] netfilter: nf_tables: remove gc sequence counter
kernel test robot noticed the following build warnings:
Hi Florian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on next-20240307]
[also build test WARNING on linus/master v6.8-rc7]
[cannot apply to nf-next/master netfilter-nf/main v6.8-rc7 v6.8-rc6 v6.8-rc5] [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-nf_tables-warn-if-set-being-destroyed-is-still-active/20240307-171729 base: next-20240307 patch link: https://lore.kernel.org/r/20240307084018.2219-10-fw%40strlen.de patch subject: [PATCH nf-next 9/9] netfilter: nf_tables: remove gc sequence counter config: s390-defconfig (https://download.01.org/0day-ci/archive/20240310/[email protected]/config) compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 503c55e17037436dcd45ac69dea8967e67e3f5e8) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240310/[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 >>):
include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
115 | #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
| ^
In file included from net/netfilter/nft_set_hash.c:14:
In file included from include/linux/netlink.h:7:
In file included from include/linux/skbuff.h:28:
In file included from include/linux/dma-mapping.h:11:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:78:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
584 | __raw_writeb(value, PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
594 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
604 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
692 | readsb(PCI_IOBASE + addr, buffer, count);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
700 | readsw(PCI_IOBASE + addr, buffer, count);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
708 | readsl(PCI_IOBASE + addr, buffer, count);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
717 | writesb(PCI_IOBASE + addr, buffer, count);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
726 | writesw(PCI_IOBASE + addr, buffer, count);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
735 | writesl(PCI_IOBASE + addr, buffer, count);
| ~~~~~~~~~~ ^
In file included from net/netfilter/nft_set_hash.c:14:
In file included from include/linux/netlink.h:9:
In file included from include/net/scm.h:9:
In file included from include/linux/security.h:35:
include/linux/bpf.h:736:48: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion]
736 | ARG_PTR_TO_MAP_VALUE_OR_NULL = PTR_MAYBE_NULL | ARG_PTR_TO_MAP_VALUE,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:737:43: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion]
737 | ARG_PTR_TO_MEM_OR_NULL = PTR_MAYBE_NULL | ARG_PTR_TO_MEM,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
include/linux/bpf.h:738:43: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion]
738 | ARG_PTR_TO_CTX_OR_NULL = PTR_MAYBE_NULL | ARG_PTR_TO_CTX,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
include/linux/bpf.h:739:45: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion]
739 | ARG_PTR_TO_SOCKET_OR_NULL = PTR_MAYBE_NULL | ARG_PTR_TO_SOCKET,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
include/linux/bpf.h:740:44: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion]
740 | ARG_PTR_TO_STACK_OR_NULL = PTR_MAYBE_NULL | ARG_PTR_TO_STACK,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~
include/linux/bpf.h:741:45: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion]
741 | ARG_PTR_TO_BTF_ID_OR_NULL = PTR_MAYBE_NULL | ARG_PTR_TO_BTF_ID,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
include/linux/bpf.h:745:38: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion]
745 | ARG_PTR_TO_UNINIT_MEM = MEM_UNINIT | ARG_PTR_TO_MEM,
| ~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
include/linux/bpf.h:747:45: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_arg_type') [-Wenum-enum-conversion]
747 | ARG_PTR_TO_FIXED_SIZE_MEM = MEM_FIXED_SIZE | ARG_PTR_TO_MEM,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
include/linux/bpf.h:770:48: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_return_type') [-Wenum-enum-conversion]
770 | RET_PTR_TO_MAP_VALUE_OR_NULL = PTR_MAYBE_NULL | RET_PTR_TO_MAP_VALUE,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:771:45: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_return_type') [-Wenum-enum-conversion]
771 | RET_PTR_TO_SOCKET_OR_NULL = PTR_MAYBE_NULL | RET_PTR_TO_SOCKET,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
include/linux/bpf.h:772:47: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_return_type') [-Wenum-enum-conversion]
772 | RET_PTR_TO_TCP_SOCK_OR_NULL = PTR_MAYBE_NULL | RET_PTR_TO_TCP_SOCK,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:773:50: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_return_type') [-Wenum-enum-conversion]
773 | RET_PTR_TO_SOCK_COMMON_OR_NULL = PTR_MAYBE_NULL | RET_PTR_TO_SOCK_COMMON,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:775:49: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_return_type') [-Wenum-enum-conversion]
775 | RET_PTR_TO_DYNPTR_MEM_OR_NULL = PTR_MAYBE_NULL | RET_PTR_TO_MEM,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
include/linux/bpf.h:776:45: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_return_type') [-Wenum-enum-conversion]
776 | RET_PTR_TO_BTF_ID_OR_NULL = PTR_MAYBE_NULL | RET_PTR_TO_BTF_ID,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
include/linux/bpf.h:777:43: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_return_type') [-Wenum-enum-conversion]
777 | RET_PTR_TO_BTF_ID_TRUSTED = PTR_TRUSTED | RET_PTR_TO_BTF_ID,
| ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
include/linux/bpf.h:888:44: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_reg_type') [-Wenum-enum-conversion]
888 | PTR_TO_MAP_VALUE_OR_NULL = PTR_MAYBE_NULL | PTR_TO_MAP_VALUE,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~
include/linux/bpf.h:889:42: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_reg_type') [-Wenum-enum-conversion]
889 | PTR_TO_SOCKET_OR_NULL = PTR_MAYBE_NULL | PTR_TO_SOCKET,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~
include/linux/bpf.h:890:46: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_reg_type') [-Wenum-enum-conversion]
890 | PTR_TO_SOCK_COMMON_OR_NULL = PTR_MAYBE_NULL | PTR_TO_SOCK_COMMON,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:891:44: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_reg_type') [-Wenum-enum-conversion]
891 | PTR_TO_TCP_SOCK_OR_NULL = PTR_MAYBE_NULL | PTR_TO_TCP_SOCK,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
include/linux/bpf.h:892:42: warning: bitwise operation between different enumeration types ('enum bpf_type_flag' and 'enum bpf_reg_type') [-Wenum-enum-conversion]
892 | PTR_TO_BTF_ID_OR_NULL = PTR_MAYBE_NULL | PTR_TO_BTF_ID,
| ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~
>> net/netfilter/nft_set_hash.c:331:14: warning: variable 'net' set but not used [-Wunused-but-set-variable]
331 | struct net *net;
| ^38 warnings generated.
vim +/net +331 net/netfilter/nft_set_hash.c
563125a73ac30d net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2020-12-09 323
5fc6ced958db70 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2017-05-22 324 static void nft_rhash_gc(struct work_struct *work)
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 325 {
3dd0673ac3cd7d net/netfilter/nft_hash.c Patrick McHardy 2015-04-05 326 struct nft_set *set;
5fc6ced958db70 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2017-05-22 327 struct nft_rhash_elem *he;
5fc6ced958db70 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2017-05-22 328 struct nft_rhash *priv;
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 329 struct rhashtable_iter hti;
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 330 struct nft_trans_gc *gc;
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 @331 struct net *net;
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 332
5fc6ced958db70 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2017-05-22 333 priv = container_of(work, struct nft_rhash, gc_work.work);
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 334 set = nft_set_container_of(priv);
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 335 net = read_pnet(&set->net);
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 336
5cc2ff2eae3d8c net/netfilter/nft_set_hash.c Florian Westphal 2024-03-07 337 gc = nft_trans_gc_alloc(set, GFP_KERNEL);
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 338 if (!gc)
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 339 goto done;
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 340
0de22baabc97f7 net/netfilter/nft_set_hash.c Taehee Yoo 2018-09-14 341 rhashtable_walk_enter(&priv->ht, &hti);
97a6ec4ac021f7 net/netfilter/nft_set_hash.c Tom Herbert 2017-12-04 342 rhashtable_walk_start(&hti);
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 343
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 344 while ((he = rhashtable_walk_next(&hti))) {
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 345 if (IS_ERR(he)) {
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 346 nft_trans_gc_destroy(gc);
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 347 gc = NULL;
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 348 goto try_later;
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 349 }
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 350
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 351 if (nft_set_elem_is_dead(&he->ext))
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 352 goto dead_elem;
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 353
563125a73ac30d net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2020-12-09 354 if (nft_set_ext_exists(&he->ext, NFT_SET_EXT_EXPRESSIONS) &&
563125a73ac30d net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2020-12-09 355 nft_rhash_expr_needs_gc_run(set, &he->ext))
563125a73ac30d net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2020-12-09 356 goto needs_gc_run;
79b174ade16d90 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2018-06-02 357
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 358 if (!nft_set_elem_expired(&he->ext))
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 359 continue;
563125a73ac30d net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2020-12-09 360 needs_gc_run:
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 361 nft_set_elem_dead(&he->ext);
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 362 dead_elem:
5cc2ff2eae3d8c net/netfilter/nft_set_hash.c Florian Westphal 2024-03-07 363 gc = nft_trans_gc_queue_async(gc, GFP_ATOMIC);
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 364 if (!gc)
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 365 goto try_later;
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 366
2e55eccd9a4596 net/netfilter/nft_set_hash.c Florian Westphal 2024-03-07 367 nft_async_gc_key_add(gc, &he->priv);
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 368 }
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 369
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 370 try_later:
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 371 /* catchall list iteration requires rcu read side lock. */
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 372 rhashtable_walk_stop(&hti);
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 373 rhashtable_walk_exit(&hti);
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 374
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 375 if (gc)
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 376 nft_trans_gc_queue_async_done(gc);
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 377
f6c383b8c31a93 net/netfilter/nft_set_hash.c Pablo Neira Ayuso 2023-08-09 378 done:
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 379 queue_delayed_work(system_power_efficient_wq, &priv->gc_work,
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 380 nft_set_gc_interval(set));
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 381 }
9d0982927e7904 net/netfilter/nft_hash.c Patrick McHardy 2015-03-26 382 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki