public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
	daniel@iogearbox.net, kafai@meta.com, kernel-team@meta.com,
	eddyz87@gmail.com, memxor@gmail.com,
	Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH bpf-next v3 02/10] rhashtable: Add rhashtable_walk_enter_from()
Date: Tue, 5 May 2026 17:57:41 +0100	[thread overview]
Message-ID: <9a83db58-5192-4d12-80f1-2a63ba29def3@gmail.com> (raw)
In-Reply-To: <afCNcFLArNkj7GXh@gondor.apana.org.au>



On 4/28/26 11:35 AM, Herbert Xu wrote:
> On Fri, Apr 24, 2026 at 12:50:44PM -0700, Mykyta Yatsenko wrote:
> .
>> diff --git a/lib/rhashtable.c b/lib/rhashtable.c
>> index 6074ed5f66f3..2a6098edf737 100644
>> --- a/lib/rhashtable.c
>> +++ b/lib/rhashtable.c
>> @@ -692,6 +692,47 @@ void rhashtable_walk_enter(struct rhashtable *ht, struct rhashtable_iter *iter)
>>  }
>>  EXPORT_SYMBOL_GPL(rhashtable_walk_enter);
>>  
>> +/**
>> + * rhashtable_walk_enter_from - Initialise a walk starting at a key's bucket
>> + * @ht:		Table to walk over
>> + * @iter:	Hash table iterator
>> + * @key:	Key whose bucket to start from
>> + * @params:	Hash table parameters
>> + *
>> + * Like rhashtable_walk_enter(), but positions the iterator at the bucket
>> + * containing @key.  If @key is not present in the main table, the iterator is
>> + * positioned at the beginning.
>> + *
>> + * Same constraints as rhashtable_walk_enter() apply.
>> + */
>> +void rhashtable_walk_enter_from(struct rhashtable *ht,
>> +				struct rhashtable_iter *iter,
>> +				const void *key,
>> +				const struct rhashtable_params params)
>> +				__must_hold(RCU)
>> +{
>> +	struct bucket_table *tbl;
>> +	struct rhash_head *he;
>> +
>> +	rhashtable_walk_enter(ht, iter);
>> +
>> +	if (!key)
>> +		return;
>> +
>> +	tbl = iter->walker.tbl;
>> +	if (!tbl)
>> +		return;
>> +
>> +	he = __rhashtable_lookup_one(ht, tbl, key, params,
>> +				     RHT_LOOKUP_NORMAL);
>> +	if (!he)
>> +		return;
>> +
>> +	iter->slot = rht_key_hashfn(ht, tbl, key, params);
>> +	iter->p = he;
>> +}
>> +EXPORT_SYMBOL_GPL(rhashtable_walk_enter_from);
> 
> I still think this is misguided.  I'm not going to stop you from
> doing it if you really wanted to, but this thing will not work well
> if your rhashtable is constantly resizing.
> 
> You also need to consider the possibility that an adversary is
> triggering the constant rehashing.
> 
> Cheers,

Herbert,
We brainstormed with Alexei on how to integrate rhashtable better,
as a BPF map, we have the next proposal:

Introduce rhashtable_next_key() API
```
static inline struct rhash_head *rhashtable_next_key(
	struct rhashtable *ht, const void *prev_key,
	const struct rhashtable_params params);
```

It returns the next element, by finding prev_key in the tbl chain
and returning the next element in whatever tbl the prev one is.
This way we keep rhashtable API tight, less surface, not exposing unnecessary
details, although, this new API will have the same issues with full
iteration support (which we fine to deal with on userspace side).
Appreciate if you share your opinion on this.



  reply	other threads:[~2026-05-05 16:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24 19:50 [PATCH bpf-next v3 00/10] bpf: Introduce resizable hash map Mykyta Yatsenko
2026-04-24 19:50 ` [PATCH bpf-next v3 01/10] bpf: Implement resizable hashmap basic functions Mykyta Yatsenko
2026-04-24 20:40   ` sashiko-bot
2026-04-25 20:41     ` Mykyta Yatsenko
2026-04-24 20:45   ` bot+bpf-ci
2026-04-25 20:50     ` Mykyta Yatsenko
2026-04-24 19:50 ` [PATCH bpf-next v3 02/10] rhashtable: Add rhashtable_walk_enter_from() Mykyta Yatsenko
2026-04-24 20:15   ` sashiko-bot
2026-04-24 20:45   ` bot+bpf-ci
2026-04-28 10:35   ` Herbert Xu
2026-05-05 16:57     ` Mykyta Yatsenko [this message]
2026-04-24 19:50 ` [PATCH bpf-next v3 03/10] bpf: Implement get_next_key() resizable hashtab Mykyta Yatsenko
2026-04-28 10:33   ` Herbert Xu
2026-04-28 13:20     ` Mykyta Yatsenko
2026-04-24 19:50 ` [PATCH bpf-next v3 04/10] bpf: Implement batch ops and iterators for " Mykyta Yatsenko
2026-04-24 20:28   ` sashiko-bot
2026-04-25 21:24     ` Mykyta Yatsenko
2026-04-27 13:36       ` Mykyta Yatsenko
2026-04-24 19:50 ` [PATCH bpf-next v3 05/10] bpf: Allow timers, workqueues and task_work in " Mykyta Yatsenko
2026-04-24 21:05   ` sashiko-bot
2026-04-25 21:29     ` Mykyta Yatsenko
2026-04-24 19:50 ` [PATCH bpf-next v3 06/10] libbpf: Support resizable hashtable Mykyta Yatsenko
2026-04-24 19:50 ` [PATCH bpf-next v3 07/10] selftests/bpf: Add basic tests for resizable hash map Mykyta Yatsenko
2026-04-24 20:02   ` sashiko-bot
2026-04-24 20:32   ` bot+bpf-ci
2026-04-24 19:50 ` [PATCH bpf-next v3 08/10] selftests/bpf: Add BPF iterator " Mykyta Yatsenko
2026-04-24 19:50 ` [PATCH bpf-next v3 09/10] bpftool: Add rhash map documentation Mykyta Yatsenko
2026-04-24 19:50 ` [PATCH bpf-next v3 10/10] selftests/bpf: Add resizable hashmap to benchmarks Mykyta Yatsenko

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=9a83db58-5192-4d12-80f1-2a63ba29def3@gmail.com \
    --to=mykyta.yatsenko5@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=kafai@meta.com \
    --cc=kernel-team@meta.com \
    --cc=memxor@gmail.com \
    --cc=yatsenko@meta.com \
    /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