Re: How to load BTF style maps?

Toke Høiland-Jørgensen <[email protected]>
Newsgroups org.kernel.vger.xdp-newbies
Message-ID <[email protected]>
Elerion <[email protected]> writes:

> I have maps written in the old style like this:
>
> struct bpf_map_def SEC("maps") xdp_stats_map = {
> .type        = BPF_MAP_TYPE_ARRAY,
> .key_size    = sizeof(__u32),
> .value_size  = sizeof(struct datarec),
> .max_entries = XDP_ACTION_MAX,
> };
>
> I changed it to the new BTF style like this but now the example BPF
> loader from the kernel doesn't work anymore.
>
> struct {
>     __uint(type, BPF_MAP_TYPE_ARRAY);
>     __uint(max_entries,  XDP_ACTION_MAX);
>     __type(key,  __u32);
>     __type(value,  struct datarec);
> }  xdp_stats_map SEC(".maps");
>
> I used this to load my program
> https://github.com/torvalds/linux/blob/master/samples/bpf/bpf_load.c
>
> But now it fails to load. First thing I noticed was the I had to
> change "maps" to ".maps"
> https://github.com/torvalds/linux/blob/master/samples/bpf/bpf_load.c#L563
>
> But then bpf_create_map_node fails because all the arguments are 0. I
> dumped the buffer here
> https://github.com/torvalds/linux/blob/master/samples/bpf/bpf_load.c#L489
> and it just copies 28 bytes of zeroes for each map I have.
>
> How do you load BTF style maps? bpf_load.c doesn't seem to work on them.

Hmm, bpf_load.c seems to be using old-style loading (not libbpf) and so
wouldn't understand BTF-defined maps. I guess we should fix that.

In the meantime, you can try one of the following options:

Use xdp-loader from xdp-tools (since this seems to be an XDP use case?):
https://github.com/xdp-project/xdp-tools

Use bpftool (in tools/bpf/bpftool in the kernel source tree).

-Toke
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.