BPF List
 help / color / mirror / Atom feed
From: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
To: Tianyi Chen <hi@tychen.cc>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	eddyz87@gmail.com, memxor@gmail.com, yatsenko@meta.com,
	shuah@kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf 1/2] bpf: Report lost RHASH batch traversal keys as EAGAIN
Date: Mon, 9 Nov 2026 18:53:38 +0000	[thread overview]
Message-ID: <85e164aa-7aa7-40ed-bfaf-883b8f51f7b2@gmail.com> (raw)
In-Reply-To: <4c32437eee7649fbd822108278a3f582bb795329.1794056839.git.hi@tychen.cc>



On 11/7/26 1:11 PM, Tianyi Chen wrote:
> If a key is deleted after a batch copies it, rhashtable_next_key()
> returns ERR_PTR(-ENOENT). The batch code treats the missing next cursor
> as end-of-iteration and returns -ENOENT with a partial batch, so callers
> can silently stop before reading keys that are still present.
> 
> Translate a lost traversal key to -EAGAIN, as for a missing input cursor,
> and preserve other iterator errors. Still copy the collected entries and
> update the count, including for lookup-and-delete batches.
> 
> Fixes: 818e00848227 ("bpf: Implement iteration ops for resizable hashtab")
> Link: https://github.com/kernel-patches/bpf/pull/14700#issuecomment-6641291019
> Assisted-by: LLM
> Signed-off-by: Tianyi Chen <hi@tychen.cc>
> ---
Looks correct: transform -ENOENT returned from rhashtable_next_key() to
-EAGAIN indicating loss of cursor.
rhashtable_next_key() returns NULL when iteration is exhausted, that
is transformed to -ENOENT in if (!has_next_cursor)

Acked-by: Mykyta Yatsenko <yatsenko@meta.com>

>  kernel/bpf/hashtab.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
> index 6e2115477cb9..346a2afb4ad3 100644
> --- a/kernel/bpf/hashtab.c
> +++ b/kernel/bpf/hashtab.c
> @@ -3556,14 +3556,15 @@ static int __rhtab_map_lookup_and_delete_batch(struct bpf_map *map,
>  
>  	rcu_read_unlock();
>  
> -	if (total == 0) {
> +	if (IS_ERR(elem)) {
> +		ret = PTR_ERR(elem);
> +		if (ret == -ENOENT)
> +			ret = -EAGAIN;
> +	} else if (!has_next_cursor) {
>  		ret = -ENOENT;
> -		goto free;
>  	}
> -
> -	/* No more elements after this batch. */
> -	if (!has_next_cursor)
> -		ret = -ENOENT;
> +	if (!total)
> +		goto free;
>  
>  	if (copy_to_user(ukeys, keys, (size_t)total * key_size) ||
>  	    copy_to_user(uvalues, values, (size_t)total * value_size) ||


  reply	other threads:[~2026-11-09 18:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07 13:11 [PATCH bpf 0/2] bpf: Fix RHASH batch cursor loss Tianyi Chen
2026-11-07 13:11 ` [PATCH bpf 1/2] bpf: Report lost RHASH batch traversal keys as EAGAIN Tianyi Chen
2026-11-09 18:53   ` Mykyta Yatsenko [this message]
2026-11-07 13:11 ` [PATCH bpf 2/2] selftests/bpf: Cover RHASH batch cursor loss Tianyi Chen
2026-11-07 13:22   ` sashiko-bot

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=85e164aa-7aa7-40ed-bfaf-883b8f51f7b2@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=hi@tychen.cc \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    --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