* How to load BTF style maps?
@ 2020-06-10 9:21 Elerion
2020-06-10 9:32 ` Toke Høiland-Jørgensen
0 siblings, 1 reply; 2+ messages in thread
From: Elerion @ 2020-06-10 9:21 UTC (permalink / raw)
To: xdp-newbies
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How to load BTF style maps?
2020-06-10 9:21 How to load BTF style maps? Elerion
@ 2020-06-10 9:32 ` Toke Høiland-Jørgensen
0 siblings, 0 replies; 2+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-06-10 9:32 UTC (permalink / raw)
To: Elerion, xdp-newbies
Elerion <elerion1000@gmail.com> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-10 9:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-10 9:21 How to load BTF style maps? Elerion
2020-06-10 9:32 ` Toke Høiland-Jørgensen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.