From: Tamir Duberstein <tamird@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
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>,
Shuah Khan <shuah@kernel.org>, Andrea Righi <arighi@nvidia.com>,
Xu Kuohai <xukuohai@huawei.com>,
Andrea Righi <andrea.righi@canonical.com>,
Bing-Jhong Billy Jheng <billy@starlabs.sg>,
David Vernet <void@manifault.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Andrew Werner <awerner32@gmail.com>,
Zvi Effron <zeffron@riotgames.com>,
Andrii Nakryiko <andriin@fb.com>,
Tamir Duberstein <tamird@kernel.org>
Subject: [PATCH bpf-next v3 7/8] selftests/bpf: Verify ringbuf callback semantics
Date: Fri, 20 Nov 2026 15:33:20 -0500 [thread overview]
Message-ID: <20261120-bpf-ringbuf-fixes-v3-7-ff7ca15d6c37@kernel.org> (raw)
In-Reply-To: <20261120-bpf-ringbuf-fixes-v3-0-ff7ca15d6c37@kernel.org>
Callback consumption ignores positive return values and publishes each
record's consumer position before invoking the next callback. Both
behaviors must survive changes to the consumption core.
Record these behaviors in ringbuf_n. Use an explicitly padded userspace
sample and a fixed-width BPF global value to match the BPF target's
64-bit layout on 32-bit systems.
Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
tools/testing/selftests/bpf/prog_tests/ringbuf.c | 34 +++++++++++++++++++---
tools/testing/selftests/bpf/progs/test_ringbuf_n.c | 2 +-
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index 633e10aa5537..cfc357dfd1e9 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -469,13 +469,35 @@ static void ringbuf_subtest(void)
/* Sample value to verify the callback validity */
#define SAMPLE_VALUE 42L
+/* Match the BPF target's 64-bit long and padding. */
+struct sample_n {
+ int pid;
+ int pad;
+ __s64 value;
+ char comm[16];
+};
+
+struct process_n_ctx {
+ struct ring *ring;
+ unsigned long consumer_pos;
+ int callback_count;
+};
+
static int process_n_sample(void *ctx, void *data, size_t len)
{
- struct sample *s = data;
+ struct process_n_ctx *callback_ctx = ctx;
+ struct sample_n *s = data;
+ unsigned long consumer_pos;
ASSERT_EQ(s->value, SAMPLE_VALUE, "sample_value");
-
- return 0;
+ consumer_pos = ring__consumer_pos(callback_ctx->ring);
+ if (callback_ctx->callback_count)
+ ASSERT_GT(consumer_pos, callback_ctx->consumer_pos,
+ "callback_consumer_pos");
+ callback_ctx->consumer_pos = consumer_pos;
+ callback_ctx->callback_count++;
+
+ return 1;
}
static int process_noop_sample(void *ctx, void *data, size_t len)
@@ -672,8 +694,9 @@ static void ringbuf_n_subtest(void)
if (!ASSERT_OK(err, "test_ringbuf_n_lskel__load"))
return;
+ struct process_n_ctx callback_ctx = {};
ringbuf = ring_buffer__new(skel_n->maps.ringbuf.map_fd,
- process_n_sample, NULL, NULL);
+ process_n_sample, &callback_ctx, NULL);
if (!ASSERT_OK_PTR(ringbuf, "ring_buffer__new"))
return;
@@ -690,6 +713,7 @@ static void ringbuf_n_subtest(void)
if (!ASSERT_OK_PTR(ring, "ring_buffer__ring"))
return;
+ callback_ctx.ring = ring;
err = ring_buffer__consume_n(ringbuf, 0);
if (!ASSERT_EQ(err, 0, "ringbuf_consume_zero"))
@@ -705,6 +729,8 @@ static void ringbuf_n_subtest(void)
if (!ASSERT_EQ(err, N_SAMPLES, "rb_consume"))
return;
}
+ ASSERT_EQ(callback_ctx.callback_count, N_TOT_SAMPLES,
+ "positive_callback");
}
static int process_map_key_sample(void *ctx, void *data, size_t len)
diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf_n.c b/tools/testing/selftests/bpf/progs/test_ringbuf_n.c
index 8669eb42dbe0..a95d4f597175 100644
--- a/tools/testing/selftests/bpf/progs/test_ringbuf_n.c
+++ b/tools/testing/selftests/bpf/progs/test_ringbuf_n.c
@@ -22,7 +22,7 @@ struct {
} ringbuf SEC(".maps");
int pid = 0;
-long value = 0;
+__s64 value = 0;
SEC("fentry/" SYS_PREFIX "sys_getpgid")
int test_ringbuf_n(void *ctx)
--
2.56.1
next prev parent reply other threads:[~2026-11-20 20:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 20:33 [PATCH bpf-next v3 0/8] bpf: Fix ring buffers and add a libbpf iterator Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 1/8] bpf: user_ringbuf: Handle position wrap Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 2/8] libbpf: ringbuf: Use compiler atomics Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 3/8] libbpf: ringbuf: Prevent missed wakeups Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 4/8] libbpf: ringbuf: Add a caller-owned iterator Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 5/8] libbpf: ringbuf: Simplify iterator implementation Tamir Duberstein
2026-11-20 20:33 ` [PATCH bpf-next v3 6/8] selftests/bpf: Refactor lifetimes and test wakeups Tamir Duberstein
2026-11-20 20:33 ` Tamir Duberstein [this message]
2026-11-20 20:33 ` [PATCH bpf-next v3 8/8] selftests/bpf: Test caller-owned ring iterators Tamir Duberstein
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=20261120-bpf-ringbuf-fixes-v3-7-ff7ca15d6c37@kernel.org \
--to=tamird@kernel.org \
--cc=andrea.righi@canonical.com \
--cc=andrii@kernel.org \
--cc=andriin@fb.com \
--cc=arighi@nvidia.com \
--cc=ast@kernel.org \
--cc=awerner32@gmail.com \
--cc=billy@starlabs.sg \
--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-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=void@manifault.com \
--cc=xukuohai@huawei.com \
--cc=yonghong.song@linux.dev \
--cc=zeffron@riotgames.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
all inboxes | Powered by JetHome®