Re: Reading Pinned maps in eBPF Programs

Andrii Nakryiko

On Mon, Aug 17, 2020 at 6:36 AM Ian <> wrote:

You can use bpf_obj_get() API to get a reference to the pinned map.

It was my understanding that bpf_obj_get was intended to be used as a user space API. I am looking to "open" or obtain a reference to a map in the actual eBPF program that is loaded into the kernel space. My eBPF programs do include linux/bpf.h but not the uapi bpf.h. Can/should you use it in the actual BPF program? Or is there an a different way to achieve this?
Libbpf supports declarative pinning of maps, that's how you easily get
"map re-use" from BPF side. See [0] for example.

But there is also bpf_map__pin() and bpf_map__reuse_fd() API on
user-space side to set everything up, if you need to do it more


I have seen a function called bpf_obj_get_user in linux/bpf.h but I cannot find any documentation on it. It also just returns an unsupported error in my kernel's source code.

static inline int bpf_obj_get_user(const char __user *pathname, int flags)




BPF_ANNOTATE_KV_PAIR is old way to provide map key/value types, mostly
for pretty print. bcc still uses it. libbpf can use more advanced
mechanisms with direct .maps section attribute.s

Ahh interesting!

Join to automatically receive all group messages.