Re: BPF arena atomic example not working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Aug 4, 2024 at 1:40 PM Jose Fernandez <jose.fernandez@xxxxxxxxx> wrote:
>
> On 24/08/04 09:59AM, Jose Fernandez wrote:
> > Hi folks,
> >
> > I have not found BPF arena documentation, beyond the patches and selftests.
> > I'm using the arena_atomics selftest as reference to create a simple BPF program
> > that increments a value atomically.
> >
> > bpf: https://github.com/jfernandez/bpf-playground/blob/main/arena.bpf.c
> > userspace: https://github.com/jfernandez/bpf-playground/blob/main/arena.c
> > common header: https://github.com/jfernandez/bpf-playground/blob/main/bpf_arena_common.h
> >
> > I'm using the 6.10.2 kernel and libbpf 1.4.3.
>
> I forgot to mention that I was using the latest clang release (18.1.8), and this
> turned out to be the issue. The arena bpf program loaded after I used clang
> compiled from the llvm-project master branch.
>
> I now realise that __BPF_FEATURE_ADDR_SPACE_CAST flag is only available starting
> with the 19.1.0 RC:
>
> $ git --no-pager tag --contains 65b123e287d1320170bb3317179bc917f21852fa
> llvmorg-19.1.0-rc1
> llvmorg-20-init


That is correct and sorry about this footgun in bpf_arena_common.h.
The cast_kern() and cast_user() macros were added there only for
selftests to make sure the kernel part of arena is tested when llvm is
older than 19 which is likely the case for many bpf developers.
The cast_kern/user() are obviously unnecessary with llvm 19+.

I think we need to create a common directory/repo somewhere
with ready-to-be-consumed .h and .c with various algorithms based on arena.
So people don't repeat your debugging experience.
For example I've copy pasted glob_match() from kernel to bpf prog and
it works:
https://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf.git/commit/?h=arena&id=7fd6f96cc80ac8e1ba2838bb1570dd4aed81c567
More such examples/samples are needed to realize the power of arena.





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux