Linux Netfilter development
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: netfilter-devel@vger.kernel.org
Cc: Jozsef Kadlecsik <kadlec@netfilter.org>
Subject: Re: [PATCH nf v3 3/5] netfilter: ipset: replace internal hash table with rhashtable
Date: Wed, 2 Sep 2026 06:32:20 +0200	[thread overview]
Message-ID: <apem1I-sJWVSfMT8@strlen.de> (raw)
In-Reply-To: <20260828152256.8759-4-fw@strlen.de>

Florian Westphal <fw@strlen.de> wrote:
> Assisted-by: Claude:claude-opus-4-6
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  v3:
>  serialize rhltable insertion with set->lock, else we can inject identical elements.
>  nit: also rename mtype_rht_size toke-replace
>  add kdoc comment to say that mtype_flush cannot guarantee set is empty
>  after flush (parallel re-add).
>  I ignored the LLM review wrt 'skipped elements' on set walks, with
>  parallel mutations (internal resizes, deletes) a stable walk would
>  require significantly more work, such as keeping elements on a
>  dedicated list.  It should be ok as-is.

[..]

> -/* Flush a hash type of set: destroy all elements */
> +/**
> + * mtype_flush() - Flush a hash set type by destroying all elements.
> + * @set: Pointer to the ip_set.
> + *
> + * Because other CPUs may concurrently insert new entries into the table
> + * while flush is in progress, there is no guarantee that the table will
> + * be empty upon return.
> + */
>  static void
>  mtype_flush(struct ip_set *set)
>  {
>  	struct htype *h = set->data;
> -#ifdef IP_SET_HASH_WITH_NETS
> -	struct net_prefixes *nets;
> -#endif
> -	struct htable *t;
> -	struct hbucket *n;
> -	u32 r, i;
> -
> -	t = ipset_dereference_nfnl(h->table);
> -	for (r = 0; r < ahash_numof_locks(t->htable_bits); r++) {
> -		spin_lock_bh(&t->hregion[r].lock);
> -		for (i = ahash_bucket_start(r, t->htable_bits);
> -		     i < ahash_bucket_end(r, t->htable_bits); i++) {
> -			n = __ipset_dereference(hbucket(t, i));
> -			if (!n)
> +	struct rhashtable_iter hti;
> +	struct mtype_rht_elem *e;
> +	unsigned int dropped;
> +
> +	ipset_hash_walk_enter(h, &hti);
> +restart:
> +	dropped = 0;
> +	rhashtable_walk_start(&hti);
> +
> +	while ((e = rhashtable_walk_next(&hti))) {
> +		if (IS_ERR(e)) {
> +			if (PTR_ERR(e) == -EAGAIN)
>  				continue;
> -			if (set->extensions & IPSET_EXT_DESTROY)
> -				mtype_ext_cleanup(set, n);
> -			/* FIXME: use slab cache */
> -			rcu_assign_pointer(hbucket(t, i), NULL);
> -			kfree_rcu(n, rcu);
> +			break;
> +		}
> +		if (ipset_hash_remove(h, e))
> +			continue; /* Concurrent delete? skip */
> +		mtype_del_cidr_all(set, h, &e->elem);
> +		ip_set_ext_destroy(set, &e->elem);
> +		kfree_rcu(e, rcu);
> +
> +		if (dropped++ > 128 && need_resched()) {
> +			rhashtable_walk_stop(&hti);
> +			cond_resched();
> +			goto restart;

As expected this triggers reject patterns in LLM.

I can go back to v1, which had no restart, which in turn triggered
'softirq lockup with large sets' reject patterns, but doesn't have
the "may skip elements" "problem".

Or we delay this while I work on an rhashtable_flush() that can
detach internal hash memory from the rhashtable set to avoid this.

I have no idea what the best course of action is here, but adding
an extra data structure (list for instance) is something I want to
avoid.

All other LLM comments were, as far as I could tell, hallucinations.

  reply	other threads:[~2026-09-02  4:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 15:22 [PATCH nf v3 0/5] netfilter: ipset: rhashtable conversion Florian Westphal
2026-08-28 15:22 ` [PATCH nf v3 1/5] netfilter: ipset: add rhashtable boilerplate stubs Florian Westphal
2026-08-28 15:22 ` [PATCH nf v3 2/5] netfilter: ipset: add rhltable " Florian Westphal
2026-08-28 15:22 ` [PATCH nf v3 3/5] netfilter: ipset: replace internal hash table with rhashtable Florian Westphal
2026-09-02  4:32   ` Florian Westphal [this message]
2026-09-02  7:35     ` Jozsef Kadlecsik
2026-09-02  7:42     ` Jozsef Kadlecsik
2026-08-28 15:22 ` [PATCH nf v3 4/5] netfilter: ipset: re-add forceadd support Florian Westphal
2026-08-28 15:22 ` [PATCH nf v3 5/5] netfilter: ipset: also report mem size for cidr storage to userspace Florian Westphal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=apem1I-sJWVSfMT8@strlen.de \
    --to=fw@strlen.de \
    --cc=kadlec@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox