From: Daniel Borkmann <daniel@iogearbox.net>
To: Joe Stringer <joe@ovn.org>
Cc: netdev <netdev@vger.kernel.org>, wangnan0@huawei.com, ast@fb.com
Subject: Re: [PATCH net-next 3/3] tools lib bpf: Sync bpf_map_def with tc
Date: Wed, 02 Nov 2016 15:12:49 +0100 [thread overview]
Message-ID: <5819F461.7050309@iogearbox.net> (raw)
In-Reply-To: <CAPWQB7GxA+imikeJEJ-JZVm+qWONM1Ronj7ucf0=QRBbrPM06g@mail.gmail.com>
On 11/02/2016 05:09 AM, Joe Stringer wrote:
> On 1 November 2016 at 20:09, Daniel Borkmann <daniel@iogearbox.net> wrote:
>> On 10/31/2016 07:39 PM, Joe Stringer wrote:
>>>
>>> TC uses a slightly different map layout in its ELFs. Update libbpf to
>>> use the same definition so that ELFs may be built using libbpf and
>>> loaded using tc.
>>>
>>> Signed-off-by: Joe Stringer <joe@ovn.org>
>>> ---
>>> tools/lib/bpf/libbpf.h | 11 +++++++----
>>> 1 file changed, 7 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
>>> index dd7a513efb10..ea70c2744f8c 100644
>>> --- a/tools/lib/bpf/libbpf.h
>>> +++ b/tools/lib/bpf/libbpf.h
>>> @@ -181,10 +181,13 @@ bool bpf_program__is_kprobe(struct bpf_program
>>> *prog);
>>> * and will be treated as an error due to -Werror.
>>> */
>>> struct bpf_map_def {
>>> - unsigned int type;
>>> - unsigned int key_size;
>>> - unsigned int value_size;
>>> - unsigned int max_entries;
>>> + uint32_t type;
>>> + uint32_t key_size;
>>> + uint32_t value_size;
>>> + uint32_t max_entries;
>>> + uint32_t flags;
>>> + uint32_t id;
>>> + uint32_t pinning;
>>> };
>>>
>>> /*
>>
>> I think the problem is that this would break existing obj files that have
>> been compiled with the current struct bpf_map_def (besides libbpf not having
>> a use for the last two members right now).
>
> Right, this is a problem. I wasn't sure whether libbpf was yet at a
> stage where it tries to retain compatibility with binaries compiled
> against older kernels.
>
>> For tc, we have a refactoring of the tc_bpf.c bits that generalizes them so
>> we can move these bits into iproute2 lib part and add new BPF types really
>> easily. What I did along with that is to implement a map compat mode, where
>> it detects the size of struct bpf_elf_map (or however you want to name it)
>> from the obj file and fixes up the missing members with some reasonable
>> default,
>> so these programs can still be loaded. Thus, the sample code using the
>> current
>> struct bpf_map_def will then work with tc as well. (I'll post the iproute2
>> patch early next week.)
>
> Are you encoding the number of maps into the start of the maps section
> in the ELF then using that to divide out and determine the size?
No. It's walking the symbol table and simply counts the number of symbols
that are present in the maps section with correct st_info attribution. It
works because that section name is fixed ABI for all cases and really per
definition only map structs are present there. The minimum attributes which
are allowed to be loaded are type, key_size, value_size and max_entries.
> I look forward to your patches. Maybe if TC is more tolerant of other
> map definition sizes then this patch is less relevant.
next prev parent reply other threads:[~2016-11-02 14:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-31 18:39 [PATCH net-next 0/3] tools lib bpf: Synchronize implementations Joe Stringer
2016-10-31 18:39 ` [PATCH net-next 1/3] tools lib bpf: Sync {tools,}/include/uapi/linux/bpf.h Joe Stringer
2016-10-31 18:39 ` [PATCH net-next 2/3] tools lib bpf: Sync with samples/bpf/libbpf Joe Stringer
2016-11-02 2:52 ` Daniel Borkmann
2016-11-02 3:50 ` Joe Stringer
2016-10-31 18:39 ` [PATCH net-next 3/3] tools lib bpf: Sync bpf_map_def with tc Joe Stringer
2016-11-02 3:09 ` Daniel Borkmann
2016-11-02 4:09 ` Joe Stringer
2016-11-02 14:12 ` Daniel Borkmann [this message]
2016-11-02 15:08 ` Daniel Borkmann
2016-11-01 15:48 ` [PATCH net-next 0/3] tools lib bpf: Synchronize implementations David Miller
2016-11-01 20:51 ` David Ahern
2016-11-01 22:17 ` Joe Stringer
2016-11-02 2:46 ` Daniel Borkmann
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=5819F461.7050309@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=ast@fb.com \
--cc=joe@ovn.org \
--cc=netdev@vger.kernel.org \
--cc=wangnan0@huawei.com \
/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 NNTP newsgroup(s).