mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: "T.J. Mercier" <tjmercier@google.com>,
	k.chen@smail.nju.edu.cn, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
	shuah@kernel.org
Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
	jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
	sumit.semwal@linaro.org, phasta@kernel.org, tj@kernel.org,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linaro-mm-sig@lists.linaro.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf] selftests/bpf: Test that a drained dmabuf iterator keeps returning NULL
Date: Thu, 12 Nov 2026 10:35:45 +0100	[thread overview]
Message-ID: <70c7192e-b9e7-4b06-9d78-38e9de85f486@amd.com> (raw)
In-Reply-To: <20261111195942.1283060-1-tjmercier@google.com>

On 11/11/26 20:59, T.J. Mercier wrote:
> The BPF iterator docs in bpf_iterators.rst specify that the next
> function of an open-coded iterator should keep returning NULL after it
> has been returned once.
> 
> Add a subtest that checks this for the dmabuf iterator. It drains an
> iterator, calls bpf_iter_dmabuf_next() once more and checks that the
> result is NULL. The dma-bufs the test creates keep the list from being
> empty, so an iterator that starts over would return one of them.
> 
> The existing open_coded subtest uses bpf_for_each(), which stops at the
> first NULL and never calls next() on a drained iterator.
> 
> Signed-off-by: T.J. Mercier <tjmercier@google.com>

Acked-by: Christian König <christian.koenig@amd.com>

Let me know if you already have drm-misc commit rights.

Regards,
Christian.

> ---
> This depends on Kang Chen's fix and fails without it:
> https://lore.kernel.org/bpf/20261110125106.2935677-1-k.chen@smail.nju.edu.cn/
> Kang, feel free to carry it as 2/2 in your v2.
> 
>  .../selftests/bpf/prog_tests/dmabuf_iter.c    | 19 +++++++++++++++++++
>  .../testing/selftests/bpf/progs/dmabuf_iter.c | 19 +++++++++++++++++++
>  2 files changed, 38 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c b/tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c
> index 1a5dc1adae73..c1f81b5dccdc 100644
> --- a/tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c
> +++ b/tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c
> @@ -265,6 +265,23 @@ static void subtest_dmabuf_iter_check_open_coded(struct dmabuf_iter *skel, int m
>  	} while (bpf_map_get_next_key(map_fd, key, key));
>  }
>  
> +static void subtest_dmabuf_iter_check_next_after_drain(struct dmabuf_iter *skel)
> +{
> +	LIBBPF_OPTS(bpf_test_run_opts, topts);
> +	int err, fd;
> +
> +	fd = bpf_program__fd(skel->progs.iter_dmabuf_next_after_drain);
> +
> +	err = bpf_prog_test_run_opts(fd, &topts);
> +	if (!ASSERT_OK(err, "test_run_opts err"))
> +		return;
> +	if (!ASSERT_OK(topts.retval, "test_run_opts retval"))
> +		return;
> +
> +	/* The test buffers exist, so a restarted iteration would find one */
> +	ASSERT_EQ(skel->data->next_after_drain, 0, "next_after_drain");
> +}
> +
>  void test_dmabuf_iter(void)
>  {
>  	struct dmabuf_iter *skel = NULL;
> @@ -315,6 +332,8 @@ void test_dmabuf_iter(void)
>  	}
>  	if (test__start_subtest("open_coded"))
>  		subtest_dmabuf_iter_check_open_coded(skel, map_fd);
> +	if (test__start_subtest("next_after_drain"))
> +		subtest_dmabuf_iter_check_next_after_drain(skel);
>  
>  destroy:
>  	destroy_test_buffers();
> diff --git a/tools/testing/selftests/bpf/progs/dmabuf_iter.c b/tools/testing/selftests/bpf/progs/dmabuf_iter.c
> index 9cbb7442646e..d5421b75c39c 100644
> --- a/tools/testing/selftests/bpf/progs/dmabuf_iter.c
> +++ b/tools/testing/selftests/bpf/progs/dmabuf_iter.c
> @@ -99,3 +99,22 @@ int iter_dmabuf_for_each(const void *ctx)
>  
>  	return 0;
>  }
> +
> +/* Result of a bpf_iter_dmabuf_next() call after the iterator was drained */
> +__u64 next_after_drain = -1;
> +
> +SEC("syscall")
> +int iter_dmabuf_next_after_drain(const void *ctx)
> +{
> +	struct bpf_iter_dmabuf it;
> +
> +	bpf_iter_dmabuf_new(&it);
> +	while (bpf_iter_dmabuf_next(&it))
> +		;
> +
> +	/* Store the raw value; the verifier would remove a branch on it */
> +	next_after_drain = (__u64)bpf_iter_dmabuf_next(&it);
> +	bpf_iter_dmabuf_destroy(&it);
> +
> +	return 0;
> +}


  reply	other threads:[~2026-11-12  9:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 12:51 [PATCH] bpf: make dmabuf iterator stay drained after NULL Kang Chen
2026-11-11  8:05 ` bot+bpf-ci
2026-11-11  8:18 ` Christian König
2026-11-11 19:54   ` T.J. Mercier
2026-11-11 19:59 ` [PATCH bpf] selftests/bpf: Test that a drained dmabuf iterator keeps returning NULL T.J. Mercier
2026-11-12  9:35   ` Christian König [this message]
2026-11-11 20:00 ` [PATCH] bpf: make dmabuf iterator stay drained after NULL T.J. Mercier

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=70c7192e-b9e7-4b06-9d78-38e9de85f486@amd.com \
    --to=christian.koenig@amd.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=k.chen@smail.nju.edu.cn \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=phasta@kernel.org \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=tj@kernel.org \
    --cc=tjmercier@google.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®