summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMenglong Dong <menglong8.dong@gmail.com>2026-03-31 10:04:34 +0300
committerAndrii Nakryiko <andrii@kernel.org>2026-04-01 01:47:14 +0300
commit3e6475dc60853456e1aca2b85bd6603eadb3f6a1 (patch)
treeaa1e56a96df02431d1ffae47f6737b42029b5a51
parentf9a80c7ce49e2a77b769264712fe2f59479b5f5a (diff)
downloadlinux-3e6475dc60853456e1aca2b85bd6603eadb3f6a1.tar.xz
selftests/bpf: Test access to ringbuf position with map pointer
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 + 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> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Leon Hwang <leon.hwang@linux.dev> Link: https://lore.kernel.org/bpf/20260331070434.10037-1-dongml2@chinatelecom.cn
-rw-r--r--tools/testing/selftests/bpf/progs/map_ptr_kern.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
index efaf622c28dd..373c8d17ea55 100644
--- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c
+++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
@@ -647,8 +647,14 @@ 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 {
@@ -659,9 +665,20 @@ 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 + BPF_RINGBUF_HDR_SZ);
+
return 1;
}