From: Jiri Olsa <olsajiri@gmail.com>
To: Menglong Dong <menglong8.dong@gmail.com>
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
yonghong.song@linux.dev, john.fastabend@gmail.com,
kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
shuah@kernel.org, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next] selftests/bpf: test access to ringbuf position with map pointer
Date: Fri, 20 Mar 2026 13:40:51 +0100 [thread overview]
Message-ID: <ab1AUyefoWABRs0T@krava> (raw)
In-Reply-To: <20260320084155.288417-1-dongml2@chinatelecom.cn>
On Fri, Mar 20, 2026 at 04:41:55PM +0800, Menglong Dong wrote:
> Add the testing to access the bpf_ringbuf with the map pointer.
> "consumer_pos" and "producer_pos" is accessed in this testing. We reserve
> 128 bytes in the ringbuf to test the producer_pos, which should be
> "128 + 8", and the "8" is BPF_RINGBUF_HDR_SZ.
>
> It will be helpful if we want to evaluate the usage of the ringbuf in bpf
> prog with the consumer and producer position.
>
> Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> ---
> .../testing/selftests/bpf/progs/map_ptr_kern.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> index efaf622c28dd..c3fa57ec430b 100644
> --- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> +++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
> @@ -647,21 +647,39 @@ static inline int check_devmap_hash(void)
> return 1;
> }
>
> +struct bpf_ringbuf {
> + unsigned long consumer_pos;
> + unsigned long producer_pos;
> +} __attribute__((preserve_access_index));
> +
> struct bpf_ringbuf_map {
> struct bpf_map map;
> + struct bpf_ringbuf *rb;
> } __attribute__((preserve_access_index));
>
> struct {
> __uint(type, BPF_MAP_TYPE_RINGBUF);
> + __uint(max_entries, 1 << 10);
do you need to set max_entries? there's already check below
making sure it's 4096
jirka
> } m_ringbuf SEC(".maps");
>
> static inline int check_ringbuf(void)
> {
> struct bpf_ringbuf_map *ringbuf = (struct bpf_ringbuf_map *)&m_ringbuf;
> struct bpf_map *map = (struct bpf_map *)&m_ringbuf;
> + struct bpf_ringbuf *rb;
> + void *ptr;
>
> VERIFY(check(&ringbuf->map, map, 0, 0, page_size));
>
> + ptr = bpf_ringbuf_reserve(&m_ringbuf, 128, 0);
> + VERIFY(ptr);
> +
> + bpf_ringbuf_discard(ptr, 0);
> + rb = ringbuf->rb;
> + VERIFY(rb);
> + VERIFY(rb->consumer_pos == 0);
> + VERIFY(rb->producer_pos == 128 + 8);
> +
> return 1;
> }
>
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-03-20 12:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 8:41 [PATCH bpf-next] selftests/bpf: test access to ringbuf position with map pointer Menglong Dong
2026-03-20 12:40 ` Jiri Olsa [this message]
2026-03-21 7:37 ` Menglong Dong
2026-03-22 1:51 ` Emil Tsalapatis
2026-03-23 2:06 ` Menglong Dong
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=ab1AUyefoWABRs0T@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=menglong8.dong@gmail.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--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