Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: kadlec@netfilter.org, linux-crypto@vger.kernel.org
Subject: Re: [v2 PATCH] rhashtable: Add rhashtable_flush_and_free helper
Date: Sat, 12 Sep 2026 20:32:44 +0200	[thread overview]
Message-ID: <aqWazNYddvTO5Sjn@strlen.de> (raw)
In-Reply-To: <aqUmlWEzhR3pKYuP@gondor.apana.org.au>

Herbert Xu <herbert@gondor.apana.org.au> wrote:
> This patch adds the helper rhashtable_flush_and_free and its
> rhltable counter-part.  The intended user is netfilter:
> 
> https://sashiko.dev/#/patchset/20260828152256.8759-1-fw%40strlen.de

Thanks for working on this.

> The hash table will briefly become NULL during the flush call,
> in order to avoid race conditions against concurrent insertions
> and removals which may schedule new rehashes.

When you send next version, could you elaborate a bit why this is
required?  rht_deferred_worker grabs the ht mutex, so I don't understand
this problem.  Worst case is a single,
"useless" rehash of a most likely empty (or at least mostly empty) table.

I don't see why the

mutex_lock(&ht->mutex);
old_tbl = rcu_replace_pointer(ht->tbl, new_tbl, lockdep_rht_mutex_is_held(ht));

is bad.  It avoids the NULL checks and concurrent insertions will work.

From your previous comments, there are two cases:

1. rehash gets queued, then flush was called (before worker runs).
   This result in a "useless" rehash of a mostly empty table, but
   I don't see the problem with this (flushes are rare).

2. flush -> table replaced with empty one; *then* a rehash gets queued
   (e.g. because of parallel mass insert into the new, now
    not-so-empty-anymore table).

In this second case, the behaviour is the same as if no flush would
have happened.

-EBUSY is always possible regardless of a flush happening or not. Also,
a possible "wrong" -EBUSY is certainly better than guaranteed
-EBUSY during the synchronize_rcu() call?

That said, if it is really needed then this "guarenteed -EBUSY" is fine
for my use case: for insertions from kernel/(iptables -j SET target),
failure is already tolerated / acceptable, and insertions from userspace
serialize on the same netlink mutex as the flush request.

  reply	other threads:[~2026-09-12 18:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12 10:16 [v2 PATCH] rhashtable: Add rhashtable_flush_and_free helper Herbert Xu
2026-09-12 18:32 ` Florian Westphal [this message]
2026-09-12 23:27   ` Herbert Xu
2026-09-13  0:12     ` [v3 " Herbert Xu
2026-09-13  1:34       ` [v4 " Herbert Xu
2026-09-13  2:53         ` [v5 " Herbert Xu
2026-09-13  6:31           ` 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=aqWazNYddvTO5Sjn@strlen.de \
    --to=fw@strlen.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=kadlec@netfilter.org \
    --cc=linux-crypto@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