mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: mt4022@columbia.edu
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Mykyta Yatsenko <yatsenko@meta.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Shuah Khan <shuah@kernel.org>, Thomas Graf <tgraf@suug.ch>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	bpf@vger.kernel.org, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	tz2294@columbia.edu
Subject: Re: [PATCH bpf v2 1/4] rhashtable: Add trylock_irqsoff for callers that can't spin
Date: Fri, 4 Dec 2026 12:47:53 +0800	[thread overview]
Message-ID: <axJF-QDb1VlRdOLl@gondor.apana.org.au> (raw)
In-Reply-To: <20261122-bpf-rhtab-irqs-disabled-v2-1-207aedcc2215@columbia.edu>

On Sun, Nov 22, 2026 at 07:25:12PM -0500, Mani Tofigh via B4 Relay wrote:
> From: Mani Tofigh <mt4022@columbia.edu>
> 
> A caller with IRQs disabled can run inside a bucket lock's critical
> section on its own CPU, e.g., in NMI or in a kprobe on the hash function
> that the resize worker calls with the lock held.  If it then inserts or
> removes a key of that bucket it spins on the bit lock forever.
> 
> Add rhashtable_params.trylock_irqsoff.  With it, inserts and removes
> called with IRQs disabled only try the bucket lock and return -EBUSY if
> it's held.  A caller with IRQs enabled can't run inside a locked section
> of its own CPU, so it still spins, and so does the resize worker.  The
> flag is a compile time constant in the fast paths like
> insecure_elasticity, so other users don't pay for it.
> 
> On UP without DEBUG_SPINLOCK the lock bit isn't kept, so these callers
> always get -EBUSY there.
> 
> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
> ---
>  include/linux/rhashtable-types.h |  3 +++
>  include/linux/rhashtable.h       | 34 ++++++++++++++++++++++++++++++++--
>  lib/rhashtable.c                 |  3 ++-
>  3 files changed, 37 insertions(+), 3 deletions(-)

I have to say that this looks horrible.

> diff --git a/include/linux/rhashtable-types.h b/include/linux/rhashtable-types.h
> index 3576b8f08aff..a5c4e696c193 100644
> --- a/include/linux/rhashtable-types.h
> +++ b/include/linux/rhashtable-types.h
> @@ -52,6 +52,8 @@ typedef int (*rht_obj_cmpfn_t)(struct rhashtable_compare_arg *arg,
>   * @min_size: Minimum size while shrinking
>   * @insecure_elasticity: Set to true to disable chain length checks
>   * @automatic_shrinking: Enable automatic shrinking of tables
> + * @trylock_irqsoff: With irqs disabled insert and remove don't spin on
> + *		     the bucket lock and return -EBUSY
>   * @hashfn: Hash function (default: jhash2 if !(key_len % 4), or jhash)
>   * @obj_hashfn: Function to hash object
>   * @obj_cmpfn: Function to compare key with object
> @@ -65,6 +67,7 @@ struct rhashtable_params {
>  	u16			min_size;
>  	bool			insecure_elasticity;
>  	bool			automatic_shrinking;
> +	bool			trylock_irqsoff;

Please call it something more obvious like used_in_nmi.

But I have to say that I'd rather draw a line and say that rhashtable
should not be used in NMI handlers and if you guys need that please
design your own data structure.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  parent reply	other threads:[~2026-12-04  4:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  0:25 [PATCH bpf v2 0/4] bpf: Don't spin on rhtab bucket locks with IRQs disabled Mani Tofigh via B4 Relay
2026-11-23  0:25 ` [PATCH bpf v2 1/4] rhashtable: Add trylock_irqsoff for callers that can't spin Mani Tofigh via B4 Relay
2026-11-23  0:58   ` bot+bpf-ci
2026-12-04  4:47   ` Herbert Xu [this message]
2026-12-05  4:23     ` Alexei Starovoitov
2026-11-23  0:25 ` [PATCH bpf v2 2/4] rhashtable: Don't retry trylock_irqsoff lookups with IRQs disabled Mani Tofigh via B4 Relay
2026-11-23  0:25 ` [PATCH bpf v2 3/4] bpf: Don't spin on rhtab bucket locks " Mani Tofigh via B4 Relay
2026-11-23  1:13   ` bot+bpf-ci
2026-11-23  0:25 ` [PATCH bpf v2 4/4] selftests/bpf: Test rhtab deletes from inside a resize Mani Tofigh via B4 Relay

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=axJF-QDb1VlRdOLl@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=mt4022@columbia.edu \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tgraf@suug.ch \
    --cc=tz2294@columbia.edu \
    --cc=yatsenko@meta.com \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®