4

Before I present my matter; I have read this Map sharing between different ebpf program types previously asked question which does not seem to answer my question.

Now, what I am doing is, I have two BPF programs, one for XDP and other for TC (No Userspace program). I have created the map in TC program and pinned it to global namespace

struct bpf_elf_map cnt_map __section("maps") = {
    .type           = BPF_MAP_TYPE_ARRAY,
    .size_key       = sizeof(uint32_t),
    .size_value     = sizeof(uint32_t),
    .pinning        = PIN_GLOBAL_NS,
    .max_elem       = 2,
};

Now, I want to access the same map in my XDP code. The document says that the pinned object can be obtained using BPF_OBJ_GET, but what all I could find is the userspace version of this.

So, I need to know, how can two kernel space BPF programs can share a map? If it's possible with BPF_OBJ_GET to get the pinned object (in my case it's a map), then how? Or is there any other way of doing it?

A code example of how to access the pinned object in other kernel space BPF program is really appreciated since I am new to XDP/BPF or tc/BPF.

Thanks.

Zarrar
  • 63
  • 3
  • Have you verified that the map is truly pinned? Do you see it in `/sys/fs/bpf/` somewhere? – wxz Aug 17 '21 at 20:12
  • 1
    Solved offline - issues were wrong command lines for compiling and loading the program. – Qeole Aug 18 '21 at 12:21
  • The second part still remains....That is how to retrieve the file descriptor (in another kernel space bpf program) of the pinned object (from one kernel space bpf program). – Zarrar Aug 19 '21 at 05:38
  • If the definition and name of the map are the same for your XDP program than for your TC program, I think `ip link` is able to handle this for you and to reuse the existing map, but I'm not 100% sure. If it's not, you can alternatively load and attach your XDP program with `bpftool`, which does support reusing the map (`bpftool prog load ... map name pinned /sys/fs/bpf/foo ...`, then `bpftool net attach ...`). See [doc](https://www.mankier.com/package/bpftool). – Qeole Aug 19 '21 at 08:55

0 Answers0