From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Elerion <elerion1000@gmail.com>, xdp-newbies@vger.kernel.org
Subject: Re: How to load BTF style maps?
Date: Wed, 10 Jun 2020 11:32:18 +0200 [thread overview]
Message-ID: <87ftb38dwd.fsf@toke.dk> (raw)
In-Reply-To: <CAMDScm=VZJMZYN=SXo9OAshY=yYxwtavLDgTvu1qEasg77JyLw@mail.gmail.com>
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
prev parent reply other threads:[~2020-06-10 9:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-10 9:21 How to load BTF style maps? Elerion
2020-06-10 9:32 ` Toke Høiland-Jørgensen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ftb38dwd.fsf@toke.dk \
--to=toke@redhat.com \
--cc=elerion1000@gmail.com \
--cc=xdp-newbies@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).