Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Menglong Dong and committed by
Andrii Nakryiko
3e6475dc f9a80c7c

+17
+17
tools/testing/selftests/bpf/progs/map_ptr_kern.c
··· 647 647 return 1; 648 648 } 649 649 650 + struct bpf_ringbuf { 651 + unsigned long consumer_pos; 652 + unsigned long producer_pos; 653 + } __attribute__((preserve_access_index)); 654 + 650 655 struct bpf_ringbuf_map { 651 656 struct bpf_map map; 657 + struct bpf_ringbuf *rb; 652 658 } __attribute__((preserve_access_index)); 653 659 654 660 struct { ··· 665 659 { 666 660 struct bpf_ringbuf_map *ringbuf = (struct bpf_ringbuf_map *)&m_ringbuf; 667 661 struct bpf_map *map = (struct bpf_map *)&m_ringbuf; 662 + struct bpf_ringbuf *rb; 663 + void *ptr; 668 664 669 665 VERIFY(check(&ringbuf->map, map, 0, 0, page_size)); 666 + 667 + ptr = bpf_ringbuf_reserve(&m_ringbuf, 128, 0); 668 + VERIFY(ptr); 669 + 670 + bpf_ringbuf_discard(ptr, 0); 671 + rb = ringbuf->rb; 672 + VERIFY(rb); 673 + VERIFY(rb->consumer_pos == 0); 674 + VERIFY(rb->producer_pos == 128 + BPF_RINGBUF_HDR_SZ); 670 675 671 676 return 1; 672 677 }